MessageHandler.c 573 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851
  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 "hashmap.h"
  21. #include "ShareMemory.h"
  22. #include "TransactionQueue.h"
  23. #include "define.h"
  24. #include "SystemLogMessage.h"
  25. //#include "config.h"
  26. #include <sys/socket.h>
  27. #include <netinet/in.h>
  28. #include <stdlib.h>
  29. /*for sendfile()*/
  30. #include <sys/sendfile.h>
  31. /*for O_RDONLY*/
  32. #include <fcntl.h>
  33. #include "sqlite3.h"
  34. #include <arpa/inet.h>
  35. //#define _GNU_SOURCE
  36. #include <time.h>
  37. #include "MessageHandler.h"
  38. #include <assert.h>
  39. #include <pthread.h>
  40. #include <mcheck.h>
  41. #define PASS 1
  42. #define FAIL -1
  43. #define FALSE 0
  44. #define TRUE 1 // Option 1
  45. //ChargePointMaxProfile
  46. #define ChargePointMaxProfile_JSON "../Storage/OCPP/ChargePointMaxProfile.json"
  47. //TxDefaultProfile
  48. #define TxDefaultProfile_0_JSON "../Storage/OCPP/TxDefaultProfile_0.json"
  49. #define TxDefaultProfile_1_JSON "../Storage/OCPP/TxDefaultProfile_1.json"
  50. #define TxDefaultProfile_2_JSON "../Storage/OCPP/TxDefaultProfile_2.json"
  51. //TxProfile
  52. #define TxProfile_1_JSON "../Storage/OCPP/TxProfile_1.json"
  53. #define TxProfile_2_JSON "../Storage/OCPP/TxProfile_2.json"
  54. #define ChargingProfile_0_JSON "../Storage/OCPP/chargingprofile_0.json"
  55. #define ChargingProfile_1_JSON "../Storage/OCPP/chargingprofile_1.json"
  56. #define ChargingProfile_2_JSON "../Storage/OCPP/chargingprofile_2.json"
  57. #define AuthorizationCache_JSON "../Storage/OCPP/AuthorizationCache.json"
  58. #define LocalAuthorizationList_JSON "../Storage/OCPP/LocalAuthorizationList.json"
  59. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  60. struct StatusCodeData *ShmStatusCodeData;
  61. struct PsuData *ShmPsuData ;
  62. struct OCPP16Data *ShmOCPP16Data;
  63. // define Macro
  64. #define SystemLogMessage
  65. // OCPP Message Type
  66. #define MESSAGE_TYPE_CALL 2
  67. #define MESSAGE_TYPE_CALLRESULT 3
  68. #define MESSAGE_TYPE_CALLERROR 4
  69. //
  70. #define server_cycle_Status 120
  71. #define MACROSTR(k) #k
  72. //ConfigurationMaxKeys
  73. #define GetConfigurationMaxKeysNUM 43
  74. //char guid[37];
  75. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  76. char queuedata[2600]={0};
  77. //===============================
  78. // Configuration: unknownkey
  79. //===============================
  80. static char unknownkey[10][20]={0};
  81. static int UnknownKeynum = 0;
  82. //===============================
  83. // Gun Total Numbers
  84. //===============================
  85. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  86. static int gunTotalNumber=0;
  87. //===============================
  88. // Local List Version
  89. //===============================
  90. static int localversion=0;
  91. static char idTagAuthorization[32]={0};
  92. //===============================
  93. // OCPP Path
  94. //===============================
  95. extern char OcppPath[160];
  96. extern char OcppProtocol[10];
  97. extern char OcppHost[50];
  98. extern char OcppTempPath[50];
  99. int OcppPort=0;
  100. //===============================
  101. // OCPP sign variable
  102. //===============================
  103. int server_sign = FALSE;
  104. int server_pending = FALSE;
  105. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  106. int BootNotificationInterval = 0;
  107. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  108. //===============================
  109. // OCPP auth variable
  110. //===============================
  111. int authenrequest = FALSE;
  112. int authorizeRetryTimes = 0; //number of Retry times
  113. //===============================
  114. // OCPP StartTransaction transactionId variables
  115. //===============================
  116. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  117. //===============================
  118. // OCPP other variables
  119. //===============================
  120. int isUpdateRequest = FALSE;
  121. static int HeartBeatWaitTime = 10;
  122. static int FirstHeartBeat = 0;
  123. static int FirmwareStatusNotificationStatus = 3; // Idle
  124. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  125. static char CurrentChargingProfileScheduleStr[30]={0};
  126. //========================================
  127. // OCPP status/previous related variables
  128. //========================================
  129. static int GunStatusInterval = 10;
  130. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  131. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  132. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  133. static int GbPreviousSystemStatus[GB_QUANTITY];
  134. static int AcPreviousSystemStatus[AC_QUANTITY];
  135. int TransactionMessageAttemptsValue = 0;
  136. int TransactionMessageRetryIntervalValue = 0;
  137. static struct OCPPAuthLocalElemet
  138. {
  139. int listVersionInt;
  140. char idTagstr[20];
  141. char parentIdTag[20];
  142. char expiryDate[30];
  143. char idTagstatus[16];
  144. }idTagQuery;
  145. //=============================================
  146. // OCPP HeartBeat Response Not Receive Counts
  147. //============================================
  148. static int HeartBeatWithNOResponse = 0;
  149. static int HeartBeatCount = 0;
  150. extern struct lws *wsi_client;
  151. extern struct lws_context *context;
  152. extern unsigned char SendBuffer[4096];
  153. extern int SendBufLen;
  154. extern char *random_uuid( char buf[37] );
  155. extern void split(char **arr, char *str, const char *del);
  156. extern pthread_mutex_t mutex1;
  157. extern struct Charger_Info Charger;
  158. extern sqlite3 *db;
  159. int TransactionMessageAttemptsGet(void);
  160. int TransactionMessageRetryIntervalGet(void);
  161. int GetOcppConnStatus(void);
  162. void SetOcppConnStatus(uint8_t status);
  163. int updateSetting(char *key, char *value);
  164. int setKeyValue(char *key, char *value);
  165. void OCPP_get_TableAuthlocalAllData(void);
  166. void processUnkownKey(void);
  167. struct StructOCPPMeterValue
  168. {
  169. unsigned char TimeStamp[28];
  170. struct StructSampledValue SampledValue[10];
  171. };
  172. struct ClientTime
  173. {
  174. unsigned int Heartbeat;
  175. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  176. unsigned int StartTransaction;
  177. unsigned int StopTransaction;
  178. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  179. }clientTime;
  180. typedef union
  181. {
  182. //Operations Initiated by Central System
  183. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  184. struct
  185. {
  186. //CsMsgValue[0]
  187. unsigned char StatusNotificationReq :1; //bit 0,
  188. unsigned char StatusNotificationConf :1; //bit 0,
  189. unsigned char :6; //bit 2~7
  190. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  191. }CpinitiateMsg;
  192. CpinitiateMsg cpinitateMsg;
  193. //==========================================
  194. // Init all Enumeration & Mapping String
  195. //==========================================
  196. /*ChargePointErrorCode*/
  197. typedef enum {
  198. ConnectorLockFailure,
  199. EVCommunicationError,
  200. GroundFailure,
  201. HighTemperature,
  202. InternalError,
  203. LocalListConflict,
  204. NoError,
  205. OtherError,
  206. OverCurrentFailure,
  207. OverVoltage,
  208. PowerMeterFailure,
  209. PowerSwitchFailure,
  210. ReaderFailure,
  211. ResetFailure,
  212. UnderVoltage,
  213. WeakSignal
  214. } ChargePointErrorCode;
  215. #if 0
  216. static char *ChargePointErrorCodeStr[] = {
  217. MACROSTR(ConnectorLockFailure),
  218. MACROSTR(EVCommunicationError),
  219. MACROSTR(GroundFailure),
  220. MACROSTR(HighTemperature),
  221. MACROSTR(InternalError),
  222. MACROSTR(LocalListConflict),
  223. MACROSTR(NoError),
  224. MACROSTR(OtherError),
  225. MACROSTR(OverCurrentFailure),
  226. MACROSTR(OverVoltage),
  227. MACROSTR(PowerMeterFailure),
  228. MACROSTR(PowerSwitchFailure),
  229. MACROSTR(ReaderFailure),
  230. MACROSTR(ResetFailure),
  231. MACROSTR(UnderVoltage),
  232. MACROSTR(WeakSignal)
  233. };
  234. #endif
  235. /*ChargePointStatus*/
  236. typedef enum {
  237. Available =0,
  238. Preparing,
  239. Charging,
  240. SuspendedEVSE,
  241. SuspendedEV,
  242. Finishing,
  243. Reserved,
  244. Unavailable,
  245. Faulted
  246. } ChargePointStatus;
  247. static char * ChargePointStatusStr[] = {
  248. MACROSTR(Available),
  249. MACROSTR(Preparing),
  250. MACROSTR(Charging),
  251. MACROSTR(SuspendedEVSE),
  252. MACROSTR(SuspendedEV),
  253. MACROSTR(Finishing),
  254. MACROSTR(Reserved),
  255. MACROSTR(Unavailable),
  256. MACROSTR(Faulted)
  257. };
  258. /*AvailabilityType*/
  259. typedef enum {
  260. RegistrationStatus_Accepted,
  261. RegistrationStatus_Pending,
  262. RegistrationStatus_Rejected
  263. } RegistrationStatus;
  264. static char *RegistrationStatusStr[] = {
  265. MACROSTR(Accepted),
  266. MACROSTR(Pending),
  267. MACROSTR(Rejected)
  268. };
  269. /*AvailabilityType*/
  270. typedef enum {
  271. Inoperative,
  272. Operative
  273. } AvailabilityType;
  274. static char *AvailabilityTypeStr[] = {
  275. MACROSTR(Inoperative),
  276. MACROSTR(Operative)
  277. };
  278. /*AvailabilityStatus*/
  279. typedef enum {
  280. Accepted,
  281. Rejected,
  282. Scheduled
  283. } AvailabilityStatus;
  284. static char *AvailabilityStatusStr[] = {
  285. MACROSTR(Accepted),
  286. MACROSTR(Rejected),
  287. MACROSTR(Scheduled)
  288. };
  289. /*ConfigurationStatus*/
  290. typedef enum {
  291. ConfigurationStatus_Accepted,
  292. ConfigurationStatus_Rejected,
  293. RebootRequired,
  294. NotSupported
  295. } ConfigurationStatus;
  296. static char *ConfigurationStatusStr[] = {
  297. MACROSTR(Accepted),
  298. MACROSTR(Rejected),
  299. MACROSTR(RebootRequired),
  300. MACROSTR(NotSupported)
  301. };
  302. /*ClearCacheStatus*/
  303. typedef enum {
  304. ClearCacheStatus_Accepted,
  305. ClearCacheStatus_Rejected
  306. } ClearCacheStatus;
  307. static char *ClearCacheStatusStr[] = {
  308. MACROSTR(Accepted),
  309. MACROSTR(Rejected)
  310. };
  311. /*ChargingProfilePurposeType*/
  312. typedef enum {
  313. ChargePointMaxProfile,
  314. TxDefaultProfile,
  315. TxProfile
  316. } ChargingProfilePurposeType;
  317. static char *ChargingProfilePurposeTypeStr[] = {
  318. MACROSTR(ChargePointMaxProfile),
  319. MACROSTR(TxDefaultProfile),
  320. MACROSTR(TxProfile)
  321. };
  322. /*ChargingProfileStatus*/
  323. typedef enum {
  324. ChargingProfileStatus_Accepted,
  325. ChargingProfileStatus_Rejected,
  326. ChargingProfileStatus_NotSupported
  327. } ChargingProfileStatus;
  328. static char *ChargingProfileStatusStr[] = {
  329. MACROSTR(Accepted),
  330. MACROSTR(Rejected),
  331. MACROSTR(NotSupported)
  332. };
  333. /*ClearChargingProfileStatus*/
  334. typedef enum {
  335. ClearChargingProfileStatus_Accepted,
  336. ClearChargingProfileStatus_Unknown
  337. } ClearChargingProfileStatus;
  338. static char *ClearChargingProfileStatusStr[] = {
  339. MACROSTR(Accepted),
  340. MACROSTR(Unknown)
  341. };
  342. /*GetCompositeScheduleStatus*/
  343. typedef enum {
  344. GetCompositeScheduleStatus_Accepted,
  345. GetCompositeScheduleStatus_Rejected
  346. } GetCompositeScheduleStatus;
  347. static char *GetCompositeScheduleStatusStr[] = {
  348. MACROSTR(Accepted),
  349. MACROSTR(Rejected)
  350. };
  351. /*ChargingRateUnitType*/
  352. typedef enum {
  353. ChargingRateUnitType_W,
  354. ChargingRateUnitType_A
  355. } ChargingRateUnitType;
  356. /*AuthorizationStatus*/
  357. typedef enum {
  358. AuthorizationStatus_Accepted ,
  359. AuthorizationStatus_Blocked ,
  360. AuthorizationStatus_Expired ,
  361. AuthorizationStatus_Invalid ,
  362. AuthorizationStatus_ConcurrentTx
  363. } AuthorizationStatus;
  364. /*UpdateType*/
  365. typedef enum {
  366. Differential ,
  367. Full
  368. } UpdateType;
  369. static char *UpdateTypeStr[] = {
  370. MACROSTR(Differential),
  371. MACROSTR(Full)
  372. };
  373. /*UpdateStatus*/
  374. typedef enum {
  375. UpdateStatus_Accepted ,
  376. UpdateStatus_Failed ,
  377. UpdateStatus_NotSupported ,
  378. UpdateStatus_VersionMismatch
  379. } UpdateStatus;
  380. static char *UpdateStatusStr[] = {
  381. MACROSTR(Accepted),
  382. MACROSTR(Failed),
  383. MACROSTR(NotSupported),
  384. MACROSTR(VersionMismatch)
  385. };
  386. /*RemoteStartStopStatus*/
  387. typedef enum {
  388. RemoteStartStopStatus_Accepted,
  389. RemoteStartStopStatus_Rejected
  390. } RemoteStartStopStatus;
  391. static char *RemoteStartStopStatusStr[] = {
  392. MACROSTR(Accepted),
  393. MACROSTR(Rejected)
  394. };
  395. /*ReservationStatus*/
  396. typedef enum {
  397. ReservationStatus_Accepted,
  398. ReservationStatus_Faulted,
  399. ReservationStatus_Occupied,
  400. ReservationStatus_Rejected,
  401. ReservationStatus_Unavailable
  402. } ReservationStatus;
  403. static char *ReservationStatusStr[] = {
  404. MACROSTR(Accepted),
  405. MACROSTR(Faulted),
  406. MACROSTR(Occupied),
  407. MACROSTR(Rejected),
  408. MACROSTR(Unavailable)
  409. };
  410. /*ResetType*/
  411. typedef enum {
  412. Hard,
  413. Soft
  414. } ResetType;
  415. static char *ResetTypeStr[] = {
  416. MACROSTR(Hard),
  417. MACROSTR(Soft)
  418. };
  419. /*ResetStatus*/
  420. typedef enum {
  421. ResetStatus_Accepted,
  422. ResetStatus_Rejected
  423. } ResetStatus;
  424. static char *ResetStatusStr[] = {
  425. MACROSTR(Accepted),
  426. MACROSTR(Rejected)
  427. };
  428. /*DiagnosticsStatus*/
  429. typedef enum {
  430. DiagnosticsStatus_Idle,
  431. DiagnosticsStatus_Uploaded,
  432. DiagnosticsStatus_UploadFailed,
  433. DiagnosticsStatus_Uploading
  434. } DiagnosticsStatus;
  435. static char * DiagnosticsStatusStr[] = {
  436. MACROSTR(Idle),
  437. MACROSTR(Uploaded),
  438. MACROSTR(UploadFailed),
  439. MACROSTR(Uploading)
  440. };
  441. /*FirmwareStatus*/
  442. typedef enum {
  443. FirmwareStatus_Downloaded,
  444. FirmwareStatus_DownloadFailed,
  445. FirmwareStatus_Downloading,
  446. FirmwareStatus_Idle,
  447. FirmwareStatus_InstallationFailed,
  448. FirmwareStatus_Installing,
  449. FirmwareStatus_Installed
  450. } FirmwareStatus;
  451. static char * FirmwareStatusStr[] = {
  452. MACROSTR(Downloaded),
  453. MACROSTR(DownloadFailed),
  454. MACROSTR(Downloading),
  455. MACROSTR(Idle),
  456. MACROSTR(InstallationFailed),
  457. MACROSTR(Installing),
  458. MACROSTR(Installed)
  459. };
  460. /*MessageTrigger*/
  461. typedef enum {
  462. BootNotification,
  463. DiagnosticsStatusNotification,
  464. FirmwareStatusNotification,
  465. Heartbeat,
  466. MeterValues,
  467. StatusNotification
  468. } MessageTrigger;
  469. static char * MessageTriggerStr[] = {
  470. MACROSTR(BootNotification),
  471. MACROSTR(DiagnosticsStatusNotification),
  472. MACROSTR(FirmwareStatusNotification),
  473. MACROSTR(Heartbeat),
  474. MACROSTR(MeterValues),
  475. MACROSTR(StatusNotification)
  476. };
  477. /*TriggerMessageStatus*/
  478. typedef enum {
  479. TriggerMessageStatus_Accepted ,
  480. TriggerMessageStatus_Rejected ,
  481. TriggerMessageStatus_NotImplemented
  482. } TriggerMessageStatus;
  483. static char * TriggerMessageStatusStr[] = {
  484. MACROSTR(Accepted),
  485. MACROSTR(Rejected),
  486. MACROSTR(NotImplemented)
  487. };
  488. /*UnlockStatus*/
  489. typedef enum {
  490. Unlocked,
  491. UnlockFailed,
  492. UnlockStatus_NotSupported
  493. } UnlockStatus;
  494. static char * UnlockStatusStr[] = {
  495. MACROSTR(Unlocked),
  496. MACROSTR(UnlockFailed),
  497. MACROSTR(NotSupported)
  498. };
  499. /*StopTransactionReason*/
  500. typedef enum {
  501. EmergencyStop,
  502. EVDisconnected,
  503. HardReset,
  504. Local,
  505. Other,
  506. PowerLoss,
  507. Reboot,
  508. Remote,
  509. SoftReset,
  510. UnlockCommand,
  511. DeAuthorized
  512. } StopTransactionReason;
  513. #if 0
  514. static char * StopTransactionReasonStr[] = {
  515. MACROSTR(EmergencyStop),
  516. MACROSTR(EVDisconnected),
  517. MACROSTR(HardReset),
  518. MACROSTR(Local),
  519. MACROSTR(Other),
  520. MACROSTR(PowerLoss),
  521. MACROSTR(Reboot),
  522. MACROSTR(Remote),
  523. MACROSTR(SoftReset),
  524. MACROSTR(UnlockCommand),
  525. MACROSTR(DeAuthorized)
  526. };
  527. #endif
  528. /*CancelReservationStatus*/
  529. typedef enum {
  530. CancelReservationStatus_Accepted,
  531. CancelReservationStatus_Rejected
  532. } CancelReservationStatus;
  533. static char * CancelReservationStatusStr[] = {
  534. MACROSTR(Accepted),
  535. MACROSTR(Rejected)
  536. };
  537. /*ReadingContext*/
  538. typedef enum {
  539. ReadingContext_Interruption_Begin,
  540. ReadingContext_Interruption_End,
  541. ReadingContext_Other,
  542. ReadingContext_Sample_Clock,
  543. ReadingContext_Sample_Periodic ,
  544. ReadingContext_Transaction_Begin ,
  545. ReadingContext_Transaction_End,
  546. ReadingContext_Trigger
  547. } ReadingContext;
  548. static char * ReadingContextStr[] = {
  549. MACROSTR(Interruption.Begin),
  550. MACROSTR(Interruption.End),
  551. MACROSTR(Other),
  552. MACROSTR(Sample.Clock),
  553. MACROSTR(Sample.Periodic),
  554. MACROSTR(Transaction.Begin),
  555. MACROSTR(Transaction.End),
  556. MACROSTR(Trigger)
  557. };
  558. /*ValueFormat*/
  559. typedef enum {
  560. Raw,
  561. SignedData
  562. } ValueFormat;
  563. static char * ValueFormatStr[] = {
  564. MACROSTR(Raw),
  565. MACROSTR(SignedData)
  566. };
  567. /*Measurand*/
  568. typedef enum {
  569. Current_Export ,
  570. Current_Import,
  571. Current_Offered,
  572. Energy_Active_Export_Register,
  573. Energy_Active_Import_Register,
  574. Energy_Reactive_Export_Register,
  575. Energy_Reactive_Import_Register,
  576. Energy_Active_Export_Interval,
  577. Energy_Active_Import_Interval,
  578. Energy_Reactive_Export_Interval,
  579. Energy_Reactive_Import_Interval,
  580. Frequency,
  581. Power_Active_Export ,
  582. Power_Active_Import,
  583. Power_Factor,
  584. Power_Offered,
  585. Power_Reactive_Export,
  586. Power_Reactive_Import,
  587. RPM,
  588. SoC,
  589. Temperature ,
  590. Voltage
  591. } Measurand;
  592. static char * MeasurandStr[] = {
  593. MACROSTR(Current.Export),
  594. MACROSTR(Current.Import),
  595. MACROSTR(Current.Offered),
  596. MACROSTR(Energy.Active.Export.Register),
  597. MACROSTR(Energy.Active.Import.Register),
  598. MACROSTR(Energy.Reactive.Export.Register),
  599. MACROSTR(Energy.Reactive.Import.Register),
  600. MACROSTR(Energy.Active.Export.Interval),
  601. MACROSTR(Energy.Active.Import.Interval),
  602. MACROSTR(Energy.Reactive.Export.Interval),
  603. MACROSTR(Energy.Reactive.Import.Interval),
  604. MACROSTR(Frequency),
  605. MACROSTR(Power.Active.Export),
  606. MACROSTR(Power.Active.Import),
  607. MACROSTR(Power.Factor),
  608. MACROSTR(Power.Offered),
  609. MACROSTR(Power.Reactive.ExportMACROSTR),
  610. MACROSTR(Power.Reactive.Import),
  611. MACROSTR(RPM),
  612. MACROSTR(SoC),
  613. MACROSTR(Temperature),
  614. MACROSTR(Voltage)
  615. };
  616. /*Location*/
  617. typedef enum {
  618. Location_Body,
  619. Location_Cable,
  620. Location_EV,
  621. Location_Inlet ,
  622. Location_Outlet
  623. } Location;
  624. static char * LocationStr[] = {
  625. MACROSTR(Body),
  626. MACROSTR(Cable),
  627. MACROSTR(EV),
  628. MACROSTR(Inlet),
  629. MACROSTR(Outlet)
  630. };
  631. /*Phase*/
  632. typedef enum {
  633. L1,
  634. L2,
  635. L3,
  636. N,
  637. L1_N,
  638. L2_N,
  639. L3_N,
  640. L1_L2,
  641. L2_L3,
  642. L3_L1
  643. } Phase;
  644. static char * PhaseStr[] = {
  645. MACROSTR(L1),
  646. MACROSTR(L2),
  647. MACROSTR(L3),
  648. MACROSTR(N),
  649. MACROSTR(L1-N),
  650. MACROSTR(L2-N),
  651. MACROSTR(L3-N),
  652. MACROSTR(L1-L2),
  653. MACROSTR(L2-L3),
  654. MACROSTR(L3-L1)
  655. };
  656. /*UnitOfMeasure*/
  657. typedef enum {
  658. UnitOfMeasure_Wh,
  659. UnitOfMeasure_kWh ,
  660. UnitOfMeasure_varh ,
  661. UnitOfMeasure_kvarh ,
  662. UnitOfMeasure_W ,
  663. UnitOfMeasure_kW ,
  664. UnitOfMeasure_VA ,
  665. UnitOfMeasure_kVA ,
  666. UnitOfMeasure_var ,
  667. UnitOfMeasure_kvar ,
  668. UnitOfMeasure_A ,
  669. UnitOfMeasure_V ,
  670. UnitOfMeasure_Celsius ,
  671. UnitOfMeasure_Fahrenheit ,
  672. UnitOfMeasure_K ,
  673. UnitOfMeasure_Percent
  674. } UnitOfMeasure;
  675. static char * UnitOfMeasureStr[] = {
  676. MACROSTR(Wh),
  677. MACROSTR(kWh),
  678. MACROSTR(varh),
  679. MACROSTR(kvarh),
  680. MACROSTR(W),
  681. MACROSTR(kW),
  682. MACROSTR(VA),
  683. MACROSTR(kVA),
  684. MACROSTR(var),
  685. MACROSTR(kvar),
  686. MACROSTR(A),
  687. MACROSTR(V),
  688. MACROSTR(Celsius),
  689. MACROSTR(Fahrenheit),
  690. MACROSTR(K),
  691. MACROSTR(Percent)
  692. };
  693. #if 0
  694. /*Configuration enum*/
  695. enum CoreProfile {
  696. AllowOfflineTxForUnknownId=0,
  697. AuthorizationCacheEnabled,
  698. AuthorizeRemoteTxRequests,
  699. BlinkRepeat,
  700. ClockAlignedDataInterval,
  701. ConnectionTimeOut,
  702. GetConfigurationMaxKeys,
  703. HeartbeatInterval,
  704. LightIntensity,
  705. LocalAuthorizeOffline,
  706. LocalPreAuthorize,
  707. MaxEnergyOnInvalidId,
  708. MeterValuesAlignedData,
  709. MeterValuesAlignedDataMaxLength,
  710. MeterValuesSampledData,
  711. MeterValuesSampledDataMaxLength,
  712. MeterValueSampleInterval,
  713. MinimumStatusDuration,
  714. NumberOfConnectors,
  715. ResetRetries,
  716. ConnectorPhaseRotation,
  717. ConnectorPhaseRotationMaxLength,
  718. StopTransactionOnEVSideDisconnect,
  719. StopTransactionOnInvalidId,
  720. StopTxnAlignedData,
  721. StopTxnAlignedDataMaxLength,
  722. StopTxnSampledData,
  723. StopTxnSampledDataMaxLength,
  724. SupportedFeatureProfiles,
  725. SupportedFeatureProfilesMaxLength,
  726. TransactionMessageAttempts,
  727. TransactionMessageRetryInterval,
  728. UnlockConnectorOnEVSideDisconnect,
  729. WebSocketPingInterval,
  730. _CoreProfile_CNT
  731. };
  732. #endif
  733. enum LocalAuthListManagementProfile{
  734. LocalAuthListEnabled=0,
  735. LocalAuthListMaxLength,
  736. SendLocalListMaxLength,
  737. _LocalAuthListManagementProfile_CNT
  738. };
  739. enum ReservationProfile{
  740. ReserveConnectorZeroSupported
  741. };
  742. enum SmartChargingProfile{
  743. ChargeProfileMaxStackLevel,
  744. ChargingScheduleAllowedChargingRateUnit,
  745. ChargingScheduleMaxPeriods,
  746. ConnectorSwitch3to1PhaseSupported,
  747. MaxChargingProfilesInstalled
  748. };
  749. enum ChargerSystemStatus{
  750. ChargerSystemStatus_Booting,
  751. ChargerSystemStatus_Idle,
  752. ChargerSystemStatus_Authorizing,
  753. ChargerSystemStatus_Preparing,
  754. ChargerSystemStatus_Charging,
  755. ChargerSystemStatus_Terminating,
  756. ChargerSystemStatus_Alarm,
  757. ChargerSystemStatus_Fault
  758. };
  759. enum GetConfigurationKey {
  760. GetConfiguration_AllowOfflineTxForUnknownId=0,
  761. GetConfiguration_AuthorizationCacheEnabled,
  762. GetConfiguration_AuthorizeRemoteTxRequests,
  763. GetConfiguration_BlinkRepeat,
  764. GetConfiguration_ClockAlignedDataInterval,
  765. GetConfiguration_ConnectionTimeOut,
  766. GetConfiguration_GetConfigurationMaxKeys,
  767. GetConfiguration_HeartbeatInterval,
  768. GetConfiguration_LightIntensity,
  769. GetConfiguration_LocalAuthorizeOffline,
  770. GetConfiguration_LocalPreAuthorize,
  771. GetConfiguration_MaxEnergyOnInvalidId,
  772. GetConfiguration_MeterValuesAlignedData,
  773. GetConfiguration_MeterValuesAlignedDataMaxLength,
  774. GetConfiguration_MeterValuesSampledData,
  775. GetConfiguration_MeterValuesSampledDataMaxLength,
  776. GetConfiguration_MeterValueSampleInterval,
  777. GetConfiguration_MinimumStatusDuration,
  778. GetConfiguration_NumberOfConnectors,
  779. GetConfiguration_ResetRetries,
  780. GetConfiguration_ConnectorPhaseRotation,
  781. GetConfiguration_ConnectorPhaseRotationMaxLength,
  782. GetConfiguration_StopTransactionOnEVSideDisconnect,
  783. GetConfiguration_StopTransactionOnInvalidId,
  784. GetConfiguration_StopTxnAlignedData,
  785. GetConfiguration_StopTxnAlignedDataMaxLength,
  786. GetConfiguration_StopTxnSampledData,
  787. GetConfiguration_StopTxnSampledDataMaxLength,
  788. GetConfiguration_SupportedFeatureProfiles,
  789. GetConfiguration_SupportedFeatureProfilesMaxLength,
  790. GetConfiguration_TransactionMessageAttempts,
  791. GetConfiguration_TransactionMessageRetryInterval,
  792. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  793. GetConfiguration_WebSocketPingInterval,
  794. GetConfiguration_LocalAuthListEnabled,
  795. GetConfiguration_LocalAuthListMaxLength,
  796. GetConfiguration_SendLocalListMaxLength,
  797. GetConfiguration_ReserveConnectorZeroSupported,
  798. GetConfiguration_ChargeProfileMaxStackLevel,
  799. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  800. GetConfiguration_ChargingScheduleMaxPeriods,
  801. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  802. GetConfiguration_MaxChargingProfilesInstalled,
  803. };
  804. //GetConfiguration Array
  805. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  806. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  807. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  808. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  809. //==========================================
  810. // Init all share memory
  811. //==========================================
  812. int InitShareMemory()
  813. {
  814. int result = PASS;
  815. int MeterSMId;
  816. //creat ShmSysConfigAndInfo
  817. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  818. {
  819. #ifdef SystemLogMessage
  820. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  821. #endif
  822. result = FAIL;
  823. }
  824. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  825. {
  826. #ifdef SystemLogMessage
  827. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  828. #endif
  829. result = FAIL;
  830. }
  831. else
  832. {}
  833. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  834. {
  835. #ifdef SystemLogMessage
  836. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  837. #endif
  838. result = FAIL;
  839. }
  840. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  841. {
  842. #ifdef SystemLogMessage
  843. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  844. #endif
  845. result = FAIL;
  846. }
  847. else
  848. {}
  849. //creat ShmPsuData
  850. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  851. {
  852. #ifdef SystemLogMessage
  853. DEBUG_ERROR("shmget ShmPsuData NG\n");
  854. #endif
  855. result = FAIL;
  856. }
  857. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  858. {
  859. #ifdef SystemLogMessage
  860. DEBUG_ERROR("shmat ShmPsuData NG\n");
  861. #endif
  862. result = FAIL;
  863. }
  864. else
  865. {}
  866. //creat ShmOCPP16Data
  867. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  868. {
  869. #ifdef SystemLogMessage
  870. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  871. #endif
  872. result = FAIL;
  873. }
  874. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  875. {
  876. #ifdef SystemLogMessage
  877. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  878. #endif
  879. result = FAIL;
  880. }
  881. else
  882. {}
  883. /****************************** For Initial Settings************************************************/
  884. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  885. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  886. {
  887. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  888. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  889. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  890. }
  891. // Charger PRE_SYS_MODE
  892. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  893. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  894. clientTime.Heartbeat=time((time_t*)NULL);
  895. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  896. {
  897. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  898. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  899. }
  900. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  901. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  902. // allocate Configuration memory address
  903. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  904. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  905. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  906. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  908. {
  909. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  910. DEBUG_INFO("DC ...\n");
  911. }
  912. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  913. {
  914. SystemInitial = AC_QUANTITY;
  915. DEBUG_INFO("AC ...\n");
  916. }
  917. //Status Setting
  918. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  919. {
  920. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  921. }
  922. for (int index = 0; index < CCS_QUANTITY; index++)
  923. {
  924. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  925. }
  926. for (int index = 0; index < GB_QUANTITY; index++)
  927. {
  928. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  929. }
  930. for (int index = 0; index < AC_QUANTITY; index++)
  931. {
  932. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  933. }
  934. return result;
  935. }
  936. int ProcessShareMemory()
  937. {
  938. if(InitShareMemory() == FAIL)
  939. {
  940. #ifdef SystemLogMessage
  941. DEBUG_ERROR("InitShareMemory NG\n");
  942. #endif
  943. if(ShmStatusCodeData!=NULL)
  944. {
  945. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  946. }
  947. sleep(5);
  948. return FAIL;
  949. }
  950. return PASS;
  951. }
  952. //---------------------------------------------
  953. // new:
  954. // enum SYSTEM_STATUS
  955. // {
  956. // SYS_MODE_BOOTING = 0,
  957. // SYS_MODE_IDLE = 1,
  958. // SYS_MODE_AUTHORIZING = 2,
  959. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  960. // SYS_MODE_REASSIGN = 4,
  961. // SYS_MODE_PREPARING = 5,
  962. // SYS_MODE_PREPARE_FOR_EV = 6,
  963. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  964. // SYS_MODE_CHARGING = 8,
  965. // SYS_MODE_TERMINATING = 9,
  966. // SYS_MODE_COMPLETE = 10,
  967. // SYS_MODE_ALARM = 11,
  968. // SYS_MODE_FAULT = 12,
  969. // SYS_MODE_RESERVATION = 13,
  970. // SYS_MODE_BOOKING = 14,
  971. // SYS_MODE_MAINTAIN = 15,
  972. // SYS_MODE_DEBUG = 16,
  973. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  974. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  975. // SYS_MODE_UPDATE = 19
  976. // };
  977. //
  978. //
  979. //-----------------------------------------
  980. void CheckSystemValue(void)
  981. {
  982. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  983. int IdleModeCnt = 0;
  984. char filenmae[100]={0};
  985. char str[100]={0};
  986. //===============================
  987. // send Heartbeat
  988. //===============================
  989. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  990. {
  991. printf("Heartbeat !!!\n");
  992. //parameter for test
  993. sendHeartbeatRequest(0);
  994. //==============================================
  995. // Reset Waiting Time
  996. //==============================================
  997. clientTime.Heartbeat=time((time_t*)NULL);
  998. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  999. }
  1000. //==============================================
  1001. // Update firmware request
  1002. //==============================================
  1003. if(isUpdateRequest == TRUE )
  1004. {
  1005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1006. {
  1007. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1008. {
  1009. //check SystemStatus
  1010. /*************************DC*******************************/
  1011. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1012. {
  1013. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1014. {
  1015. IdleModeCnt = IdleModeCnt + 1;
  1016. }
  1017. }
  1018. for (int index = 0; index < CCS_QUANTITY; index++)
  1019. {
  1020. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1021. {
  1022. IdleModeCnt = IdleModeCnt + 1;
  1023. }
  1024. }
  1025. for (int index = 0; index < GB_QUANTITY; index++)
  1026. {
  1027. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1028. {
  1029. IdleModeCnt = IdleModeCnt + 1;
  1030. }
  1031. }
  1032. }
  1033. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1034. {
  1035. isUpdateRequest = FALSE;
  1036. }
  1037. }
  1038. else
  1039. {
  1040. /*************************AC*******************************/
  1041. for (int index = 0; index < AC_QUANTITY; index++)
  1042. {
  1043. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1044. {
  1045. IdleModeCnt = IdleModeCnt + 1;
  1046. }
  1047. }
  1048. if(IdleModeCnt == AC_QUANTITY)
  1049. {
  1050. isUpdateRequest = FALSE;
  1051. }
  1052. }
  1053. }
  1054. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1055. {
  1056. //===============================
  1057. // CSU Trigger Reset Conf
  1058. //===============================
  1059. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1060. {
  1061. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1062. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1063. {
  1064. server_sign = FALSE;
  1065. }
  1066. }
  1067. //===============================
  1068. // CSU Trigger Authorize Request
  1069. //===============================
  1070. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1071. {
  1072. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1073. {
  1074. sendAuthorizeRequest(0);
  1075. authorizeRetryTimes = authorizeRetryTimes + 1;
  1076. // authenrequest = TRUE
  1077. if(authorizeRetryTimes < 3)
  1078. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1079. }
  1080. }
  1081. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1082. {
  1083. authorizeRetryTimes = 0;
  1084. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1085. server_sign = FALSE;
  1086. }
  1087. //===============================
  1088. // CSU Trigger Smart Charging Profilw
  1089. //===============================
  1090. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1091. {
  1092. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1093. GetChargingProfileRequest(gun_index);
  1094. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1095. }
  1096. //==============================================
  1097. // Charger start transaction
  1098. //==============================================
  1099. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1100. {
  1101. sendStartTransactionRequest(gun_index);
  1102. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1103. clientTime.StartTransaction = time((time_t*)NULL);
  1104. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1105. }
  1106. //==============================================
  1107. // Charger stop transaction
  1108. //==============================================
  1109. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1110. {
  1111. sendStopTransactionRequest(gun_index);
  1112. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1113. clientTime.StopTransaction = time((time_t*)NULL);
  1114. }
  1115. //==============================================
  1116. // Charger status report
  1117. //==============================================
  1118. /* Check Mode Change */
  1119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1120. {
  1121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1122. {
  1123. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1124. {
  1125. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1126. {
  1127. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1128. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1129. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1130. statusModeChage[gun_index] = TRUE;
  1131. }
  1132. }
  1133. }
  1134. for (int index = 0; index < CCS_QUANTITY; index++)
  1135. {
  1136. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1137. {
  1138. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1139. {
  1140. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1141. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1142. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1143. statusModeChage[gun_index] = TRUE;
  1144. }
  1145. }
  1146. }
  1147. for (int index = 0; index < GB_QUANTITY; index++)
  1148. {
  1149. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1150. {
  1151. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1152. {
  1153. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1154. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1155. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1156. statusModeChage[gun_index] = TRUE;
  1157. }
  1158. }
  1159. }
  1160. }
  1161. else //AC
  1162. {
  1163. for (int index = 0; index < AC_QUANTITY; index++)
  1164. {
  1165. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1166. {
  1167. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1168. {
  1169. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1170. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1171. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1172. statusModeChage[gun_index] = TRUE;
  1173. }
  1174. }
  1175. }// END OF FOR
  1176. }// END OF ELSE
  1177. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1178. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1179. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1180. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1181. {
  1182. if(SystemInitial != 0)
  1183. SystemInitial = SystemInitial -1;
  1184. sendStatusNotificationRequest(gun_index);
  1185. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1186. statusModeChage[gun_index] = FALSE;
  1187. }
  1188. //==============================================
  1189. // Meter report
  1190. //==============================================
  1191. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1192. {
  1193. //check Transaction active
  1194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1195. {
  1196. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1197. {
  1198. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1199. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1200. {
  1201. meterValueSend[gun_index] =1;
  1202. }
  1203. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1204. {
  1205. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1206. if((access(filenmae,F_OK))!=-1)
  1207. {
  1208. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1209. sprintf(str,"rm -f %s",filenmae);
  1210. system(str);
  1211. }
  1212. }
  1213. }// End for CHAdeMO
  1214. for (int index = 0; index < CCS_QUANTITY; index++)
  1215. {
  1216. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1217. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1218. {
  1219. meterValueSend[gun_index] =1;
  1220. }
  1221. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1222. {
  1223. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1224. if((access(filenmae,F_OK))!=-1)
  1225. {
  1226. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1227. sprintf(str,"rm -f %s",filenmae);
  1228. system(str);
  1229. }
  1230. }
  1231. } // End for CCS
  1232. for (int index = 0; index < GB_QUANTITY; index++)
  1233. {
  1234. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1235. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1236. {
  1237. meterValueSend[gun_index] =1;
  1238. }
  1239. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1240. {
  1241. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1242. if((access(filenmae,F_OK))!=-1)
  1243. {
  1244. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1245. sprintf(str,"rm -f %s",filenmae);
  1246. system(str);
  1247. }
  1248. }
  1249. }// End for GB
  1250. }
  1251. else
  1252. {
  1253. for (int index = 0; index < AC_QUANTITY; index++)
  1254. {
  1255. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1256. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1257. {
  1258. meterValueSend[gun_index] =1;
  1259. }
  1260. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1261. {
  1262. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1263. if((access(filenmae,F_OK))!=-1)
  1264. {
  1265. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1266. sprintf(str,"rm -f %s",filenmae);
  1267. system(str);
  1268. }
  1269. }
  1270. }//End for AC
  1271. }//END OF ELSE
  1272. // sleep(1);
  1273. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1274. if(meterValueSend[gun_index] == 1)
  1275. sendMeterValuesRequest(gun_index);
  1276. }
  1277. //==============================================
  1278. // Check Connector reserved
  1279. //==============================================
  1280. //===============================
  1281. // Check if Reserve is expired
  1282. //===============================
  1283. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1284. {
  1285. double diff_t;
  1286. struct tm tp;
  1287. // current time
  1288. time_t t = time(NULL);
  1289. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1290. tp.tm_isdst = -1;
  1291. time_t utc = mktime(&tp);
  1292. diff_t = difftime(utc, t);
  1293. if(diff_t <= 0)
  1294. {
  1295. DEBUG_INFO("reserve expired !!! \n");
  1296. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1297. }
  1298. }//END OF Check if Reserve is expired
  1299. //==========================================
  1300. // csu trigger FirmwareStatusNotificationReq
  1301. //==========================================
  1302. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1303. {
  1304. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1305. }
  1306. //==========================================
  1307. // csu trigger CancelReservationConf
  1308. //==========================================
  1309. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1310. {
  1311. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1312. }
  1313. //==========================================
  1314. // csu trigger ChangeAvailabilityConf
  1315. //==========================================
  1316. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1317. {
  1318. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1319. }
  1320. //==========================================
  1321. // csu trigger UnlockConnectorConf
  1322. //==========================================
  1323. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1324. {
  1325. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1326. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1327. }
  1328. //==========================================
  1329. // csu trigger ReserveNowConf
  1330. //==========================================
  1331. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1332. {
  1333. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1334. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1335. }
  1336. //==========================================
  1337. // csu trigger DataTransferReq
  1338. //==========================================
  1339. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1340. {
  1341. sendDataTransferRequest(gun_index);
  1342. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1343. }
  1344. }
  1345. }
  1346. //==========================================
  1347. // send request routine
  1348. //==========================================
  1349. int sendAuthorizeRequest(int gun_index)
  1350. {
  1351. mtrace();
  1352. int result = FAIL;
  1353. char message[100]={0};
  1354. char guid[37];
  1355. char tempdata[65]={0};
  1356. DEBUG_INFO("sendAuthorizeRequest \n");
  1357. //Local Authorize
  1358. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))
  1359. {
  1360. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1361. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1362. {
  1363. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1364. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1365. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1366. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1367. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1368. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1369. authorizeRetryTimes = 0;
  1370. return result;
  1371. }
  1372. else
  1373. {
  1374. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1375. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1376. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1377. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1378. result = PASS;
  1379. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1380. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1381. authorizeRetryTimes = 0;
  1382. return result;
  1383. }
  1384. }
  1385. //initailize struct Authorize
  1386. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1387. //get data from shared memory
  1388. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1389. random_uuid(guid);
  1390. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1391. LWS_Send(message);
  1392. sprintf(tempdata, "Authorize,%d", gun_index);
  1393. if(hashmap_operation(0, guid, tempdata) == 1)
  1394. {
  1395. result = PASS;
  1396. DEBUG_ERROR("Authorize mapItem pass\n");
  1397. }
  1398. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1399. return result;
  1400. }
  1401. int sendBootNotificationRequest(void)
  1402. {
  1403. mtrace();
  1404. int result = FAIL;
  1405. char message[500]={0}, payload[700]={0};
  1406. char guid[37]={0};
  1407. char tempdata[65]={0};
  1408. int IsGunCharging = FALSE;
  1409. //check Transaction active
  1410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1411. {
  1412. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1413. {
  1414. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1415. {
  1416. IsGunCharging = TRUE;
  1417. }
  1418. }
  1419. for (int index = 0; index < CCS_QUANTITY; index++)
  1420. {
  1421. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1422. {
  1423. IsGunCharging = TRUE;
  1424. }
  1425. }
  1426. for (int index = 0; index < GB_QUANTITY; index++)
  1427. {
  1428. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1429. {
  1430. IsGunCharging = TRUE;
  1431. }
  1432. }
  1433. }
  1434. else
  1435. {
  1436. for (int index = 0; index < AC_QUANTITY; index++)
  1437. {
  1438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1439. {
  1440. IsGunCharging = TRUE;
  1441. }
  1442. }
  1443. }
  1444. if(IsGunCharging == TRUE)
  1445. {
  1446. server_sign = TRUE;
  1447. return result;
  1448. }
  1449. // Fill BootNotification fields
  1450. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1451. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1452. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1453. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1454. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1455. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1456. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1457. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1458. ShmOCPP16Data->ChargeBoxId
  1459. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1460. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1461. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1462. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1463. ,ShmOCPP16Data->BootNotification.CpIccid
  1464. ,ShmOCPP16Data->BootNotification.CpImsi
  1465. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1466. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1467. random_uuid(guid);
  1468. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1469. LWS_Send(message);
  1470. sprintf(tempdata, "BootNotification,0");
  1471. 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*/)
  1472. {
  1473. result = PASS;
  1474. }
  1475. memset(queuedata, 0, sizeof(queuedata));
  1476. strcpy(queuedata,message);
  1477. HeartBeatCount = 0;
  1478. //#ifdef SystemLogMessage
  1479. //DEBUG_INFO(">>>>>BootNotification request\n");
  1480. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1481. //#endif
  1482. return result;
  1483. }
  1484. int sendDataTransferRequest(int gun_index)
  1485. {
  1486. mtrace();
  1487. char message[1000]={0};
  1488. char guid[37]={0};
  1489. char tempdata[65]={0};
  1490. int result = FAIL;
  1491. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1492. random_uuid(guid);
  1493. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1494. MESSAGE_TYPE_CALL,
  1495. guid,
  1496. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1497. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1498. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1499. LWS_Send(message);
  1500. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1501. 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*/)
  1502. {
  1503. result = PASS;
  1504. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1505. }
  1506. return result;
  1507. }
  1508. int sendDiagnosticsStatusNotificationRequest(char *status)
  1509. {
  1510. mtrace();
  1511. int result = FAIL;
  1512. char message[110]={0};
  1513. char guid[37]={0};
  1514. char tempdata[65]={0};
  1515. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1516. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1517. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1518. random_uuid(guid);
  1519. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1520. LWS_Send(message);
  1521. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1522. if(hashmap_operation(0, guid, tempdata) == 1)
  1523. {
  1524. result = PASS;
  1525. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1526. }
  1527. //#ifdef SystemLogMessage
  1528. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1529. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1530. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1531. //#endif
  1532. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1533. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1534. //record status
  1535. if(strcmp(status,"Idle")==0)
  1536. {
  1537. DiagnosticsStatusNotificationStatus = 0;
  1538. }
  1539. else if(strcmp(status,"Uploaded")==0)
  1540. {
  1541. DiagnosticsStatusNotificationStatus = 1;
  1542. }
  1543. else if(strcmp(status,"UploadFailed")==0)
  1544. {
  1545. DiagnosticsStatusNotificationStatus = 2;
  1546. }
  1547. else if(strcmp(status,"Uploading")==0)
  1548. {
  1549. DiagnosticsStatusNotificationStatus = 3;
  1550. }
  1551. return result;
  1552. }
  1553. int sendFirmwareStatusNotificationRequest(char *status)
  1554. {
  1555. mtrace();
  1556. int result = FAIL;
  1557. char message[110]={0};
  1558. char guid[37]={0};
  1559. char tempdata[65]={0};
  1560. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1561. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1562. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1563. random_uuid(guid);
  1564. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1565. LWS_Send(message);
  1566. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1567. 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*/)
  1568. {
  1569. result = PASS;
  1570. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1571. }
  1572. //#ifdef SystemLogMessage
  1573. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1574. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1575. //#endif
  1576. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1577. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1578. //record status
  1579. if(strcmp(status,"Downloaded")==0)
  1580. {
  1581. FirmwareStatusNotificationStatus = 0;
  1582. }
  1583. else if(strcmp(status,"DownloadFailed")==0)
  1584. {
  1585. FirmwareStatusNotificationStatus = 1;
  1586. }
  1587. else if(strcmp(status,"Downloading")==0)
  1588. {
  1589. FirmwareStatusNotificationStatus = 2;
  1590. }
  1591. else if(strcmp(status,"Idle")==0)
  1592. {
  1593. FirmwareStatusNotificationStatus = 3;
  1594. }
  1595. else if(strcmp(status,"InstallationFailed")==0)
  1596. {
  1597. FirmwareStatusNotificationStatus = 4;
  1598. }
  1599. else if(strcmp(status,"Installing")==0)
  1600. {
  1601. FirmwareStatusNotificationStatus = 5;
  1602. }
  1603. else if(strcmp(status,"Installed")==0)
  1604. {
  1605. FirmwareStatusNotificationStatus = 6;
  1606. }
  1607. return result;
  1608. }
  1609. int sendHeartbeatRequest(int gun_index)
  1610. {
  1611. mtrace();
  1612. int result = FAIL;
  1613. char message[80]={0};
  1614. char guid[37]={0};
  1615. char tempdata[65]={0};
  1616. random_uuid(guid);
  1617. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1618. , MESSAGE_TYPE_CALL
  1619. , guid );
  1620. LWS_Send(message);
  1621. sprintf(tempdata, "Heartbeat,%d", 0);
  1622. 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*/)
  1623. {
  1624. result = PASS;
  1625. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1626. }
  1627. return result;
  1628. }
  1629. int sendStartTransactionRequest(int gun_index)
  1630. {
  1631. mtrace();
  1632. int result = FAIL;
  1633. char message[250]={0};
  1634. char guid[37]={0};
  1635. struct timeval tmnow;
  1636. struct tm *tm;
  1637. char buf[28];//, usec_buf[6];
  1638. char tempdata[65]={0};
  1639. DEBUG_INFO("sendStartTransactionRequest...");
  1640. gettimeofday(&tmnow, NULL);
  1641. time_t t;
  1642. t = time(NULL);
  1643. /*UTC time and date*/
  1644. tm = gmtime(&t);
  1645. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1646. #if 0 // remove temporally
  1647. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1648. strcat(buf,".");
  1649. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1650. strcat(buf,usec_buf);
  1651. #endif
  1652. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1653. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1654. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1656. {
  1657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1658. {
  1659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1660. {
  1661. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1662. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1663. }
  1664. }
  1665. for (int index = 0; index < CCS_QUANTITY; index++)
  1666. {
  1667. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1668. {
  1669. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1670. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1671. }
  1672. }
  1673. for (int index = 0; index < GB_QUANTITY; index++)
  1674. {
  1675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1676. {
  1677. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1678. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1679. }
  1680. }
  1681. }
  1682. else
  1683. {
  1684. for (int index = 0; index < AC_QUANTITY; index++)
  1685. {
  1686. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1687. {
  1688. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1689. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1690. }
  1691. }
  1692. }//END OF ELSE
  1693. random_uuid(guid);
  1694. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1695. , MESSAGE_TYPE_CALL
  1696. , guid
  1697. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1698. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1699. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1700. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1701. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1702. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1703. 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*/)
  1704. {
  1705. result = PASS;
  1706. }
  1707. strcpy(queuedata, message);
  1708. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1709. LWS_Send(message);
  1710. #if 0
  1711. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1712. 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*/)
  1713. {
  1714. result = PASS;
  1715. }
  1716. strcpy(queuedata, message);
  1717. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1718. #endif
  1719. //#ifdef SystemLogMessage
  1720. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1721. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1722. //#endif
  1723. return result;
  1724. }
  1725. int sendStatusNotificationRequest(int gun_index)
  1726. {
  1727. mtrace();
  1728. int result = FAIL;
  1729. char message[600]={0};
  1730. char guid[37];
  1731. int currentStatus = 0;
  1732. struct timeval tmnow;
  1733. struct tm *tm;
  1734. char buf[28];//, usec_buf[6];
  1735. char tempdata[65]={0};
  1736. gettimeofday(&tmnow, NULL);
  1737. time_t t;
  1738. t = time(NULL);
  1739. /*UTC time and date*/
  1740. tm = gmtime(&t);
  1741. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1742. #if 0 // remove temporally
  1743. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1744. strcat(buf,".");
  1745. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1746. strcat(buf,usec_buf);
  1747. #endif
  1748. printf("%s",buf);
  1749. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1750. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1751. // it's option
  1752. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1753. /*
  1754. enum _SYSTEM_STATUS
  1755. {
  1756. S_BOOTING = 0,
  1757. S_IDLE, = 1
  1758. S_AUTHORIZING, =2
  1759. S_REASSIGN_CHECK, =3
  1760. S_REASSIGN, =4
  1761. S_PRECHARGE, =5
  1762. S_PREPARING_FOR_EV, =6
  1763. S_PREPARING_FOR_EVSE, =7
  1764. S_CHARGING, =8
  1765. S_TERMINATING, =9
  1766. S_COMPLETE, =10
  1767. S_ALARM, =11
  1768. S_FAULT =12
  1769. }
  1770. */
  1771. //check Transaction active
  1772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1773. {
  1774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1775. {
  1776. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1777. {
  1778. currentStatus = 0; //OCPP Status: Available
  1779. }
  1780. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1781. {
  1782. currentStatus = 1; //OCPP Status: Preparing
  1783. }
  1784. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1785. {
  1786. currentStatus = 2; //OCPP Status: Charging
  1787. }
  1788. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1789. {
  1790. currentStatus = 5; //OCPP Status: Finishing
  1791. }
  1792. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1793. {
  1794. currentStatus = 4; //OCPP Status: SuspendedEV
  1795. }
  1796. 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
  1797. {
  1798. currentStatus = 7; //OCPP Status: Unavailable
  1799. }
  1800. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1801. {
  1802. currentStatus = 8; //OCPP Status: Faulted
  1803. }
  1804. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1805. {
  1806. currentStatus = 6; //OCPP Status: Reserved
  1807. }
  1808. }//end of for CHAdeMO_QUANTITY
  1809. for (int index = 0; index < CCS_QUANTITY; index++)
  1810. {
  1811. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1812. {
  1813. currentStatus = 0; //OCPP Status: Available
  1814. }
  1815. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1816. {
  1817. currentStatus = 1; //OCPP Status: Preparing
  1818. }
  1819. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1820. {
  1821. currentStatus = 2; //OCPP Status: Charging
  1822. }
  1823. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1824. {
  1825. currentStatus = 5; //OCPP Status: Finishing
  1826. }
  1827. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM ,S_TERMINATING ---> SuspendedEV
  1828. {
  1829. currentStatus = 4; //OCPP Status: SuspendedEV
  1830. }
  1831. 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
  1832. {
  1833. currentStatus = 7; //OCPP Status : Unavailable
  1834. }
  1835. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1836. {
  1837. currentStatus = 8; //OCPP Status: Faulted
  1838. }
  1839. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1840. {
  1841. currentStatus = 6; //OCPP Status: Reserved
  1842. }
  1843. }
  1844. for (int index = 0; index < GB_QUANTITY; index++)
  1845. {
  1846. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1847. {
  1848. currentStatus = 0; //OCPP Status: Available
  1849. }
  1850. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1851. {
  1852. currentStatus = 1; //OCPP Status: Preparing
  1853. }
  1854. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1855. {
  1856. currentStatus = 2; //OCPP Status: Charging
  1857. }
  1858. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1859. {
  1860. currentStatus = 5; //OCPP Status: Finishing
  1861. }
  1862. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM , S_TERMINATING ---> SuspendedEV
  1863. {
  1864. currentStatus = 4; //OCPP Status: SuspendedEV
  1865. }
  1866. 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
  1867. {
  1868. currentStatus = 7; //OCPP Status: Unavailable
  1869. }
  1870. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1871. {
  1872. currentStatus = 8; //OCPP Status: Faulted
  1873. }
  1874. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1875. {
  1876. currentStatus = 6; //OCPP Status: Reserved
  1877. }
  1878. }
  1879. }
  1880. else
  1881. {
  1882. for (int index = 0; index < AC_QUANTITY; index++)
  1883. {
  1884. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1885. {
  1886. currentStatus = 0; //OCPP Status: Available
  1887. }
  1888. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1889. {
  1890. currentStatus = 1; //OCPP Status: Preparing
  1891. }
  1892. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1893. {
  1894. currentStatus = 2; //OCPP Status: Charging
  1895. }
  1896. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1897. {
  1898. currentStatus = 5; //OCPP Status: Finishing
  1899. }
  1900. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1901. {
  1902. currentStatus = 4; //OCPP Status: SuspendedEV
  1903. }
  1904. 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
  1905. {
  1906. currentStatus = 7; //OCPP Status: Unavailable
  1907. }
  1908. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1909. {
  1910. currentStatus = 8; //OCPP Status: Faulted
  1911. }
  1912. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1913. {
  1914. currentStatus = 6; //OCPP Status: Reserved
  1915. }
  1916. }//end of for AC_QUANTITY
  1917. }//END OF ELSE
  1918. //it's option
  1919. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1920. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1921. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1922. random_uuid(guid);
  1923. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1924. , MESSAGE_TYPE_CALL
  1925. , guid
  1926. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1927. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1928. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1929. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1930. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1931. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1932. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1933. LWS_Send(message);
  1934. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1935. 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*/)
  1936. {
  1937. //DEBUG_ERROR("statusNotification mapitem pass");
  1938. result = PASS;
  1939. }
  1940. return result;
  1941. }
  1942. int sendStopTransactionRequest(int gun_index)
  1943. {
  1944. mtrace();
  1945. int result = FAIL;
  1946. //char message[1500]={0};
  1947. char guid[37]={0};
  1948. char tempdata[65]={0};
  1949. //int idx_sample=0;
  1950. DEBUG_ERROR("sendStopTransactionRequest \n");
  1951. memset(queuedata, 0, sizeof(queuedata));
  1952. //ENERGY_ACTIVE_IMPORT_REGISTER
  1953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1954. {
  1955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1956. {
  1957. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1958. {
  1959. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1960. }
  1961. }// END OF CHAdeMO_QUANTITY
  1962. for (int index = 0; index < CCS_QUANTITY; index++)
  1963. {
  1964. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1965. {
  1966. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1967. }
  1968. }// END OF CCS_QUANTITY
  1969. for (int index = 0; index < GB_QUANTITY; index++)
  1970. {
  1971. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1972. {
  1973. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1974. }
  1975. }// END OF GB_QUANTITY
  1976. }
  1977. else
  1978. {
  1979. for (int index = 0; index < AC_QUANTITY; index++)
  1980. {
  1981. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1982. {
  1983. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1984. }
  1985. }// END OF AC_QUANTITY
  1986. }//END OF ELSE
  1987. //Stop Transaction Time
  1988. struct timeval tmnow;
  1989. struct tm *tm;
  1990. char buf[28];//, usec_buf[6];
  1991. gettimeofday(&tmnow, NULL);
  1992. time_t t;
  1993. t = time(NULL);
  1994. /*UTC time and date*/
  1995. tm = gmtime(&t);
  1996. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  1998. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  1999. random_uuid(guid);
  2000. /***********************************transactionData******************************************************/
  2001. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2003. //=================================
  2004. // Transaction_Begin
  2005. //=================================
  2006. // Energy.Active.Export.Interval
  2007. //idx_sample=0;
  2008. 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
  2009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2011. 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*/]);
  2012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2013. {
  2014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2015. }
  2016. else
  2017. {
  2018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2019. }
  2020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2022. //=================================
  2023. // Transaction_End
  2024. //=================================
  2025. //Current.Export
  2026. //idx_sample=1;
  2027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2028. {
  2029. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2030. {
  2031. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2032. {
  2033. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2034. }
  2035. }
  2036. for (int index = 0; index < CCS_QUANTITY; index++)
  2037. {
  2038. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2039. {
  2040. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2041. }
  2042. }
  2043. for (int index = 0; index < GB_QUANTITY; index++)
  2044. {
  2045. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2046. {
  2047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2048. }
  2049. }
  2050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2051. }
  2052. else
  2053. {
  2054. for (int index = 0; index < AC_QUANTITY; index++)
  2055. {
  2056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2057. {
  2058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2059. }
  2060. }
  2061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2062. }// END FOR AC ELSE
  2063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2066. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2069. //Energy.Active.Export.Interval
  2070. //idx_sample=2;
  2071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2072. {
  2073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2074. {
  2075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2076. {
  2077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2078. }
  2079. }
  2080. for (int index = 0; index < CCS_QUANTITY; index++)
  2081. {
  2082. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2083. {
  2084. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2085. }
  2086. }
  2087. for (int index = 0; index < GB_QUANTITY; index++)
  2088. {
  2089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2090. {
  2091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2092. }
  2093. }
  2094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2095. }
  2096. else
  2097. {
  2098. for (int index = 0; index < AC_QUANTITY; index++)
  2099. {
  2100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2101. {
  2102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2103. }
  2104. }
  2105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2106. }// END FOR AC ELSE
  2107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2110. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2113. //Power.Active.Export
  2114. //idx_sample=3;
  2115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2116. {
  2117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2118. {
  2119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2120. {
  2121. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2122. }
  2123. }
  2124. for (int index = 0; index < CCS_QUANTITY; index++)
  2125. {
  2126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2127. {
  2128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2129. }
  2130. }
  2131. for (int index = 0; index < GB_QUANTITY; index++)
  2132. {
  2133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2134. {
  2135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2136. }
  2137. }
  2138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2139. }
  2140. else
  2141. {
  2142. for (int index = 0; index < AC_QUANTITY; index++)
  2143. {
  2144. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2145. {
  2146. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2147. }
  2148. }
  2149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2150. }// END FOR AC ELSE
  2151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2154. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2157. //Voltage
  2158. //idx_sample=4;
  2159. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2160. {
  2161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2162. {
  2163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2164. {
  2165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2166. }
  2167. }
  2168. for (int index = 0; index < CCS_QUANTITY; index++)
  2169. {
  2170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2171. {
  2172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2173. }
  2174. }
  2175. for (int index = 0; index < GB_QUANTITY; index++)
  2176. {
  2177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2178. {
  2179. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2180. }
  2181. }
  2182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2183. }
  2184. else
  2185. {
  2186. for (int index = 0; index < AC_QUANTITY; index++)
  2187. {
  2188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2189. {
  2190. 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
  2191. }
  2192. }
  2193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2194. }// END FOR AC ELSE
  2195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2198. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2201. //SoC
  2202. //idx_sample=5;
  2203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2204. {
  2205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2206. {
  2207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2208. {
  2209. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2210. }
  2211. }
  2212. for (int index = 0; index < CCS_QUANTITY; index++)
  2213. {
  2214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2215. {
  2216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2217. }
  2218. }
  2219. for (int index = 0; index < GB_QUANTITY; index++)
  2220. {
  2221. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2222. {
  2223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2224. }
  2225. }
  2226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2232. } // END FOR DC CASE
  2233. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2234. {
  2235. 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\" } ] } ] } ]"
  2236. ,MESSAGE_TYPE_CALL
  2237. ,guid
  2238. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2239. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2240. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2241. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2242. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2243. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2244. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2245. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2246. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2247. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2248. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2249. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2250. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2251. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2252. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2253. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2254. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2255. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2256. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2257. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2258. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2259. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2260. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2261. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2262. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2263. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2264. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2265. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2266. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2267. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2268. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2269. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2270. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2271. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2272. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2273. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2274. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2275. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2276. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2277. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2278. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2279. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2280. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2281. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2282. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2283. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2284. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2285. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2286. );
  2287. }
  2288. else
  2289. {
  2290. 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\" } ] } ] } ]"
  2291. ,MESSAGE_TYPE_CALL
  2292. ,guid
  2293. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2294. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2295. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2296. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2297. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2298. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2299. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2304. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2334. );
  2335. }
  2336. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2337. if(hashmap_operation(0, guid, tempdata) == 1)
  2338. {
  2339. result = PASS;
  2340. DEBUG_INFO("StopTransaction mapitem pass\n");
  2341. }
  2342. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2343. LWS_Send(queuedata);
  2344. #if 0
  2345. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2346. if(hashmap_operation(0, guid, tempdata) == 1)
  2347. {
  2348. result = PASS;
  2349. DEBUG_INFO("StopTransaction mapitem pass\n");
  2350. }
  2351. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2352. #endif
  2353. //for test
  2354. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2355. return result;
  2356. }
  2357. int sendMeterValuesRequest(int gun_index)
  2358. {
  2359. mtrace();
  2360. int result = FAIL;
  2361. // char message[1500]={0};
  2362. char guid[37]={0};
  2363. //int idx_sample=0;
  2364. //int length = 0;
  2365. char tempdata[65]={0};
  2366. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2367. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2368. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2369. {
  2370. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2371. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2372. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2373. return result;
  2374. }
  2375. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2376. {
  2377. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2378. }
  2379. memset(queuedata, 0, sizeof(queuedata));
  2380. //set value
  2381. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2382. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2383. random_uuid(guid);
  2384. //UTC Date time
  2385. struct timeval tmnow;
  2386. struct tm *tm;
  2387. char buf[28];//, usec_buf[6];
  2388. gettimeofday(&tmnow, NULL);
  2389. time_t t;
  2390. t = time(NULL);
  2391. /*UTC time and date*/
  2392. tm = gmtime(&t);
  2393. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2395. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2396. //idx_sample=0;
  2397. //********************************(1)Current.Export************************************************/
  2398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2399. {
  2400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2401. {
  2402. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2403. {
  2404. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2405. }
  2406. }
  2407. for (int index = 0; index < CCS_QUANTITY; index++)
  2408. {
  2409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2410. {
  2411. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2412. }
  2413. }
  2414. for (int index = 0; index < GB_QUANTITY; index++)
  2415. {
  2416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2417. {
  2418. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2419. }
  2420. }
  2421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2422. }
  2423. else
  2424. {
  2425. for (int index = 0; index < AC_QUANTITY; index++)
  2426. {
  2427. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2428. {
  2429. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2430. }
  2431. }
  2432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2433. }// END FOR AC ELSE
  2434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2437. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2438. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2440. //idx_sample=1;
  2441. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2443. {
  2444. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2445. {
  2446. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2447. {
  2448. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2449. }
  2450. }
  2451. for (int index = 0; index < CCS_QUANTITY; index++)
  2452. {
  2453. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2454. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2455. {
  2456. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2457. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2458. }
  2459. }
  2460. for (int index = 0; index < GB_QUANTITY; index++)
  2461. {
  2462. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2463. {
  2464. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2465. }
  2466. }
  2467. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2468. }
  2469. else
  2470. {
  2471. for (int index = 0; index < AC_QUANTITY; index++)
  2472. {
  2473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2474. {
  2475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2476. }
  2477. }
  2478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2479. }//END FOR AC ELSE
  2480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2483. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2486. //idx_sample=2;
  2487. //********************************(4)Power.Active.Export************************************************/
  2488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2489. {
  2490. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2491. {
  2492. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2493. {
  2494. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2495. }
  2496. }
  2497. for (int index = 0; index < CCS_QUANTITY; index++)
  2498. {
  2499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2500. {
  2501. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2502. }
  2503. }
  2504. for (int index = 0; index < GB_QUANTITY; index++)
  2505. {
  2506. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2507. {
  2508. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2509. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2510. }
  2511. }
  2512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2513. }
  2514. else
  2515. {
  2516. for (int index = 0; index < AC_QUANTITY; index++)
  2517. {
  2518. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2519. {
  2520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2521. }
  2522. }
  2523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2524. }// END FOR AC ELSE
  2525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2527. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2528. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2529. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2531. //idx_sample=3;
  2532. //***********************************************(5)VOLTAGE******************************************************/
  2533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2534. {
  2535. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2536. {
  2537. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2538. {
  2539. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2540. }
  2541. }
  2542. for (int index = 0; index < CCS_QUANTITY; index++)
  2543. {
  2544. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2545. {
  2546. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2547. }
  2548. }
  2549. for (int index = 0; index < GB_QUANTITY; index++)
  2550. {
  2551. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2552. {
  2553. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2554. }
  2555. }
  2556. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2557. }
  2558. else
  2559. {
  2560. for (int index = 0; index < AC_QUANTITY; index++)
  2561. {
  2562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2563. {
  2564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2565. }
  2566. }
  2567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2568. }//END FOR AC ELSE
  2569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2570. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2572. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2576. {
  2577. //idx_sample=4;
  2578. //sampledValue = NULL;
  2579. //***********************************************(6)SOC******************************************************/
  2580. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2581. {
  2582. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2583. {
  2584. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2585. }
  2586. }
  2587. for (int index = 0; index < CCS_QUANTITY; index++)
  2588. {
  2589. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2590. {
  2591. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2592. }
  2593. }
  2594. for (int index = 0; index < GB_QUANTITY; index++)
  2595. {
  2596. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2597. {
  2598. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2599. }
  2600. }
  2601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2607. }
  2608. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2609. {
  2610. 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\"}]}]}]"
  2611. ,MESSAGE_TYPE_CALL
  2612. ,guid
  2613. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2614. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2615. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2616. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2617. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2618. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2619. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2620. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2621. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2622. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2623. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2624. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2651. );
  2652. }
  2653. else
  2654. {
  2655. 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\"}]}]}]"
  2656. ,MESSAGE_TYPE_CALL
  2657. ,guid
  2658. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2659. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2660. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2662. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2663. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2664. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2689. );
  2690. }
  2691. // Put request guid to hash map
  2692. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2693. 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*/)
  2694. {
  2695. result = PASS;
  2696. DEBUG_INFO("MeterValues mapitem pass\n");
  2697. }
  2698. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2699. LWS_Send(queuedata);
  2700. #if 0
  2701. // Put request guid to hash map
  2702. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2703. 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*/)
  2704. {
  2705. result = PASS;
  2706. DEBUG_INFO("MeterValues mapitem pass\n");
  2707. }
  2708. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2709. #endif
  2710. return result;
  2711. }
  2712. //==========================================
  2713. // send confirm routine
  2714. //==========================================
  2715. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2716. {
  2717. mtrace();
  2718. int result = FAIL;
  2719. char message[100]={0};
  2720. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2721. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2722. LWS_Send(message);
  2723. result = TRUE;
  2724. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2725. return result;
  2726. }
  2727. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2728. {
  2729. mtrace();
  2730. int result = FAIL;
  2731. char message[100]={0};
  2732. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2733. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2734. LWS_Send(message);
  2735. result = TRUE;
  2736. return result;
  2737. }
  2738. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2739. {
  2740. mtrace();
  2741. int result = FAIL;
  2742. char message[100]={0};
  2743. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2744. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2745. LWS_Send(message);
  2746. result = TRUE;
  2747. return result;
  2748. }
  2749. int sendClearCacheConfirmation(char *uuid,char *payload)
  2750. {
  2751. mtrace();
  2752. int result = FAIL;
  2753. char message[500]={0};
  2754. // int count = 0;
  2755. // int gun_index = 0;
  2756. // char guid[37];
  2757. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2758. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2759. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2760. LWS_Send(message);
  2761. return result;
  2762. }
  2763. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2764. {
  2765. mtrace();
  2766. int result = FAIL;
  2767. char message[500]={0};
  2768. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2769. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2770. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2771. LWS_Send(message);
  2772. return result;
  2773. }
  2774. int sendDataTransferConfirmation(char *uuid,char *payload)
  2775. {
  2776. mtrace();
  2777. char statusStr[20]={0};
  2778. char dataStr[10]={0};
  2779. char sstr[20]={0};
  2780. int c = 0;
  2781. char *loc;
  2782. int result = FAIL;
  2783. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2784. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2785. /**********************status**************************/
  2786. loc = strstr(payload, "status");
  2787. memset(sstr ,0, sizeof(sstr) );
  2788. c = 0;
  2789. while (loc[3+strlen("status")+c] != '\"')
  2790. {
  2791. sstr[c] = loc[3+strlen("status")+c];
  2792. c++;
  2793. }
  2794. sstr[c] = '\0';
  2795. strcpy(statusStr, sstr);
  2796. /**********************data**************************/
  2797. loc = strstr(payload, "data");
  2798. memset(sstr ,0, sizeof(sstr) );
  2799. c = 0;
  2800. while (loc[3+strlen("data")+c] != '\"')
  2801. {
  2802. sstr[c] = loc[3+strlen("data")+c];
  2803. c++;
  2804. }
  2805. sstr[c] = '\0';
  2806. strcpy(dataStr, sstr);
  2807. return result;
  2808. }
  2809. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2810. {
  2811. mtrace();
  2812. int result = FAIL;
  2813. char message[1000]={0};
  2814. double diff_f = 0.0;
  2815. int diff_i = 0;
  2816. int diffSeconds = 0;
  2817. struct tm tp;
  2818. int TimeZero = FALSE;
  2819. int CompositeScheduleIndex = 0;
  2820. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2821. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2822. {
  2823. TimeZero = TRUE;
  2824. }
  2825. else
  2826. {
  2827. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2828. }
  2829. if(TimeZero == FALSE)
  2830. {
  2831. tp.tm_isdst = -1;
  2832. time_t utc = mktime(&tp);
  2833. time_t t = time(NULL);
  2834. diff_f = difftime(t, utc);
  2835. diff_i = (int)diff_f;
  2836. diffSeconds = diff_i % 86400;//86400 seconds/day
  2837. }
  2838. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2839. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2840. #if 0 //remove temporally
  2841. 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}"
  2842. ,MESSAGE_TYPE_CALLRESULT
  2843. ,uuid
  2844. ,payload
  2845. ,connectorIdInt
  2846. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2847. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2848. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2849. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2850. #endif
  2851. if(nPeriod == 0)
  2852. {
  2853. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2854. ,MESSAGE_TYPE_CALLRESULT
  2855. ,uuid
  2856. ,payload
  2857. ,connectorIdInt
  2858. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2859. }
  2860. else
  2861. {
  2862. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2863. ,MESSAGE_TYPE_CALLRESULT
  2864. ,uuid
  2865. ,payload
  2866. ,connectorIdInt
  2867. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2868. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2869. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2870. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2871. int len = nPeriod;
  2872. //Last Period StartPriod is less than diffSeconds
  2873. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2874. {
  2875. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2876. , 0
  2877. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2878. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2879. }
  2880. else
  2881. {
  2882. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2883. {
  2884. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2885. {
  2886. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2887. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2888. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2889. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2890. }
  2891. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2892. {
  2893. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2894. , (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - 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*/))
  2895. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2896. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2897. }
  2898. }
  2899. }
  2900. sprintf(message + strlen(message), "]}}]");
  2901. }
  2902. LWS_Send(message);
  2903. result = TRUE;
  2904. return result;
  2905. }
  2906. int sendGetConfigurationConfirmation(char *uuid)
  2907. {
  2908. mtrace();
  2909. int result = FAIL;
  2910. int MaxKeySupported = 0;
  2911. int sentConfigurationNumber= 0;
  2912. int sentunConfigurationNumber= 0;
  2913. char message[4000]={0};
  2914. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2915. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2916. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2917. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  2918. ,MESSAGE_TYPE_CALLRESULT
  2919. ,uuid );
  2920. //configuration key
  2921. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2922. {
  2923. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2924. {
  2925. if (sentConfigurationNumber == 0)
  2926. {
  2927. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  2928. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2929. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2930. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2931. }
  2932. else
  2933. {
  2934. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2935. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2936. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2937. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2938. }
  2939. sentConfigurationNumber = sentConfigurationNumber + 1;
  2940. }
  2941. }
  2942. sprintf(message + strlen(message), "]");
  2943. if(UnknownKeynum != 0)
  2944. {
  2945. sprintf(message + strlen(message), ",\"unknownKey\":[");
  2946. //unkown key
  2947. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  2948. {
  2949. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  2950. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  2951. if(sentunConfigurationNumber == 0)
  2952. {
  2953. sprintf(message + strlen(message), "\"%s\""
  2954. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2955. }
  2956. else
  2957. {
  2958. sprintf(message + strlen(message), ",\"%s\""
  2959. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2960. }
  2961. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  2962. }
  2963. sprintf(message + strlen(message), "]");
  2964. }
  2965. sprintf(message + strlen(message), "} ]");
  2966. LWS_Send(message);
  2967. return result;
  2968. }
  2969. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  2970. {
  2971. mtrace();
  2972. int result = FAIL;
  2973. char message[400]={0};
  2974. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  2975. if(strcmp(payload,"")==0)
  2976. {
  2977. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  2978. }
  2979. else
  2980. {
  2981. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  2982. }
  2983. LWS_Send(message);
  2984. result = TRUE;
  2985. return result;
  2986. }
  2987. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  2988. {
  2989. mtrace();
  2990. int result = FAIL;
  2991. char message[80]={0};
  2992. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  2993. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  2994. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  2995. LWS_Send(message);
  2996. result = TRUE;
  2997. return result;
  2998. }
  2999. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3000. {
  3001. mtrace();
  3002. int result = FAIL;
  3003. char message[80]={0};
  3004. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3005. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3006. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3007. LWS_Send(message);
  3008. result = TRUE;
  3009. return result;
  3010. }
  3011. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3012. {
  3013. mtrace();
  3014. int result = FAIL;
  3015. char message[80]={0};
  3016. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3017. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3018. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3019. LWS_Send(message);
  3020. result = TRUE;
  3021. return result;
  3022. }
  3023. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3024. {
  3025. mtrace();
  3026. int result = FAIL;
  3027. char message[80]={0};
  3028. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3029. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3030. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3031. LWS_Send(message);
  3032. result = TRUE;
  3033. return result;
  3034. }
  3035. int sendResetConfirmation(char *uuid,char *payload)
  3036. {
  3037. mtrace();
  3038. int result = FAIL;
  3039. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3040. char message[80]={0};
  3041. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3042. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3043. LWS_Send(message);
  3044. result = TRUE;
  3045. return result;
  3046. }
  3047. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3048. {
  3049. mtrace();
  3050. int result = FAIL;
  3051. char message[500]={0};
  3052. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3053. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3054. LWS_Send(message);
  3055. result = TRUE;
  3056. return result;
  3057. }
  3058. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3059. {
  3060. mtrace();
  3061. int result = FAIL;
  3062. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3063. char message[80]={0};
  3064. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3065. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3066. LWS_Send(message);
  3067. result = TRUE;
  3068. return result;
  3069. }
  3070. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3071. {
  3072. mtrace();
  3073. int result = FAIL;
  3074. char message[80]={0};
  3075. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3076. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3077. LWS_Send(message);
  3078. result = TRUE;
  3079. return result;
  3080. }
  3081. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3082. {
  3083. mtrace();
  3084. int result = FAIL;
  3085. char message[80]={0};
  3086. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3087. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3088. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3089. LWS_Send(message);
  3090. result = TRUE;
  3091. return result;
  3092. }
  3093. int sendUpdateFirmwareConfirmation(char *uuid)
  3094. {
  3095. mtrace();
  3096. int result = FAIL;
  3097. char message[60]={0};
  3098. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3099. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3100. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3101. LWS_Send(message);
  3102. result = TRUE;
  3103. return result;
  3104. }
  3105. //==========================================
  3106. // send CallError routine
  3107. //==========================================
  3108. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3109. {
  3110. mtrace();
  3111. //int result = FAIL;
  3112. char message[220]={0};
  3113. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3114. #ifdef SystemLogMessage
  3115. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3116. uniqueId, action, errorCode, errorDescription);
  3117. #endif
  3118. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3119. LWS_Send(message);
  3120. //result = TRUE;
  3121. }
  3122. //==========================================
  3123. // Handle server request routine Start
  3124. //==========================================
  3125. #define GUN_NUM 1
  3126. int handleCancelReservationRequest(char *uuid, char *payload)
  3127. {
  3128. mtrace();
  3129. int result = FAIL;
  3130. int gunNO = 0;
  3131. int reservationIdInt =0;
  3132. char comfirmstr[20];
  3133. int c = 0;
  3134. char *loc;
  3135. char sstr[100]={0};
  3136. DEBUG_INFO("handle CancelReservationRequest\n");
  3137. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3138. c = 0;
  3139. loc = strstr(payload, "reservationId");
  3140. memset(sstr ,0, sizeof(sstr) );
  3141. while (loc[strlen("reservationId")+2+c] != '}')
  3142. {
  3143. sstr[c] = loc[strlen("reservationId")+2+c];
  3144. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3145. c++;
  3146. }
  3147. sstr[c] = '\0';
  3148. reservationIdInt = atoi(sstr);
  3149. memset(comfirmstr, 0, sizeof comfirmstr);
  3150. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3151. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3152. //check Transaction active
  3153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3154. {
  3155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3156. {
  3157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3158. {
  3159. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3160. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3161. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3162. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3163. goto end;
  3164. }
  3165. }
  3166. for (int index = 0; index < CCS_QUANTITY; index++)
  3167. {
  3168. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3169. {
  3170. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3171. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3172. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3173. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3174. goto end;
  3175. }
  3176. }
  3177. for (int index = 0; index < GB_QUANTITY; index++)
  3178. {
  3179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3180. {
  3181. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3182. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3183. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3184. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3185. goto end;
  3186. }
  3187. }
  3188. }
  3189. else
  3190. {
  3191. for (int index = 0; index < AC_QUANTITY; index++)
  3192. {
  3193. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3194. {
  3195. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3196. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3197. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3198. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3199. goto end;
  3200. }
  3201. }
  3202. }// END FOR AC ELSE
  3203. //The reservationId does NOT match the reservationId
  3204. sendCancelReservationConfirmation(uuid, comfirmstr);
  3205. end:
  3206. // Fill in ocpp packet uuid
  3207. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3208. return result;
  3209. }
  3210. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3211. {
  3212. mtrace();
  3213. int result = FAIL;
  3214. int gunIndex = 0;
  3215. char sstr[90]={0};
  3216. char typeStr[16]={0};
  3217. char comfirmstr[20];
  3218. int specificId = FALSE;
  3219. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3220. char *loc;
  3221. //int intervalInt = 0;
  3222. int c = 0;
  3223. /*** connectorId ****/
  3224. c = 0;
  3225. loc = strstr(payload, "connectorId");
  3226. memset(sstr ,0, sizeof(sstr) );
  3227. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3228. {
  3229. sstr[c] = loc[strlen("connectorId")+2+c];
  3230. c++;
  3231. }
  3232. sstr[c] = '\0';
  3233. gunIndex = atoi(sstr);
  3234. /***type ****/
  3235. loc = strstr(payload, "type");
  3236. memset(sstr ,0, sizeof(sstr) );
  3237. c = 0;
  3238. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3239. {
  3240. sstr[c] = loc[3+strlen("type")+c];
  3241. c++;
  3242. }
  3243. sstr[c] = '\0';
  3244. strcpy(typeStr, sstr);
  3245. if(gunIndex != 0)
  3246. {
  3247. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3248. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3249. }
  3250. else
  3251. {
  3252. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3253. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3254. }
  3255. memset(comfirmstr, 0, sizeof comfirmstr);
  3256. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3257. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3258. {
  3259. specificId = TRUE;
  3260. }
  3261. if(specificId == FALSE)
  3262. goto end;
  3263. if(gunIndex != 0)
  3264. {
  3265. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3266. }
  3267. else
  3268. {
  3269. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3270. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3271. }
  3272. /*
  3273. enum SYSTEM_STATUS
  3274. {
  3275. SYS_MODE_BOOTING = 0,
  3276. SYS_MODE_IDLE = 1,
  3277. SYS_MODE_AUTHORIZING = 2,
  3278. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3279. SYS_MODE_REASSIGN = 4,
  3280. SYS_MODE_PREPARING = 5,
  3281. SYS_MODE_PREPARE_FOR_EV = 6,
  3282. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3283. SYS_MODE_CHARGING = 8,
  3284. SYS_MODE_TERMINATING = 9,
  3285. SYS_MODE_COMPLETE = 10,
  3286. SYS_MODE_ALARM = 11,
  3287. SYS_MODE_FAULT = 12,
  3288. SYS_MODE_RESERVATION = 13,
  3289. SYS_MODE_BOOKING = 14,
  3290. SYS_MODE_MAINTAIN = 15,
  3291. SYS_MODE_DEBUG = 16,
  3292. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3293. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3294. SYS_MODE_UPDATE = 19
  3295. };
  3296. */
  3297. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3298. {
  3299. //check Transaction active
  3300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3301. {
  3302. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3303. {
  3304. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3305. {
  3306. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3307. {
  3308. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3309. }
  3310. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3311. {
  3312. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3313. }
  3314. else
  3315. {
  3316. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3317. }
  3318. goto end;
  3319. }
  3320. }//END FOR CHAdeMO_QUANTITY
  3321. for (int index = 0; index < CCS_QUANTITY; index++)
  3322. {
  3323. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3324. {
  3325. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3326. {
  3327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3328. }
  3329. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3330. {
  3331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3332. }
  3333. else
  3334. {
  3335. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3336. }
  3337. goto end;
  3338. }
  3339. }//END FOR CCS_QUANTITY
  3340. for (int index = 0; index < GB_QUANTITY; index++)
  3341. {
  3342. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3343. {
  3344. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3345. {
  3346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3347. }
  3348. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3349. {
  3350. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3351. }
  3352. else
  3353. {
  3354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3355. }
  3356. goto end;
  3357. }
  3358. }// END FOR GB_QUANTITY
  3359. }
  3360. else
  3361. {
  3362. for (int index = 0; index < AC_QUANTITY; index++)
  3363. {
  3364. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3365. {
  3366. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3367. {
  3368. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3369. }
  3370. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3371. {
  3372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3373. }
  3374. else
  3375. {
  3376. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3377. }
  3378. goto end;
  3379. }
  3380. }//END FOR AC_QUANTITY
  3381. }// END FOR AC ELSE
  3382. }//END FOR AvailabilityTypeStr[Inoperative]
  3383. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3384. {
  3385. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3386. //check Transaction active
  3387. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3388. {
  3389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3390. {
  3391. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3392. {
  3393. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3394. goto end;
  3395. }
  3396. }//END FOR CHAdeMO_QUANTITY
  3397. for (int index = 0; index < CCS_QUANTITY; index++)
  3398. {
  3399. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3400. {
  3401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3402. goto end;
  3403. }
  3404. }//END FOR CCS_QUANTITY
  3405. for (int index = 0; index < GB_QUANTITY; index++)
  3406. {
  3407. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3408. {
  3409. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3410. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3411. goto end;
  3412. }
  3413. }// END FOR GB_QUANTITY
  3414. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3415. }
  3416. else
  3417. {
  3418. for (int index = 0; index < AC_QUANTITY; index++)
  3419. {
  3420. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3421. {
  3422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3423. goto end;
  3424. }
  3425. }//END FOR CHAdeMO_QUANTITY
  3426. }//END FOR AC ELSE
  3427. }//END FOR AvailabilityTypeStr[Operative]
  3428. end:
  3429. if(gunIndex != 0)
  3430. {
  3431. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3432. }
  3433. else
  3434. {
  3435. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3436. }
  3437. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3438. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3439. return result;
  3440. }
  3441. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3442. {
  3443. mtrace();
  3444. int result = FAIL;
  3445. char sstr[100]={0};
  3446. char keystr[40]={0};
  3447. char valuestr[100]={0};
  3448. char *loc;
  3449. int c = 0;
  3450. char comfirmstr[20]={0};
  3451. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3452. /***key ****/
  3453. loc = strstr(payload, "key");
  3454. memset(sstr ,0, sizeof(sstr) );
  3455. c = 0;
  3456. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3457. {
  3458. sstr[c] = loc[3+strlen("key")+c];
  3459. c++;
  3460. }
  3461. sstr[c] = '\0';
  3462. strcpy(keystr, sstr);
  3463. //DEBUG_INFO( "keystr=%s\n",keystr);
  3464. /***value ****/
  3465. loc = strstr(payload, "value");
  3466. memset(sstr ,0, sizeof(sstr) );
  3467. c = 0;
  3468. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3469. {
  3470. sstr[c] = loc[3+strlen("value")+c];
  3471. c++;
  3472. }
  3473. sstr[c] = '\0';
  3474. strcpy(valuestr, sstr);
  3475. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3476. if((uuid==NULL) || (payload ==NULL) )
  3477. {
  3478. #ifdef Debug
  3479. DEBUG_INFO("payload is null\n");
  3480. #endif
  3481. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3482. }
  3483. else
  3484. {
  3485. int status = setKeyValue(keystr, valuestr);
  3486. switch(status)
  3487. {
  3488. case ConfigurationStatus_Accepted:
  3489. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3490. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3491. StoreConfigurationTable();
  3492. break;
  3493. case ConfigurationStatus_Rejected:
  3494. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3495. break;
  3496. case RebootRequired:
  3497. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3498. StoreConfigurationTable();
  3499. break;
  3500. case NotSupported:
  3501. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3502. break;
  3503. default:
  3504. break;
  3505. }
  3506. }
  3507. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3508. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3509. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3510. return result;
  3511. }
  3512. int handleClearCacheRequest(char *uuid, char *payload)
  3513. {
  3514. mtrace();
  3515. int result = FAIL;
  3516. char comfirmstr[20];
  3517. int fd;
  3518. char rmFileCmd[100]={0};
  3519. struct stat stats;
  3520. DEBUG_INFO("handle ClearCacheRequest\n");
  3521. stat("../Storage/OCPP", &stats);
  3522. // Check for directory existence
  3523. if (S_ISDIR(stats.st_mode) == 1)
  3524. {
  3525. //DEBUG_ERROR("\n OCPP directory exist \n");
  3526. }
  3527. else
  3528. {
  3529. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3530. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3531. system(rmFileCmd);
  3532. }
  3533. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3534. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3535. {
  3536. DEBUG_INFO("AuthorizationCache file exist.\n");
  3537. }
  3538. else
  3539. {
  3540. DEBUG_INFO("AuthorizationCache file not exist\n");
  3541. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3542. if(log == NULL)
  3543. {
  3544. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3545. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3546. goto end;
  3547. }
  3548. else
  3549. {
  3550. fclose(log);
  3551. }
  3552. }
  3553. fd = open(AuthorizationCache_JSON,O_RDWR);
  3554. if(fd < 0)
  3555. {
  3556. DEBUG_INFO("open AuthorizationCache file failed\n");
  3557. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3558. }
  3559. else
  3560. {
  3561. DEBUG_INFO("open AuthorizationCache file successful\n");
  3562. //* 清空? 件 */
  3563. ftruncate(fd,0);
  3564. //* ? 新设置? 件? 移??*/
  3565. lseek(fd,0,SEEK_SET);
  3566. close(fd);
  3567. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3568. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3569. }
  3570. end:
  3571. sendClearCacheConfirmation(uuid, comfirmstr);
  3572. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3573. return result;
  3574. }
  3575. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3576. {
  3577. mtrace();
  3578. int result = FAIL;
  3579. int resultRename;
  3580. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3581. char chargingProfilePurposeStr[26]={0};
  3582. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3583. char tempchargingProfilePurposeStr[26]={0};
  3584. char sstr[160]={0};//sstr[200]={ 0 };
  3585. char str[100]={0};
  3586. int c = 0;
  3587. //int i = 0;
  3588. //char * pch;
  3589. char *loc;
  3590. char fname[200];
  3591. char comfirmstr[20]={0};
  3592. char word[1000]={0};
  3593. int clearflag = FALSE;
  3594. int chargingProfileIdIsNULL = FALSE;
  3595. int connectorIsNULL = FALSE;
  3596. int chargingProfilePurposeIsNULL = FALSE;
  3597. int stackLevelIsNULL = FALSE;
  3598. FILE *fptr1, *fptr2;
  3599. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3600. int n_chargingProfile=0;
  3601. char sLineWord[1060]={0};
  3602. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3603. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3604. //***id ****/
  3605. c = 0;
  3606. loc = strstr(payload, "id");
  3607. memset(sstr ,0, sizeof(sstr) );
  3608. if(loc == NULL)
  3609. {
  3610. chargingProfileIdIsNULL = TRUE;
  3611. }
  3612. else
  3613. {
  3614. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3615. {
  3616. sstr[c] = loc[strlen("id")+2+c];
  3617. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3618. c++;
  3619. }
  3620. sstr[c] = '\0';
  3621. chargingProfileIdInt = atoi(sstr);
  3622. }
  3623. //***connectorId ****/
  3624. c=0;
  3625. loc = strstr(payload, "connectorId");
  3626. memset(sstr ,0, sizeof(sstr) );
  3627. if(loc == NULL)
  3628. {
  3629. connectorIsNULL = TRUE;
  3630. }
  3631. else
  3632. {
  3633. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3634. {
  3635. sstr[c] = loc[strlen("connectorId")+2+c];
  3636. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3637. c++;
  3638. }
  3639. sstr[c] = '\0';
  3640. connectorIdInt = atoi(sstr);
  3641. }
  3642. //***chargingProfilePurpose ****/
  3643. loc = strstr(payload, "chargingProfilePurpose");
  3644. memset(sstr ,0, sizeof(sstr) );
  3645. c = 0;
  3646. if(loc == NULL)
  3647. {
  3648. chargingProfilePurposeIsNULL = TRUE;
  3649. }
  3650. else
  3651. {
  3652. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3653. {
  3654. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3655. c++;
  3656. }
  3657. sstr[c] = '\0';
  3658. strcpy(chargingProfilePurposeStr, sstr);
  3659. }
  3660. //***stackLevel ****/
  3661. c=0;
  3662. loc = strstr(payload, "stackLevel");
  3663. memset(sstr ,0, sizeof(sstr) );
  3664. if(loc == NULL)
  3665. {
  3666. stackLevelIsNULL = TRUE;
  3667. }
  3668. else
  3669. {
  3670. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3671. {
  3672. sstr[c] = loc[strlen("stackLevel")+2+c];
  3673. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3674. c++;
  3675. }
  3676. sstr[c] = '\0';
  3677. stackLevelInt = atoi(sstr);
  3678. }
  3679. if(connectorIsNULL == FALSE)
  3680. {
  3681. switch(connectorIdInt)
  3682. {
  3683. case 0:
  3684. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3685. {
  3686. strcpy(fname, ChargePointMaxProfile_JSON);
  3687. }
  3688. // else
  3689. // {
  3690. // strcpy(fname, TxDefaultProfile_0_JSON);
  3691. // }
  3692. break;
  3693. case 1:
  3694. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3695. {
  3696. strcpy(fname, TxDefaultProfile_1_JSON);
  3697. }
  3698. // else
  3699. // {
  3700. // strcpy(fname, TxProfile_1_JSON);
  3701. // }
  3702. break;
  3703. case 2:
  3704. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3705. {
  3706. strcpy(fname, TxDefaultProfile_2_JSON);
  3707. }
  3708. // else
  3709. // {
  3710. // strcpy(fname, TxProfile_2_JSON);
  3711. // }
  3712. break;
  3713. default:
  3714. strcpy(fname, ChargePointMaxProfile_JSON );
  3715. break;
  3716. }
  3717. }
  3718. else
  3719. {
  3720. strcpy(fname, ChargePointMaxProfile_JSON );
  3721. }
  3722. fptr1 = fopen(fname, "r");
  3723. if (!fptr1)
  3724. {
  3725. //file not exist
  3726. DEBUG_INFO("Unable to open the input file!!\n");
  3727. fptr1 = fopen(fname, "w+");
  3728. }
  3729. fclose(fptr1);
  3730. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3731. {
  3732. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3733. goto end;
  3734. }
  3735. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3736. {
  3737. //clear the whole contents of a file in C
  3738. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3739. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3740. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3741. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3742. fclose(fopen(TxProfile_1_JSON, "w"));
  3743. fclose(fopen(TxProfile_2_JSON, "w"));
  3744. #if 0
  3745. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3746. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3747. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3748. #endif
  3749. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3750. }
  3751. else
  3752. {
  3753. fptr1 = fopen(fname, "r");
  3754. fptr2 = fopen(temp, "w+");
  3755. while(fscanf(fptr1, "%s", word) != EOF)
  3756. {
  3757. //DEBUG_INFO("word=%s\n",word);
  3758. if(strcmp(word, "chargingProfileId") == 0)
  3759. {
  3760. n_chargingProfile = n_chargingProfile + 1;
  3761. DEBUG_INFO("chargingProfileId Found\n");
  3762. }
  3763. }
  3764. rewind(fptr1);
  3765. //search Charging Profile Element
  3766. //int i= 0;
  3767. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3768. {
  3769. //*************************tempconnectorIdInt*********************************/
  3770. loc = strstr(sLineWord, "connectorId");
  3771. c = 0;
  3772. memset(sstr ,0, sizeof(sstr) );
  3773. while (loc[strlen("connectorId")+2+c] != ',')
  3774. {
  3775. sstr[c] = loc[strlen("connectorId")+2+c];
  3776. c++;
  3777. }
  3778. sstr[c] = '\0';
  3779. tempconnectorIdInt = atoi(sstr);
  3780. //chargingProfileId
  3781. c = 0;
  3782. loc = strstr(sLineWord, "chargingProfileId");
  3783. memset(sstr ,0, sizeof(sstr) );
  3784. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3785. {
  3786. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3787. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3788. c++;
  3789. }
  3790. sstr[c] = '\0';
  3791. tempchargingProfileIdInt = atoi(sstr);
  3792. //stackLevel
  3793. c = 0;
  3794. loc = strstr(sLineWord, "stackLevel");
  3795. memset(sstr ,0, sizeof(sstr) );
  3796. while (loc[strlen("stackLevel")+2+c] != ',')
  3797. {
  3798. sstr[c] = loc[strlen("stackLevel")+2+c];
  3799. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3800. c++;
  3801. }
  3802. sstr[c] = '\0';
  3803. tempstackLevelInt = atoi(sstr);
  3804. c = 0;
  3805. loc = strstr(sLineWord, "chargingProfilePurpose");
  3806. memset(sstr ,0, sizeof(sstr) );
  3807. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3808. {
  3809. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3810. c++;
  3811. }
  3812. sstr[c] = '\0';
  3813. strcpy(tempchargingProfilePurposeStr, sstr);
  3814. if(chargingProfileIdIsNULL == FALSE)
  3815. {
  3816. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3817. {
  3818. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3819. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3820. clearflag = TRUE;
  3821. continue;
  3822. }
  3823. else
  3824. {
  3825. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3826. //json_object_array_add(newHeatMap, jsonitem);
  3827. fprintf(fptr2, sLineWord);//writing data into file
  3828. }
  3829. }
  3830. else
  3831. {
  3832. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3833. {
  3834. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3835. {
  3836. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3837. clearflag = TRUE;
  3838. continue;
  3839. }
  3840. }
  3841. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3842. {
  3843. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3844. {
  3845. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3846. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3847. {
  3848. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3849. clearflag = TRUE;
  3850. continue;
  3851. }
  3852. }
  3853. }
  3854. else
  3855. {
  3856. //json_object_array_add(newHeatMap, jsonitem);
  3857. fprintf(fptr2, sLineWord);//writing data into file
  3858. }
  3859. }
  3860. memset(sLineWord, 0, sizeof sLineWord);
  3861. }
  3862. if(clearflag == FALSE)
  3863. {
  3864. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3865. goto end;
  3866. }
  3867. fclose(fptr1);
  3868. fclose(fptr2);
  3869. sprintf(str,"rm -f %s",fname);
  3870. system(str);
  3871. resultRename = rename(temp, fname);
  3872. if(resultRename == 0)
  3873. {
  3874. DEBUG_INFO("File ChargingProfile renamed successfully");
  3875. }
  3876. else
  3877. {
  3878. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  3879. }
  3880. }
  3881. end:
  3882. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3883. return result;
  3884. }
  3885. int handleDataTransferRequest(char *uuid, char *payload)
  3886. {
  3887. mtrace();
  3888. int result = FAIL;
  3889. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  3890. char tempvendorId[255]={0};
  3891. char tempmessageId[50]={0};
  3892. char tempdata[50]={0};
  3893. char sstr[160]={0};//sstr[200]={ 0 };
  3894. char message[80]={0};
  3895. int c = 0;
  3896. char *loc;
  3897. DEBUG_INFO("handle DataTransferRequest\n");
  3898. if((uuid != NULL) && (payload != NULL))
  3899. {
  3900. //===============================
  3901. // vendorId
  3902. //===============================
  3903. c = 0;
  3904. loc = strstr(payload, "vendorId");
  3905. while (loc[strlen("vendorId")+3+c] != '\"')
  3906. {
  3907. sstr[c] = loc[strlen("vendorId")+3+c];
  3908. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3909. c++;
  3910. }
  3911. sstr[c] = '\0';
  3912. strcpy(tempvendorId,sstr);
  3913. //===============================
  3914. // messageId
  3915. //===============================
  3916. memset(sstr ,0, sizeof(sstr) );
  3917. c = 0;
  3918. loc = strstr(payload, "messageId");
  3919. while (loc[strlen("messageId")+3+c] != '\"')
  3920. {
  3921. sstr[c] = loc[strlen("messageId")+3+c];
  3922. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3923. c++;
  3924. }
  3925. sstr[c] = '\0';
  3926. strcpy(tempmessageId,sstr);
  3927. //===============================
  3928. // data
  3929. //===============================
  3930. memset(sstr ,0, sizeof(sstr) );
  3931. c = 0;
  3932. loc = strstr(payload, "data");
  3933. printf("loc=%s\n",loc);
  3934. while (loc[strlen("data")+3+c] != '\"')
  3935. {
  3936. sstr[c] = loc[strlen("data")+3+c];
  3937. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3938. c++;
  3939. }
  3940. sstr[c] = '\0';
  3941. strcpy(tempdata,sstr);
  3942. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  3943. }
  3944. else
  3945. {
  3946. char guid[37]={0};
  3947. random_uuid(guid);
  3948. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  3949. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  3950. }
  3951. LWS_Send(message);
  3952. return result;
  3953. }
  3954. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  3955. {
  3956. mtrace();
  3957. int result = FAIL;
  3958. int connectorIdInt, durationInt;
  3959. char chargingRateUnitStr[4]={0};
  3960. //int tempconnectorIdInt,
  3961. int tempdurationInt;
  3962. float tempminChargingRateFloat = 0.0;
  3963. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  3964. int tempStartPeriodInt=0;
  3965. float tempLimitInt=0.0;//0.1;
  3966. int tempNumberPhasesInt=0;
  3967. char fname[200];
  3968. char comfirmstr[20];
  3969. //float totallimit =0.0;
  3970. float MinChargingRate =0.0;
  3971. //double diff_t;
  3972. //struct tm tp;
  3973. FILE *fptr1;
  3974. int c = 0;
  3975. //int i = 0;
  3976. char * pch;
  3977. char *loc;
  3978. char sstr[200]={ 0 };
  3979. int n_chargingProfile = 0;
  3980. int n_SchedulePeriods = 0;
  3981. char SchedulePeriodList[10][200]={0};
  3982. char sLineWord[800]={0};
  3983. //int n_periods = 0;
  3984. char word[1000]={0};
  3985. int confirmPeriods = 0;
  3986. struct StructProfile ChargePointMaxProfile;
  3987. struct StructProfile TxDefaultProfile;
  3988. struct StructProfile TxProfile;
  3989. struct StructProfile TxDefaultProfiletemp[2]={0};
  3990. int TxDefaultProfileFileIsNull=FALSE;
  3991. int ChargePointMaxProfileIsNull=FALSE;
  3992. int TxProfileIsNull=FALSE;
  3993. int CompositeSceduleIndex = 0;
  3994. char ChargePointMaxProfileScheduleStr[30]={0};
  3995. char TxDefaultProfileScheduleStr[30]={0};
  3996. char TxProfileScheduleStr[30]={0};
  3997. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  3998. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  3999. memset(&TxProfile,0,sizeof(struct StructProfile));
  4000. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4001. c=0;
  4002. loc = strstr(payload, "connectorId");
  4003. memset(sstr ,0, sizeof(sstr) );
  4004. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4005. {
  4006. sstr[c] = loc[strlen("connectorId")+2+c];
  4007. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4008. c++;
  4009. }
  4010. sstr[c] = '\0';
  4011. connectorIdInt = atoi(sstr);
  4012. c=0;
  4013. loc = strstr(payload, "duration");
  4014. memset(sstr ,0, sizeof(sstr) );
  4015. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4016. {
  4017. sstr[c] = loc[strlen("duration")+2+c];
  4018. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4019. c++;
  4020. }
  4021. sstr[c] = '\0';
  4022. durationInt = atoi(sstr);
  4023. c = 0;
  4024. loc = strstr(payload, "chargingRateUnit");
  4025. memset(sstr ,0, sizeof(sstr) );
  4026. if(loc == NULL)
  4027. {
  4028. }
  4029. else
  4030. {
  4031. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4032. {
  4033. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4034. c++;
  4035. }
  4036. sstr[c] = '\0';
  4037. strcpy(chargingRateUnitStr, sstr);
  4038. }
  4039. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4040. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4041. if(connectorIdInt==0) // connectorId is 0
  4042. {
  4043. //******************************ChargePointMaxProfile*****************************************************/
  4044. strcpy(fname, ChargePointMaxProfile_JSON );
  4045. char word[30]={0};
  4046. char sLineWord[1060]={0};
  4047. int n_chargingProfile=0;
  4048. ChargePointMaxProfileIsNull=TRUE;
  4049. if((access(fname,F_OK))!=-1)
  4050. {
  4051. fptr1 = fopen(fname, "r");
  4052. int c;
  4053. c = fgetc(fptr1);
  4054. //DEBUG_INFO("c:%d\n",c);
  4055. rewind(fptr1);
  4056. if(c == EOF)
  4057. {
  4058. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4059. ChargePointMaxProfileIsNull=TRUE;
  4060. fclose(fptr1);
  4061. }
  4062. else
  4063. {
  4064. ChargePointMaxProfileIsNull=FALSE;
  4065. while(fscanf(fptr1, "%s", word) != EOF)
  4066. {
  4067. if(strcmp(word, "chargingProfileId") == 0)
  4068. {
  4069. n_chargingProfile = n_chargingProfile + 1;
  4070. printf("Found\n");
  4071. }
  4072. }
  4073. rewind(fptr1);
  4074. //search Charging Profile Element
  4075. int i= 0;
  4076. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4077. #if 0
  4078. /***********connectorId****************/
  4079. c = 0;
  4080. loc = strstr(sLineWord, "connectorId");
  4081. // printf("loc=%s\n",loc);
  4082. memset(sstr ,0, sizeof(sstr) );
  4083. while (loc[strlen("connectorId")+2+c] != ',')
  4084. {
  4085. sstr[c] = loc[strlen("connectorId")+2+c];
  4086. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4087. c++;
  4088. }
  4089. sstr[c] = '\0';
  4090. tempconnectorIdInt = atoi(sstr);
  4091. #endif
  4092. //***********validFrom**************/
  4093. c = 0;
  4094. loc = strstr(sLineWord, "validFrom");
  4095. //DEBUG_INFO("loc=%s\n",loc);
  4096. memset(sstr ,0, sizeof(sstr) );
  4097. if(loc != NULL)
  4098. {
  4099. while (loc[3+strlen("validFrom")+c] != '\"')
  4100. {
  4101. sstr[c] = loc[3+strlen("validFrom")+c];
  4102. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4103. c++;
  4104. }
  4105. sstr[c] = '\0';
  4106. DEBUG_INFO("validFrom=%s\n",sstr);
  4107. strcpy(tempvalidFromStr,sstr);
  4108. }
  4109. else
  4110. {
  4111. strcpy(tempvalidFromStr,"");
  4112. }
  4113. //**********startSchedule**********/
  4114. c = 0;
  4115. loc = strstr(sLineWord, "startSchedule");
  4116. //DEBUG_INFO("loc=%s\n",loc);
  4117. memset(sstr ,0, sizeof(sstr) );
  4118. while (loc[3+strlen("startSchedule")+c] != '\"')
  4119. {
  4120. sstr[c] = loc[3+strlen("startSchedule")+c];
  4121. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4122. c++;
  4123. }
  4124. sstr[c] = '\0';
  4125. strcpy(tempstartScheduleStr, sstr);
  4126. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4127. //**********chargingRateUnit**********/
  4128. c = 0;
  4129. loc = strstr(sLineWord, "chargingRateUnit");
  4130. memset(sstr ,0, sizeof(sstr) );
  4131. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4132. {
  4133. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4134. c++;
  4135. }
  4136. sstr[c] = '\0';
  4137. strcpy(tempchargingRateUnitStr, sstr);
  4138. //**********minChargingRate*******/
  4139. c = 0;
  4140. loc = strstr(sLineWord, "minChargingRate");
  4141. //printf("loc=%s\n",loc);
  4142. if(loc != NULL)
  4143. {
  4144. memset(sstr ,0, sizeof(sstr) );
  4145. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4146. {
  4147. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4148. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4149. c++;
  4150. }
  4151. sstr[c] = '\0';
  4152. tempminChargingRateFloat = atof(sstr);
  4153. }
  4154. else
  4155. {
  4156. tempminChargingRateFloat = 0.0;
  4157. }
  4158. //
  4159. #if 0
  4160. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4161. tp.tm_isdst = -1;
  4162. time_t utc = mktime(&tp);
  4163. // current time
  4164. time_t t = time(NULL);
  4165. #endif
  4166. //diff_t = difftime(t, utc);
  4167. //parsing strings to words
  4168. i = 0;
  4169. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4170. loc = loc+3+strlen("chargingSchedulePeriod");
  4171. pch = strtok(loc ,"{");
  4172. while (pch != NULL)
  4173. {
  4174. strcpy(SchedulePeriodList[i], pch);
  4175. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4176. //printf ("%s\n",pch);
  4177. pch = strtok (NULL, "{");
  4178. i = i + 1;
  4179. }
  4180. n_SchedulePeriods = i;
  4181. for(int i=0;i<n_SchedulePeriods;i++)
  4182. {
  4183. //*************startPeriod****************/
  4184. c = 0;
  4185. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4186. memset(sstr ,0, sizeof(sstr) );
  4187. while (loc[strlen("startPeriod")+2+c] != ',')
  4188. {
  4189. sstr[c] = loc[strlen("startPeriod")+2+c];
  4190. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4191. c++;
  4192. }
  4193. sstr[c] = '\0';
  4194. tempStartPeriodInt = atoi(sstr);
  4195. //*************limit****************/
  4196. c = 0;
  4197. loc = strstr(SchedulePeriodList[i], "limit");
  4198. memset(sstr ,0, sizeof(sstr) );
  4199. while (loc[strlen("limit")+2+c] != ',')
  4200. {
  4201. sstr[c] = loc[strlen("limit")+2+c];
  4202. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4203. c++;
  4204. }
  4205. sstr[c] = '\0';
  4206. tempLimitInt = atof(sstr);
  4207. //*************numberPhases****************/
  4208. c = 0;
  4209. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4210. memset(sstr ,0, sizeof(sstr) );
  4211. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4212. {
  4213. sstr[c] = loc[strlen("numberPhases")+2+c];
  4214. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4215. c++;
  4216. }
  4217. sstr[c] = '\0';
  4218. tempNumberPhasesInt = atoi(sstr);
  4219. ChargePointMaxProfile.Duration = durationInt;
  4220. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4221. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4222. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4223. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4224. }
  4225. if(MinChargingRate < tempminChargingRateFloat)
  4226. MinChargingRate = tempminChargingRateFloat;
  4227. }
  4228. }// End of file ChargingProfile
  4229. } //THE END OF ACCESS ChargePointMaxProfile
  4230. //******************************TxDefaultProfile***********************************************/
  4231. strcpy(fname, TxDefaultProfile_0_JSON);
  4232. memset(word, 0, 30);
  4233. memset(sLineWord, 0, 1060);
  4234. //char word[30]={0};
  4235. //char sLineWord[1060]={0};
  4236. n_chargingProfile=0;
  4237. TxDefaultProfileFileIsNull=TRUE;
  4238. if((access(fname,F_OK))!=-1)
  4239. {
  4240. fptr1 = fopen(fname, "r");
  4241. c = 0;
  4242. c = fgetc(fptr1);
  4243. //DEBUG_INFO("c:%d\n",c);
  4244. rewind(fptr1);
  4245. if(c == EOF)
  4246. {
  4247. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4248. TxDefaultProfileFileIsNull=TRUE;
  4249. fclose(fptr1);
  4250. }
  4251. else
  4252. {
  4253. TxDefaultProfileFileIsNull=FALSE;
  4254. while(fscanf(fptr1, "%s", word) != EOF)
  4255. {
  4256. if(strcmp(word, "chargingProfileId") == 0)
  4257. {
  4258. n_chargingProfile = n_chargingProfile + 1;
  4259. printf("Found\n");
  4260. }
  4261. }
  4262. rewind(fptr1);
  4263. //search Charging Profile Element
  4264. int i= 0;
  4265. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4266. #if 0
  4267. /***********connectorId****************/
  4268. c = 0;
  4269. loc = strstr(sLineWord, "connectorId");
  4270. // printf("loc=%s\n",loc);
  4271. memset(sstr ,0, sizeof(sstr) );
  4272. while (loc[strlen("connectorId")+2+c] != ',')
  4273. {
  4274. sstr[c] = loc[strlen("connectorId")+2+c];
  4275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4276. c++;
  4277. }
  4278. sstr[c] = '\0';
  4279. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4280. tempconnectorIdInt = atoi(sstr);
  4281. #endif
  4282. //***********validFrom**************/
  4283. c = 0;
  4284. loc = strstr(sLineWord, "validFrom");
  4285. //DEBUG_INFO("loc=%s\n",loc);
  4286. memset(sstr ,0, sizeof(sstr) );
  4287. if(loc != NULL)
  4288. {
  4289. while (loc[3+strlen("validFrom")+c] != '\"')
  4290. {
  4291. sstr[c] = loc[3+strlen("validFrom")+c];
  4292. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4293. c++;
  4294. }
  4295. sstr[c] = '\0';
  4296. DEBUG_INFO("validFrom=%s\n",sstr);
  4297. strcpy(tempvalidFromStr,sstr);
  4298. }
  4299. else
  4300. {
  4301. strcpy(tempvalidFromStr,"");
  4302. }
  4303. //**********startSchedule**********/
  4304. c = 0;
  4305. loc = strstr(sLineWord, "startSchedule");
  4306. //DEBUG_INFO("loc=%s\n",loc);
  4307. memset(sstr ,0, sizeof(sstr) );
  4308. while (loc[3+strlen("startSchedule")+c] != '\"')
  4309. {
  4310. sstr[c] = loc[3+strlen("startSchedule")+c];
  4311. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4312. c++;
  4313. }
  4314. sstr[c] = '\0';
  4315. strcpy(tempstartScheduleStr, sstr);
  4316. strcpy(TxDefaultProfileScheduleStr, sstr);
  4317. DEBUG_INFO(" debug 3-1\n");
  4318. //**********chargingRateUnit**********/
  4319. c = 0;
  4320. loc = strstr(sLineWord, "chargingRateUnit");
  4321. memset(sstr ,0, sizeof(sstr) );
  4322. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4323. {
  4324. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4325. c++;
  4326. }
  4327. sstr[c] = '\0';
  4328. strcpy(tempchargingRateUnitStr, sstr);
  4329. //**********minChargingRate*******/
  4330. c = 0;
  4331. loc = strstr(sLineWord, "minChargingRate");
  4332. //printf("loc=%s\n",loc);
  4333. if(loc != NULL)
  4334. {
  4335. memset(sstr ,0, sizeof(sstr) );
  4336. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4337. {
  4338. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4339. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4340. c++;
  4341. }
  4342. sstr[c] = '\0';
  4343. tempminChargingRateFloat = atof(sstr);
  4344. }
  4345. else
  4346. {
  4347. tempminChargingRateFloat = 0.0;
  4348. }
  4349. #if 0
  4350. //
  4351. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4352. tp.tm_isdst = -1;
  4353. time_t utc = mktime(&tp);
  4354. // current time
  4355. time_t t = time(NULL);
  4356. //diff_t = difftime(t, utc);
  4357. #endif
  4358. //parsing strings to words
  4359. i = 0;
  4360. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4361. loc = loc+3+strlen("chargingSchedulePeriod");
  4362. pch = strtok(loc ,"{");
  4363. while (pch != NULL)
  4364. {
  4365. strcpy(SchedulePeriodList[i], pch);
  4366. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4367. //printf ("%s\n",pch);
  4368. pch = strtok (NULL, "{");
  4369. i = i + 1;
  4370. }
  4371. n_SchedulePeriods = i;
  4372. for(int i=0;i<n_SchedulePeriods;i++)
  4373. {
  4374. //*************startPeriod****************/
  4375. c = 0;
  4376. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4377. memset(sstr ,0, sizeof(sstr) );
  4378. while (loc[strlen("startPeriod")+2+c] != ',')
  4379. {
  4380. sstr[c] = loc[strlen("startPeriod")+2+c];
  4381. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4382. c++;
  4383. }
  4384. sstr[c] = '\0';
  4385. tempStartPeriodInt = atoi(sstr);
  4386. //*************limit****************/
  4387. c = 0;
  4388. loc = strstr(SchedulePeriodList[i], "limit");
  4389. memset(sstr ,0, sizeof(sstr) );
  4390. while (loc[strlen("limit")+2+c] != ',')
  4391. {
  4392. sstr[c] = loc[strlen("limit")+2+c];
  4393. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4394. c++;
  4395. }
  4396. sstr[c] = '\0';
  4397. tempLimitInt = atof(sstr);
  4398. //*************numberPhases****************/
  4399. c = 0;
  4400. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4401. memset(sstr ,0, sizeof(sstr) );
  4402. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4403. {
  4404. sstr[c] = loc[strlen("numberPhases")+2+c];
  4405. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4406. c++;
  4407. }
  4408. sstr[c] = '\0';
  4409. tempNumberPhasesInt = atoi(sstr);
  4410. TxDefaultProfile.Duration = durationInt;
  4411. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4412. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4413. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4414. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4415. }
  4416. if(MinChargingRate < tempminChargingRateFloat)
  4417. MinChargingRate = tempminChargingRateFloat;
  4418. }
  4419. }
  4420. }// the end of ACCESS TxDefaultProfile
  4421. // Composite Schedule
  4422. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4423. {
  4424. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4425. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4426. {
  4427. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4428. {
  4429. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4430. }
  4431. else
  4432. {
  4433. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4434. }
  4435. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4436. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4437. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4438. }
  4439. }
  4440. //* Define temporary variables */
  4441. struct tm *gtime;
  4442. time_t now;
  4443. char buf[28];
  4444. /* Read the current system time */
  4445. time(&now);
  4446. /* Convert the system time to GMT (now UTC) */
  4447. gtime = gmtime(&now);
  4448. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4449. // make .conf
  4450. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4451. //MaxChargingProfilesInstalled is 10
  4452. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4453. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4454. //nPeriod = 1;
  4455. if(chargingRateUnitStr[0] != 0)
  4456. {
  4457. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4458. }
  4459. else
  4460. {
  4461. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4462. }
  4463. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4464. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4465. confirmPeriods = 1;
  4466. }
  4467. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4468. {
  4469. //*****************************ChargePointMaxProfile******************************************/
  4470. strcpy(fname, ChargePointMaxProfile_JSON);
  4471. ChargePointMaxProfileIsNull=TRUE;
  4472. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4473. {
  4474. fptr1 = fopen(fname, "r");
  4475. int c;
  4476. c = fgetc(fptr1);
  4477. //DEBUG_INFO("c:%d\n",c);
  4478. rewind(fptr1);
  4479. if(c == EOF)
  4480. {
  4481. DEBUG_INFO("\n End of file reached.");
  4482. ChargePointMaxProfileIsNull=TRUE;
  4483. fclose(fptr1);
  4484. }
  4485. else
  4486. {
  4487. ChargePointMaxProfileIsNull=FALSE;
  4488. while(fscanf(fptr1, "%s", word) != EOF)
  4489. {
  4490. if(strcmp(word, "chargingProfileId") == 0)
  4491. {
  4492. n_chargingProfile = n_chargingProfile + 1;
  4493. }
  4494. }
  4495. rewind(fptr1);
  4496. //search Charging Profile Element
  4497. int i = 0;
  4498. int j = 0;
  4499. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4500. #if 0
  4501. /***********connectorId****************/
  4502. c = 0;
  4503. loc = strstr(sLineWord, "connectorId");
  4504. memset(sstr ,0, sizeof(sstr) );
  4505. while (loc[strlen("connectorId")+2+c] != ',')
  4506. {
  4507. sstr[c] = loc[strlen("connectorId")+2+c];
  4508. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4509. c++;
  4510. }
  4511. sstr[c] = '\0';
  4512. tempconnectorIdInt = atoi(sstr);
  4513. #endif
  4514. //***********validFrom**************/
  4515. c = 0;
  4516. loc = strstr(sLineWord, "validFrom");
  4517. if(loc != NULL)
  4518. {
  4519. memset(sstr ,0, sizeof(sstr) );
  4520. while (loc[3+strlen("validFrom")+c] != '\"')
  4521. {
  4522. sstr[c] = loc[3+strlen("validFrom")+c];
  4523. c++;
  4524. }
  4525. sstr[c] = '\0';
  4526. strcpy(tempvalidFromStr,sstr);
  4527. }
  4528. else
  4529. {
  4530. strcpy(tempvalidFromStr,"");
  4531. }
  4532. //***********validFrom**************/
  4533. c = 0;
  4534. loc = strstr(sLineWord, "duration");
  4535. if(loc != NULL)
  4536. {
  4537. memset(sstr ,0, sizeof(sstr) );
  4538. while (loc[2+strlen("duration")+c] != ',')
  4539. {
  4540. sstr[c] = loc[2+strlen("duration")+c];
  4541. c++;
  4542. }
  4543. sstr[c] = '\0';
  4544. tempdurationInt = atoi(sstr);
  4545. }
  4546. else
  4547. {
  4548. tempdurationInt = 0;
  4549. }
  4550. //**********startSchedule**********/
  4551. c = 0;
  4552. loc = strstr(sLineWord, "startSchedule");
  4553. memset(sstr ,0, sizeof(sstr) );
  4554. while (loc[3+strlen("startSchedule")+c] != '\"')
  4555. {
  4556. sstr[c] = loc[3+strlen("startSchedule")+c];
  4557. c++;
  4558. }
  4559. sstr[c] = '\0';
  4560. strcpy(tempstartScheduleStr, sstr);
  4561. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4562. //**********chargingRateUnit**********/
  4563. c = 0;
  4564. loc = strstr(sLineWord, "chargingRateUnit");
  4565. memset(sstr ,0, sizeof(sstr) );
  4566. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4567. {
  4568. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4569. c++;
  4570. }
  4571. sstr[c] = '\0';
  4572. strcpy(tempchargingRateUnitStr, sstr);
  4573. //**********minChargingRate*******/
  4574. c = 0;
  4575. loc = strstr(sLineWord, "minChargingRate");
  4576. if(loc != NULL)
  4577. {
  4578. memset(sstr ,0, sizeof(sstr) );
  4579. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4580. {
  4581. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4582. c++;
  4583. }
  4584. sstr[c] = '\0';
  4585. tempminChargingRateFloat = atof(sstr);
  4586. }
  4587. else
  4588. {
  4589. tempminChargingRateFloat = 0.0;
  4590. }
  4591. #if 0
  4592. //
  4593. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4594. tp.tm_isdst = -1;
  4595. time_t utc = mktime(&tp);
  4596. time_t t = time(NULL);
  4597. //diff_t = difftime(t, utc);
  4598. #endif
  4599. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4600. //DEBUG_INFO(" debug 5 -1\n");
  4601. //parsing strings to words
  4602. i = 0;
  4603. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4604. loc = loc+3+strlen("chargingSchedulePeriod");
  4605. pch = strtok(loc ,"{");
  4606. while (pch != NULL)
  4607. {
  4608. strcpy(SchedulePeriodList[i], pch);
  4609. pch = strtok (NULL, "{");
  4610. i = i + 1;
  4611. }
  4612. n_SchedulePeriods = i;
  4613. for(int i=0;i<n_SchedulePeriods;i++)
  4614. {
  4615. //*************startPeriod****************/
  4616. c = 0;
  4617. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4618. memset(sstr ,0, sizeof(sstr) );
  4619. while (loc[strlen("startPeriod")+2+c] != ',')
  4620. {
  4621. sstr[c] = loc[strlen("startPeriod")+2+c];
  4622. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4623. c++;
  4624. }
  4625. sstr[c] = '\0';
  4626. tempStartPeriodInt = atoi(sstr);
  4627. //*************limit****************/
  4628. c = 0;
  4629. loc = strstr(SchedulePeriodList[i], "limit");
  4630. memset(sstr ,0, sizeof(sstr) );
  4631. while (loc[strlen("limit")+2+c] != ',')
  4632. {
  4633. sstr[c] = loc[strlen("limit")+2+c];
  4634. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4635. c++;
  4636. }
  4637. sstr[c] = '\0';
  4638. tempLimitInt = atof(sstr);
  4639. //*************numberPhases****************/
  4640. c = 0;
  4641. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4642. memset(sstr ,0, sizeof(sstr) );
  4643. while (loc[strlen("numberPhases")+2+c] != '}')
  4644. {
  4645. sstr[c] = loc[strlen("numberPhases")+2+c];
  4646. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4647. c++;
  4648. }
  4649. sstr[c] = '\0';
  4650. tempNumberPhasesInt = atoi(sstr);
  4651. if(j == 0)
  4652. {
  4653. ChargePointMaxProfile.Duration = tempdurationInt;
  4654. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4655. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4656. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4657. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4658. }
  4659. }
  4660. if(MinChargingRate < tempminChargingRateFloat)
  4661. {
  4662. MinChargingRate = tempminChargingRateFloat;
  4663. }
  4664. if(confirmPeriods < n_SchedulePeriods)
  4665. {
  4666. confirmPeriods = n_SchedulePeriods;
  4667. }
  4668. j = j + 1;
  4669. }
  4670. fclose(fptr1);
  4671. }
  4672. }// the end of access file ChargePointMaxProfile
  4673. //****************************TxDefaultProfile************************************************/
  4674. switch(connectorIdInt)
  4675. {
  4676. case 0:
  4677. break;
  4678. case 1:
  4679. strcpy(fname, TxDefaultProfile_1_JSON );
  4680. break;
  4681. case 2:
  4682. strcpy(fname, TxDefaultProfile_2_JSON );
  4683. break;
  4684. default:
  4685. strcpy(fname, TxDefaultProfile_1_JSON );
  4686. break;
  4687. }
  4688. TxDefaultProfileFileIsNull=TRUE;
  4689. if((access(fname,F_OK))!=-1)
  4690. {
  4691. fptr1 = fopen(fname, "r");
  4692. c = 0;
  4693. c = fgetc(fptr1);
  4694. //DEBUG_INFO("c:%d\n",c);
  4695. rewind(fptr1);
  4696. if(c == EOF)
  4697. {
  4698. DEBUG_INFO("\n End of file reached.");
  4699. TxDefaultProfileFileIsNull=TRUE;
  4700. fclose(fptr1);
  4701. }
  4702. else
  4703. {
  4704. TxDefaultProfileFileIsNull=FALSE;
  4705. while(fscanf(fptr1, "%s", word) != EOF)
  4706. {
  4707. if(strcmp(word, "chargingProfileId") == 0)
  4708. {
  4709. n_chargingProfile = n_chargingProfile + 1;
  4710. }
  4711. }
  4712. rewind(fptr1);
  4713. //search Charging Profile Element
  4714. int i = 0;
  4715. int j = 0;
  4716. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4717. //DEBUG_INFO(" 1-1\n");
  4718. #if 0
  4719. /***********connectorId****************/
  4720. c = 0;
  4721. loc = strstr(sLineWord, "connectorId");
  4722. memset(sstr ,0, sizeof(sstr) );
  4723. while (loc[strlen("connectorId")+2+c] != ',')
  4724. {
  4725. sstr[c] = loc[strlen("connectorId")+2+c];
  4726. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4727. c++;
  4728. }
  4729. sstr[c] = '\0';
  4730. tempconnectorIdInt = atoi(sstr);
  4731. #endif
  4732. //***********validFrom**************/
  4733. c = 0;
  4734. loc = strstr(sLineWord, "validFrom");
  4735. if(loc != NULL)
  4736. {
  4737. memset(sstr ,0, sizeof(sstr) );
  4738. while (loc[3+strlen("validFrom")+c] != '\"')
  4739. {
  4740. sstr[c] = loc[3+strlen("validFrom")+c];
  4741. c++;
  4742. }
  4743. sstr[c] = '\0';
  4744. strcpy(tempvalidFromStr,sstr);
  4745. }
  4746. else
  4747. {
  4748. strcpy(tempvalidFromStr,"");
  4749. }
  4750. //***********validFrom**************/
  4751. c = 0;
  4752. loc = strstr(sLineWord, "duration");
  4753. if(loc != NULL)
  4754. {
  4755. memset(sstr ,0, sizeof(sstr) );
  4756. while (loc[2+strlen("duration")+c] != ',')
  4757. {
  4758. sstr[c] = loc[2+strlen("duration")+c];
  4759. c++;
  4760. }
  4761. sstr[c] = '\0';
  4762. tempdurationInt = atoi(sstr);
  4763. }
  4764. else
  4765. {
  4766. tempdurationInt = 0;
  4767. }
  4768. //**********startSchedule**********/
  4769. c = 0;
  4770. loc = strstr(sLineWord, "startSchedule");
  4771. memset(sstr ,0, sizeof(sstr) );
  4772. while (loc[3+strlen("startSchedule")+c] != '\"')
  4773. {
  4774. sstr[c] = loc[3+strlen("startSchedule")+c];
  4775. c++;
  4776. }
  4777. sstr[c] = '\0';
  4778. strcpy(tempstartScheduleStr, sstr);
  4779. strcpy(TxDefaultProfileScheduleStr, sstr);
  4780. //**********chargingRateUnit**********/
  4781. c = 0;
  4782. loc = strstr(sLineWord, "chargingRateUnit");
  4783. memset(sstr ,0, sizeof(sstr) );
  4784. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4785. {
  4786. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4787. c++;
  4788. }
  4789. sstr[c] = '\0';
  4790. strcpy(tempchargingRateUnitStr, sstr);
  4791. //**********minChargingRate*******/
  4792. c = 0;
  4793. loc = strstr(sLineWord, "minChargingRate");
  4794. if(loc != NULL)
  4795. {
  4796. memset(sstr ,0, sizeof(sstr) );
  4797. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4798. {
  4799. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4800. c++;
  4801. }
  4802. sstr[c] = '\0';
  4803. tempminChargingRateFloat = atof(sstr);
  4804. }
  4805. else
  4806. {
  4807. tempminChargingRateFloat = 0.0;
  4808. }
  4809. #if 0
  4810. //
  4811. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4812. tp.tm_isdst = -1;
  4813. time_t utc = mktime(&tp);
  4814. time_t t = time(NULL);
  4815. //diff_t = difftime(t, utc);
  4816. #endif
  4817. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4818. //parsing strings to words
  4819. i = 0;
  4820. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4821. loc = loc+3+strlen("chargingSchedulePeriod");
  4822. pch = strtok(loc ,"{");
  4823. while (pch != NULL)
  4824. {
  4825. strcpy(SchedulePeriodList[i], pch);
  4826. pch = strtok (NULL, "{");
  4827. i = i + 1;
  4828. }
  4829. n_SchedulePeriods = i;
  4830. for(int i=0;i<n_SchedulePeriods;i++)
  4831. {
  4832. //*************startPeriod****************/
  4833. c = 0;
  4834. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4835. memset(sstr ,0, sizeof(sstr) );
  4836. while (loc[strlen("startPeriod")+2+c] != ',')
  4837. {
  4838. sstr[c] = loc[strlen("startPeriod")+2+c];
  4839. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4840. c++;
  4841. }
  4842. sstr[c] = '\0';
  4843. tempStartPeriodInt = atoi(sstr);
  4844. //*************limit****************/
  4845. c = 0;
  4846. loc = strstr(SchedulePeriodList[i], "limit");
  4847. memset(sstr ,0, sizeof(sstr) );
  4848. while (loc[strlen("limit")+2+c] != ',')
  4849. {
  4850. sstr[c] = loc[strlen("limit")+2+c];
  4851. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4852. c++;
  4853. }
  4854. sstr[c] = '\0';
  4855. tempLimitInt = atof(sstr);
  4856. //*************numberPhases****************/
  4857. c = 0;
  4858. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4859. memset(sstr ,0, sizeof(sstr) );
  4860. while (loc[strlen("numberPhases")+2+c] != '}')
  4861. {
  4862. sstr[c] = loc[strlen("numberPhases")+2+c];
  4863. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4864. c++;
  4865. }
  4866. sstr[c] = '\0';
  4867. tempNumberPhasesInt = atoi(sstr);
  4868. if(j == 0)
  4869. {
  4870. TxDefaultProfile.Duration = tempdurationInt;
  4871. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4872. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4873. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4874. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4875. }
  4876. else
  4877. {
  4878. //other stack level charging Profile
  4879. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  4880. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  4881. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  4882. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  4883. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  4884. }
  4885. }
  4886. if(MinChargingRate < tempminChargingRateFloat)
  4887. MinChargingRate = tempminChargingRateFloat;
  4888. if(confirmPeriods < n_SchedulePeriods)
  4889. confirmPeriods = n_SchedulePeriods;
  4890. j = j + 1;
  4891. //DEBUG_INFO(" 1-2\n");
  4892. }
  4893. fclose(fptr1);
  4894. //Stacking Charging Profiles
  4895. for(int l=0; l <(j-1) ;l++)
  4896. {
  4897. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  4898. {
  4899. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  4900. {
  4901. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  4902. {
  4903. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  4904. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  4905. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  4906. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4907. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4908. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4909. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4910. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4911. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4912. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4913. }
  4914. else
  4915. {
  4916. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4917. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4918. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4919. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4920. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4921. }
  4922. }
  4923. }
  4924. }
  4925. //end of Stacking Charging Profiles
  4926. }
  4927. }// the end of ACCESS TxDefaultProfile
  4928. //****************************TxProfile************************************************/
  4929. switch(connectorIdInt)
  4930. {
  4931. case 0:
  4932. break;
  4933. case 1:
  4934. strcpy(fname, TxProfile_1_JSON );
  4935. break;
  4936. case 2:
  4937. strcpy(fname, TxProfile_2_JSON );
  4938. break;
  4939. default:
  4940. strcpy(fname, TxProfile_1_JSON );
  4941. break;
  4942. }
  4943. TxProfileIsNull=TRUE;
  4944. if((access(fname,F_OK))!=-1)
  4945. {
  4946. fptr1 = fopen(fname, "r");
  4947. c = 0;
  4948. c = fgetc(fptr1);
  4949. //DEBUG_INFO("c:%d\n",c);
  4950. rewind(fptr1);
  4951. if(c == EOF)
  4952. {
  4953. DEBUG_INFO("\n End of file reached.");
  4954. TxProfileIsNull=TRUE;
  4955. fclose(fptr1);
  4956. }
  4957. else
  4958. {
  4959. TxProfileIsNull=FALSE;
  4960. while(fscanf(fptr1, "%s", word) != EOF)
  4961. {
  4962. if(strcmp(word, "chargingProfileId") == 0)
  4963. {
  4964. n_chargingProfile = n_chargingProfile + 1;
  4965. }
  4966. }
  4967. rewind(fptr1);
  4968. //search Charging Profile Element
  4969. int i= 0;
  4970. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4971. #if 0
  4972. /***********connectorId****************/
  4973. c = 0;
  4974. loc = strstr(sLineWord, "connectorId");
  4975. memset(sstr ,0, sizeof(sstr) );
  4976. while (loc[strlen("connectorId")+2+c] != ',')
  4977. {
  4978. sstr[c] = loc[strlen("connectorId")+2+c];
  4979. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4980. c++;
  4981. }
  4982. sstr[c] = '\0';
  4983. tempconnectorIdInt = atoi(sstr);
  4984. #endif
  4985. //***********validFrom**************/
  4986. c = 0;
  4987. loc = strstr(sLineWord, "validFrom");
  4988. if(loc != NULL)
  4989. {
  4990. memset(sstr ,0, sizeof(sstr) );
  4991. while (loc[3+strlen("validFrom")+c] != '\"')
  4992. {
  4993. sstr[c] = loc[3+strlen("validFrom")+c];
  4994. c++;
  4995. }
  4996. sstr[c] = '\0';
  4997. strcpy(tempvalidFromStr,sstr);
  4998. }
  4999. else
  5000. {
  5001. strcpy(tempvalidFromStr,"");
  5002. }
  5003. //**********startSchedule**********/
  5004. c = 0;
  5005. loc = strstr(sLineWord, "startSchedule");
  5006. memset(sstr ,0, sizeof(sstr) );
  5007. while (loc[3+strlen("startSchedule")+c] != '\"')
  5008. {
  5009. sstr[c] = loc[3+strlen("startSchedule")+c];
  5010. c++;
  5011. }
  5012. sstr[c] = '\0';
  5013. strcpy(tempstartScheduleStr, sstr);
  5014. strcpy(TxProfileScheduleStr, sstr);
  5015. //**********chargingRateUnit**********/
  5016. c = 0;
  5017. loc = strstr(sLineWord, "chargingRateUnit");
  5018. memset(sstr ,0, sizeof(sstr) );
  5019. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5020. {
  5021. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5022. c++;
  5023. }
  5024. sstr[c] = '\0';
  5025. strcpy(tempchargingRateUnitStr, sstr);
  5026. //**********minChargingRate*******/
  5027. c = 0;
  5028. loc = strstr(sLineWord, "minChargingRate");
  5029. if(loc != NULL)
  5030. {
  5031. memset(sstr ,0, sizeof(sstr) );
  5032. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5033. {
  5034. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5035. c++;
  5036. }
  5037. sstr[c] = '\0';
  5038. tempminChargingRateFloat = atof(sstr);
  5039. }
  5040. else
  5041. {
  5042. tempminChargingRateFloat = 0.0;
  5043. }
  5044. #if 0
  5045. //
  5046. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5047. tp.tm_isdst = -1;
  5048. time_t utc = mktime(&tp);
  5049. time_t t = time(NULL);
  5050. //diff_t = difftime(t, utc);
  5051. #endif
  5052. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5053. //parsing strings to words
  5054. i = 0;
  5055. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5056. loc = loc+3+strlen("chargingSchedulePeriod");
  5057. pch = strtok(loc ,"{");
  5058. while (pch != NULL)
  5059. {
  5060. strcpy(SchedulePeriodList[i], pch);
  5061. pch = strtok (NULL, "{");
  5062. i = i + 1;
  5063. }
  5064. n_SchedulePeriods = i;
  5065. for(int i=0;i<n_SchedulePeriods;i++)
  5066. {
  5067. //*************startPeriod****************/
  5068. c = 0;
  5069. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5070. memset(sstr ,0, sizeof(sstr) );
  5071. while (loc[strlen("startPeriod")+2+c] != ',')
  5072. {
  5073. sstr[c] = loc[strlen("startPeriod")+2+c];
  5074. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5075. c++;
  5076. }
  5077. sstr[c] = '\0';
  5078. tempStartPeriodInt = atoi(sstr);
  5079. //*************limit****************/
  5080. c = 0;
  5081. loc = strstr(SchedulePeriodList[i], "limit");
  5082. memset(sstr ,0, sizeof(sstr) );
  5083. while (loc[strlen("limit")+2+c] != ',')
  5084. {
  5085. sstr[c] = loc[strlen("limit")+2+c];
  5086. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5087. c++;
  5088. }
  5089. sstr[c] = '\0';
  5090. tempLimitInt = atof(sstr);
  5091. //*************numberPhases****************/
  5092. c = 0;
  5093. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5094. memset(sstr ,0, sizeof(sstr) );
  5095. while (loc[strlen("numberPhases")+2+c] != '}')
  5096. {
  5097. sstr[c] = loc[strlen("numberPhases")+2+c];
  5098. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5099. c++;
  5100. }
  5101. sstr[c] = '\0';
  5102. tempNumberPhasesInt = atoi(sstr);
  5103. TxProfile.Duration = durationInt;
  5104. TxProfile.TotalPeriod = n_SchedulePeriods;
  5105. TxProfile.Period[i].Limit = tempLimitInt;
  5106. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5107. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5108. }
  5109. if(MinChargingRate < tempminChargingRateFloat)
  5110. MinChargingRate = tempminChargingRateFloat;
  5111. if(confirmPeriods < n_SchedulePeriods)
  5112. confirmPeriods = n_SchedulePeriods;
  5113. }
  5114. fclose(fptr1);
  5115. }
  5116. }// the end of ACCESS TxProfile
  5117. //CompositeSchedule
  5118. int period=0;
  5119. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5120. {
  5121. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5122. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5123. {
  5124. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5125. {
  5126. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5127. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5128. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5129. period = period + 1;
  5130. }
  5131. else
  5132. {
  5133. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5134. {
  5135. }
  5136. else
  5137. {
  5138. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5139. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5140. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5141. period = period + 1;
  5142. }
  5143. }
  5144. }
  5145. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5146. {
  5147. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5148. {
  5149. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5150. {
  5151. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5152. }
  5153. else
  5154. {
  5155. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5156. }
  5157. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5158. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5159. period = period + 1;
  5160. }
  5161. }
  5162. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5163. {
  5164. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5165. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5166. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5167. period = period + 1;
  5168. }
  5169. }
  5170. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5171. {
  5172. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5173. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5174. {
  5175. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5176. {
  5177. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5178. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5179. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5180. period = period + 1;
  5181. }
  5182. else
  5183. {
  5184. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5185. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5186. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5187. period = period + 1;
  5188. }
  5189. }
  5190. }
  5191. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5192. {
  5193. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5194. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5195. {
  5196. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5197. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5198. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5199. period = period + 1;
  5200. }
  5201. }
  5202. confirmPeriods = period;
  5203. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5204. //* Define temporary variables */
  5205. struct tm *gtime;
  5206. time_t now;
  5207. char buf[28];
  5208. //* Read the current system time */
  5209. time(&now);
  5210. //* Convert the system time to GMT (now UTC) */
  5211. gtime = gmtime(&now);
  5212. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5213. // make .conf
  5214. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5215. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5216. //DEBUG_INFO(" debug 11\n");
  5217. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5218. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5219. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5220. }
  5221. else
  5222. {
  5223. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5224. }
  5225. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5226. return result;
  5227. }
  5228. int handleGetConfigurationRequest(char *uuid, char *payload)
  5229. {
  5230. mtrace();
  5231. int result = FAIL;
  5232. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5233. //struct json_object *jsonitem;
  5234. int MaxKeySupported = 0;
  5235. int n_keys = 0;
  5236. char requestKey[43][50]={0};
  5237. char search[]="[";
  5238. char sstr[500]={ 0 };
  5239. //int pos;
  5240. int l, c = 0;
  5241. int i = 0;
  5242. char *delim = "\",\"";
  5243. char * pch;
  5244. char *loc = strstr(payload, search);
  5245. //********************* Parsing String ***********************************/
  5246. if(loc == NULL) {
  5247. DEBUG_INFO("no key match in Configuration \n");
  5248. }
  5249. else {
  5250. //pos = loc - payload;
  5251. l = strlen(loc)-4;
  5252. while (c < l)
  5253. {
  5254. sstr[c] = loc[c+2];
  5255. c++;
  5256. }
  5257. sstr[c] = '\0';
  5258. //parsing strings to words
  5259. pch = strtok(sstr,delim);
  5260. if(pch == NULL)
  5261. {
  5262. strcpy(requestKey[0], sstr);
  5263. }
  5264. else
  5265. {
  5266. while (pch != NULL)
  5267. {
  5268. strcpy(requestKey[i], pch);
  5269. pch = strtok (NULL, delim);
  5270. i = i + 1;
  5271. }
  5272. n_keys = i;
  5273. }
  5274. }
  5275. UnknownKeynum = 0;
  5276. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5277. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5278. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5279. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5280. if(n_keys != 0)
  5281. {
  5282. for(int i=0;i<n_keys;i++)
  5283. {
  5284. getKeyValue(requestKey[i]);
  5285. //json_object_put(jsonitem);
  5286. }
  5287. }
  5288. else
  5289. {
  5290. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5291. getKeyValue("");
  5292. }
  5293. processUnkownKey();
  5294. sendGetConfigurationConfirmation(uuid);
  5295. return result;
  5296. }
  5297. static char fnamePlusPath[100]={0};
  5298. static char fnamePWithNoPath[60]={0};
  5299. void checkUploadLog(void)
  5300. {
  5301. FILE *fp;
  5302. /* Open the command for reading. */
  5303. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5304. if (fp == NULL) {
  5305. printf("Failed to run command\n" );
  5306. exit(1);
  5307. }
  5308. int ftppathlen = 0;
  5309. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5310. int i = 0;
  5311. /* Read the output a line at a time - output it. */
  5312. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5313. if(i==0)
  5314. {
  5315. ftppathlen = strlen(fnamePlusPath);
  5316. printf("%s\n", fnamePlusPath);
  5317. fnamePlusPath[ftppathlen]='\0';
  5318. break;
  5319. }
  5320. i= i+1;
  5321. }
  5322. /* close */
  5323. pclose(fp);
  5324. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5325. {
  5326. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5327. {
  5328. fnamePlusPath[k]='\0';
  5329. }
  5330. }
  5331. i=1;
  5332. //char fname[60]={0};
  5333. while(i < ftppathlen)
  5334. {
  5335. int len=ftppathlen-i;
  5336. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5337. {
  5338. printf("compare '/' all right\n");
  5339. break;
  5340. }
  5341. i=i+1;
  5342. }
  5343. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5344. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5345. fnamePWithNoPath[i+1] = '\0';
  5346. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5347. {
  5348. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5349. {
  5350. fnamePWithNoPath[j]='\0';
  5351. }
  5352. }
  5353. FILE* fp1 = fopen(fnamePlusPath, "r");
  5354. if (fp1)
  5355. {
  5356. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5357. // file exists
  5358. fclose(fp1);
  5359. }
  5360. else
  5361. {
  5362. // file doesn't exist
  5363. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5364. }
  5365. }
  5366. static char GetDiagnosticspayloadData[300]={0};
  5367. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5368. {
  5369. mtrace();
  5370. int result = FAIL;
  5371. //void *ret; //
  5372. //char fnamePlusPath[100]="";
  5373. //char fname[40]="";
  5374. pthread_t t; // pthread 變數
  5375. //time_t rawtime;
  5376. //struct tm * timeinfo;
  5377. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5378. system("exec /root/logPackTools 'log' 6");
  5379. #if 0
  5380. //char buffer [128];
  5381. time (&rawtime);
  5382. //printf("%ld\n", rawtime);
  5383. timeinfo = localtime (&rawtime);
  5384. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5385. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5386. if((access(fnamePlusPath,F_OK))!=-1)
  5387. {
  5388. DEBUG_INFO("fnamePlusPath exist.\n");
  5389. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5390. }
  5391. else
  5392. {
  5393. DEBUG_INFO("fnamePlusPath not exist!\n");
  5394. }
  5395. #endif
  5396. checkUploadLog();
  5397. memset(GetDiagnosticspayloadData, 0, 300);
  5398. strcpy(GetDiagnosticspayloadData, payload);
  5399. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5400. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5401. // pthread_join(t, NULL/*&ret*/);
  5402. return result;
  5403. }
  5404. void* GetDiagnosticsProcess(void* data)
  5405. {
  5406. pthread_detach(pthread_self());
  5407. mtrace();
  5408. int retriesInt=0, retryIntervalInt=0;
  5409. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5410. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5411. 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};
  5412. int port=0;
  5413. //char fnamePlusPath[100]="";//="00000_2019-06-09_160902_CSULog.zip";
  5414. //char fname[40]="";
  5415. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5416. int c = 0;
  5417. char *loc;
  5418. int isSuccess = FALSE;
  5419. char ftpbuf[200]={0};
  5420. //char temp[100]={0};
  5421. char * pch;
  5422. // [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"}]
  5423. //char *str = (char*) data; // ? ?輸入資 ?
  5424. char str[300]={ 0 };
  5425. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5426. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5427. DEBUG_INFO("GetDiagnosticsProcess\n");
  5428. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5429. //****************location*******************/
  5430. c = 0;
  5431. memset(sstr ,0, sizeof(sstr) );
  5432. loc = strstr(str, "location");
  5433. while (loc[3+strlen("location")+c] != '\"')
  5434. {
  5435. sstr[c] = loc[3+strlen("location")+c];
  5436. c++;
  5437. }
  5438. sstr[c] = '\0';
  5439. strcpy(locationstr,sstr);
  5440. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5441. if(strcmp(locationstr,"")==0)
  5442. {
  5443. DEBUG_INFO("location is <Empty>!\n");
  5444. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5445. goto end;
  5446. }
  5447. //****************retries*******************/
  5448. c = 0;
  5449. loc = strstr(str, "retries");
  5450. if(loc == NULL)
  5451. {
  5452. retriesIsNULL = TRUE;
  5453. }
  5454. else
  5455. {
  5456. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5457. {
  5458. sstr[c] = loc[strlen("retries")+2+c];
  5459. c++;
  5460. }
  5461. sstr[c] = '\0';
  5462. retriesInt = atoi(sstr);
  5463. }
  5464. if(retriesIsNULL == TRUE)
  5465. {
  5466. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5467. }
  5468. //****************retryInterval*******************/
  5469. c = 0;
  5470. loc = strstr(str, "retryInterval");
  5471. if(loc == NULL)
  5472. {
  5473. retryIntervalIsNULL = TRUE;
  5474. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5475. }
  5476. else
  5477. {
  5478. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5479. {
  5480. sstr[c] = loc[strlen("retryInterval")+2+c];
  5481. c++;
  5482. }
  5483. sstr[c] = '\0';
  5484. retryIntervalInt = atoi(sstr);
  5485. }
  5486. //****************startTime*******************/
  5487. c = 0;
  5488. memset(sstr ,0, sizeof(sstr) );
  5489. loc = strstr(str, "startTime");
  5490. if(loc == NULL)
  5491. {
  5492. startTimeIsNULL = TRUE;
  5493. }
  5494. else
  5495. {
  5496. while (loc[3+strlen("startTime")+c] != '\"')
  5497. {
  5498. sstr[c] = loc[3+strlen("startTime")+c];
  5499. c++;
  5500. }
  5501. sstr[c] = '\0';
  5502. strcpy(startTimestr,sstr);
  5503. }
  5504. //****************stopTime*******************/
  5505. c = 0;
  5506. memset(sstr ,0, sizeof(sstr) );
  5507. loc = strstr(str, "stopTime");
  5508. if(loc == NULL)
  5509. {
  5510. stopTimeIsNULL = TRUE;
  5511. }
  5512. else
  5513. {
  5514. while (loc[3+strlen("stopTime")+c] != '\"')
  5515. {
  5516. sstr[c] = loc[3+strlen("stopTime")+c];
  5517. c++;
  5518. }
  5519. sstr[c] = '\0';
  5520. strcpy(stopTimestr,sstr);
  5521. }
  5522. memset(protocol, 0, sizeof(protocol));
  5523. memset(user, 0, sizeof(user) );
  5524. memset(password, 0, sizeof(password));
  5525. memset(host, 0, sizeof(host));
  5526. memset(path, 0, sizeof(path));
  5527. memset(ftppath, 0, sizeof(ftppath));
  5528. memset(host1, 0, sizeof(host1));
  5529. memset(path1, 0, sizeof(path1));
  5530. /*location: ftp://user:password@host:port/path*/
  5531. #if 0
  5532. time_t rawtime;
  5533. struct tm * timeinfo;
  5534. //char buffer [128];
  5535. time (&rawtime);
  5536. //printf("%ld\n", rawtime);
  5537. timeinfo = localtime (&rawtime);
  5538. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5539. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5540. #endif
  5541. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5542. if((access(fnamePlusPath,F_OK))!=-1)
  5543. {
  5544. DEBUG_INFO("fnamePlusPath exist.\n");
  5545. }
  5546. else
  5547. {
  5548. DEBUG_INFO("fnamePlusPath not exist!\n");
  5549. goto end;
  5550. }
  5551. pch=strchr(locationstr,'@');
  5552. if(pch==NULL)
  5553. {
  5554. sscanf(locationstr,
  5555. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5556. protocol, host, &port, path);
  5557. strcpy(user,"anonymous");
  5558. strcpy(password,"");
  5559. }
  5560. else
  5561. {
  5562. //DEBUG_INFO("pch=%s\n", pch);
  5563. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5564. protocol, user, password, host, &port, path);
  5565. }
  5566. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5567. {
  5568. DEBUG_INFO("protocol is not ftp/http ! \n");
  5569. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5570. goto end;
  5571. }
  5572. if(strncmp(locationstr,"http", 4) == 0)
  5573. {
  5574. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  5575. protocol, host, path);
  5576. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  5577. // protocol, user, password, host, path);
  5578. sprintf(ftppath,"/%s", path);
  5579. //DEBUG_INFO("protocol =%s\n",protocol);
  5580. //DEBUG_INFO("host =%s\n",host);
  5581. //DEBUG_INFO("path =%s\n",path);
  5582. //DEBUG_INFO("ftppath=%s\n",ftppath);
  5583. //int ftppathlen=strlen(ftppath);
  5584. //int i=1;
  5585. //char filenametemp[50];
  5586. //while(i < ftppathlen)
  5587. //{
  5588. // int len=ftppathlen-i;
  5589. // if(ftppath[len]== 47) // '/' ascll code: 47
  5590. // {
  5591. // DEBUG_INFO("compare '/' all right\n");
  5592. // break;
  5593. // }
  5594. // i=i+1;
  5595. //}
  5596. //memset(filenametemp, 0, sizeof(filenametemp));
  5597. //strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5598. //filenametemp[i+1] = 0;
  5599. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  5600. //memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5601. //strftime (fnamePlusPath,sizeof(fnamePlusPath),"/mnt/%4Y-%2m.zip",timeinfo);
  5602. do{
  5603. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);//httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5604. sleep(retryIntervalInt);
  5605. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5606. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  5607. if(!isSuccess)
  5608. {
  5609. //BulldogUtil.sleepMs(interval*1000);
  5610. DEBUG_INFO("Diagnostics fail.\n");
  5611. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5612. }
  5613. else
  5614. {
  5615. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5616. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5617. //isUpdateRequest = TRUE;
  5618. }
  5619. }
  5620. else
  5621. {
  5622. sscanf(host,"%[^/]%s",host1, path1);
  5623. sprintf(ftppath,"%s", path1);
  5624. DEBUG_INFO("protocol =%s\n",protocol);
  5625. DEBUG_INFO("user =%s\n",user);
  5626. DEBUG_INFO("password =%s\n",password);
  5627. DEBUG_INFO("host1 =%s\n",host1);
  5628. DEBUG_INFO("port =%d\n",port);
  5629. DEBUG_INFO("path1 =%s\n",path1);
  5630. DEBUG_INFO("ftppath=%s\n",ftppath);
  5631. int ftppathlen=strlen(ftppath);
  5632. int i=1;
  5633. char filenametemp[50];
  5634. while(i < ftppathlen)
  5635. {
  5636. int len=ftppathlen-i;
  5637. if(ftppath[len]== 47) // '/' ascll code: 47
  5638. {
  5639. DEBUG_INFO("find '/' all right\n");
  5640. break;
  5641. }
  5642. i=i+1;
  5643. }
  5644. memset(filenametemp, 0, sizeof(filenametemp));
  5645. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5646. filenametemp[i+1] = 0;
  5647. memset(ftpbuf, 0, sizeof(ftpbuf));
  5648. if(port == 0)
  5649. port = 21;
  5650. do{
  5651. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  5652. sleep(retryIntervalInt);
  5653. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5654. if(!isSuccess)
  5655. {
  5656. //BulldogUtil.sleepMs(interval*1000);
  5657. DEBUG_INFO("Diagnostics fail.\n");
  5658. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5659. }
  5660. else
  5661. {
  5662. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5663. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5664. //isUpdateRequest = TRUE;
  5665. }
  5666. }
  5667. end:
  5668. // json_object_put(obj);
  5669. DiagnosticsStatusNotificationStatus = 0; //Idle
  5670. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5671. }
  5672. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5673. {
  5674. mtrace();
  5675. int result = FAIL;
  5676. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5677. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5678. {
  5679. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5680. localversion = -1;
  5681. }
  5682. else
  5683. {
  5684. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5685. OCPP_getListVerion();
  5686. }
  5687. //from db.OCPP_getListVerion
  5688. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5689. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5690. sendGetLocalListVersionConfirmation(uuid,"");
  5691. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5692. return result;
  5693. }
  5694. int handleRemoteStartRequest(char *uuid, char *payload)
  5695. {
  5696. mtrace();
  5697. int result = FAIL;
  5698. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5699. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5700. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5701. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5702. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5703. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5704. int chargingSchedulePeriodCount = 0;
  5705. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5706. int c = 0;
  5707. char *loc;
  5708. char comfirmstr[20]={0};
  5709. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5710. if(server_pending == TRUE)
  5711. {
  5712. return 0;
  5713. }
  5714. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5715. //**********connectorId****************/
  5716. c = 0;
  5717. memset(sstr ,0, sizeof(sstr) );
  5718. loc = strstr(payload, "connectorId");
  5719. if(loc == NULL)
  5720. {
  5721. connectorIdIsNULL = TRUE;
  5722. }
  5723. else
  5724. {
  5725. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5726. {
  5727. sstr[c] = loc[strlen("connectorId")+2+c];
  5728. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5729. c++;
  5730. }
  5731. sstr[c] = '\0';
  5732. connectorIdInt = atoi(sstr);
  5733. }
  5734. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  5735. {
  5736. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5737. goto end;
  5738. }
  5739. //****************idTag*******************/
  5740. c = 0;
  5741. memset(sstr ,0, sizeof(sstr) );
  5742. loc = strstr(payload, "idTag");
  5743. while (loc[3+strlen("idTag")+c] != '\"')
  5744. {
  5745. sstr[c] = loc[3+strlen("idTag")+c];
  5746. c++;
  5747. }
  5748. sstr[c] = '\0';
  5749. strcpy(idTagstr,sstr);
  5750. //****************chargingProfile*******************/
  5751. c = 0;
  5752. memset(sstr ,0, sizeof(sstr) );
  5753. loc = strstr(payload, "chargingProfile");
  5754. if(loc == NULL)
  5755. {
  5756. chargingProfileIsNULL = TRUE;
  5757. }
  5758. else
  5759. {
  5760. //****************chargingProfileId*******************/
  5761. c=0;
  5762. loc = strstr(payload, "chargingProfileId");
  5763. memset(sstr ,0, sizeof(sstr) );
  5764. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5765. {
  5766. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5767. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5768. c++;
  5769. }
  5770. sstr[c] = '\0';
  5771. chargingProfileIdInt = atoi(sstr);
  5772. //****************transactionId*******************/
  5773. loc = strstr(payload, "transactionId");
  5774. if(loc == NULL)
  5775. {
  5776. transactionIdIsNULL = TRUE;
  5777. }
  5778. else
  5779. {
  5780. c=0;
  5781. memset(sstr ,0, sizeof(sstr) );
  5782. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5783. {
  5784. sstr[c] = loc[strlen("transactionId")+2+c];
  5785. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5786. c++;
  5787. }
  5788. sstr[c] = '\0';
  5789. transactionIdInt = atoi(sstr);
  5790. }
  5791. //****************stackLevel*******************/
  5792. c=0;
  5793. loc = strstr(payload, "stackLevel");
  5794. memset(sstr ,0, sizeof(sstr) );
  5795. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5796. {
  5797. sstr[c] = loc[strlen("stackLevel")+2+c];
  5798. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5799. c++;
  5800. }
  5801. sstr[c] = '\0';
  5802. stackLevelInt = atoi(sstr);
  5803. //****************chargingProfilePurpose*******************/
  5804. c = 0;
  5805. memset(sstr ,0, sizeof(sstr) );
  5806. loc = strstr(payload, "chargingProfilePurpose");
  5807. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5808. {
  5809. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5810. c++;
  5811. }
  5812. sstr[c] = '\0';
  5813. strcpy(chargingProfilePurposestr,sstr);
  5814. //****************chargingProfileKind*******************/
  5815. c = 0;
  5816. memset(sstr ,0, sizeof(sstr) );
  5817. loc = strstr(payload, "chargingProfileKind");
  5818. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5819. {
  5820. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5821. c++;
  5822. }
  5823. sstr[c] = '\0';
  5824. strcpy(chargingProfileKindstr,sstr);
  5825. //****************recurrencyKind*******************/
  5826. loc = strstr(payload, "recurrencyKind");
  5827. if(loc == NULL)
  5828. {
  5829. recurrencyKindIsNULL = TRUE;
  5830. }
  5831. else
  5832. {
  5833. c = 0;
  5834. memset(sstr ,0, sizeof(sstr) );
  5835. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5836. {
  5837. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5838. c++;
  5839. }
  5840. sstr[c] = '\0';
  5841. strcpy(recurrencyKindstr,sstr);
  5842. }
  5843. //****************validFrom*******************/
  5844. loc = strstr(payload, "validFrom");
  5845. if(loc == NULL)
  5846. {
  5847. validFromIsNULL = TRUE;
  5848. }
  5849. else
  5850. {
  5851. c = 0;
  5852. memset(sstr ,0, sizeof(sstr) );
  5853. while (loc[3+strlen("validFrom")+c] != '\"')
  5854. {
  5855. sstr[c] = loc[3+strlen("validFrom")+c];
  5856. c++;
  5857. }
  5858. sstr[c] = '\0';
  5859. strcpy(validFromstr,sstr);
  5860. }
  5861. //****************validTo*******************/
  5862. loc = strstr(payload, "validTo");
  5863. if(loc == NULL)
  5864. {
  5865. validToIsNULL = TRUE;
  5866. }
  5867. else
  5868. {
  5869. c = 0;
  5870. memset(sstr ,0, sizeof(sstr) );
  5871. while (loc[3+strlen("validTo")+c] != '\"')
  5872. {
  5873. sstr[c] = loc[3+strlen("validTo")+c];
  5874. c++;
  5875. }
  5876. sstr[c] = '\0';
  5877. strcpy(validTostr,sstr);
  5878. }
  5879. //****************chargingSchedule*******************/
  5880. loc = strstr(payload, "chargingSchedule");
  5881. if(loc != NULL)
  5882. {
  5883. //****************duration*******************/
  5884. loc = strstr(payload, "duration");
  5885. if(loc == NULL)
  5886. {
  5887. durationIsNULL = TRUE;
  5888. }
  5889. else
  5890. {
  5891. c=0;
  5892. memset(sstr ,0, sizeof(sstr) );
  5893. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5894. {
  5895. sstr[c] = loc[strlen("duration")+2+c];
  5896. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5897. c++;
  5898. }
  5899. sstr[c] = '\0';
  5900. durationInt = atoi(sstr);
  5901. }
  5902. //****************startSchedule******************/
  5903. loc = strstr(payload, "startSchedule");
  5904. if(loc == NULL)
  5905. {
  5906. startScheduleIsNULL = TRUE;
  5907. }
  5908. else
  5909. {
  5910. c = 0;
  5911. memset(sstr ,0, sizeof(sstr) );
  5912. while (loc[3+strlen("startSchedule")+c] != '\"')
  5913. {
  5914. sstr[c] = loc[3+strlen("startSchedule")+c];
  5915. c++;
  5916. }
  5917. sstr[c] = '\0';
  5918. strcpy(startSchedulestr,sstr);
  5919. }
  5920. //****************chargingRateUnit*******************/
  5921. c = 0;
  5922. memset(sstr ,0, sizeof(sstr) );
  5923. loc = strstr(payload, "chargingRateUnit");
  5924. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5925. {
  5926. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5927. c++;
  5928. }
  5929. sstr[c] = '\0';
  5930. strcpy(chargingRateUnitstr,sstr);
  5931. //****************minChargingRate*******************/
  5932. loc = strstr(payload, "minChargingRate");
  5933. if(loc == NULL)
  5934. {
  5935. minChargingRateIsNULL = TRUE;
  5936. }
  5937. else
  5938. {
  5939. c=0;
  5940. memset(sstr ,0, sizeof(sstr) );
  5941. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5942. {
  5943. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5944. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5945. c++;
  5946. }
  5947. sstr[c] = '\0';
  5948. minChargingRateflaot = atof(sstr);
  5949. }
  5950. //****************chargingSchedulePeriod count*******************/
  5951. int what_len = strlen("startPeriod");
  5952. char *where = payload;
  5953. while ((where = strstr(where, "startPeriod"))) {
  5954. where += what_len;
  5955. chargingSchedulePeriodCount++;
  5956. }
  5957. where = payload;
  5958. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5959. {
  5960. //****************startPeriod*******************/
  5961. c=0;
  5962. loc = strstr(where, "startPeriod");
  5963. memset(sstr ,0, sizeof(sstr) );
  5964. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5965. {
  5966. sstr[c] = loc[strlen("startPeriod")+2+c];
  5967. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5968. c++;
  5969. }
  5970. sstr[c] = '\0';
  5971. startPeriodInt[periodNums] = atoi(sstr);
  5972. //****************limit*******************/
  5973. c=0;
  5974. loc = strstr(where, "limit");
  5975. memset(sstr ,0, sizeof(sstr) );
  5976. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5977. {
  5978. sstr[c] = loc[strlen("limit")+2+c];
  5979. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5980. c++;
  5981. }
  5982. sstr[c] = '\0';
  5983. limitflaot[periodNums] = atof(sstr);
  5984. //****************numberPhases*******************/
  5985. loc = strstr(where, "numberPhases");
  5986. if(loc == NULL)
  5987. {
  5988. numberPhasesIsNULL = TRUE;
  5989. }
  5990. else
  5991. {
  5992. c=0;
  5993. memset(sstr ,0, sizeof(sstr) );
  5994. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  5995. {
  5996. sstr[c] = loc[strlen("numberPhases")+2+c];
  5997. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5998. c++;
  5999. }
  6000. sstr[c] = '\0';
  6001. numberPhasesInt[periodNums] = atoi(sstr);
  6002. }
  6003. where = loc;
  6004. }
  6005. }
  6006. }
  6007. /*
  6008. enum _SYSTEM_STATUS
  6009. {
  6010. S_BOOTING = 0,
  6011. S_IDLE, = 1
  6012. S_AUTHORIZING, =2
  6013. S_REASSIGN_CHECK, =3
  6014. S_REASSIGN, =4
  6015. S_PRECHARGE, =5
  6016. S_PREPARING_FOR_EV, =6
  6017. S_PREPARING_FOR_EVSE, =7
  6018. S_CHARGING, =8
  6019. S_TERMINATING, =9
  6020. S_COMPLETE, =10
  6021. S_ALARM, =11
  6022. S_FAULT =12
  6023. }
  6024. */
  6025. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6026. {
  6027. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6028. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6029. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6030. //check Transaction active
  6031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6032. {
  6033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6034. {
  6035. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6036. {
  6037. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6038. {
  6039. //Reserved
  6040. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6041. }
  6042. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6043. {
  6044. //Reserved
  6045. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6046. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6047. goto end;
  6048. }
  6049. else
  6050. {
  6051. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6052. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6053. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6054. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6055. {
  6056. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6057. goto end;
  6058. }
  6059. }//END FOR ELSE
  6060. }
  6061. }// END FOR CHAdeMO_QUANTITY
  6062. for (int index = 0; index < CCS_QUANTITY; index++)
  6063. {
  6064. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6065. {
  6066. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6067. {
  6068. //Reserved
  6069. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6070. }
  6071. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6072. {
  6073. //Reserved
  6074. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6075. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6076. goto end;
  6077. }
  6078. else
  6079. {
  6080. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6081. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6082. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6083. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6084. {
  6085. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6086. goto end;
  6087. }
  6088. }// END FOR ELSE
  6089. }
  6090. }// END FOR CCS_QUANTITY
  6091. for (int index = 0; index < GB_QUANTITY; index++)
  6092. {
  6093. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6094. {
  6095. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6096. {
  6097. //Reserved
  6098. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6099. }
  6100. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6101. {
  6102. //Reserved
  6103. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6104. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6105. goto end;
  6106. }
  6107. else
  6108. {
  6109. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6110. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6111. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6112. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6113. {
  6114. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6115. goto end;
  6116. }
  6117. }// END FOR ELSE
  6118. }
  6119. } // END FOR GB_QUANTITY
  6120. }
  6121. else
  6122. {
  6123. for (int index = 0; index < AC_QUANTITY; index++)
  6124. {
  6125. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6126. {
  6127. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6128. {
  6129. //Reserved
  6130. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6131. }
  6132. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6133. {
  6134. //Reserved
  6135. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6136. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6137. goto end;
  6138. }
  6139. else
  6140. {
  6141. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6142. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6143. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6144. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6145. {
  6146. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6147. goto end;
  6148. }
  6149. }//END FOR ELSE
  6150. }
  6151. }// END FOR AC_QUANTITY
  6152. }
  6153. if(chargingProfileIsNULL == FALSE)
  6154. {
  6155. //ChargingProfile
  6156. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6157. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6158. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6159. if(recurrencyKindIsNULL == FALSE) //OPTION
  6160. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6161. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6162. if(transactionIdIsNULL == FALSE) // OPTION
  6163. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6164. if(validFromIsNULL == FALSE) // OPTION
  6165. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6166. if(validToIsNULL == FALSE) //OPTION
  6167. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6168. //ChargingSchedule
  6169. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6170. if(durationIsNULL == FALSE) //OPTION
  6171. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6172. if(minChargingRateIsNULL == FALSE) //OPTION
  6173. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6174. if(startScheduleIsNULL == FALSE) //OPTION
  6175. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6176. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6177. {
  6178. //ChargingSchedulePeriod
  6179. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6180. if(numberPhasesIsNULL == FALSE)
  6181. {
  6182. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6183. }
  6184. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6185. }
  6186. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6187. {
  6188. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6189. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6190. //memset idTag
  6191. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6192. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6193. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6194. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6195. }
  6196. else
  6197. {
  6198. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6199. }
  6200. }
  6201. else
  6202. {
  6203. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6204. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6205. //memset idTag
  6206. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6207. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6208. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6209. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6210. }
  6211. }
  6212. else
  6213. {
  6214. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6215. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6216. }
  6217. end:
  6218. if(connectorIdIsNULL == FALSE)
  6219. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6220. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6221. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6222. //OCPP send RemoteStartConfirmation by first.
  6223. sendRemoteStartConfirmation(uuid, comfirmstr);
  6224. return result;
  6225. }
  6226. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6227. {
  6228. mtrace();
  6229. int result = FAIL;
  6230. int match = FALSE;
  6231. int GunNO = 0;
  6232. int transactionIdInt=0;
  6233. int transactionIdIsNULL= FALSE;
  6234. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6235. int c = 0;
  6236. char *loc;
  6237. char comfirmstr[20];
  6238. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6239. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6240. if(server_pending == TRUE)
  6241. {
  6242. return 0;
  6243. }
  6244. c=0;
  6245. loc = strstr(payload, "transactionId");
  6246. if(loc == NULL)
  6247. {
  6248. transactionIdIsNULL= TRUE;
  6249. }
  6250. else
  6251. {
  6252. memset(sstr ,0, sizeof(sstr) );
  6253. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6254. {
  6255. sstr[c] = loc[strlen("transactionId")+2+c];
  6256. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6257. c++;
  6258. }
  6259. sstr[c] = '\0';
  6260. transactionIdInt = atoi(sstr);
  6261. }
  6262. if(transactionIdIsNULL == FALSE)
  6263. {
  6264. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6265. {
  6266. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6267. {
  6268. //check Transaction active
  6269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6270. {
  6271. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6272. {
  6273. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6274. {
  6275. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6276. {
  6277. match = TRUE;
  6278. GunNO = gun_index;
  6279. }
  6280. }
  6281. }// END FOR CHAdeMO_QUANTITY
  6282. for (int index = 0; index < CCS_QUANTITY; index++)
  6283. {
  6284. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6285. {
  6286. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6287. {
  6288. match = TRUE;
  6289. GunNO = gun_index;
  6290. }
  6291. }
  6292. }// END FOR CCS_QUANTITY
  6293. for (int index = 0; index < GB_QUANTITY; index++)
  6294. {
  6295. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6296. {
  6297. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6298. {
  6299. match = TRUE;
  6300. GunNO = gun_index;
  6301. }
  6302. }
  6303. }// END FOR GB_QUANTITY
  6304. }
  6305. else
  6306. {
  6307. for (int index = 0; index < AC_QUANTITY; index++)
  6308. {
  6309. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6310. {
  6311. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6312. {
  6313. match = TRUE;
  6314. GunNO = gun_index;
  6315. }
  6316. }
  6317. }// END FOR CHAdeMO_QUANTITY
  6318. }// END FOR AC ELSE
  6319. }// CHECK IF ResponseTransactionId == transactionIdInt
  6320. }//END FOR
  6321. if( match == TRUE)
  6322. {
  6323. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6324. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6325. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6326. }
  6327. else
  6328. {
  6329. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6330. }
  6331. }
  6332. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6333. return result;
  6334. }
  6335. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6336. {
  6337. mtrace();
  6338. int result = FAIL;
  6339. int connectorIdInt=0, reservationIdInt=0;
  6340. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6341. char comfirmstr[20]={0};
  6342. char sstr[180]={ 0 };
  6343. int c = 0;
  6344. char *loc;
  6345. //char *ptr;
  6346. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6347. //***(1)connectorId ****/
  6348. c=0;
  6349. loc = strstr(payload, "connectorId");
  6350. memset(sstr ,0, sizeof(sstr) );
  6351. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6352. {
  6353. sstr[c] = loc[strlen("connectorId")+2+c];
  6354. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6355. c++;
  6356. }
  6357. sstr[c] = '\0';
  6358. connectorIdInt = atoi(sstr);
  6359. //***(2)expiryDate ****/
  6360. loc = strstr(payload, "expiryDate");
  6361. memset(sstr ,0, sizeof(sstr) );
  6362. c = 0;
  6363. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6364. {
  6365. sstr[c] = loc[3+strlen("expiryDate")+c];
  6366. c++;
  6367. }
  6368. sstr[c] = '\0';
  6369. strcpy(expiryDatestr, sstr);
  6370. //***(3)idTag ****/
  6371. loc = strstr(payload, "idTag");
  6372. memset(sstr ,0, sizeof(sstr) );
  6373. c = 0;
  6374. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6375. {
  6376. sstr[c] = loc[3+strlen("idTag")+c];
  6377. c++;
  6378. }
  6379. sstr[c] = '\0';
  6380. strcpy(idTagstr, sstr);
  6381. //***(4)parentIdTag ****/
  6382. loc = strstr(payload, "parentIdTag");
  6383. memset(sstr ,0, sizeof(sstr) );
  6384. c = 0;
  6385. if(loc == NULL)
  6386. {
  6387. strcpy(parentIdTagstr, "");
  6388. }
  6389. else
  6390. {
  6391. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6392. {
  6393. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6394. c++;
  6395. }
  6396. sstr[c] = '\0';
  6397. strcpy(parentIdTagstr, sstr);
  6398. }
  6399. //***(5)reservationId ****/
  6400. c=0;
  6401. loc = strstr(payload, "reservationId");
  6402. memset(sstr ,0, sizeof(sstr) );
  6403. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6404. {
  6405. sstr[c] = loc[strlen("reservationId")+2+c];
  6406. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6407. c++;
  6408. }
  6409. sstr[c] = '\0';
  6410. reservationIdInt = atoi(sstr);
  6411. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6412. /*
  6413. enum SYSTEM_STATUS
  6414. {
  6415. SYS_MODE_BOOTING = 0,
  6416. SYS_MODE_IDLE = 1,
  6417. SYS_MODE_AUTHORIZING = 2,
  6418. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6419. SYS_MODE_REASSIGN = 4,
  6420. SYS_MODE_PREPARING = 5,
  6421. SYS_MODE_PREPARE_FOR_EV = 6,
  6422. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6423. SYS_MODE_CHARGING = 8,
  6424. SYS_MODE_TERMINATING = 9,
  6425. SYS_MODE_COMPLETE = 10,
  6426. SYS_MODE_ALARM = 11,
  6427. SYS_MODE_FAULT = 12,
  6428. SYS_MODE_RESERVATION = 13,
  6429. SYS_MODE_BOOKING = 14,
  6430. SYS_MODE_MAINTAIN = 15,
  6431. SYS_MODE_DEBUG = 16,
  6432. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6433. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6434. SYS_MODE_UPDATE = 19
  6435. };
  6436. */
  6437. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6438. {
  6439. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6440. goto end;
  6441. }
  6442. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6443. {
  6444. //check Transaction active
  6445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6446. {
  6447. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6448. {
  6449. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6450. {
  6451. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6452. {
  6453. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6454. {
  6455. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6456. {
  6457. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6458. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6459. }
  6460. 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'))
  6461. {
  6462. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6463. }
  6464. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6465. {
  6466. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6467. }
  6468. else
  6469. {
  6470. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6471. }
  6472. }
  6473. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6474. {
  6475. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6476. }
  6477. }
  6478. else
  6479. {
  6480. //replace reservation
  6481. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6483. }
  6484. }
  6485. } // END FOR CHAdeMO_QUANTITY
  6486. for (int index = 0; index < CCS_QUANTITY; index++)
  6487. {
  6488. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6489. {
  6490. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6491. {
  6492. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6493. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6494. {
  6495. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6496. {
  6497. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6499. }
  6500. 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'))
  6501. {
  6502. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6503. }
  6504. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6505. {
  6506. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6507. }
  6508. else
  6509. {
  6510. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6511. }
  6512. }
  6513. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6514. {
  6515. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6516. }
  6517. }
  6518. else
  6519. {
  6520. //replace reservation
  6521. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6523. }
  6524. }
  6525. } // END FOR CCS_QUANTITY
  6526. for (int index = 0; index < GB_QUANTITY; index++)
  6527. {
  6528. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6529. {
  6530. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6531. {
  6532. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6533. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6534. {
  6535. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6536. {
  6537. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6539. }
  6540. 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'))
  6541. {
  6542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6543. }
  6544. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6545. {
  6546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6547. }
  6548. else
  6549. {
  6550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6551. }
  6552. }
  6553. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6554. {
  6555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6556. }
  6557. }
  6558. else
  6559. {
  6560. //replace reservation
  6561. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6562. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6563. }
  6564. }
  6565. }// END FOR GB_QUANTITY
  6566. }
  6567. else
  6568. {
  6569. for (int index = 0; index < AC_QUANTITY; index++)
  6570. {
  6571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6572. {
  6573. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6574. {
  6575. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6576. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6577. {
  6578. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6579. {
  6580. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6582. }
  6583. 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'))
  6584. {
  6585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6586. }
  6587. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6588. {
  6589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6590. }
  6591. else
  6592. {
  6593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6594. }
  6595. }
  6596. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6597. {
  6598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6599. }
  6600. }
  6601. else
  6602. {
  6603. //replace reservation
  6604. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6606. }
  6607. }
  6608. } // END FOR AC_QUANTITY
  6609. }//END FOR AC ELSE
  6610. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6611. }
  6612. else if(connectorIdInt == 0)
  6613. {
  6614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6615. {
  6616. //check Transaction active
  6617. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6618. {
  6619. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6620. {
  6621. 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'))
  6622. {
  6623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6624. goto end;
  6625. }
  6626. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6627. {
  6628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6629. goto end;
  6630. }
  6631. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6632. {
  6633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6634. goto end;
  6635. }
  6636. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6637. {
  6638. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6639. goto end;
  6640. }
  6641. }
  6642. }// END FOR CHAdeMO_QUANTITY
  6643. for (int index = 0; index < CCS_QUANTITY; index++)
  6644. {
  6645. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6646. {
  6647. 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'))
  6648. {
  6649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6650. }
  6651. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6652. {
  6653. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6654. }
  6655. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6656. {
  6657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6658. }
  6659. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6660. {
  6661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6662. }
  6663. }
  6664. } // END FOR CCS_QUANTITY
  6665. for (int index = 0; index < GB_QUANTITY; index++)
  6666. {
  6667. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6668. {
  6669. 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'))
  6670. {
  6671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6672. }
  6673. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6674. {
  6675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6676. }
  6677. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6678. {
  6679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6680. }
  6681. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6682. {
  6683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6684. }
  6685. }
  6686. } // END FOR GB_QUANTITY
  6687. }
  6688. else
  6689. {
  6690. for (int index = 0; index < AC_QUANTITY; index++)
  6691. {
  6692. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6693. {
  6694. 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'))
  6695. {
  6696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6697. goto end;
  6698. }
  6699. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6700. {
  6701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6702. goto end;
  6703. }
  6704. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6705. {
  6706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6707. goto end;
  6708. }
  6709. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6710. {
  6711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6712. goto end;
  6713. }
  6714. }
  6715. }// END FOR AC_QUANTITY
  6716. }
  6717. //The connectorId is 0
  6718. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6720. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6721. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6722. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6723. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6724. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6725. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6726. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6727. result = TRUE;
  6728. return result;
  6729. }
  6730. else
  6731. {
  6732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6733. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6734. }
  6735. if(strcmp(comfirmstr,"Accepted") == 0)
  6736. {
  6737. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6738. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6739. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6740. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6741. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6742. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6743. result = TRUE;
  6744. return result;
  6745. }
  6746. end:
  6747. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6748. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6749. return result;
  6750. }
  6751. int handleResetRequest(char *uuid, char *payload)
  6752. {
  6753. mtrace();
  6754. int result = FAIL;
  6755. char sstr[10]={0};
  6756. char typestr[10]={0};
  6757. char comfirmstr[20]={0};
  6758. int c = 0;
  6759. char *loc;
  6760. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6761. DEBUG_INFO("handleResetRequest ...\n");
  6762. loc = strstr(payload, "type");
  6763. memset(sstr ,0, sizeof(sstr) );
  6764. c = 0;
  6765. while (loc[3+strlen("type")+c] != '\"')
  6766. {
  6767. sstr[c] = loc[3+strlen("type")+c];
  6768. c++;
  6769. }
  6770. sstr[c] = '\0';
  6771. strcpy(typestr,sstr);
  6772. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6773. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6774. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6775. {
  6776. //check Transaction active
  6777. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6778. {
  6779. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6780. {
  6781. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6782. {
  6783. //0: unplug, 1: Plug-in
  6784. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6785. }
  6786. }
  6787. for (int index = 0; index < CCS_QUANTITY; index++)
  6788. {
  6789. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6790. {
  6791. //0: unplug, 1: Plug-in
  6792. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6793. }
  6794. }
  6795. for (int index = 0; index < GB_QUANTITY; index++)
  6796. {
  6797. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6798. {
  6799. //0: unplug, 1: Plug-in
  6800. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6801. }
  6802. }
  6803. }
  6804. else
  6805. {
  6806. for (int index = 0; index < AC_QUANTITY; index++)
  6807. {
  6808. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6809. {
  6810. //0: unplug, 1: Plug-in
  6811. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6812. }
  6813. }
  6814. }// END FOR AC ELSE
  6815. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6816. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6817. result = TRUE;
  6818. return result;
  6819. }
  6820. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6821. {
  6822. //check Transaction active
  6823. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6824. {
  6825. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6826. {
  6827. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6828. {
  6829. //0: unplug, 1: Plug-in
  6830. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6831. }
  6832. }
  6833. for (int index = 0; index < CCS_QUANTITY; index++)
  6834. {
  6835. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6836. {
  6837. //0: unplug, 1: Plug-in
  6838. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6839. }
  6840. }
  6841. for (int index = 0; index < GB_QUANTITY; index++)
  6842. {
  6843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6844. {
  6845. //0: unplug, 1: Plug-in
  6846. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6847. }
  6848. }
  6849. }
  6850. else
  6851. {
  6852. for (int index = 0; index < AC_QUANTITY; index++)
  6853. {
  6854. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6855. {
  6856. //0: unplug, 1: Plug-in
  6857. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6858. }
  6859. }
  6860. }// END FOR AC ELSE
  6861. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6862. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6863. result = TRUE;
  6864. return result;
  6865. }
  6866. else
  6867. {
  6868. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6869. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6870. goto errorend;
  6871. }
  6872. errorend:
  6873. sendResetConfirmation(uuid, comfirmstr);
  6874. return result;
  6875. }
  6876. int handleSendLocalListRequest(char *uuid, char *payload)
  6877. {
  6878. mtrace();
  6879. int result = FAIL;
  6880. int listVersionInt;
  6881. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6882. char listsearch[]="listVersion";
  6883. char updateTypesearch[]="updateType";
  6884. char localAuthorizationListsearch[]="localAuthorizationList";
  6885. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6886. char CardList[500][160]={0};
  6887. char updateTypestr[15]={0};
  6888. char idTagstr[20]={0};
  6889. char parentIdTag[20]={0};
  6890. char expiryDate[30]={0};
  6891. char idTagstatus[16]={0};
  6892. int c = 0;
  6893. int i = 0;
  6894. char *delim1 = "}";
  6895. char * pch;
  6896. char *loc;
  6897. //char *ptr;
  6898. char comfirmstr[20];
  6899. //int n_localAuthorizations = 0;
  6900. int checkState_Faulted = FALSE;
  6901. DEBUG_INFO("handleSendLocalListRequest\n");
  6902. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6903. {
  6904. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6905. goto end;
  6906. }
  6907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6908. {
  6909. //check Charge Point state
  6910. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6911. {
  6912. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6913. {
  6914. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6915. }
  6916. }
  6917. for (int index = 0; index < CCS_QUANTITY; index++)
  6918. {
  6919. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6920. {
  6921. checkState_Faulted = TRUE; //OCPP Status
  6922. }
  6923. }
  6924. for (int index = 0; index < GB_QUANTITY; index++)
  6925. {
  6926. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6927. {
  6928. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6929. }
  6930. }
  6931. }
  6932. else
  6933. {
  6934. //check Charge Point state
  6935. for (int index = 0; index < AC_QUANTITY; index++)
  6936. {
  6937. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6938. {
  6939. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6940. }
  6941. }
  6942. }// END FOR AC ELSE
  6943. if(checkState_Faulted == TRUE)
  6944. {
  6945. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6946. goto end;
  6947. }
  6948. //listVersion
  6949. c = 0;
  6950. loc = strstr(payload, listsearch);
  6951. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  6952. {
  6953. sstr[c] = loc[strlen("listVersion")+2+c];
  6954. c++;
  6955. }
  6956. sstr[c] = '\0';
  6957. listVersionInt = atoi(sstr);
  6958. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6959. //updateType
  6960. loc = strstr(payload, updateTypesearch);
  6961. c = 0;
  6962. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6963. {
  6964. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6965. c++;
  6966. }
  6967. sstr[c] = '\0';
  6968. strcpy(updateTypestr, sstr);
  6969. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6970. //localAuthorizationList
  6971. memset(sstr ,0, sizeof(sstr) );
  6972. loc = strstr(payload, localAuthorizationListsearch);
  6973. if(loc != NULL) // localAuthorizationList is not NULL
  6974. {
  6975. //Check UpdateType
  6976. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6977. {
  6978. //Local list full update
  6979. printf("Local list full update.\n");
  6980. OCPP_cleanLocalList();
  6981. }
  6982. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6983. {
  6984. //Local list different update
  6985. printf("Local list different update.\n");
  6986. OCPP_getListVerion();
  6987. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6988. {
  6989. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6990. goto end;
  6991. }
  6992. }
  6993. else
  6994. {
  6995. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6996. goto end;
  6997. }
  6998. c = 0;
  6999. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7000. {
  7001. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7002. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7003. c++;
  7004. }
  7005. sstr[c] = '\0';
  7006. //DEBUG_INFO("sstr=%s\n", sstr);
  7007. //parsing strings to words
  7008. i = 0;
  7009. pch = strtok(sstr,delim1);
  7010. while (pch != NULL)
  7011. {
  7012. strcpy(CardList[i], pch);
  7013. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7014. pch = strtok (NULL, delim1);
  7015. i = i + 1;
  7016. }
  7017. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7018. //local Authorizations List Numbers
  7019. //n_localAuthorizations = i;
  7020. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7021. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7022. c= 0;
  7023. while(c < i)
  7024. {
  7025. //Search "IdToken"
  7026. memset(sstr ,0, sizeof(sstr) );
  7027. loc = strstr(CardList[c], "idTag");
  7028. int j = 0;
  7029. while (loc[3+strlen("idTag")+j] != '\"')
  7030. {
  7031. sstr[j] = loc[3+strlen("idTag")+j];
  7032. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7033. j++;
  7034. }
  7035. sstr[j] = '\0';
  7036. strcpy(idTagstr, sstr);
  7037. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7038. //Search "expiryDate"
  7039. memset(sstr ,0, sizeof(sstr) );
  7040. loc = strstr(CardList[c], "expiryDate");
  7041. j = 0;
  7042. if(loc != NULL)
  7043. {
  7044. while (loc[3+strlen("expiryDate")+j] != '\"')
  7045. {
  7046. sstr[j] = loc[3+strlen("expiryDate")+j];
  7047. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7048. j++;
  7049. }
  7050. sstr[j] = '\0';
  7051. strcpy(expiryDate, sstr);
  7052. }
  7053. else
  7054. {
  7055. strcpy(expiryDate, "");
  7056. }
  7057. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7058. //Search "parentIdTag"
  7059. memset(sstr ,0, sizeof(sstr) );
  7060. loc = strstr(CardList[c], "parentIdTag");
  7061. j = 0;
  7062. if(loc != NULL)
  7063. {
  7064. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7065. {
  7066. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7067. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7068. j++;
  7069. }
  7070. sstr[j] = '\0';
  7071. strcpy(parentIdTag, sstr);
  7072. }
  7073. else
  7074. {
  7075. strcpy(parentIdTag, "");
  7076. }
  7077. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7078. //Search "status"
  7079. memset(sstr ,0, sizeof(sstr) );
  7080. loc = strstr(CardList[c], "status");
  7081. j = 0;
  7082. while (loc[3+strlen("status")+j] != '\"')
  7083. {
  7084. sstr[j] = loc[3+strlen("status")+j];
  7085. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7086. j++;
  7087. }
  7088. sstr[j] = '\0';
  7089. strcpy(idTagstatus, sstr);
  7090. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7091. OCPP_getIdTag(idTagstr);
  7092. //OCPP_getIdTag("test"); For Test
  7093. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7094. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7095. {
  7096. //Local list full update
  7097. DEBUG_INFO("Local list full update.\n");
  7098. // update list
  7099. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7100. OCPP_get_TableAuthlocalAllData();
  7101. }
  7102. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7103. {
  7104. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7105. {
  7106. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7107. }
  7108. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7109. {
  7110. OCPP_deleteIdTag(idTagstr);
  7111. }
  7112. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7113. {
  7114. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7115. }
  7116. }
  7117. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7118. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7119. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7120. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7121. c++;
  7122. }
  7123. }
  7124. else
  7125. {
  7126. //Check UpdateType
  7127. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7128. {
  7129. //Local list full update
  7130. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7131. OCPP_cleanLocalList();
  7132. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7133. goto end;
  7134. }
  7135. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7136. {
  7137. //Local list different update
  7138. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7139. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7140. goto end;
  7141. }
  7142. }
  7143. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7144. end:
  7145. sendSendLocalListConfirmation(uuid, comfirmstr);
  7146. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7147. return result;
  7148. }
  7149. #define MAX 200
  7150. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7151. {
  7152. mtrace();
  7153. int result = FAIL;
  7154. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7155. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7156. char chargingProfilePurposeStr[30]={0};
  7157. char chargingProfileKindStr[16]={0};
  7158. char recurrencyKindStr[10]={0};
  7159. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7160. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7161. int chargingSchedulePeriodCount = 0;
  7162. //int updateflag = FALSE;
  7163. char comfirmstr[20]={0};
  7164. int meet= FALSE;
  7165. char sstr[10]={0};
  7166. int c = 0;
  7167. char *loc;
  7168. FILE *fptr1;//, *fptr2;
  7169. //int lno=0;//, linectr = 0;
  7170. //int modifyflag = FALSE;
  7171. char filename[MAX]={0};
  7172. char tempfile[] = "../Storage/OCPP/temp.json";
  7173. //int resultRename=0;
  7174. char rmFileCmd[50]={0};
  7175. char tempchargingProfilePurposeStr[30]={0};
  7176. //[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}}}]
  7177. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7178. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7179. //*********************connectorId***************************/
  7180. loc = strstr(payload, "connectorId");
  7181. c = 0;
  7182. memset(sstr ,0, sizeof(sstr) );
  7183. while (loc[strlen("connectorId")+2+c] != ',')
  7184. {
  7185. sstr[c] = loc[strlen("connectorId")+2+c];
  7186. c++;
  7187. }
  7188. sstr[c] = '\0';
  7189. connectorIdInt = atoi(sstr);
  7190. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7191. {
  7192. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7193. }
  7194. else
  7195. {
  7196. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7197. }
  7198. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7199. //*********************chargingProfileId***************************/
  7200. loc = strstr(payload, "chargingProfileId");
  7201. c = 0;
  7202. memset(sstr ,0, sizeof(sstr) );
  7203. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7204. {
  7205. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7206. c++;
  7207. }
  7208. sstr[c] = '\0';
  7209. chargingProfileIdInt = atoi(sstr);
  7210. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7211. {
  7212. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7213. }
  7214. else
  7215. {
  7216. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7217. }
  7218. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7219. //*********************transactionId***************************/
  7220. loc = strstr(payload, "transactionId");
  7221. if(loc != NULL)
  7222. {
  7223. c = 0;
  7224. memset(sstr ,0, sizeof(sstr) );
  7225. while (loc[strlen("transactionId")+2+c] != ',')
  7226. {
  7227. sstr[c] = loc[strlen("transactionId")+2+c];
  7228. c++;
  7229. }
  7230. sstr[c] = '\0';
  7231. transactionIdInt = atoi(sstr);
  7232. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7233. {
  7234. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7235. }
  7236. else
  7237. {
  7238. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7239. }
  7240. }
  7241. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7242. //*********************stackLevel***************************/
  7243. loc = strstr(payload, "stackLevel");
  7244. c = 0;
  7245. memset(sstr ,0, sizeof(sstr) );
  7246. while (loc[strlen("stackLevel")+2+c] != ',')
  7247. {
  7248. sstr[c] = loc[strlen("stackLevel")+2+c];
  7249. c++;
  7250. }
  7251. sstr[c] = '\0';
  7252. stackLevelInt = atoi(sstr);
  7253. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7254. {
  7255. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7256. }
  7257. else
  7258. {
  7259. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7260. }
  7261. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7262. //*********************chargingProfilePurpose***************************/
  7263. loc = strstr(payload, "chargingProfilePurpose");
  7264. c = 0;
  7265. memset(sstr ,0, sizeof(sstr) );
  7266. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7267. {
  7268. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7269. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7270. c++;
  7271. }
  7272. sstr[c] = '\0';
  7273. strcpy(chargingProfilePurposeStr,sstr);
  7274. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7275. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7276. {
  7277. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7278. }
  7279. else
  7280. {
  7281. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7282. }
  7283. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7284. //*********************chargingProfileKind***************************/
  7285. loc = strstr(payload, "chargingProfileKind");
  7286. c = 0;
  7287. memset(sstr ,0, sizeof(sstr) );
  7288. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7289. {
  7290. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7291. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7292. c++;
  7293. }
  7294. sstr[c] = '\0';
  7295. strcpy(chargingProfileKindStr,sstr);
  7296. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7297. {
  7298. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7299. }
  7300. else
  7301. {
  7302. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7303. }
  7304. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7305. //*********************recurrencyKind***************************/
  7306. loc = strstr(payload, "recurrencyKind");
  7307. if(loc != NULL)
  7308. {
  7309. c = 0;
  7310. memset(sstr ,0, sizeof(sstr) );
  7311. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7312. {
  7313. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7314. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7315. c++;
  7316. }
  7317. sstr[c] = '\0';
  7318. strcpy(recurrencyKindStr,sstr);
  7319. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7320. {
  7321. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7322. }
  7323. else
  7324. {
  7325. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7326. }
  7327. }
  7328. else
  7329. {
  7330. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7331. {
  7332. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7333. }
  7334. else
  7335. {
  7336. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7337. }
  7338. }
  7339. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7340. //*********************validFrom***************************/
  7341. loc = strstr(payload, "validFrom");
  7342. if(loc != NULL)
  7343. {
  7344. c = 0;
  7345. memset(sstr ,0, sizeof(sstr) );
  7346. while (loc[3+strlen("validFrom")+c] != '\"')
  7347. {
  7348. sstr[c] = loc[3+strlen("validFrom")+c];
  7349. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7350. c++;
  7351. }
  7352. sstr[c] = '\0';
  7353. strcpy(validFromStr,sstr);
  7354. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7355. {
  7356. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7357. }
  7358. else
  7359. {
  7360. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7361. }
  7362. }
  7363. else
  7364. {
  7365. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7366. {
  7367. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7368. }
  7369. else
  7370. {
  7371. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7372. }
  7373. }
  7374. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7375. //*********************validTo***************************/
  7376. loc = strstr(payload, "validTo");
  7377. if(loc != NULL)
  7378. {
  7379. c = 0;
  7380. memset(sstr ,0, sizeof(sstr) );
  7381. while (loc[3+strlen("validTo")+c] != '\"')
  7382. {
  7383. sstr[c] = loc[3+strlen("validTo")+c];
  7384. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7385. c++;
  7386. }
  7387. sstr[c] = '\0';
  7388. strcpy(validToStr,sstr);
  7389. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7390. {
  7391. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7392. }
  7393. else
  7394. {
  7395. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7396. }
  7397. }
  7398. else
  7399. {
  7400. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7401. {
  7402. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7403. }
  7404. else
  7405. {
  7406. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7407. }
  7408. }
  7409. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7410. //*********************duration***************************/
  7411. loc = strstr(payload, "duration");
  7412. if(loc != NULL)
  7413. {
  7414. c = 0;
  7415. memset(sstr ,0, sizeof(sstr) );
  7416. while (loc[strlen("duration")+2+c] != ',')
  7417. {
  7418. sstr[c] = loc[strlen("duration")+2+c];
  7419. c++;
  7420. }
  7421. sstr[c] = '\0';
  7422. durationInt = atoi(sstr);
  7423. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7424. {
  7425. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7426. }
  7427. else
  7428. {
  7429. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7430. }
  7431. }
  7432. else
  7433. {
  7434. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7435. {
  7436. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7437. }
  7438. else
  7439. {
  7440. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7441. }
  7442. }
  7443. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7444. //*********************startSchedule***************************/
  7445. loc = strstr(payload, "startSchedule");
  7446. if(loc != NULL)
  7447. {
  7448. c = 0;
  7449. memset(sstr ,0, sizeof(sstr) );
  7450. while (loc[3+strlen("startSchedule")+c] != '\"')
  7451. {
  7452. sstr[c] = loc[3+strlen("startSchedule")+c];
  7453. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7454. c++;
  7455. }
  7456. sstr[c] = '\0';
  7457. strcpy(startScheduleStr,sstr);
  7458. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7459. {
  7460. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7461. }
  7462. else
  7463. {
  7464. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7465. }
  7466. }
  7467. else
  7468. {
  7469. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7470. {
  7471. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7472. }
  7473. else
  7474. {
  7475. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7476. }
  7477. }
  7478. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7479. //*********************chargingRateUnit***************************/
  7480. loc = strstr(payload, "chargingRateUnit");
  7481. if(loc != NULL)
  7482. {
  7483. c = 0;
  7484. memset(sstr ,0, sizeof(sstr) );
  7485. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7486. {
  7487. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7488. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7489. c++;
  7490. }
  7491. sstr[c] = '\0';
  7492. strcpy(chargingRateUnitStr,sstr);
  7493. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7494. {
  7495. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7496. }
  7497. else
  7498. {
  7499. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7500. }
  7501. }
  7502. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7503. //****************chargingSchedulePeriod count start*******************/
  7504. int what_len = strlen("startPeriod");
  7505. char tempChargingProfile[1000]={0};
  7506. strcpy(tempChargingProfile,(const char*)payload);
  7507. char *where = tempChargingProfile;
  7508. if (what_len)
  7509. {
  7510. while ((where = strstr(where, "startPeriod"))) {
  7511. where += what_len;
  7512. chargingSchedulePeriodCount++;
  7513. }
  7514. }
  7515. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7516. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7517. //where = payload;
  7518. int templength = 0;
  7519. //int searchstart = 0;
  7520. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7521. {
  7522. //****************startPeriod*******************/
  7523. c=0;
  7524. loc = strstr(tempChargingProfile + templength, "startPeriod");
  7525. memset(sstr ,0, sizeof(sstr) );
  7526. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7527. {
  7528. sstr[c] = loc[strlen("startPeriod")+2+c];
  7529. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7530. c++;
  7531. }
  7532. sstr[c] = '\0';
  7533. startPeriodInt[periodNums] = atoi(sstr);
  7534. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7535. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7536. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7537. {
  7538. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7539. }
  7540. else
  7541. {
  7542. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7543. }
  7544. templength = strlen("startPeriod")+2+c;
  7545. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7546. //****************limit*******************/
  7547. c=0;
  7548. loc = strstr(tempChargingProfile + templength, "limit");
  7549. memset(sstr ,0, sizeof(sstr) );
  7550. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7551. {
  7552. sstr[c] = loc[strlen("limit")+2+c];
  7553. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7554. c++;
  7555. }
  7556. sstr[c] = '\0';
  7557. limitflaot[periodNums] = atof(sstr);
  7558. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7559. {
  7560. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7561. }
  7562. else
  7563. {
  7564. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7565. }
  7566. templength = templength + strlen("limit")+2+c;
  7567. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7568. //****************numberPhases*******************/
  7569. loc = strstr(tempChargingProfile + templength, "numberPhases");
  7570. if(loc != NULL)
  7571. {
  7572. c=0;
  7573. memset(sstr ,0, sizeof(sstr) );
  7574. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7575. {
  7576. sstr[c] = loc[strlen("numberPhases")+2+c];
  7577. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7578. c++;
  7579. }
  7580. sstr[c] = '\0';
  7581. numberPhasesInt[periodNums] = atoi(sstr);
  7582. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7583. {
  7584. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7585. }
  7586. else
  7587. {
  7588. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7589. }
  7590. templength = templength + strlen("numberPhases")+2+c;
  7591. }
  7592. //where = loc;
  7593. }
  7594. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7595. //****************chargingSchedulePeriod count end*******************/
  7596. //*********************minChargingRate***************************/
  7597. loc = strstr(payload, "minChargingRate");
  7598. if(loc != NULL)
  7599. {
  7600. c = 0;
  7601. memset(sstr ,0, sizeof(sstr) );
  7602. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7603. {
  7604. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7605. c++;
  7606. }
  7607. sstr[c] = '\0';
  7608. minChargingRateFloat = atof(sstr);
  7609. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7610. {
  7611. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7612. }
  7613. else
  7614. {
  7615. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7616. }
  7617. }
  7618. else
  7619. {
  7620. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7621. {
  7622. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7623. }
  7624. else
  7625. {
  7626. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7627. }
  7628. }
  7629. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7630. {
  7631. //printf("set chargingProfile 1-2\n");
  7632. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7633. if(connectorIdInt != 0)
  7634. {
  7635. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7636. goto end;
  7637. }
  7638. strcpy(filename, ChargePointMaxProfile_JSON );
  7639. fptr1 = fopen(filename, "r");
  7640. if (!fptr1)
  7641. {
  7642. //file not exist
  7643. DEBUG_INFO("Unable to open the input file!!\n");
  7644. fptr1 = fopen(filename, "w+");
  7645. }
  7646. fclose(fptr1);
  7647. }
  7648. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7649. {
  7650. //printf("set chargingProfile 1-3\n");
  7651. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7652. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7653. {
  7654. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7655. goto end;
  7656. }
  7657. switch(connectorIdInt)
  7658. {
  7659. case 0:
  7660. strcpy(filename, TxDefaultProfile_0_JSON );
  7661. break;
  7662. case 1:
  7663. strcpy(filename, TxDefaultProfile_1_JSON );
  7664. break;
  7665. case 2:
  7666. strcpy(filename, TxDefaultProfile_2_JSON );
  7667. break;
  7668. default:
  7669. strcpy(filename, TxDefaultProfile_0_JSON );
  7670. break;
  7671. }
  7672. fptr1 = fopen(filename, "r");
  7673. if (!fptr1)
  7674. {
  7675. //file not exist
  7676. //DEBUG_INFO("Unable to open the input file!!\n");
  7677. fptr1 = fopen(filename, "w+");
  7678. }
  7679. fclose(fptr1);
  7680. }
  7681. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7682. {
  7683. //printf("set chargingProfile 1-4\n");
  7684. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7685. //check Transaction active
  7686. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7687. {
  7688. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7689. {
  7690. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7691. {
  7692. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7693. {
  7694. meet = TRUE;
  7695. break;
  7696. }
  7697. }
  7698. }
  7699. }
  7700. for (int index = 0; index < CCS_QUANTITY; index++)
  7701. {
  7702. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7703. {
  7704. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7705. {
  7706. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7707. {
  7708. meet = TRUE;
  7709. break;
  7710. }
  7711. }
  7712. }
  7713. }
  7714. for (int index = 0; index < GB_QUANTITY; index++)
  7715. {
  7716. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7717. {
  7718. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7719. {
  7720. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7721. {
  7722. meet = TRUE;
  7723. break;
  7724. }
  7725. }
  7726. }
  7727. }
  7728. if(meet == FALSE)
  7729. {
  7730. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7731. goto end;
  7732. }
  7733. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7734. {
  7735. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7736. goto end;
  7737. }
  7738. switch(connectorIdInt)
  7739. {
  7740. case 0:
  7741. break;
  7742. case 1:
  7743. strcpy(filename, TxProfile_1_JSON);
  7744. break;
  7745. case 2:
  7746. strcpy(filename, TxProfile_2_JSON);
  7747. break;
  7748. default:
  7749. strcpy(filename, TxProfile_1_JSON);
  7750. break;
  7751. }
  7752. fptr1 = fopen(filename, "r");
  7753. if (!fptr1)
  7754. {
  7755. //file not exist
  7756. DEBUG_INFO("Unable to open the input file!!\n");
  7757. fptr1 = fopen(filename, "w+");
  7758. }
  7759. fclose(fptr1);
  7760. }
  7761. //**********************************Write to File********************************************************/
  7762. FILE *infile;
  7763. FILE *outfile;
  7764. // open file for writing
  7765. infile = fopen (filename, "r");
  7766. outfile = fopen (tempfile, "w");
  7767. int d =0;
  7768. d = fgetc(infile);
  7769. //DEBUG_INFO("d:%d\n",d);
  7770. rewind(infile);
  7771. //*检测到文件结束标识返回1,否则返回0。*/
  7772. if(d == EOF)
  7773. {
  7774. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7775. fprintf(outfile,"%s\n",payload);
  7776. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7777. fclose(infile);
  7778. fclose(outfile);
  7779. sprintf(rmFileCmd,"rm -f %s",filename);
  7780. system(rmFileCmd);
  7781. rename(tempfile, filename);
  7782. #if 0
  7783. resultRename = rename(tempfile, filename);
  7784. if(resultRename == 0)
  7785. {
  7786. DEBUG_INFO("File chargingProfile renamed successfully");
  7787. }
  7788. else
  7789. {
  7790. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7791. }
  7792. #endif
  7793. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7794. //system(rmFileCmd);
  7795. }
  7796. else
  7797. {
  7798. char buf[1000]={0};
  7799. int ChargingProfileAdded = FALSE;
  7800. while (fgets(buf, sizeof(buf), infile) != NULL)
  7801. {
  7802. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7803. //*************************tempconnectorIdInt*********************************/
  7804. loc = strstr(buf, "connectorId");
  7805. c = 0;
  7806. memset(sstr ,0, sizeof(sstr) );
  7807. while (loc[strlen("connectorId")+2+c] != ',')
  7808. {
  7809. sstr[c] = loc[strlen("connectorId")+2+c];
  7810. c++;
  7811. }
  7812. sstr[c] = '\0';
  7813. tempconnectorIdInt = atoi(sstr);
  7814. //*************************tempchargingProfileIdInt*********************************/
  7815. loc = strstr(buf, "chargingProfileId");
  7816. c = 0;
  7817. memset(sstr ,0, sizeof(sstr) );
  7818. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7819. {
  7820. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7821. c++;
  7822. }
  7823. sstr[c] = '\0';
  7824. tempchargingProfileIdInt = atoi(sstr);
  7825. //*************************tempstackLevelInt*********************************/
  7826. loc = strstr(buf, "stackLevel");
  7827. c = 0;
  7828. memset(sstr ,0, sizeof(sstr) );
  7829. while (loc[strlen("stackLevel")+2+c] != ',')
  7830. {
  7831. sstr[c] = loc[strlen("stackLevel")+2+c];
  7832. c++;
  7833. }
  7834. sstr[c] = '\0';
  7835. tempstackLevelInt = atoi(sstr);
  7836. //*************************tempchargingProfilePurposeStr*********************************/
  7837. loc = strstr(payload, "chargingProfilePurpose");
  7838. c = 0;
  7839. memset(sstr ,0, sizeof(sstr) );
  7840. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7841. {
  7842. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7843. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7844. c++;
  7845. }
  7846. sstr[c] = '\0';
  7847. strcpy(tempchargingProfilePurposeStr,sstr);
  7848. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7849. {
  7850. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7851. {
  7852. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7853. if(ChargingProfileAdded == FALSE)
  7854. {
  7855. fprintf(outfile,"%s\n",payload);
  7856. ChargingProfileAdded = TRUE;
  7857. }
  7858. }
  7859. else
  7860. {
  7861. if(tempstackLevelInt < stackLevelInt)
  7862. {
  7863. if(ChargingProfileAdded == FALSE)
  7864. {
  7865. fprintf(outfile,"%s\n",payload);
  7866. ChargingProfileAdded = TRUE;
  7867. fprintf(outfile,"%s\n",buf);
  7868. }
  7869. else
  7870. {
  7871. fprintf(outfile,"%s\n",buf);
  7872. }
  7873. }
  7874. else
  7875. {
  7876. if(ChargingProfileAdded == FALSE)
  7877. {
  7878. fprintf(outfile,"%s\n",buf);
  7879. fprintf(outfile,"%s\n",payload);
  7880. ChargingProfileAdded = TRUE;
  7881. }
  7882. else
  7883. {
  7884. fprintf(outfile,"%s\n",buf);
  7885. }
  7886. }
  7887. }
  7888. }
  7889. else
  7890. {
  7891. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7892. {
  7893. if(ChargingProfileAdded == FALSE)
  7894. {
  7895. fprintf(outfile,"%s\n",payload);
  7896. ChargingProfileAdded = TRUE;
  7897. fprintf(outfile,"%s\n",buf);
  7898. }
  7899. else
  7900. {
  7901. fprintf(outfile,"%s\n",buf);
  7902. }
  7903. }
  7904. else if(tempstackLevelInt < stackLevelInt)
  7905. {
  7906. if(ChargingProfileAdded == FALSE)
  7907. {
  7908. fprintf(outfile,"%s\n",payload);
  7909. ChargingProfileAdded = TRUE;
  7910. fprintf(outfile,"%s\n",buf);
  7911. }
  7912. else
  7913. {
  7914. fprintf(outfile,"%s\n",buf);
  7915. }
  7916. }
  7917. else
  7918. {
  7919. if(ChargingProfileAdded == FALSE)
  7920. {
  7921. fprintf(outfile,"%s\n",buf);
  7922. fprintf(outfile,"%s\n",payload);
  7923. ChargingProfileAdded = TRUE;
  7924. }
  7925. else
  7926. {
  7927. fprintf(outfile,"%s\n",buf);
  7928. }
  7929. }
  7930. }
  7931. } // end of while loop
  7932. fclose(infile);
  7933. fclose(outfile);
  7934. sprintf(rmFileCmd,"rm -f %s",filename);
  7935. system(rmFileCmd);
  7936. rename(tempfile, filename);
  7937. #if 0
  7938. resultRename = rename(tempfile, filename);
  7939. if(resultRename == 0)
  7940. {
  7941. DEBUG_INFO("File chargingProfile renamed successfully");
  7942. }
  7943. else
  7944. {
  7945. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7946. }
  7947. #endif
  7948. result = TRUE;
  7949. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7950. }
  7951. end:
  7952. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7953. return result;
  7954. return result;
  7955. }
  7956. int handleTriggerMessageRequest(char *uuid, char *payload)
  7957. {
  7958. mtrace();
  7959. int result = FAIL;
  7960. int connectorIdIsNULL = FALSE;
  7961. int connectorIdInt =0;
  7962. char sstr[40]={0};
  7963. char requestedMessagestr[40]={0};
  7964. char comfirmstr[20]={0};
  7965. int c = 0;
  7966. char *loc;
  7967. DEBUG_INFO("handleTriggerMessageRequest\n");
  7968. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7969. c = 0;
  7970. loc = strstr(payload, "requestedMessage");
  7971. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7972. {
  7973. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7974. c++;
  7975. }
  7976. sstr[c] = '\0';
  7977. strcpy(requestedMessagestr, sstr);
  7978. c = 0;
  7979. loc = strstr(payload, "connectorId");
  7980. if(loc == NULL)
  7981. {
  7982. connectorIdIsNULL = TRUE;
  7983. }
  7984. else
  7985. {
  7986. memset(sstr ,0, sizeof(sstr) );
  7987. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7988. {
  7989. sstr[c] = loc[strlen("connectorId")+2+c];
  7990. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7991. c++;
  7992. }
  7993. sstr[c] = '\0';
  7994. connectorIdInt = atoi(sstr);
  7995. }
  7996. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7997. {
  7998. //connectorIdInt = json_object_get_int(connectorId);
  7999. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8000. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8001. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8002. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8003. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8004. }
  8005. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8006. {
  8007. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8008. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8009. return TRUE;
  8010. }
  8011. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8012. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8013. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8014. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8015. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8016. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8017. {
  8018. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8019. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8020. return TRUE;
  8021. }
  8022. else
  8023. {
  8024. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8025. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8026. }
  8027. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8028. {
  8029. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8030. {
  8031. FirmwareStatusNotificationStatus = 3;
  8032. }
  8033. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8034. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8035. }
  8036. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8037. {
  8038. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8039. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8040. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8041. }
  8042. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8043. {
  8044. sendBootNotificationRequest();
  8045. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8046. }
  8047. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8048. {
  8049. sendHeartbeatRequest(connectorIdInt);
  8050. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8051. }
  8052. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8053. {
  8054. if(connectorIdIsNULL == FALSE)
  8055. {
  8056. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8057. {
  8058. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8059. sendMeterValuesRequest(connectorIdInt -1);
  8060. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8061. }
  8062. }
  8063. else
  8064. {
  8065. for(int idx=0;idx< gunTotalNumber;idx++)
  8066. {
  8067. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8068. sendMeterValuesRequest(idx);
  8069. }
  8070. }
  8071. }
  8072. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8073. {
  8074. if(connectorIdIsNULL == FALSE)
  8075. {
  8076. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8077. {
  8078. sendStatusNotificationRequest(connectorIdInt -1);
  8079. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8080. }
  8081. }
  8082. else
  8083. {
  8084. for(int idx=0;idx< gunTotalNumber;idx++)
  8085. sendStatusNotificationRequest(idx);
  8086. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8087. }
  8088. }
  8089. return result;
  8090. }
  8091. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8092. {
  8093. mtrace();
  8094. int result = FAIL;
  8095. char sstr[6]={0};
  8096. int connectorIdInt =0;
  8097. char comfirmstr[20]={0};
  8098. int c = 0;
  8099. char *loc;
  8100. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8101. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8102. c = 0;
  8103. loc = strstr(payload, "connectorId");
  8104. memset(sstr ,0, sizeof(sstr) );
  8105. while (loc[strlen("connectorId")+2+c] != '}')
  8106. {
  8107. sstr[c] = loc[strlen("connectorId")+2+c];
  8108. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8109. c++;
  8110. }
  8111. sstr[c] = '\0';
  8112. connectorIdInt = atoi(sstr);
  8113. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8114. if(gunTotalNumber == 0)
  8115. {
  8116. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8117. goto end;
  8118. }
  8119. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8120. {
  8121. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8122. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8123. goto end;
  8124. }
  8125. else
  8126. {
  8127. //check Transaction active
  8128. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8129. {
  8130. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8131. {
  8132. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8133. {
  8134. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8135. }
  8136. }
  8137. for (int index = 0; index < CCS_QUANTITY; index++)
  8138. {
  8139. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8140. {
  8141. //stop Transaction
  8142. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8143. }
  8144. }
  8145. for (int index = 0; index < GB_QUANTITY; index++)
  8146. {
  8147. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8148. {
  8149. //stop Transaction
  8150. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8151. }
  8152. }
  8153. }
  8154. else
  8155. {
  8156. for (int index = 0; index < AC_QUANTITY; index++)
  8157. {
  8158. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8159. {
  8160. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8161. }
  8162. }
  8163. }// END FOR AC ELSE
  8164. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8165. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8166. result = TRUE;
  8167. return result;
  8168. }
  8169. end:
  8170. //json_object_put(obj); --- remove temporally
  8171. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8172. return result;
  8173. }
  8174. static char UpdateFirmwarepayloadData[300]={0};
  8175. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8176. {
  8177. mtrace();
  8178. int result = FAIL;
  8179. pthread_t t;
  8180. sendUpdateFirmwareConfirmation(uuid);
  8181. memset(UpdateFirmwarepayloadData, 0, 300);
  8182. strcpy(UpdateFirmwarepayloadData, payload);
  8183. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8184. ////pthread_join(t, NULL); //
  8185. //pthread_detach(t);
  8186. //sendUpdateFirmwareConfirmation(uuid);
  8187. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8188. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8189. return result;
  8190. }
  8191. void *UpdateFirmwareProcess(void *data)
  8192. {
  8193. pthread_detach(pthread_self());
  8194. mtrace();
  8195. int retriesInt =0, retryIntervalInt=0;
  8196. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8197. int port=0;
  8198. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8199. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8200. //char comfirmstr[20];
  8201. int isSuccess = 0;
  8202. char ftpbuf[200];
  8203. char temp[100];
  8204. char * pch;
  8205. int retriesISNULL=FALSE;
  8206. int retryInterval=FALSE;
  8207. int c = 0;
  8208. //int i = 0;
  8209. char *loc;
  8210. char sstr[300]={ 0 };
  8211. char str[300]={ 0 };
  8212. //char *str = (char*) data; // ? ?輸入資 ?
  8213. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8214. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8215. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8216. //***************location **************/
  8217. loc = strstr(str, "location");
  8218. memset(sstr ,0, sizeof(sstr) );
  8219. c = 0;
  8220. while (loc[3+strlen("location")+c] != '\"')
  8221. {
  8222. sstr[c] = loc[3+strlen("location")+c];
  8223. c++;
  8224. }
  8225. sstr[c] = '\0';
  8226. strcpy(locationstr, sstr);
  8227. //***************retries**************/
  8228. c = 0;
  8229. loc = strstr(str, "retries");
  8230. if(loc == NULL)
  8231. {
  8232. retriesISNULL=TRUE;
  8233. }
  8234. else
  8235. {
  8236. memset(sstr ,0, sizeof(sstr) );
  8237. while (loc[strlen("retries")+2+c] != ',')
  8238. {
  8239. sstr[c] = loc[strlen("retries")+2+c];
  8240. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8241. c++;
  8242. }
  8243. sstr[c] = '\0';
  8244. }
  8245. if(retriesISNULL == FALSE)
  8246. {
  8247. retriesInt = atoi(sstr);
  8248. }
  8249. //***************retrieveDate **************/
  8250. loc = strstr(str, "retrieveDate");
  8251. memset(sstr ,0, sizeof(sstr) );
  8252. c = 0;
  8253. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8254. {
  8255. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8256. c++;
  8257. }
  8258. sstr[c] = '\0';
  8259. strcpy(retrieveDatestr, sstr);
  8260. //***************retryInterval **************/
  8261. c = 0;
  8262. loc = strstr(str, "retryInterval");
  8263. memset(sstr ,0, sizeof(sstr) );
  8264. if(loc == NULL)
  8265. {
  8266. retryInterval=TRUE;
  8267. }
  8268. else
  8269. {
  8270. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8271. {
  8272. sstr[c] = loc[strlen("retryInterval")+2+c];
  8273. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8274. c++;
  8275. }
  8276. sstr[c] = '\0';
  8277. }
  8278. if(retryInterval==FALSE)
  8279. {
  8280. retryIntervalInt = atoi(sstr);
  8281. }
  8282. memset(ftppath, 0, sizeof(ftppath));
  8283. memset(path, 0, sizeof(path));
  8284. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8285. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8286. if(strncmp(locationstr,"http", 4) == 0)
  8287. {
  8288. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8289. protocol, host, path);
  8290. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8291. // protocol, user, password, host, path);
  8292. sprintf(ftppath,"/%s", path);
  8293. //DEBUG_INFO("protocol =%s\n",protocol);
  8294. //DEBUG_INFO("host =%s\n",host);
  8295. //DEBUG_INFO("path =%s\n",path);
  8296. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8297. int ftppathlen=strlen(ftppath);
  8298. int i=1;
  8299. char filenametemp[50];
  8300. while(i < ftppathlen)
  8301. {
  8302. int len=ftppathlen-i;
  8303. if(ftppath[len]== 47) // '/' ascll code: 47
  8304. {
  8305. DEBUG_INFO("compare '/' all right\n");
  8306. break;
  8307. }
  8308. i=i+1;
  8309. }
  8310. memset(filenametemp, 0, sizeof(filenametemp));
  8311. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8312. filenametemp[i+1] = 0;
  8313. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8314. do{
  8315. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8316. sleep(retryIntervalInt);
  8317. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8318. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8319. if(!isSuccess)
  8320. {
  8321. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8322. }
  8323. else
  8324. {
  8325. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8326. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8327. isUpdateRequest = TRUE;
  8328. }
  8329. }
  8330. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8331. {
  8332. memset(ftpbuf, 0, sizeof(ftpbuf));
  8333. memset(temp, 0, sizeof(temp));
  8334. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8335. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8336. int ftppathlen=strlen(ftpbuf);
  8337. int i=1;
  8338. char filenametemp[50];
  8339. while(i < ftppathlen)
  8340. {
  8341. int len=ftppathlen-i;
  8342. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8343. {
  8344. DEBUG_INFO(" compare '/' all right\n");
  8345. break;
  8346. }
  8347. i=i+1;
  8348. }
  8349. memset(filenametemp, 0, sizeof(filenametemp));
  8350. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8351. filenametemp[i+1] = 0;
  8352. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8353. pch=strchr(temp,'@');
  8354. if(pch==NULL)
  8355. {
  8356. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8357. protocol, host, &port, path);
  8358. strcpy(user,"anonymous");
  8359. strcpy(password,"");
  8360. }
  8361. else
  8362. {
  8363. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8364. protocol, user, password, host, &port, path);
  8365. }
  8366. sscanf(host,"%[^/]%s",host1, path1);
  8367. sprintf(ftppath,"%s", path1);
  8368. //DEBUG_INFO("protocol =%s\n",protocol);
  8369. //DEBUG_INFO("user =%s\n",user);
  8370. //DEBUG_INFO("password =%s\n",password);
  8371. //DEBUG_INFO("host1 =%s\n",host1);
  8372. //DEBUG_INFO("port =%d\n",port);
  8373. //DEBUG_INFO("path1 =%s\n",path1);
  8374. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8375. //ftpFile(host, user, password, port, ftppath, fname);
  8376. //download firmware pthred
  8377. if(port == 0)
  8378. {
  8379. port = 21;
  8380. }
  8381. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8382. do{
  8383. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8384. sleep(retryIntervalInt);
  8385. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8386. if(!isSuccess)
  8387. {
  8388. //BulldogUtil.sleepMs(interval*1000);
  8389. DEBUG_INFO("Update firmware request and download file fail.\n");
  8390. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8391. }
  8392. else
  8393. {
  8394. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8395. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8396. isUpdateRequest = TRUE;
  8397. }
  8398. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8399. }
  8400. else
  8401. {
  8402. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8403. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8404. }
  8405. pthread_exit(NULL);
  8406. }
  8407. //==========================================
  8408. // Handle server response routine
  8409. //==========================================
  8410. void handleAuthorizeResponse(char *payload, int gun_index)
  8411. {
  8412. mtrace();
  8413. char expiryDatestr[30]={0};
  8414. char parentIdTagstr[20]={0};
  8415. char statusstr[20]={0};
  8416. char expiryDatestrtemp[30]={0};
  8417. char parentIdTagstrtemp[20]={0};
  8418. char IdTagstrtemp[20]={0};
  8419. char statusstrtemp[20]={0};
  8420. int expiryDateISNULL=FALSE;
  8421. int parentIdTagISNULL=FALSE;
  8422. char sstr[160]={ 0 };
  8423. char* filename = AuthorizationCache_JSON;
  8424. char tempfile[] = "../Storage/OCPP/temp.json";
  8425. int c = 0;
  8426. char *loc;
  8427. int resultRename=0;
  8428. int responseIdTagInfoAsZero= 0;
  8429. char rmFileCmd[50]={0};
  8430. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8431. //***********expiryDate*************/
  8432. loc = strstr(payload, "expiryDate");
  8433. memset(sstr ,0, sizeof(sstr) );
  8434. c = 0;
  8435. if(loc == NULL)
  8436. {
  8437. expiryDateISNULL = TRUE;
  8438. }
  8439. else
  8440. {
  8441. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8442. {
  8443. sstr[c] = loc[3+strlen("expiryDate")+c];
  8444. c++;
  8445. }
  8446. sstr[c] = '\0';
  8447. strcpy(expiryDatestr, sstr);
  8448. }
  8449. //***********parentIdTag*************/
  8450. loc = strstr(payload, "parentIdTag");
  8451. memset(sstr ,0, sizeof(sstr) );
  8452. c = 0;
  8453. if(loc == NULL)
  8454. {
  8455. parentIdTagISNULL = TRUE;
  8456. }
  8457. else
  8458. {
  8459. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8460. {
  8461. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8462. c++;
  8463. }
  8464. sstr[c] = '\0';
  8465. strcpy(parentIdTagstr, sstr);
  8466. }
  8467. //***********status*************/
  8468. loc = strstr(payload, "status");
  8469. memset(sstr ,0, sizeof(sstr) );
  8470. c = 0;
  8471. while (loc[3+strlen("status")+c] != '\"')
  8472. {
  8473. sstr[c] = loc[3+strlen("status")+c];
  8474. c++;
  8475. }
  8476. sstr[c] = '\0';
  8477. strcpy(statusstr, sstr);
  8478. if(expiryDateISNULL == FALSE)
  8479. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8480. if(parentIdTagISNULL == FALSE)
  8481. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8482. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8483. //Update idTag information to authorization cache if supproted
  8484. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8485. {
  8486. if((access(filename,F_OK))!=-1)
  8487. {
  8488. printf("AuthorizationCache exist.\n");
  8489. }
  8490. else
  8491. {
  8492. printf("AuthorizationCache not exist\n");
  8493. FILE *log = fopen(filename, "w+");
  8494. if(log == NULL)
  8495. {
  8496. printf("log is NULL\n");
  8497. goto out;
  8498. }
  8499. else
  8500. {
  8501. fclose(log);
  8502. }
  8503. }
  8504. FILE *infile;
  8505. FILE *outfile;
  8506. // open file for writing
  8507. infile = fopen (filename, "r");
  8508. outfile = fopen (tempfile, "w");
  8509. //*检测到文件结束标识返回1,否则返回0。*/
  8510. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8511. int c;
  8512. c = fgetc(infile);
  8513. //DEBUG_INFO("c:%d\n",c);
  8514. rewind(infile);
  8515. if(c == EOF)
  8516. {
  8517. DEBUG_INFO("Orignal File is NULL\n");
  8518. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8519. {
  8520. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8521. }
  8522. else
  8523. {
  8524. strcpy(expiryDatestrtemp, "");
  8525. }
  8526. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8527. {
  8528. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8529. }
  8530. else
  8531. {
  8532. //write Authorize IdTag
  8533. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8534. }
  8535. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8536. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8537. fclose(infile);
  8538. fclose(outfile);
  8539. sprintf(rmFileCmd,"rm -f %s",filename);
  8540. system(rmFileCmd);
  8541. resultRename = rename(tempfile, filename);
  8542. if(resultRename == 0)
  8543. {
  8544. printf("File renamed successfully");
  8545. }
  8546. else
  8547. {
  8548. printf("Error: unable to rename the file");
  8549. }
  8550. }
  8551. else
  8552. {
  8553. char buf[160]={0};
  8554. while (fgets(buf, sizeof(buf), infile) != NULL)
  8555. {
  8556. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8557. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8558. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8559. memset(statusstr, 0, sizeof(statusstrtemp));
  8560. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8561. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8562. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8563. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8564. //------------------IdTag-----------------------
  8565. loc = strstr(buf, "idTag");
  8566. memset(sstr ,0, sizeof(sstr) );
  8567. c = 0;
  8568. while (loc[3+strlen("idTag")+c] != '\"')
  8569. {
  8570. sstr[c] = loc[3+strlen("idTag")+c];
  8571. c++;
  8572. }
  8573. sstr[c] = '\0';
  8574. strcpy(IdTagstrtemp,sstr);
  8575. //*********************expiryDate***************/
  8576. loc = strstr(buf, "expiryDate");
  8577. memset(sstr ,0, sizeof(sstr) );
  8578. c = 0;
  8579. while (loc[3+strlen("expiryDate")+c] != '\"')
  8580. {
  8581. sstr[c] = loc[3+strlen("expiryDate")+c];
  8582. c++;
  8583. }
  8584. sstr[c] = '\0';
  8585. strcpy(expiryDatestr,sstr);
  8586. //*********************parentIdTag***************/
  8587. loc = strstr(buf, "parentIdTag");
  8588. memset(sstr ,0, sizeof(sstr) );
  8589. c = 0;
  8590. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8591. {
  8592. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8593. c++;
  8594. }
  8595. sstr[c] = '\0';
  8596. strcpy(parentIdTagstr,sstr);
  8597. //*********************status***************/
  8598. loc = strstr(buf, "status");
  8599. memset(sstr ,0, sizeof(sstr) );
  8600. c = 0;
  8601. while (loc[3+strlen("status")+c] != '\"')
  8602. {
  8603. sstr[c] = loc[3+strlen("status")+c];
  8604. c++;
  8605. }
  8606. sstr[c] = '\0';
  8607. strcpy(statusstr,sstr);
  8608. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8609. {
  8610. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8611. responseIdTagInfoAsZero = 1;
  8612. }
  8613. else
  8614. {
  8615. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8616. }
  8617. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8618. {
  8619. //modify item
  8620. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8621. {
  8622. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8623. }
  8624. else
  8625. {
  8626. strcpy(expiryDatestrtemp, "");
  8627. }
  8628. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8629. {
  8630. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8631. }
  8632. else
  8633. {
  8634. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8635. }
  8636. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8637. }
  8638. else
  8639. {
  8640. //wrie original item
  8641. strcpy(expiryDatestrtemp, expiryDatestr);
  8642. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8643. strcpy(statusstrtemp, statusstr);
  8644. }
  8645. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8646. }
  8647. fclose(infile);
  8648. fclose(outfile);
  8649. sprintf(rmFileCmd,"rm -f %s",filename);
  8650. system(rmFileCmd);
  8651. resultRename = rename(tempfile, filename);
  8652. if(resultRename == 0)
  8653. {
  8654. DEBUG_INFO("File renamed successfully");
  8655. }
  8656. else
  8657. {
  8658. DEBUG_INFO("Error: unable to rename the file");
  8659. }
  8660. }
  8661. }
  8662. out:
  8663. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8664. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8665. authorizeRetryTimes = 0;
  8666. }
  8667. void handleBootNotificationResponse(char *payload, int gun_index)
  8668. {
  8669. mtrace();
  8670. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8671. char statusStr[12]={0};
  8672. char currentTimeStr[30]={0};
  8673. char *loc;
  8674. int intervalInt = 0;
  8675. int c = 0;
  8676. //double diff_t;
  8677. struct tm tp;
  8678. char buf[28]={0};
  8679. char timebuf[50]={0};
  8680. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8681. //*** interval ****/
  8682. c = 0;
  8683. loc = strstr(payload, "interval");
  8684. //printf("loc=%s\n",loc);
  8685. memset(sstr ,0, sizeof(sstr) );
  8686. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8687. {
  8688. sstr[c] = loc[strlen("interval")+2+c];
  8689. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8690. c++;
  8691. }
  8692. sstr[c] = '\0';
  8693. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8694. intervalInt = atoi(sstr);
  8695. //***status ****/
  8696. loc = strstr(payload, "status");
  8697. memset(sstr ,0, sizeof(sstr) );
  8698. c = 0;
  8699. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8700. {
  8701. sstr[c] = loc[3+strlen("status")+c];
  8702. c++;
  8703. }
  8704. sstr[c] = '\0';
  8705. strcpy(statusStr, sstr);
  8706. //***currentTime ****/
  8707. loc = strstr(payload, "currentTime");
  8708. //printf("loc=%s\n",loc);
  8709. memset(sstr ,0, sizeof(sstr) );
  8710. c = 0;
  8711. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8712. {
  8713. sstr[c] = loc[3+strlen("currentTime")+c];
  8714. c++;
  8715. }
  8716. sstr[c] = '\0';
  8717. strcpy(currentTimeStr, sstr);
  8718. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8719. HeartBeatWaitTime = BootNotificationInterval;
  8720. clientTime.Heartbeat=time((time_t*)NULL);
  8721. //write back to ShmOCPP16Data->BootNotification
  8722. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8723. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8724. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8725. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8726. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8727. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8728. {
  8729. server_sign = TRUE;
  8730. server_pending =FALSE;
  8731. }
  8732. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8733. {
  8734. server_pending = TRUE;
  8735. }
  8736. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8737. tp.tm_isdst = -1;
  8738. //time_t utc = mktime(&tp);
  8739. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8740. memset(timebuf, 0, sizeof timebuf);
  8741. sprintf(timebuf,"date -s '%s'",buf);
  8742. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8743. system(timebuf);
  8744. //==============================================
  8745. // RTC sync
  8746. //==============================================
  8747. system("/sbin/hwclock -w --systohc");
  8748. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8749. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8750. }
  8751. void handleDataTransferResponse(char *payload, int gun_index)
  8752. {
  8753. char sstr[160]={0};//sstr[200]={ 0 };
  8754. int c = 0;
  8755. char *loc;
  8756. DEBUG_INFO("handleDataTransferResponse ...\n");
  8757. loc = strstr(payload, "status");
  8758. printf("loc=%s\n",loc);
  8759. c = 0;
  8760. while (loc[3+strlen("status")+c] != '\"')
  8761. {
  8762. sstr[c] = loc[3+strlen("status")+c];
  8763. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8764. c++;
  8765. }
  8766. sstr[c] = '\0';
  8767. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8768. }
  8769. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8770. {
  8771. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8772. //struct json_object *obj;
  8773. // obj = json_tokener_parse(payload);
  8774. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8775. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8776. //No fields are defined.
  8777. }
  8778. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8779. {
  8780. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8781. //struct json_object *obj;
  8782. // obj = json_tokener_parse(payload);
  8783. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8784. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8785. //No fields are defined.
  8786. }
  8787. void handleHeartbeatResponse(char *payload, int gun_index)
  8788. {
  8789. mtrace();
  8790. //double diff_t;
  8791. struct tm tp;
  8792. char buf[28]={0};
  8793. char timebuf[50]={0};
  8794. char sstr[30]={ 0 };
  8795. int c = 0;
  8796. char *loc;
  8797. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8798. if((HeartBeatCount%360) == 0)
  8799. {
  8800. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8801. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8802. }
  8803. HeartBeatCount = HeartBeatCount + 1;
  8804. c = 0;
  8805. loc = strstr(payload, "currentTime");
  8806. memset(sstr ,0, sizeof(sstr) );
  8807. while (loc[3+strlen("currentTime")+c] != '\"')
  8808. {
  8809. sstr[c] = loc[3+strlen("currentTime")+c];
  8810. c++;
  8811. }
  8812. sstr[c] = '\0';
  8813. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8814. // #ifdef SystemLogMessage
  8815. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8816. // #endif
  8817. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8818. tp.tm_isdst = -1;
  8819. //time_t utc = mktime(&tp);
  8820. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8821. memset(timebuf, 0, sizeof timebuf);
  8822. sprintf(timebuf,"date -s '%s'",buf);
  8823. system(timebuf);
  8824. //==============================================
  8825. // RTC sync
  8826. //==============================================
  8827. system("/sbin/hwclock -w --systohc");
  8828. if(FirstHeartBeat == 0)
  8829. {
  8830. FirstHeartBeat = 1;
  8831. }
  8832. HeartBeatWithNOResponse = 0;
  8833. }
  8834. void handleMeterValuesResponse(char *payload, int gun_index)
  8835. {
  8836. mtrace();
  8837. //struct json_object *obj;
  8838. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8839. //No fields are defined.
  8840. }
  8841. void handleStartTransactionResponse(char *payload, int gun_index)
  8842. {
  8843. mtrace();
  8844. char sstr[28]={ 0 };
  8845. int c = 0;
  8846. char *loc;
  8847. int transactionIdInt = 0;
  8848. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8849. DEBUG_INFO("handleStartTransactionResponse\n");
  8850. //****************expiryDate********************/
  8851. loc = strstr(payload, "expiryDate");
  8852. if(loc == NULL)
  8853. {
  8854. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8855. }
  8856. else
  8857. {
  8858. c = 0;
  8859. memset(sstr ,0, sizeof(sstr) );
  8860. while (loc[3+strlen("expiryDate")+c] != '\"')
  8861. {
  8862. sstr[c] = loc[3+strlen("expiryDate")+c];
  8863. c++;
  8864. }
  8865. sstr[c] = '\0';
  8866. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8867. }
  8868. //****************parentIdTag********************/
  8869. loc = strstr(payload, "parentIdTag");
  8870. if(loc == NULL)
  8871. {
  8872. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8873. }
  8874. else
  8875. {
  8876. c = 0;
  8877. memset(sstr ,0, sizeof(sstr) );
  8878. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8879. {
  8880. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8881. c++;
  8882. }
  8883. sstr[c] = '\0';
  8884. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8885. }
  8886. //****************status********************/
  8887. loc = strstr(payload, "status");
  8888. if(loc == NULL)
  8889. {
  8890. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8891. }
  8892. else
  8893. {
  8894. c = 0;
  8895. memset(sstr ,0, sizeof(sstr) );
  8896. while (loc[3+strlen("status")+c] != '\"')
  8897. {
  8898. sstr[c] = loc[3+strlen("status")+c];
  8899. c++;
  8900. }
  8901. sstr[c] = '\0';
  8902. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8903. }
  8904. //****************transactionId********************/
  8905. c=0;
  8906. loc = strstr(payload, "transactionId");
  8907. memset(sstr ,0, sizeof(sstr) );
  8908. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8909. {
  8910. sstr[c] = loc[strlen("transactionId")+2+c];
  8911. c++;
  8912. }
  8913. sstr[c] = '\0';
  8914. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8915. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8916. TransactionId[gun_index] = transactionIdInt;
  8917. DEBUG_INFO("gun_index: %d\n", gun_index);
  8918. DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  8919. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8920. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8921. #ifdef SystemLogMessage
  8922. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8923. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8924. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8925. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8926. #endif
  8927. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8928. {
  8929. //add Charging Record
  8930. SettingChargingRecord(gun_index, transactionIdInt);
  8931. }
  8932. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8933. }
  8934. void handleStatusNotificationResponse(char *payload, int gun_index)
  8935. {
  8936. mtrace();
  8937. printf("handleStatusNotificationResponse\n");
  8938. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8939. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8940. }
  8941. void handleStopTransactionnResponse(char *payload, int gun_index)
  8942. {
  8943. mtrace();
  8944. char sstr[30]={ 0 };
  8945. int c = 0;
  8946. char *loc;
  8947. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8948. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8949. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8950. loc = strstr(payload, "idTagInfo");
  8951. //***********************idTagInfo************************/
  8952. if(loc != NULL)
  8953. {
  8954. //***********************expiryDate************************/
  8955. loc = strstr(payload, "expiryDate");
  8956. if(loc != NULL)
  8957. {
  8958. memset(sstr ,0, sizeof(sstr) );
  8959. c = 0;
  8960. while (loc[3+strlen("expiryDate")+c] != '\"')
  8961. {
  8962. sstr[c] = loc[3+strlen("expiryDate")+c];
  8963. c++;
  8964. }
  8965. sstr[c] = '\0';
  8966. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8967. }
  8968. //***********************parentIdTag************************/
  8969. loc = strstr(payload, "parentIdTag");
  8970. if(loc != NULL)
  8971. {
  8972. memset(sstr ,0, sizeof(sstr) );
  8973. c = 0;
  8974. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8975. {
  8976. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8977. c++;
  8978. }
  8979. sstr[c] = '\0';
  8980. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8981. }
  8982. //***********************status************************/
  8983. loc = strstr(payload, "status");
  8984. memset(sstr ,0, sizeof(sstr) );
  8985. c = 0;
  8986. while (loc[3+strlen("status")+c] != '\"')
  8987. {
  8988. sstr[c] = loc[3+strlen("status")+c];
  8989. c++;
  8990. }
  8991. sstr[c] = '\0';
  8992. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8993. }
  8994. #ifdef SystemLogMessage
  8995. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8996. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8997. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8998. #endif
  8999. }
  9000. //==========================================
  9001. // Handle Error routine
  9002. //==========================================
  9003. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9004. {
  9005. mtrace();
  9006. #ifdef SystemLogMessage
  9007. DEBUG_INFO("errorCode: %s\n", errorCode);
  9008. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9009. DEBUG_INFO("errorDetails: %s\n", payload);
  9010. #endif
  9011. }
  9012. //===============================================
  9013. // Common routine
  9014. //===============================================
  9015. int initialConfigurationTable(void)
  9016. {
  9017. FILE *fp;
  9018. FILE *outfile;
  9019. char str[200]={0};
  9020. char sstr[100]={0};
  9021. int c = 0;
  9022. char *loc;
  9023. printf("initialConfigurationTable \n");
  9024. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9025. if((access("../Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9026. {
  9027. outfile = fopen("../Storage/OCPP/OCPPConfiguration" , "w+");
  9028. if(outfile == NULL) {
  9029. DEBUG_INFO("Error opening file");
  9030. return FALSE;
  9031. }
  9032. //outfile = fopen ("../Storage/OCPP/OCPPConfiguration", "a");
  9033. /*Core Profile*/
  9034. //AllowOfflineTxForUnknownId
  9035. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9036. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9039. //DEBUG_INFO("data=%s\n",data);
  9040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  9041. //AuthorizationCacheEnabled
  9042. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9046. //AuthorizeRemoteTxRequests
  9047. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "TRUE");
  9051. //BlinkRepeat
  9052. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9056. //ClockAlignedDataInterval
  9057. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9061. //ConnectionTimeOut
  9062. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9066. //GetConfigurationMaxKeys
  9067. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9071. // HeartbeatInterval
  9072. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9076. // LightIntensity
  9077. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9081. // LocalAuthorizeOffline
  9082. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9086. // LocalPreAuthorize
  9087. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9091. // MaxEnergyOnInvalidId
  9092. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9095. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9097. // MeterValuesAlignedData
  9098. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9102. // MeterValuesAlignedDataMaxLength
  9103. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9107. // MeterValuesSampledData
  9108. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9112. // MeterValuesSampledDataMaxLength
  9113. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9117. // MeterValueSampleInterval
  9118. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9122. // MinimumStatusDuration
  9123. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9127. // NumberOfConnectors
  9128. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9130. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9131. {
  9132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9133. }
  9134. else
  9135. {
  9136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9137. }
  9138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9139. // ResetRetries
  9140. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9144. // ConnectorPhaseRotation
  9145. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9149. // ConnectorPhaseRotationMaxLength
  9150. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9154. // StopTransactionOnEVSideDisconnect
  9155. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9159. // StopTransactionOnInvalidId
  9160. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9164. // StopTxnAlignedData
  9165. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9169. // StopTxnAlignedDataMaxLength
  9170. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9174. // StopTxnSampledData
  9175. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Energy.Active.Import.Register");
  9179. // StopTxnSampledDataMaxLength
  9180. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", "0");
  9184. // SupportedFeatureProfiles
  9185. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "0");
  9189. // SupportedFeatureProfilesMaxLength
  9190. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9194. // TransactionMessageAttempts
  9195. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9198. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9200. // TransactionMessageRetryInterval
  9201. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9204. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9206. // UnlockConnectorOnEVSideDisconnect
  9207. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9211. // WebSocketPingInterval
  9212. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9216. //* Local Auth List Management Profile*/
  9217. #if 0
  9218. //For OCTT Test Case
  9219. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9222. #endif
  9223. #if 1
  9224. //LocalAuthListEnabled
  9225. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9229. #endif
  9230. //LocalAuthListMaxLength
  9231. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9235. //SendLocalListMaxLength
  9236. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9240. //ReserveConnectorZeroSupported
  9241. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9245. //* Smart Charging Profile */
  9246. //ChargeProfileMaxStackLevel
  9247. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9251. // ChargingScheduleAllowedChargingRateUnit
  9252. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9256. // ChargingScheduleMaxPeriods
  9257. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9261. // ConnectorSwitch3to1PhaseSupported
  9262. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9266. // MaxChargingProfilesInstalled
  9267. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9271. fclose(outfile);
  9272. }
  9273. else
  9274. {
  9275. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9276. char keystr[60]={0};
  9277. char readonlystr[10]={0};
  9278. char valuestr[100]={0};
  9279. fp = fopen("../Storage/OCPP/OCPPConfiguration" , "r");
  9280. if(fp == NULL) {
  9281. DEBUG_INFO("Error opening file");
  9282. return FALSE;
  9283. }
  9284. while( fgets (str, sizeof(str), fp)!=NULL )
  9285. {
  9286. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9287. //*************************key*********************************/
  9288. loc = strstr(str, "key");
  9289. c = 0;
  9290. memset(sstr ,0, sizeof(sstr) );
  9291. while (loc[strlen("key")+3+c] != '\"')
  9292. {
  9293. sstr[c] = loc[strlen("key")+3+c];
  9294. c++;
  9295. }
  9296. sstr[c] = '\0';
  9297. strcpy(keystr,sstr);
  9298. //*************************readonly*********************************/
  9299. loc = strstr(str, "readonly");
  9300. c = 0;
  9301. memset(sstr ,0, sizeof(sstr) );
  9302. while (loc[strlen("readonly")+2+c] != ',')
  9303. {
  9304. sstr[c] = loc[strlen("readonly")+2+c];
  9305. c++;
  9306. }
  9307. sstr[c] = '\0';
  9308. strcpy(readonlystr,sstr);
  9309. //*************************value*********************************/
  9310. loc = strstr(str, "value");
  9311. c = 0;
  9312. memset(sstr ,0, sizeof(sstr) );
  9313. while (loc[strlen("value")+3+c] != '\"')
  9314. {
  9315. sstr[c] = loc[strlen("value")+3+c];
  9316. c++;
  9317. }
  9318. sstr[c] = '\0';
  9319. strcpy(valuestr,sstr);
  9320. // DEBUG_INFO("keystr=%s\n",keystr);
  9321. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9322. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9323. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9324. {
  9325. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9326. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9328. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9329. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9330. }
  9331. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9332. {
  9333. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9334. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9336. }
  9337. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9338. {
  9339. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9341. }
  9342. if(strcmp(keystr, "BlinkRepeat") == 0)
  9343. {
  9344. //Charger.BlinkRepeat = Integer.parseInt(value);
  9345. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9347. }
  9348. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9349. {
  9350. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9352. }
  9353. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9354. {
  9355. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9357. }
  9358. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9359. {
  9360. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9362. }
  9363. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9364. {
  9365. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9367. HeartBeatWaitTime = atoi(valuestr);
  9368. }
  9369. if(strcmp(keystr, "LightIntensity") == 0)
  9370. {
  9371. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9373. }
  9374. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9375. {
  9376. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9378. }
  9379. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9380. {
  9381. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9383. }
  9384. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9385. {
  9386. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9388. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9389. }
  9390. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9391. {
  9392. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9394. }
  9395. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9396. {
  9397. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9399. }
  9400. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9401. {
  9402. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9404. }
  9405. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9406. {
  9407. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9409. }
  9410. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9411. {
  9412. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9414. }
  9415. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9416. {
  9417. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9419. }
  9420. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9421. {
  9422. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9424. }
  9425. if(strcmp(keystr, "ResetRetries") == 0)
  9426. {
  9427. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9429. }
  9430. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9431. {
  9432. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9434. }
  9435. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9436. {
  9437. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9439. }
  9440. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  9441. {
  9442. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  9444. }
  9445. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  9446. {
  9447. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  9449. }
  9450. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  9451. {
  9452. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  9454. }
  9455. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  9456. {
  9457. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9459. }
  9460. if(strcmp(keystr, "StopTxnSampledData") == 0)
  9461. {
  9462. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  9464. }
  9465. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  9466. {
  9467. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9469. }
  9470. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  9471. {
  9472. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  9474. }
  9475. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  9476. {
  9477. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  9479. }
  9480. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  9481. {
  9482. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  9484. TransactionMessageAttemptsValue = atoi(valuestr);
  9485. }
  9486. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  9487. {
  9488. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  9490. TransactionMessageRetryIntervalValue = atoi(valuestr);
  9491. }
  9492. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  9493. {
  9494. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  9496. }
  9497. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  9498. {
  9499. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  9501. }
  9502. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  9503. {
  9504. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  9506. }
  9507. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  9508. {
  9509. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  9511. }
  9512. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  9513. {
  9514. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  9516. }
  9517. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  9518. {
  9519. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  9521. }
  9522. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  9523. {
  9524. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  9526. }
  9527. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  9528. {
  9529. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  9531. }
  9532. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  9533. {
  9534. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  9536. }
  9537. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  9538. {
  9539. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  9541. }
  9542. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  9543. {
  9544. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  9546. }
  9547. }
  9548. fclose(fp);
  9549. }
  9550. return 0;
  9551. }
  9552. void StoreConfigurationTable(void)
  9553. {
  9554. FILE *outfile;
  9555. outfile = fopen("../Storage/OCPP/OCPPConfiguration" , "w+");
  9556. if(outfile == NULL)
  9557. {
  9558. DEBUG_INFO("Error opening file");
  9559. return ;
  9560. }
  9561. /*Core Profile*/
  9562. //AllowOfflineTxForUnknownId
  9563. /*
  9564. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9565. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9568. */
  9569. //DEBUG_INFO("data=%s\n",data);
  9570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9571. //AuthorizationCacheEnabled
  9572. /*
  9573. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9576. */
  9577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9578. //AuthorizeRemoteTxRequests
  9579. /*
  9580. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9583. */
  9584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9585. //BlinkRepeat
  9586. /*
  9587. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9590. */
  9591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9592. //ClockAlignedDataInterval
  9593. /*
  9594. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9597. */
  9598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9599. //ConnectionTimeOut
  9600. /*
  9601. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9604. */
  9605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9606. //GetConfigurationMaxKeys
  9607. /*
  9608. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9611. */
  9612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9613. // HeartbeatInterval
  9614. /*
  9615. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9618. */
  9619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9620. // LightIntensity
  9621. /*
  9622. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9625. */
  9626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9627. // LocalAuthorizeOffline
  9628. /*
  9629. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9632. */
  9633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9634. // LocalPreAuthorize
  9635. /*
  9636. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9639. */
  9640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9641. // MaxEnergyOnInvalidId
  9642. /*
  9643. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9646. */
  9647. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9649. // MeterValuesAlignedData
  9650. /*
  9651. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9654. */
  9655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9656. // MeterValuesAlignedDataMaxLength
  9657. /*
  9658. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9661. */
  9662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9663. // MeterValuesSampledData
  9664. /*
  9665. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9668. */
  9669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9670. // MeterValuesSampledDataMaxLength
  9671. /*
  9672. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9675. */
  9676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9677. // MeterValueSampleInterval
  9678. /*
  9679. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9682. */
  9683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9684. // MinimumStatusDuration
  9685. /*
  9686. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9689. */
  9690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9691. // NumberOfConnectors
  9692. /*
  9693. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9695. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9696. {
  9697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9698. }
  9699. else
  9700. {
  9701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9702. }
  9703. */
  9704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9705. // ResetRetries
  9706. /*
  9707. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9710. */
  9711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9712. // ConnectorPhaseRotation
  9713. /*
  9714. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9717. */
  9718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9719. // ConnectorPhaseRotationMaxLength
  9720. /*
  9721. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9724. */
  9725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9726. // StopTransactionOnEVSideDisconnect
  9727. /*
  9728. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9731. */
  9732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9733. // StopTransactionOnInvalidId
  9734. /*
  9735. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9738. */
  9739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9740. // StopTxnAlignedData
  9741. /*
  9742. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9745. */
  9746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9747. // StopTxnAlignedDataMaxLength
  9748. /*
  9749. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9752. */
  9753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9754. // StopTxnSampledData
  9755. /*
  9756. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9759. */
  9760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9761. // StopTxnSampledDataMaxLength
  9762. /*
  9763. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9766. */
  9767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9768. // SupportedFeatureProfiles
  9769. /*
  9770. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9773. */
  9774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  9775. // SupportedFeatureProfilesMaxLength
  9776. /*
  9777. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9780. */
  9781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  9782. // TransactionMessageAttempts
  9783. /*
  9784. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9787. */
  9788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9789. // TransactionMessageRetryInterval
  9790. /*
  9791. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9794. */
  9795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9796. // UnlockConnectorOnEVSideDisconnect
  9797. /*
  9798. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9801. */
  9802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  9803. // WebSocketPingInterval
  9804. /*
  9805. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9808. */
  9809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  9810. //* Local Auth List Management Profile*/
  9811. //LocalAuthListEnabled
  9812. /*
  9813. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9816. */
  9817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9818. //LocalAuthListMaxLength
  9819. /*
  9820. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9823. */
  9824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  9825. //SendLocalListMaxLength
  9826. /*
  9827. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9830. */
  9831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  9832. //ReserveConnectorZeroSupported
  9833. /*
  9834. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9837. */
  9838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9839. //* Smart Charging Profile */
  9840. //ChargeProfileMaxStackLevel
  9841. /*
  9842. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9845. */
  9846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9847. // ChargingScheduleAllowedChargingRateUnit
  9848. /*
  9849. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9852. */
  9853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9854. // ChargingScheduleMaxPeriods
  9855. /*
  9856. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9859. */
  9860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9861. // ConnectorSwitch3to1PhaseSupported
  9862. /*
  9863. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9866. */
  9867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9868. // MaxChargingProfilesInstalled
  9869. /*
  9870. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9873. */
  9874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9875. fclose(outfile);
  9876. }
  9877. void getKeyValue(char *keyReq)
  9878. {
  9879. int isEmpty = FALSE;
  9880. int isKnowKey = FALSE;
  9881. //int unKnowIndex = 0;
  9882. DEBUG_INFO("getKeyValue \n");
  9883. DEBUG_INFO("keyReq=%s \n",keyReq);
  9884. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9885. isEmpty = TRUE;
  9886. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9887. {
  9888. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  9889. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9892. {
  9893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9894. }
  9895. else
  9896. {
  9897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9898. }
  9899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9900. isKnowKey = TRUE;
  9901. }
  9902. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9903. {
  9904. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9907. {
  9908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9909. }
  9910. else
  9911. {
  9912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9913. }
  9914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9915. isKnowKey = TRUE;
  9916. }
  9917. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9918. {
  9919. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9922. {
  9923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9924. }
  9925. else
  9926. {
  9927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9928. }
  9929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9930. isKnowKey = TRUE;
  9931. }
  9932. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9933. {
  9934. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9937. {
  9938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9939. }
  9940. else
  9941. {
  9942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9943. }
  9944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9945. isKnowKey = TRUE;
  9946. }
  9947. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9948. {
  9949. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9952. {
  9953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9954. }
  9955. else
  9956. {
  9957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9958. }
  9959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9960. isKnowKey = TRUE;
  9961. }
  9962. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9963. {
  9964. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9967. {
  9968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9969. }
  9970. else
  9971. {
  9972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9973. }
  9974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9975. isKnowKey = TRUE;
  9976. }
  9977. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9978. {
  9979. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9982. {
  9983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9984. }
  9985. else
  9986. {
  9987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9988. }
  9989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9990. isKnowKey = TRUE;
  9991. }
  9992. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9993. {
  9994. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9996. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9997. {
  9998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9999. }
  10000. else
  10001. {
  10002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10003. }
  10004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10005. isKnowKey = TRUE;
  10006. }
  10007. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10008. {
  10009. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10012. {
  10013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10014. }
  10015. else
  10016. {
  10017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10018. }
  10019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10020. isKnowKey = TRUE;
  10021. }
  10022. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10023. {
  10024. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10027. {
  10028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10029. }
  10030. else
  10031. {
  10032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10033. }
  10034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10035. isKnowKey = TRUE;
  10036. }
  10037. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10038. {
  10039. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10042. {
  10043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10044. }
  10045. else
  10046. {
  10047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10048. }
  10049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10050. isKnowKey = TRUE;
  10051. }
  10052. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10053. {
  10054. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10057. {
  10058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10059. }
  10060. else
  10061. {
  10062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10063. }
  10064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10065. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10066. isKnowKey = TRUE;
  10067. }
  10068. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10069. {
  10070. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10073. {
  10074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10075. }
  10076. else
  10077. {
  10078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10079. }
  10080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10081. isKnowKey = TRUE;
  10082. }
  10083. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10084. {
  10085. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10088. {
  10089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10090. }
  10091. else
  10092. {
  10093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10094. }
  10095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10096. isKnowKey = TRUE;
  10097. }
  10098. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10099. {
  10100. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10103. {
  10104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10105. }
  10106. else
  10107. {
  10108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10109. }
  10110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10111. isKnowKey = TRUE;
  10112. }
  10113. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10114. {
  10115. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10118. {
  10119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10120. }
  10121. else
  10122. {
  10123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10124. }
  10125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10126. isKnowKey = TRUE;
  10127. }
  10128. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10129. {
  10130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10133. {
  10134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10135. }
  10136. else
  10137. {
  10138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10139. }
  10140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10141. isKnowKey = TRUE;
  10142. }
  10143. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10144. {
  10145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10148. {
  10149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10150. }
  10151. else
  10152. {
  10153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10154. }
  10155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10156. isKnowKey = TRUE;
  10157. }
  10158. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10159. {
  10160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10163. {
  10164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10165. }
  10166. else
  10167. {
  10168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10169. }
  10170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10171. isKnowKey = TRUE;
  10172. }
  10173. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10174. {
  10175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10178. {
  10179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10180. }
  10181. else
  10182. {
  10183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10184. }
  10185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10186. isKnowKey = TRUE;
  10187. }
  10188. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10189. {
  10190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10193. {
  10194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10195. }
  10196. else
  10197. {
  10198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10199. }
  10200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10201. isKnowKey = TRUE;
  10202. }
  10203. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10204. {
  10205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10208. {
  10209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10210. }
  10211. else
  10212. {
  10213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10214. }
  10215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10216. isKnowKey = TRUE;
  10217. }
  10218. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10219. {
  10220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10223. {
  10224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10225. }
  10226. else
  10227. {
  10228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10229. }
  10230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10231. isKnowKey = TRUE;
  10232. }
  10233. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10234. {
  10235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10238. {
  10239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10240. }
  10241. else
  10242. {
  10243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10244. }
  10245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10246. isKnowKey = TRUE;
  10247. }
  10248. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10249. {
  10250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10253. {
  10254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10255. }
  10256. else
  10257. {
  10258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10259. }
  10260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10261. isKnowKey = TRUE;
  10262. }
  10263. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10264. {
  10265. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10268. {
  10269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10270. }
  10271. else
  10272. {
  10273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10274. }
  10275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10276. isKnowKey = TRUE;
  10277. }
  10278. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10279. {
  10280. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10283. {
  10284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10285. }
  10286. else
  10287. {
  10288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10289. }
  10290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10291. isKnowKey = TRUE;
  10292. }
  10293. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10294. {
  10295. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10298. {
  10299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10300. }
  10301. else
  10302. {
  10303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10304. }
  10305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10306. isKnowKey = TRUE;
  10307. }
  10308. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10309. {
  10310. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10313. {
  10314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10315. }
  10316. else
  10317. {
  10318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10319. }
  10320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10321. isKnowKey = TRUE;
  10322. }
  10323. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10324. {
  10325. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10327. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10328. {
  10329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10330. }
  10331. else
  10332. {
  10333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10334. }
  10335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10336. isKnowKey = TRUE;
  10337. }
  10338. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10339. {
  10340. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10342. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10343. {
  10344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10345. }
  10346. else
  10347. {
  10348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10349. }
  10350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10351. isKnowKey = TRUE;
  10352. }
  10353. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10354. {
  10355. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10358. {
  10359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10360. }
  10361. else
  10362. {
  10363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10364. }
  10365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10366. isKnowKey = TRUE;
  10367. }
  10368. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10369. {
  10370. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10373. {
  10374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10375. }
  10376. else
  10377. {
  10378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10379. }
  10380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10381. isKnowKey = TRUE;
  10382. }
  10383. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10384. {
  10385. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10388. {
  10389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10390. }
  10391. else
  10392. {
  10393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10394. }
  10395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10396. isKnowKey = TRUE;
  10397. }
  10398. #if 0
  10399. //For OCTT Test Case
  10400. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10401. {
  10402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10404. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10405. {
  10406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10407. }
  10408. else
  10409. {
  10410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10411. }
  10412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10413. isKnowKey = TRUE;
  10414. }
  10415. #endif
  10416. #if 1
  10417. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10418. {
  10419. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10421. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10422. {
  10423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10424. }
  10425. else
  10426. {
  10427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10428. }
  10429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10430. isKnowKey = TRUE;
  10431. }
  10432. #endif
  10433. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10434. {
  10435. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10437. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10438. {
  10439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10440. }
  10441. else
  10442. {
  10443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10444. }
  10445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  10446. isKnowKey = TRUE;
  10447. }
  10448. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  10449. {
  10450. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  10451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  10452. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  10453. {
  10454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10455. }
  10456. else
  10457. {
  10458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10459. }
  10460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  10461. isKnowKey = TRUE;
  10462. }
  10463. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  10464. {
  10465. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  10466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  10467. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  10468. {
  10469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  10470. }
  10471. else
  10472. {
  10473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  10474. }
  10475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10476. isKnowKey = TRUE;
  10477. }
  10478. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  10479. {
  10480. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  10481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  10482. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  10483. {
  10484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  10485. }
  10486. else
  10487. {
  10488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  10489. }
  10490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10491. isKnowKey = TRUE;
  10492. }
  10493. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  10494. {
  10495. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  10496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  10497. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  10498. {
  10499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  10500. }
  10501. else
  10502. {
  10503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  10504. }
  10505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10506. isKnowKey = TRUE;
  10507. }
  10508. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  10509. {
  10510. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  10511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  10512. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  10513. {
  10514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  10515. }
  10516. else
  10517. {
  10518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  10519. }
  10520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10521. isKnowKey = TRUE;
  10522. }
  10523. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  10524. {
  10525. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  10526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  10527. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  10528. {
  10529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  10530. }
  10531. else
  10532. {
  10533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  10534. }
  10535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10536. isKnowKey = TRUE;
  10537. }
  10538. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  10539. {
  10540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  10541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  10542. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  10543. {
  10544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  10545. }
  10546. else
  10547. {
  10548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  10549. }
  10550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10551. isKnowKey = TRUE;
  10552. }
  10553. //=========================================================
  10554. if(!isEmpty && !isKnowKey)
  10555. {
  10556. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  10557. strcpy(unknownkey[UnknownKeynum], keyReq);
  10558. UnknownKeynum = UnknownKeynum + 1;
  10559. }
  10560. }
  10561. void processUnkownKey(void)
  10562. {
  10563. DEBUG_INFO("processUnkownKey\n");
  10564. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  10565. for(int index=0; index < UnknownKeynum; index++)
  10566. {
  10567. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  10568. {
  10569. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  10570. }
  10571. }
  10572. }
  10573. int setKeyValue(char *key, char *value)
  10574. {
  10575. int isSuccess = NotSupported;
  10576. int check_ascii=0;
  10577. char str[10]={0};
  10578. #ifdef Debug
  10579. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  10580. #endif
  10581. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  10582. {
  10583. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10585. {
  10586. strcpy(str, (const char*)value);
  10587. for(int i = 0; str[i]; i++){
  10588. str[i] = tolower(str[i]);
  10589. }
  10590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10591. isSuccess = ConfigurationStatus_Accepted;
  10592. }
  10593. else
  10594. {
  10595. isSuccess = ConfigurationStatus_Rejected;
  10596. }
  10597. }
  10598. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  10599. {
  10600. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10602. {
  10603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  10604. isSuccess = ConfigurationStatus_Accepted;
  10605. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  10606. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  10607. }
  10608. else
  10609. {
  10610. isSuccess = ConfigurationStatus_Rejected;
  10611. }
  10612. }
  10613. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  10614. {
  10615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10616. {
  10617. strcpy(str, (const char*)value);
  10618. for(int i = 0; str[i]; i++)
  10619. {
  10620. str[i] = tolower(str[i]);
  10621. }
  10622. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  10623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10624. isSuccess = ConfigurationStatus_Accepted;
  10625. }
  10626. else
  10627. {
  10628. isSuccess = ConfigurationStatus_Rejected;
  10629. }
  10630. }
  10631. if(strcmp(key, "BlinkRepeat") == 0)
  10632. {
  10633. //Charger.BlinkRepeat = Integer.parseInt(value);
  10634. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10635. {
  10636. check_ascii = value[0];
  10637. if( (check_ascii < 48) || (check_ascii > 57) )
  10638. {
  10639. isSuccess = ConfigurationStatus_Rejected;
  10640. }
  10641. else
  10642. {
  10643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  10644. isSuccess = ConfigurationStatus_Accepted;
  10645. }
  10646. }
  10647. else
  10648. {
  10649. isSuccess = ConfigurationStatus_Rejected;
  10650. }
  10651. }
  10652. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  10653. {
  10654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10655. {
  10656. check_ascii = value[0];
  10657. if( (check_ascii < 48) || (check_ascii > 57) )
  10658. {
  10659. isSuccess = ConfigurationStatus_Rejected;
  10660. }
  10661. else
  10662. {
  10663. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  10664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  10665. isSuccess = ConfigurationStatus_Accepted;
  10666. }
  10667. }
  10668. else
  10669. {
  10670. isSuccess = ConfigurationStatus_Rejected;
  10671. }
  10672. }
  10673. if(strcmp(key, "ConnectionTimeOut") == 0 )
  10674. {
  10675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10676. {
  10677. check_ascii = value[0];
  10678. if( (check_ascii < 48) || (check_ascii > 57) )
  10679. {
  10680. isSuccess = ConfigurationStatus_Rejected;
  10681. }
  10682. else
  10683. {
  10684. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  10685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  10686. isSuccess = ConfigurationStatus_Accepted;
  10687. }
  10688. }
  10689. else
  10690. {
  10691. isSuccess = ConfigurationStatus_Rejected;
  10692. }
  10693. }
  10694. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  10695. {
  10696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10697. {
  10698. check_ascii = value[0];
  10699. if( (check_ascii < 48) || (check_ascii > 57) )
  10700. {
  10701. isSuccess = ConfigurationStatus_Rejected;
  10702. }
  10703. else
  10704. {
  10705. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  10707. isSuccess = ConfigurationStatus_Accepted;
  10708. }
  10709. }
  10710. else
  10711. {
  10712. isSuccess = ConfigurationStatus_Rejected;
  10713. }
  10714. }
  10715. if(strcmp(key, "HeartbeatInterval") == 0)
  10716. {
  10717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10718. {
  10719. check_ascii = value[0];
  10720. if( (check_ascii < 48) || (check_ascii > 57) )
  10721. {
  10722. isSuccess = ConfigurationStatus_Rejected;
  10723. }
  10724. else
  10725. {
  10726. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  10728. HeartBeatWaitTime = atoi(value);
  10729. isSuccess = ConfigurationStatus_Accepted;
  10730. }
  10731. }
  10732. else
  10733. {
  10734. isSuccess = ConfigurationStatus_Rejected;
  10735. }
  10736. }
  10737. if(strcmp(key, "LightIntensity") == 0)
  10738. {
  10739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10740. {
  10741. check_ascii = value[0];
  10742. if( (check_ascii < 48) || (check_ascii > 57) )
  10743. {
  10744. isSuccess = ConfigurationStatus_Rejected;
  10745. }
  10746. else
  10747. {
  10748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10749. isSuccess = ConfigurationStatus_Accepted;
  10750. }
  10751. }
  10752. else
  10753. {
  10754. isSuccess = ConfigurationStatus_Rejected;
  10755. }
  10756. }
  10757. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10758. {
  10759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10760. {
  10761. strcpy(str, (const char*)value);
  10762. for(int i = 0; str[i]; i++)
  10763. {
  10764. str[i] = tolower(str[i]);
  10765. }
  10766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10767. isSuccess = ConfigurationStatus_Accepted;
  10768. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10769. }
  10770. else
  10771. {
  10772. isSuccess = ConfigurationStatus_Rejected;
  10773. }
  10774. }
  10775. if(strcmp(key, "LocalPreAuthorize") == 0)
  10776. {
  10777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10778. {
  10779. strcpy(str, (const char*)value);
  10780. for(int i = 0; str[i]; i++)
  10781. {
  10782. str[i] = tolower(str[i]);
  10783. }
  10784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10785. isSuccess = ConfigurationStatus_Accepted;
  10786. }
  10787. else
  10788. {
  10789. isSuccess = ConfigurationStatus_Rejected;
  10790. }
  10791. }
  10792. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10793. {
  10794. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10795. {
  10796. check_ascii = value[0];
  10797. if( (check_ascii < 48) || (check_ascii > 57) )
  10798. {
  10799. isSuccess = ConfigurationStatus_Rejected;
  10800. }
  10801. else
  10802. {
  10803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10804. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  10805. isSuccess = ConfigurationStatus_Accepted;
  10806. }
  10807. }
  10808. else
  10809. {
  10810. isSuccess = ConfigurationStatus_Rejected;
  10811. }
  10812. }
  10813. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10814. {
  10815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10816. {
  10817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10818. isSuccess = ConfigurationStatus_Accepted;
  10819. }
  10820. else
  10821. {
  10822. isSuccess = ConfigurationStatus_Rejected;
  10823. }
  10824. }
  10825. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  10826. {
  10827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10828. {
  10829. check_ascii = value[0];
  10830. if( (check_ascii < 48) || (check_ascii > 57) )
  10831. {
  10832. isSuccess = ConfigurationStatus_Rejected;
  10833. }
  10834. else
  10835. {
  10836. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  10838. isSuccess = ConfigurationStatus_Accepted;
  10839. }
  10840. }
  10841. else
  10842. {
  10843. isSuccess = ConfigurationStatus_Rejected;
  10844. }
  10845. }
  10846. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10847. {
  10848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10849. {
  10850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10851. isSuccess = ConfigurationStatus_Accepted;
  10852. }
  10853. else
  10854. {
  10855. isSuccess = ConfigurationStatus_Rejected;
  10856. }
  10857. }
  10858. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  10859. {
  10860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10861. {
  10862. check_ascii = value[0];
  10863. if( (check_ascii < 48) || (check_ascii > 57) )
  10864. {
  10865. isSuccess = ConfigurationStatus_Rejected;
  10866. }
  10867. else
  10868. {
  10869. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  10871. isSuccess = ConfigurationStatus_Accepted;
  10872. }
  10873. }
  10874. else
  10875. {
  10876. isSuccess = ConfigurationStatus_Rejected;
  10877. }
  10878. }
  10879. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10880. {
  10881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10882. {
  10883. check_ascii = value[0];
  10884. if( (check_ascii < 48) || (check_ascii > 57) )
  10885. {
  10886. isSuccess = ConfigurationStatus_Rejected;
  10887. }
  10888. else
  10889. {
  10890. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10892. isSuccess = ConfigurationStatus_Accepted;
  10893. }
  10894. }
  10895. else
  10896. {
  10897. isSuccess = ConfigurationStatus_Rejected;
  10898. }
  10899. }
  10900. if(strcmp(key, "MinimumStatusDuration") == 0)
  10901. {
  10902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10903. {
  10904. check_ascii = value[0];
  10905. if( (check_ascii < 48) || (check_ascii > 57) )
  10906. {
  10907. isSuccess = ConfigurationStatus_Rejected;
  10908. }
  10909. else
  10910. {
  10911. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10913. isSuccess = ConfigurationStatus_Accepted;
  10914. }
  10915. }
  10916. else
  10917. {
  10918. isSuccess = ConfigurationStatus_Rejected;
  10919. }
  10920. }
  10921. if(strcmp(key, "NumberOfConnectors") == 0)
  10922. {
  10923. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10924. {
  10925. check_ascii = value[0];
  10926. if( (check_ascii < 48) || (check_ascii > 57) )
  10927. {
  10928. isSuccess = ConfigurationStatus_Rejected;
  10929. }
  10930. else
  10931. {
  10932. //Charger.ResetRetries = Integer.parseInt(value);
  10933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  10934. isSuccess = ConfigurationStatus_Accepted;
  10935. }
  10936. }
  10937. else
  10938. {
  10939. isSuccess = ConfigurationStatus_Rejected;
  10940. }
  10941. }
  10942. if(strcmp(key, "ResetRetries") == 0)
  10943. {
  10944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10945. {
  10946. check_ascii = value[0];
  10947. if( (check_ascii < 48) || (check_ascii > 57) )
  10948. {
  10949. isSuccess = ConfigurationStatus_Rejected;
  10950. }
  10951. else
  10952. {
  10953. //Charger.ResetRetries = Integer.parseInt(value);
  10954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10955. isSuccess = ConfigurationStatus_Accepted;
  10956. }
  10957. }
  10958. else
  10959. {
  10960. isSuccess = ConfigurationStatus_Rejected;
  10961. }
  10962. }
  10963. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10964. {
  10965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10966. {
  10967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10968. isSuccess = ConfigurationStatus_Accepted;
  10969. }
  10970. else
  10971. {
  10972. isSuccess = ConfigurationStatus_Rejected;
  10973. }
  10974. }
  10975. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  10976. {
  10977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10978. {
  10979. check_ascii = value[0];
  10980. if( (check_ascii < 48) || (check_ascii > 57) )
  10981. {
  10982. isSuccess = ConfigurationStatus_Rejected;
  10983. }
  10984. else
  10985. {
  10986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  10987. isSuccess = ConfigurationStatus_Accepted;
  10988. }
  10989. }
  10990. else
  10991. {
  10992. isSuccess = ConfigurationStatus_Rejected;
  10993. }
  10994. }
  10995. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10996. {
  10997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10998. {
  10999. strcpy(str, (const char*)value);
  11000. for(int i = 0; str[i]; i++)
  11001. {
  11002. str[i] = tolower(str[i]);
  11003. }
  11004. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11006. isSuccess = ConfigurationStatus_Accepted;
  11007. }
  11008. else
  11009. {
  11010. isSuccess = ConfigurationStatus_Rejected;
  11011. }
  11012. }
  11013. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11014. {
  11015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11016. {
  11017. strcpy(str, (const char*)value);
  11018. for(int i = 0; str[i]; i++)
  11019. {
  11020. str[i] = tolower(str[i]);
  11021. }
  11022. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11024. isSuccess = ConfigurationStatus_Accepted;
  11025. }
  11026. else
  11027. {
  11028. isSuccess = ConfigurationStatus_Rejected;
  11029. }
  11030. }
  11031. if(strcmp(key, "StopTxnAlignedData") == 0)
  11032. {
  11033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11034. {
  11035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11036. isSuccess = ConfigurationStatus_Accepted;
  11037. }
  11038. else
  11039. {
  11040. isSuccess = ConfigurationStatus_Rejected;
  11041. }
  11042. }
  11043. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11044. {
  11045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11046. {
  11047. check_ascii = value[0];
  11048. if( (check_ascii < 48) || (check_ascii > 57) )
  11049. {
  11050. isSuccess = ConfigurationStatus_Rejected;
  11051. }
  11052. else
  11053. {
  11054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11055. isSuccess = ConfigurationStatus_Accepted;
  11056. }
  11057. }
  11058. else
  11059. {
  11060. isSuccess = ConfigurationStatus_Rejected;
  11061. }
  11062. }
  11063. if(strcmp(key, "StopTxnSampledData") == 0)
  11064. {
  11065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11066. {
  11067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11068. isSuccess = ConfigurationStatus_Accepted;
  11069. }
  11070. else
  11071. {
  11072. isSuccess = ConfigurationStatus_Rejected;
  11073. }
  11074. }
  11075. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11076. {
  11077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11078. {
  11079. check_ascii = value[0];
  11080. if( (check_ascii < 48) || (check_ascii > 57) )
  11081. {
  11082. isSuccess = ConfigurationStatus_Rejected;
  11083. }
  11084. else
  11085. {
  11086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11087. isSuccess = ConfigurationStatus_Accepted;
  11088. }
  11089. }
  11090. else
  11091. {
  11092. isSuccess = ConfigurationStatus_Rejected;
  11093. }
  11094. }
  11095. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11096. {
  11097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11098. {
  11099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11100. isSuccess = ConfigurationStatus_Accepted;
  11101. }
  11102. else
  11103. {
  11104. isSuccess = ConfigurationStatus_Rejected;
  11105. }
  11106. }
  11107. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11108. {
  11109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11110. {
  11111. check_ascii = value[0];
  11112. if( (check_ascii < 48) || (check_ascii > 57) )
  11113. {
  11114. isSuccess = ConfigurationStatus_Rejected;
  11115. }
  11116. else
  11117. {
  11118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11119. isSuccess = ConfigurationStatus_Accepted;
  11120. }
  11121. }
  11122. else
  11123. {
  11124. isSuccess = ConfigurationStatus_Rejected;
  11125. }
  11126. }
  11127. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11128. {
  11129. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11130. {
  11131. check_ascii = value[0];
  11132. if( (check_ascii < 48) || (check_ascii > 57) )
  11133. {
  11134. isSuccess = ConfigurationStatus_Rejected;
  11135. }
  11136. else
  11137. {
  11138. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11140. TransactionMessageAttemptsValue = atoi(value);
  11141. isSuccess = ConfigurationStatus_Accepted;
  11142. }
  11143. }
  11144. else
  11145. {
  11146. isSuccess = ConfigurationStatus_Rejected;
  11147. }
  11148. }
  11149. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11150. {
  11151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11152. {
  11153. check_ascii = value[0];
  11154. if( (check_ascii < 48) || (check_ascii > 57) )
  11155. {
  11156. isSuccess = ConfigurationStatus_Rejected;
  11157. }
  11158. else
  11159. {
  11160. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11162. TransactionMessageRetryIntervalValue = atoi(value);
  11163. isSuccess = ConfigurationStatus_Accepted;
  11164. }
  11165. }
  11166. else
  11167. {
  11168. isSuccess = ConfigurationStatus_Rejected;
  11169. }
  11170. }
  11171. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11172. {
  11173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11174. {
  11175. strcpy(str, (const char*)value);
  11176. for(int i = 0; str[i]; i++)
  11177. {
  11178. str[i] = tolower(str[i]);
  11179. }
  11180. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11182. isSuccess = ConfigurationStatus_Accepted;
  11183. }
  11184. else
  11185. {
  11186. isSuccess = ConfigurationStatus_Rejected;
  11187. }
  11188. }
  11189. if(strcmp(key, "WebSocketPingInterval") == 0)
  11190. {
  11191. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11192. {
  11193. check_ascii = value[0];
  11194. if( (check_ascii < 48) || (check_ascii > 57) )
  11195. {
  11196. isSuccess = ConfigurationStatus_Rejected;
  11197. }
  11198. else
  11199. {
  11200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11201. isSuccess = ConfigurationStatus_Accepted;
  11202. }
  11203. }
  11204. else
  11205. {
  11206. isSuccess = ConfigurationStatus_Rejected;
  11207. }
  11208. }
  11209. #if 0
  11210. //For OCPP Test Case
  11211. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11212. {
  11213. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11214. {
  11215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11216. isSuccess = ConfigurationStatus_Accepted;
  11217. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11218. }
  11219. else
  11220. {
  11221. isSuccess = ConfigurationStatus_Rejected;
  11222. }
  11223. }
  11224. #endif
  11225. #if 1
  11226. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11227. {
  11228. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11229. {
  11230. strcpy(str, (const char*)value);
  11231. for(int i = 0; str[i]; i++)
  11232. {
  11233. str[i] = tolower(str[i]);
  11234. }
  11235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11236. isSuccess = ConfigurationStatus_Accepted;
  11237. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11238. }
  11239. else
  11240. {
  11241. isSuccess = ConfigurationStatus_Rejected;
  11242. }
  11243. }
  11244. #endif
  11245. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11246. {
  11247. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11248. {
  11249. check_ascii = value[0];
  11250. if( (check_ascii < 48) || (check_ascii > 57) )
  11251. {
  11252. isSuccess = ConfigurationStatus_Rejected;
  11253. }
  11254. else
  11255. {
  11256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11257. isSuccess = ConfigurationStatus_Accepted;
  11258. }
  11259. }
  11260. else
  11261. {
  11262. isSuccess = ConfigurationStatus_Rejected;
  11263. }
  11264. }
  11265. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11266. {
  11267. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11268. {
  11269. check_ascii = value[0];
  11270. if( (check_ascii < 48) || (check_ascii > 57) )
  11271. {
  11272. isSuccess = ConfigurationStatus_Rejected;
  11273. }
  11274. else
  11275. {
  11276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11277. isSuccess = ConfigurationStatus_Accepted;
  11278. }
  11279. }
  11280. else
  11281. {
  11282. isSuccess = ConfigurationStatus_Rejected;
  11283. }
  11284. }
  11285. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11286. {
  11287. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11288. {
  11289. strcpy(str, (const char*)value);
  11290. for(int i = 0; str[i]; i++)
  11291. {
  11292. str[i] = tolower(str[i]);
  11293. }
  11294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11295. isSuccess = ConfigurationStatus_Accepted;
  11296. }
  11297. else
  11298. {
  11299. isSuccess = ConfigurationStatus_Rejected;
  11300. }
  11301. }
  11302. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11303. {
  11304. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11305. {
  11306. check_ascii = value[0];
  11307. if( (check_ascii < 48) || (check_ascii > 57) )
  11308. {
  11309. isSuccess = ConfigurationStatus_Rejected;
  11310. }
  11311. else
  11312. {
  11313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11314. isSuccess = ConfigurationStatus_Accepted;
  11315. }
  11316. }
  11317. else
  11318. {
  11319. isSuccess = ConfigurationStatus_Rejected;
  11320. }
  11321. }
  11322. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11323. {
  11324. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11325. {
  11326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11327. isSuccess = ConfigurationStatus_Accepted;
  11328. }
  11329. else
  11330. {
  11331. isSuccess = ConfigurationStatus_Rejected;
  11332. }
  11333. }
  11334. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11335. {
  11336. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11337. {
  11338. check_ascii = value[0];
  11339. if( (check_ascii < 48) || (check_ascii > 57) )
  11340. {
  11341. isSuccess = ConfigurationStatus_Rejected;
  11342. }
  11343. else
  11344. {
  11345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11346. isSuccess = ConfigurationStatus_Accepted;
  11347. }
  11348. }
  11349. else
  11350. {
  11351. isSuccess = ConfigurationStatus_Rejected;
  11352. }
  11353. }
  11354. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11355. {
  11356. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11357. {
  11358. strcpy(str, (const char*)value);
  11359. for(int i = 0; str[i]; i++)
  11360. {
  11361. str[i] = tolower(str[i]);
  11362. }
  11363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11364. isSuccess = ConfigurationStatus_Accepted;
  11365. }
  11366. else
  11367. {
  11368. isSuccess = ConfigurationStatus_Rejected;
  11369. }
  11370. }
  11371. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11372. {
  11373. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11374. {
  11375. check_ascii = value[0];
  11376. if( (check_ascii < 48) || (check_ascii > 57) )
  11377. {
  11378. isSuccess = ConfigurationStatus_Rejected;
  11379. }
  11380. else
  11381. {
  11382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11383. isSuccess = ConfigurationStatus_Accepted;
  11384. }
  11385. }
  11386. else
  11387. {
  11388. isSuccess = ConfigurationStatus_Rejected;
  11389. }
  11390. }
  11391. return isSuccess;
  11392. }
  11393. int updateSetting(char *key, char *value)
  11394. {
  11395. mtrace();
  11396. int isSuccess = FALSE;
  11397. char string[1000]={0}, buffer[1000]={0};
  11398. char strtemp[50]={0};
  11399. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11400. int pos, c = 0;
  11401. char *loc;
  11402. int pos1=0;
  11403. FILE *f = fopen("/var/www/settings1", "r");
  11404. if(f == NULL)
  11405. {
  11406. #ifdef Debug
  11407. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11408. #endif
  11409. return isSuccess;
  11410. }
  11411. fseek(f, 0, SEEK_END);
  11412. long fsize = ftell(f);
  11413. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11414. fread(string, 1, fsize, f);
  11415. fclose(f);
  11416. string[fsize] = 0;
  11417. loc = strstr(string, key);
  11418. if(loc != NULL)
  11419. {
  11420. DEBUG_INFO("key exist!\n");
  11421. pos = loc - string-1;
  11422. f = fopen("/var/www/settings1", "w");
  11423. strncpy(buffer, string, pos);
  11424. fprintf(f, "%s", buffer);
  11425. memset(sstr ,0, sizeof(sstr) );
  11426. c = 0;
  11427. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11428. {
  11429. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11430. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11431. c++;
  11432. }
  11433. sstr[c] = '\0';
  11434. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11435. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11436. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11437. memset(buffer ,0, sizeof(buffer) );
  11438. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11439. //printf("buffer=%s",buffer);
  11440. fprintf(f, "%s", buffer);
  11441. fclose(f);
  11442. }
  11443. else
  11444. {
  11445. printf("key not exist!\n");
  11446. f = fopen("/var/www/settings1", "w+");
  11447. fputs(string, f);
  11448. fseek(f, -1, SEEK_CUR);
  11449. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  11450. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  11451. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  11452. fclose(f);
  11453. }
  11454. isSuccess = TRUE;
  11455. return isSuccess;
  11456. }
  11457. int TransactionMessageAttemptsGet(void)
  11458. {
  11459. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11460. }
  11461. int FirstHeartBeatResponse(void)
  11462. {
  11463. return FirstHeartBeat;
  11464. }
  11465. int TransactionMessageRetryIntervalGet(void)
  11466. {
  11467. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11468. }
  11469. #define SA struct sockaddr
  11470. #define MAXBUF 1024
  11471. //static int m_socket_data;
  11472. //static int sockfd;
  11473. int ReadHttpStatus(int sock){
  11474. //char c;
  11475. char buff[1024]="",*ptr=buff+1;
  11476. int bytes_received, status;
  11477. DEBUG_INFO("Begin Response ..\n");
  11478. while((bytes_received = recv(sock, ptr, 1, 0))){
  11479. if(bytes_received==-1){
  11480. perror("ReadHttpStatus");
  11481. exit(1);
  11482. }
  11483. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  11484. ptr++;
  11485. }
  11486. *ptr=0;
  11487. ptr=buff+1;
  11488. sscanf(ptr,"%*s %d ", &status);
  11489. DEBUG_INFO("%s\n",ptr);
  11490. DEBUG_INFO("status=%d\n",status);
  11491. DEBUG_INFO("End Response ..\n");
  11492. return (bytes_received>0)?status:0;
  11493. }
  11494. //the only filed that it parsed is 'Content-Length'
  11495. int ParseHeader(int sock){
  11496. //char c;
  11497. char buff[1024]="",*ptr=buff+4;
  11498. int bytes_received;
  11499. DEBUG_INFO("Begin HEADER ..\n");
  11500. while((bytes_received = recv(sock, ptr, 1, 0))){
  11501. if(bytes_received==-1){
  11502. perror("Parse Header");
  11503. exit(1);
  11504. }
  11505. if(
  11506. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  11507. (ptr[-1]=='\r') && (*ptr=='\n' )
  11508. ) break;
  11509. ptr++;
  11510. }
  11511. *ptr=0;
  11512. ptr=buff+4;
  11513. //printf("%s",ptr);
  11514. if(bytes_received){
  11515. ptr=strstr(ptr,"Content-Length:");
  11516. if(ptr){
  11517. sscanf(ptr,"%*s %d",&bytes_received);
  11518. }else
  11519. bytes_received=-1; //unknown size
  11520. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  11521. }
  11522. DEBUG_INFO("End HEADER ..\n");
  11523. return bytes_received ;
  11524. }
  11525. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  11526. {
  11527. char rmFileCmd[100]={0};
  11528. char FilePath[100]={0};
  11529. char ftpbuf[200];
  11530. int systemresult;
  11531. //DEBUG_INFO("filename=%s\n",filename);
  11532. //DEBUG_INFO("url=%s\n",url);
  11533. sprintf(FilePath,"../mnt/%s",filename);
  11534. if((access(FilePath,F_OK))!=-1)
  11535. {
  11536. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11537. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11538. system(rmFileCmd);
  11539. }
  11540. memset(ftpbuf, 0, sizeof(ftpbuf));
  11541. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11542. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11543. systemresult = system(ftpbuf);
  11544. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11545. if(systemresult != 0)
  11546. {
  11547. DEBUG_INFO("http DownLoad error!\n");
  11548. return FALSE;
  11549. }
  11550. return TRUE;
  11551. }
  11552. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  11553. {
  11554. char rmFileCmd[100]={0};
  11555. char FilePath[100]={0};
  11556. char ftpbuf[200];
  11557. int systemresult;
  11558. //char temp[100];
  11559. #if 0
  11560. struct hostent* server;
  11561. char *IPbuffer;
  11562. server = gethostbyname(location);
  11563. // To convert an Internet network
  11564. // address into ASCII string
  11565. IPbuffer = inet_ntoa(*((struct in_addr*)
  11566. server->h_addr_list[0]));
  11567. #endif
  11568. sprintf(FilePath,"../mnt/%s",filename);
  11569. if((access(FilePath,F_OK))!=-1)
  11570. {
  11571. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11572. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11573. system(rmFileCmd);
  11574. }
  11575. memset(ftpbuf, 0, sizeof(ftpbuf));
  11576. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11577. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  11578. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11579. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11580. systemresult = system(ftpbuf);
  11581. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11582. if(systemresult != 0)
  11583. {
  11584. printf("wget error!\n");
  11585. return FALSE;
  11586. }
  11587. return TRUE;
  11588. }
  11589. int httpUploadFile(char *location, char *path, char *filename,char *url)
  11590. {
  11591. char rmFileCmd[100]={0};
  11592. char FilePath[100]={0};
  11593. char ftpbuf[200];
  11594. int systemresult;
  11595. DEBUG_INFO("filename=%s\n",filename);
  11596. DEBUG_INFO("url=%s\n",url);
  11597. sprintf(FilePath,"%s","../mnt/upload_file.txt");
  11598. if((access(FilePath,F_OK))!=-1)
  11599. {
  11600. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11601. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11602. system(rmFileCmd);
  11603. }
  11604. FILE *fp = fopen("../mnt/upload_file.txt", "w+");
  11605. if(fp == NULL)
  11606. {
  11607. DEBUG_INFO("log is NULL\n");
  11608. return 0;
  11609. }
  11610. else
  11611. {
  11612. fprintf(fp, "%s\n", url);
  11613. fprintf(fp, "%s\n", filename);
  11614. fclose(fp);
  11615. }
  11616. memset(ftpbuf, 0, sizeof(ftpbuf));
  11617. //sprintf(ftpbuf, "%s","../bin/php-cgi /var/www/ocpp_upload.php");
  11618. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11619. //curl -i -F filename=image.jpg -F image=@/path/to/image.jpg http://localhost/xmlcreate/curlupload.php
  11620. sprintf(ftpbuf, "curl -i -F filename=%s -F image=@%s%s %s",filename,path,filename,url);
  11621. systemresult = system(ftpbuf);
  11622. DEBUG_INFO("systemresult=%d\n",systemresult);
  11623. if(systemresult != 0)
  11624. {
  11625. DEBUG_INFO("http upload error!\n");
  11626. return FALSE;
  11627. }
  11628. return TRUE;
  11629. }
  11630. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  11631. {
  11632. struct hostent* server;
  11633. char *IPbuffer;
  11634. char ftpbuf[200];
  11635. int systemresult;
  11636. // To retrieve host information
  11637. server = gethostbyname(location);
  11638. // To convert an Internet network
  11639. // address into ASCII string
  11640. IPbuffer = inet_ntoa(*((struct in_addr*)
  11641. server->h_addr_list[0]));
  11642. memset(ftpbuf, 0, sizeof(ftpbuf));
  11643. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  11644. /* format : ftpput -u username -p passwd IP target source*/
  11645. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  11646. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11647. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11648. systemresult = system(ftpbuf);
  11649. DEBUG_INFO("systemresult=%d\n",systemresult);
  11650. if(systemresult != 0)
  11651. {
  11652. DEBUG_INFO("ftpput error!\n");
  11653. return FALSE;
  11654. }
  11655. return TRUE;
  11656. }
  11657. int SettingChargingRecord(int target, int transactionId)
  11658. {
  11659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11660. {
  11661. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11662. {
  11663. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11664. {
  11665. addBuff(target, transactionId, 0);
  11666. return TRUE;
  11667. }
  11668. }
  11669. for (int index = 0; index < CCS_QUANTITY; index++)
  11670. {
  11671. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11672. {
  11673. addBuff(target, transactionId, 0);
  11674. return TRUE;
  11675. }
  11676. }
  11677. for (int index = 0; index < GB_QUANTITY; index++)
  11678. {
  11679. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11680. {
  11681. addBuff(target, transactionId, 0);
  11682. return TRUE;
  11683. }
  11684. }
  11685. }
  11686. else
  11687. {
  11688. for (int index = 0; index < AC_QUANTITY; index++)
  11689. {
  11690. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11691. {
  11692. addBuff(target, transactionId, 0);
  11693. return TRUE;
  11694. }
  11695. }
  11696. }
  11697. return FALSE;
  11698. }
  11699. int addBuff(int gun_idx, int user_id, int cmd_sn)
  11700. {
  11701. int isSuccess = FALSE;
  11702. //char *query = NULL;
  11703. sqlite3_stmt *stmt;
  11704. int rc; // return code
  11705. char str[20];
  11706. sprintf(str,"%d",user_id);
  11707. 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 */
  11708. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  11709. rc = sqlite3_step(stmt); /* 3 */
  11710. if (rc != SQLITE_DONE) {
  11711. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  11712. goto out;
  11713. }
  11714. sqlite3_finalize(stmt);
  11715. // free(query);
  11716. out:
  11717. //----------------------
  11718. // close SQLite database
  11719. //----------------------
  11720. sqlite3_close(db);
  11721. printf("database closed.\n");
  11722. return isSuccess;
  11723. }
  11724. /**
  11725. * Place the contents of the specified file into a memory buffer
  11726. *
  11727. * @param[in] filename The path and name of the file to read
  11728. * @param[out] filebuffer A pointer to the contents in memory
  11729. * @return status 0 success, 1 on failure
  11730. */
  11731. int get_file_contents(const char* filename, char** outbuffer) {
  11732. FILE* file = NULL;
  11733. long filesize;
  11734. const int blocksize = 1;
  11735. size_t readsize;
  11736. char* filebuffer;
  11737. // Open the file
  11738. file = fopen(filename, "r");
  11739. if (NULL == file)
  11740. {
  11741. printf("'%s' not opened\n", filename);
  11742. exit(EXIT_FAILURE);
  11743. }
  11744. // Determine the file size
  11745. fseek(file, 0, SEEK_END);
  11746. filesize = ftell(file);
  11747. rewind (file);
  11748. // Allocate memory for the file contents
  11749. filebuffer = (char*) malloc(sizeof(char) * filesize);
  11750. *outbuffer = filebuffer;
  11751. if (filebuffer == NULL)
  11752. {
  11753. fputs ("malloc out-of-memory", stderr);
  11754. exit(EXIT_FAILURE);
  11755. }
  11756. // Read in the file
  11757. readsize = fread(filebuffer, blocksize, filesize, file);
  11758. if (readsize != filesize)
  11759. {
  11760. fputs ("didn't read file completely",stderr);
  11761. exit(EXIT_FAILURE);
  11762. }
  11763. // Clean exit
  11764. fclose(file);
  11765. return EXIT_SUCCESS;
  11766. }
  11767. static int selectSqlCount = 0;
  11768. static int callback(void *data, int argc, char **argv, char **azColName){
  11769. int i;
  11770. printf("%s: ", (const char*)data);
  11771. selectSqlCount = argc;
  11772. for(i = 0; i<argc; i++){
  11773. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  11774. }
  11775. printf("\n");
  11776. return 0;
  11777. }
  11778. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  11779. //int i;
  11780. //printf("%s:\n", (const char*)data);
  11781. localversion = argv[5] ? atoi(argv[5]) : 0;
  11782. printf("localversion=%d\n", localversion);
  11783. return 0;
  11784. }
  11785. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  11786. //int i;
  11787. //printf("%s:\n", (const char*)data);
  11788. //idTag
  11789. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  11790. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  11791. //parentIdTag
  11792. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  11793. //expir_date
  11794. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  11795. //status
  11796. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  11797. //version
  11798. idTagQuery.listVersionInt = atoi(argv[5]);
  11799. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  11800. return 0;
  11801. }
  11802. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  11803. int i;
  11804. //printf("%s:\n", (const char*)data);
  11805. #if 1
  11806. for(i=0; i<argc; i++){
  11807. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  11808. }
  11809. //printf("");
  11810. #endif
  11811. // localversion = argv[5] ? atoi(argv[5]) : 0;
  11812. // printf("localversion=%d\n", localversion);
  11813. return 0;
  11814. }
  11815. /** sqlite3_exec的回调。
  11816. *
  11817. * 向控制台打印查询的结果。
  11818. *
  11819. * @param in data 传递给回调函数的数据。
  11820. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  11821. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  11822. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  11823. * @return 状态码。
  11824. */
  11825. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  11826. {
  11827. for (int i = 0; i < n_columns; i++)
  11828. {
  11829. DEBUG_INFO("%s/t", col_values[i]);
  11830. }
  11831. DEBUG_INFO("/n");
  11832. return 0;
  11833. }
  11834. void OCPP_getListVerion()
  11835. {
  11836. int rc = 0;
  11837. // const char* data = "Callback function called";
  11838. char sql[100];
  11839. char zErrMsg[100];
  11840. memset(sql, 0, 100);
  11841. memset(zErrMsg, 0, 100);
  11842. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  11843. /* Execute SQL statement */
  11844. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  11845. DEBUG_INFO("rc=%d\n",rc);
  11846. if( rc != SQLITE_OK ){
  11847. DEBUG_INFO("SQL error: %s", zErrMsg);
  11848. //sqlite3_free(zErrMsg);
  11849. }else{
  11850. DEBUG_INFO("Operation done successfully");
  11851. }
  11852. }
  11853. void OCPP_getIdTag(char *idTag)
  11854. {
  11855. int rc = 0;
  11856. // const char* data = "Callback function called";
  11857. char sql[100];
  11858. char zErrMsg[100];
  11859. memset(sql, 0, 100);
  11860. memset(zErrMsg, 0, 100);
  11861. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  11862. memset(&idTagQuery, 0, sizeof(idTagQuery));
  11863. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11864. /* Execute SQL statement */
  11865. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  11866. if( rc != SQLITE_OK ){
  11867. DEBUG_INFO("SQL error: %s", zErrMsg);
  11868. //sqlite3_free(zErrMsg);
  11869. }else{
  11870. printf("Operation done successfully");
  11871. }
  11872. //return ver;
  11873. }
  11874. void OCPP_get_TableAuthlocalAllData(void)
  11875. {
  11876. int rc = 0;
  11877. // const char* data = "Callback function called";
  11878. char sql[100];
  11879. char zErrMsg[100];
  11880. memset(sql, 0, 100);
  11881. memset(zErrMsg, 0, 100);
  11882. sprintf(sql,"select * from ocpp_auth_local ");
  11883. /* Execute SQL statement */
  11884. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  11885. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  11886. if( rc != SQLITE_OK ){
  11887. DEBUG_INFO("SQL error: %s", zErrMsg);
  11888. //sqlite3_free(zErrMsg);
  11889. }else{
  11890. DEBUG_INFO("Operation done successfully");
  11891. }
  11892. //return ver;
  11893. }
  11894. int OCPP_cleanLocalList()
  11895. {
  11896. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  11897. char *errMsg = 0;
  11898. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  11899. if (SQLITE_OK != rc)
  11900. {
  11901. DEBUG_INFO("%s\n",errMsg);
  11902. return FALSE;
  11903. }
  11904. else
  11905. {
  11906. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  11907. }
  11908. return TRUE;
  11909. }
  11910. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11911. {
  11912. int isSuccess = FALSE;
  11913. int ret = 0;
  11914. //const char* data = "Callback function called";
  11915. char sql[200];
  11916. char zErrMsg[100];
  11917. memset(sql, 0, 200);
  11918. memset(zErrMsg, 0, 100);
  11919. 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);
  11920. //* Execute SQL statement */
  11921. //zErrMsg = 0;
  11922. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  11923. if( ret != SQLITE_OK ){
  11924. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  11925. // free(zErrMsg);
  11926. // free(sql);
  11927. return isSuccess;
  11928. }
  11929. DEBUG_INFO("successfully Insert records created\n");
  11930. isSuccess = TRUE;
  11931. return isSuccess;
  11932. }
  11933. void OCPP_deleteIdTag(char *idTag)
  11934. {
  11935. //int ver = 0;
  11936. //int isSuccess = FALSE;
  11937. int rc = 0;
  11938. char sql[100];
  11939. char zErrMsg[100];
  11940. memset(sql, 0, 100);
  11941. memset(zErrMsg, 0, 100);
  11942. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  11943. //* Execute SQL statement */
  11944. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  11945. if( rc != SQLITE_OK ){
  11946. DEBUG_INFO("SQL error: %s", zErrMsg);
  11947. //sqlite3_free(zErrMsg);
  11948. }else{
  11949. DEBUG_INFO("Operation done successfully");
  11950. }
  11951. }
  11952. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11953. {
  11954. int isSuccess = FALSE;
  11955. int ret = 0;
  11956. const char* data = "Callback function called";
  11957. char sql[200];
  11958. char zErrMsg[100];
  11959. memset(sql, 0, 200);
  11960. memset(zErrMsg, 0, 100);
  11961. //* selectFromTable */
  11962. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  11963. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11964. //* Execute SQL statement */
  11965. selectSqlCount = 0;
  11966. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11967. if( ret != SQLITE_OK ){
  11968. printf("Error SQL: %s\n", zErrMsg);
  11969. }
  11970. printf("successfully select operation done\n");
  11971. memset(sql, 0, 200);
  11972. memset(zErrMsg, 0, 100);
  11973. if(selectSqlCount == 0)
  11974. {
  11975. //Insert
  11976. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  11977. 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);
  11978. DEBUG_INFO("sql:%s\n", sql);
  11979. //* Execute SQL statement */
  11980. //zErrMsg = 0;
  11981. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  11982. if( ret != SQLITE_OK ){
  11983. printf("SQL error: %s\n", zErrMsg);
  11984. return isSuccess;
  11985. }
  11986. DEBUG_INFO("successfully Insert records created\n");
  11987. isSuccess = TRUE;
  11988. }
  11989. else
  11990. {
  11991. //Update
  11992. //* Create merged SQL statement */
  11993. 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);
  11994. /* Execute SQL statement */
  11995. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11996. if( ret != SQLITE_OK ){
  11997. printf("SQL error: %s\n", zErrMsg);
  11998. //sqlite3_free(zErrMsg);
  11999. //sqlite3_free(sql);
  12000. return isSuccess;
  12001. }
  12002. DEBUG_INFO("Successfully operation done \n");
  12003. isSuccess = TRUE;
  12004. }
  12005. return isSuccess;
  12006. }
  12007. int GetOcppServerURL()
  12008. {
  12009. int result = FALSE;
  12010. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12011. memset(OcppHost, 0, sizeof(OcppHost));
  12012. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12013. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12014. {
  12015. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12016. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12017. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12018. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12019. result = TRUE;
  12020. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12021. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12022. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12023. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12024. goto End;
  12025. }
  12026. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12027. {
  12028. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12029. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12030. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12031. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12032. result = TRUE;
  12033. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12034. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12035. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12036. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12037. goto End;
  12038. }
  12039. else
  12040. {
  12041. strcpy(OcppHost,"");
  12042. }
  12043. End:
  12044. return result;
  12045. }
  12046. int GetOcppPath()
  12047. {
  12048. int result = FALSE;
  12049. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12050. {
  12051. if(OcppTempPath == NULL)
  12052. {
  12053. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12054. }
  12055. else
  12056. {
  12057. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12058. }
  12059. result = TRUE;
  12060. goto End;
  12061. }
  12062. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12063. {
  12064. if(OcppTempPath == NULL)
  12065. {
  12066. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12067. }
  12068. else
  12069. {
  12070. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12071. }
  12072. result = TRUE;
  12073. goto End;
  12074. }
  12075. else
  12076. {
  12077. strcpy(OcppPath,"");
  12078. }
  12079. End:
  12080. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12081. return result;
  12082. }
  12083. int GetOcppPort()
  12084. {
  12085. return OcppPort;
  12086. }
  12087. int GetOcppConnStatus(void)
  12088. {
  12089. return ShmOCPP16Data->OcppConnStatus;
  12090. }
  12091. void SetOcppConnStatus(uint8_t status)
  12092. {
  12093. ShmOCPP16Data->OcppConnStatus = status;
  12094. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12095. if(status == FALSE)
  12096. {
  12097. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12098. {
  12099. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12100. }
  12101. else
  12102. {
  12103. SystemInitial = AC_QUANTITY;
  12104. }
  12105. }
  12106. }
  12107. int GetHeartBeatWithNOResponse(void)
  12108. {
  12109. return HeartBeatWithNOResponse;
  12110. }
  12111. void SetHeartBeatWithNOResponse(void)
  12112. {
  12113. HeartBeatWithNOResponse = 0;
  12114. }
  12115. int GetTransactionId(int gunindex)
  12116. {
  12117. return TransactionId[gunindex];
  12118. }
  12119. void SetTransactionIdZero(int gunindex)
  12120. {
  12121. TransactionId[gunindex] = 0;
  12122. }
  12123. int InternetDisconnect(void)
  12124. {
  12125. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12126. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12127. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12128. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12129. }
  12130. void GetChargingProfileRequest(int gunindex)
  12131. {
  12132. mtrace();
  12133. //int connectorIdInt, durationInt;
  12134. //char chargingRateUnitStr[4]={0};
  12135. int tempdurationInt = 0;
  12136. int tempchargingProfileId = 0;
  12137. int tempstackLevel = 0;
  12138. int temptransactionId = 0;
  12139. float tempminChargingRateFloat = 0.0;
  12140. char tempchargingProfilePurposeStr[24]={0};
  12141. char tempchargingProfileKindStr[12]={0};
  12142. char temprecurrencyKindStr[8]={0};
  12143. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12144. char tempvalidToStr[28]={0};
  12145. int tempStartPeriodInt = 0;
  12146. float tempLimitInt = 0.0;//0.1;
  12147. int tempNumberPhasesInt=0;
  12148. char fname[200];
  12149. //char comfirmstr[20];
  12150. float MinChargingRate =0.0;
  12151. double diff_t;
  12152. struct tm tp;
  12153. FILE *fptr1;//, *fptr2;
  12154. int c = 0;
  12155. char * pch;
  12156. char *loc;
  12157. char sstr[200]={ 0 };
  12158. int n_chargingProfile = 0;
  12159. int n_SchedulePeriods = 0;
  12160. char SchedulePeriodList[10][200]={0};
  12161. char sLineWord[800]={0};
  12162. char word[1000]={0};
  12163. int confirmPeriods = 0;
  12164. struct StructProfile ChargePointMaxProfile;
  12165. struct StructProfile TxDefaultProfile;
  12166. struct StructProfile TxProfile;
  12167. struct StructProfile TxDefaultProfiletemp[2]={0};
  12168. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12169. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12170. struct StructChargingProfile TxProfile_TEMP={0};
  12171. int TxDefaultProfileFileIsNull=FALSE;
  12172. int ChargePointMaxProfileIsNull=FALSE;
  12173. int TxProfileIsNull=FALSE;
  12174. // int CompositeSceduleIndex = 0;
  12175. char ChargePointMaxProfileScheduleStr[30]={0};
  12176. char TxDefaultProfileScheduleStr[30]={0};
  12177. char TxProfileScheduleStr[30]={0};
  12178. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12179. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12180. memset(&TxProfile,0,sizeof(struct StructProfile));
  12181. DEBUG_INFO("GetChargingProfileRequest\n");
  12182. //*****************************ChargePointMaxProfile******************************************/
  12183. strcpy(fname, ChargePointMaxProfile_JSON);
  12184. ChargePointMaxProfileIsNull=TRUE;
  12185. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12186. {
  12187. fptr1 = fopen(fname, "r");
  12188. int c;
  12189. c = fgetc(fptr1);
  12190. //DEBUG_INFO("c:%d\n",c);
  12191. rewind(fptr1);
  12192. if(c == EOF)
  12193. {
  12194. DEBUG_INFO("\n End of file reached.");
  12195. ChargePointMaxProfileIsNull=TRUE;
  12196. fclose(fptr1);
  12197. }
  12198. else
  12199. {
  12200. ChargePointMaxProfileIsNull=FALSE;
  12201. while(fscanf(fptr1, "%s", word) != EOF)
  12202. {
  12203. if(strcmp(word, "chargingProfileId") == 0)
  12204. {
  12205. n_chargingProfile = n_chargingProfile + 1;
  12206. }
  12207. }
  12208. rewind(fptr1);
  12209. //search Charging Profile Element
  12210. int i = 0;
  12211. int j = 0;
  12212. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12213. //***********chargingProfileId**************/
  12214. c = 0;
  12215. loc = strstr(sLineWord, "chargingProfileId");
  12216. //DEBUG_INFO("loc=%s\n",loc);
  12217. memset(sstr ,0, sizeof(sstr) );
  12218. if(loc != NULL)
  12219. {
  12220. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12221. {
  12222. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12223. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12224. c++;
  12225. }
  12226. sstr[c] = '\0';
  12227. tempchargingProfileId = atoi(sstr);
  12228. }
  12229. else
  12230. {
  12231. tempchargingProfileId = 0;
  12232. }
  12233. //***********stackLevel**************/
  12234. c = 0;
  12235. loc = strstr(sLineWord, "stackLevel");
  12236. //DEBUG_INFO("loc=%s\n",loc);
  12237. memset(sstr ,0, sizeof(sstr) );
  12238. if(loc != NULL)
  12239. {
  12240. while (loc[2+strlen("stackLevel")+c] != '\"')
  12241. {
  12242. sstr[c] = loc[2+strlen("stackLevel")+c];
  12243. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12244. c++;
  12245. }
  12246. sstr[c] = '\0';
  12247. tempstackLevel = atoi(sstr);
  12248. }
  12249. else
  12250. {
  12251. tempstackLevel = 0;
  12252. }
  12253. //***********chargingProfilePurpose **************/
  12254. c = 0;
  12255. loc = strstr(sLineWord, "chargingProfilePurpose");
  12256. //DEBUG_INFO("loc=%s\n",loc);
  12257. memset(sstr ,0, sizeof(sstr) );
  12258. if(loc != NULL)
  12259. {
  12260. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12261. {
  12262. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12263. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12264. c++;
  12265. }
  12266. sstr[c] = '\0';
  12267. strcpy(tempchargingProfilePurposeStr,sstr);
  12268. }
  12269. else
  12270. {
  12271. strcpy(tempchargingProfilePurposeStr,"");
  12272. }
  12273. //***********chargingProfileKind **************/
  12274. c = 0;
  12275. loc = strstr(sLineWord, "chargingProfileKind");
  12276. //DEBUG_INFO("loc=%s\n",loc);
  12277. memset(sstr ,0, sizeof(sstr) );
  12278. if(loc != NULL)
  12279. {
  12280. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12281. {
  12282. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12283. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12284. c++;
  12285. }
  12286. sstr[c] = '\0';
  12287. strcpy(tempchargingProfileKindStr,sstr);
  12288. }
  12289. else
  12290. {
  12291. strcpy(tempchargingProfileKindStr,"");
  12292. }
  12293. //***********recurrencyKind **************/
  12294. c = 0;
  12295. loc = strstr(sLineWord, "recurrencyKind");
  12296. //DEBUG_INFO("loc=%s\n",loc);
  12297. memset(sstr ,0, sizeof(sstr) );
  12298. if(loc != NULL)
  12299. {
  12300. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12301. {
  12302. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12303. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12304. c++;
  12305. }
  12306. sstr[c] = '\0';
  12307. strcpy(temprecurrencyKindStr,sstr);
  12308. }
  12309. else
  12310. {
  12311. strcpy(temprecurrencyKindStr,"");
  12312. }
  12313. //***********validFrom**************/
  12314. c = 0;
  12315. loc = strstr(sLineWord, "validFrom");
  12316. //DEBUG_INFO("loc=%s\n",loc);
  12317. memset(sstr ,0, sizeof(sstr) );
  12318. if(loc != NULL)
  12319. {
  12320. while (loc[3+strlen("validFrom")+c] != '\"')
  12321. {
  12322. sstr[c] = loc[3+strlen("validFrom")+c];
  12323. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12324. c++;
  12325. }
  12326. sstr[c] = '\0';
  12327. strcpy(tempvalidFromStr,sstr);
  12328. }
  12329. else
  12330. {
  12331. strcpy(tempvalidFromStr,"");
  12332. }
  12333. //***********validTo **************/
  12334. c = 0;
  12335. loc = strstr(sLineWord, "validTo");
  12336. //DEBUG_INFO("loc=%s\n",loc);
  12337. memset(sstr ,0, sizeof(sstr) );
  12338. if(loc != NULL)
  12339. {
  12340. while (loc[3+strlen("validTo")+c] != '\"')
  12341. {
  12342. sstr[c] = loc[3+strlen("validTo")+c];
  12343. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12344. c++;
  12345. }
  12346. sstr[c] = '\0';
  12347. strcpy(tempvalidToStr,sstr);
  12348. }
  12349. else
  12350. {
  12351. strcpy(tempvalidToStr,"");
  12352. }
  12353. //***********validFrom**************/
  12354. c = 0;
  12355. loc = strstr(sLineWord, "validFrom");
  12356. if(loc != NULL)
  12357. {
  12358. memset(sstr ,0, sizeof(sstr) );
  12359. while (loc[3+strlen("validFrom")+c] != '\"')
  12360. {
  12361. sstr[c] = loc[3+strlen("validFrom")+c];
  12362. c++;
  12363. }
  12364. sstr[c] = '\0';
  12365. strcpy(tempvalidFromStr,sstr);
  12366. }
  12367. else
  12368. {
  12369. strcpy(tempvalidFromStr,"");
  12370. }
  12371. //***********duration**************/
  12372. c = 0;
  12373. loc = strstr(sLineWord, "duration");
  12374. if(loc != NULL)
  12375. {
  12376. memset(sstr ,0, sizeof(sstr) );
  12377. while (loc[2+strlen("duration")+c] != ',')
  12378. {
  12379. sstr[c] = loc[2+strlen("duration")+c];
  12380. c++;
  12381. }
  12382. sstr[c] = '\0';
  12383. tempdurationInt = atoi(sstr);
  12384. }
  12385. else
  12386. {
  12387. tempdurationInt = 0;
  12388. }
  12389. //**********startSchedule**********/
  12390. c = 0;
  12391. loc = strstr(sLineWord, "startSchedule");
  12392. memset(sstr ,0, sizeof(sstr) );
  12393. while (loc[3+strlen("startSchedule")+c] != '\"')
  12394. {
  12395. sstr[c] = loc[3+strlen("startSchedule")+c];
  12396. c++;
  12397. }
  12398. sstr[c] = '\0';
  12399. strcpy(tempstartScheduleStr, sstr);
  12400. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  12401. //**********chargingRateUnit**********/
  12402. c = 0;
  12403. loc = strstr(sLineWord, "chargingRateUnit");
  12404. memset(sstr ,0, sizeof(sstr) );
  12405. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12406. {
  12407. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12408. c++;
  12409. }
  12410. sstr[c] = '\0';
  12411. strcpy(tempchargingRateUnitStr, sstr);
  12412. //**********minChargingRate*******/
  12413. c = 0;
  12414. loc = strstr(sLineWord, "minChargingRate");
  12415. if(loc != NULL)
  12416. {
  12417. memset(sstr ,0, sizeof(sstr) );
  12418. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12419. {
  12420. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12421. c++;
  12422. }
  12423. sstr[c] = '\0';
  12424. tempminChargingRateFloat = atof(sstr);
  12425. }
  12426. else
  12427. {
  12428. tempminChargingRateFloat = 0.0;
  12429. }
  12430. //
  12431. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12432. tp.tm_isdst = -1;
  12433. time_t utc = mktime(&tp);
  12434. time_t t = time(NULL);
  12435. diff_t = difftime(t, utc);
  12436. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12437. //parsing strings to words
  12438. i = 0;
  12439. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12440. loc = loc+3+strlen("chargingSchedulePeriod");
  12441. pch = strtok(loc ,"{");
  12442. while (pch != NULL)
  12443. {
  12444. strcpy(SchedulePeriodList[i], pch);
  12445. pch = strtok (NULL, "{");
  12446. i = i + 1;
  12447. }
  12448. n_SchedulePeriods = i;
  12449. for(int i=0;i<n_SchedulePeriods;i++)
  12450. {
  12451. //*************startPeriod****************/
  12452. c = 0;
  12453. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12454. memset(sstr ,0, sizeof(sstr) );
  12455. while (loc[strlen("startPeriod")+2+c] != ',')
  12456. {
  12457. sstr[c] = loc[strlen("startPeriod")+2+c];
  12458. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12459. c++;
  12460. }
  12461. sstr[c] = '\0';
  12462. tempStartPeriodInt = atoi(sstr);
  12463. //*************limit****************/
  12464. c = 0;
  12465. loc = strstr(SchedulePeriodList[i], "limit");
  12466. memset(sstr ,0, sizeof(sstr) );
  12467. while (loc[strlen("limit")+2+c] != ',')
  12468. {
  12469. sstr[c] = loc[strlen("limit")+2+c];
  12470. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12471. c++;
  12472. }
  12473. sstr[c] = '\0';
  12474. tempLimitInt = atof(sstr);
  12475. //*************numberPhases****************/
  12476. c = 0;
  12477. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12478. memset(sstr ,0, sizeof(sstr) );
  12479. while (loc[strlen("numberPhases")+2+c] != '}')
  12480. {
  12481. sstr[c] = loc[strlen("numberPhases")+2+c];
  12482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12483. c++;
  12484. }
  12485. sstr[c] = '\0';
  12486. tempNumberPhasesInt = atoi(sstr);
  12487. if(j == 0)
  12488. {
  12489. ChargePointMaxProfile.Duration = tempdurationInt;
  12490. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  12491. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  12492. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12493. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12494. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12495. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  12496. ChargePointMaxProfile_TEMP.TransactionId = 0;
  12497. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12498. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12499. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12500. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12501. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12502. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12503. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12504. }
  12505. }
  12506. if(MinChargingRate < tempminChargingRateFloat)
  12507. {
  12508. MinChargingRate = tempminChargingRateFloat;
  12509. }
  12510. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12511. if(confirmPeriods < n_SchedulePeriods)
  12512. {
  12513. confirmPeriods = n_SchedulePeriods;
  12514. }
  12515. j = j + 1;
  12516. }
  12517. fclose(fptr1);
  12518. }
  12519. }// the end of access file ChargePointMaxProfile
  12520. //****************************TxDefaultProfile************************************************/
  12521. switch(gunindex + 1)
  12522. {
  12523. case 0:
  12524. break;
  12525. case 1:
  12526. strcpy(fname, TxDefaultProfile_1_JSON );
  12527. break;
  12528. case 2:
  12529. strcpy(fname, TxDefaultProfile_2_JSON );
  12530. break;
  12531. default:
  12532. strcpy(fname, TxDefaultProfile_1_JSON );
  12533. break;
  12534. }
  12535. TxDefaultProfileFileIsNull=TRUE;
  12536. if((access(fname,F_OK))!=-1)
  12537. {
  12538. fptr1 = fopen(fname, "r");
  12539. c = 0;
  12540. c = fgetc(fptr1);
  12541. //DEBUG_INFO("c:%d\n",c);
  12542. rewind(fptr1);
  12543. if(c == EOF)
  12544. {
  12545. DEBUG_INFO("\n End of file reached.");
  12546. TxDefaultProfileFileIsNull=TRUE;
  12547. fclose(fptr1);
  12548. }
  12549. else
  12550. {
  12551. TxDefaultProfileFileIsNull=FALSE;
  12552. while(fscanf(fptr1, "%s", word) != EOF)
  12553. {
  12554. if(strcmp(word, "chargingProfileId") == 0)
  12555. {
  12556. n_chargingProfile = n_chargingProfile + 1;
  12557. }
  12558. }
  12559. rewind(fptr1);
  12560. //search Charging Profile Element
  12561. int i = 0;
  12562. int j = 0;
  12563. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12564. #if 0
  12565. /***********connectorId****************/
  12566. c = 0;
  12567. loc = strstr(sLineWord, "connectorId");
  12568. memset(sstr ,0, sizeof(sstr) );
  12569. while (loc[strlen("connectorId")+2+c] != ',')
  12570. {
  12571. sstr[c] = loc[strlen("connectorId")+2+c];
  12572. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12573. c++;
  12574. }
  12575. sstr[c] = '\0';
  12576. tempconnectorIdInt = atoi(sstr);
  12577. #endif
  12578. //***********chargingProfileId**************/
  12579. c = 0;
  12580. loc = strstr(sLineWord, "chargingProfileId");
  12581. //DEBUG_INFO("loc=%s\n",loc);
  12582. memset(sstr ,0, sizeof(sstr) );
  12583. if(loc != NULL)
  12584. {
  12585. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12586. {
  12587. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12588. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12589. c++;
  12590. }
  12591. sstr[c] = '\0';
  12592. tempchargingProfileId = atoi(sstr);
  12593. }
  12594. else
  12595. {
  12596. tempchargingProfileId = 0;
  12597. }
  12598. //***********stackLevel**************/
  12599. c = 0;
  12600. loc = strstr(sLineWord, "stackLevel");
  12601. //DEBUG_INFO("loc=%s\n",loc);
  12602. memset(sstr ,0, sizeof(sstr) );
  12603. if(loc != NULL)
  12604. {
  12605. while (loc[2+strlen("stackLevel")+c] != '\"')
  12606. {
  12607. sstr[c] = loc[2+strlen("stackLevel")+c];
  12608. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12609. c++;
  12610. }
  12611. sstr[c] = '\0';
  12612. tempstackLevel = atoi(sstr);
  12613. }
  12614. else
  12615. {
  12616. tempstackLevel = 0;
  12617. }
  12618. //***********chargingProfilePurpose **************/
  12619. c = 0;
  12620. loc = strstr(sLineWord, "chargingProfilePurpose");
  12621. //DEBUG_INFO("loc=%s\n",loc);
  12622. memset(sstr ,0, sizeof(sstr) );
  12623. if(loc != NULL)
  12624. {
  12625. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12626. {
  12627. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12628. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12629. c++;
  12630. }
  12631. sstr[c] = '\0';
  12632. strcpy(tempchargingProfilePurposeStr,sstr);
  12633. }
  12634. else
  12635. {
  12636. strcpy(tempchargingProfilePurposeStr,"");
  12637. }
  12638. //***********chargingProfileKind **************/
  12639. c = 0;
  12640. loc = strstr(sLineWord, "chargingProfileKind");
  12641. //DEBUG_INFO("loc=%s\n",loc);
  12642. memset(sstr ,0, sizeof(sstr) );
  12643. if(loc != NULL)
  12644. {
  12645. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12646. {
  12647. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12648. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12649. c++;
  12650. }
  12651. sstr[c] = '\0';
  12652. strcpy(tempchargingProfileKindStr,sstr);
  12653. }
  12654. else
  12655. {
  12656. strcpy(tempchargingProfileKindStr,"");
  12657. }
  12658. //***********recurrencyKind **************/
  12659. c = 0;
  12660. loc = strstr(sLineWord, "recurrencyKind");
  12661. //DEBUG_INFO("loc=%s\n",loc);
  12662. memset(sstr ,0, sizeof(sstr) );
  12663. if(loc != NULL)
  12664. {
  12665. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12666. {
  12667. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12668. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12669. c++;
  12670. }
  12671. sstr[c] = '\0';
  12672. strcpy(temprecurrencyKindStr,sstr);
  12673. }
  12674. else
  12675. {
  12676. strcpy(temprecurrencyKindStr,"");
  12677. }
  12678. //***********validFrom**************/
  12679. c = 0;
  12680. loc = strstr(sLineWord, "validFrom");
  12681. if(loc != NULL)
  12682. {
  12683. memset(sstr ,0, sizeof(sstr) );
  12684. while (loc[3+strlen("validFrom")+c] != '\"')
  12685. {
  12686. sstr[c] = loc[3+strlen("validFrom")+c];
  12687. c++;
  12688. }
  12689. sstr[c] = '\0';
  12690. strcpy(tempvalidFromStr,sstr);
  12691. }
  12692. else
  12693. {
  12694. strcpy(tempvalidFromStr,"");
  12695. }
  12696. //***********validFrom**************/
  12697. c = 0;
  12698. loc = strstr(sLineWord, "duration");
  12699. if(loc != NULL)
  12700. {
  12701. memset(sstr ,0, sizeof(sstr) );
  12702. while (loc[2+strlen("duration")+c] != ',')
  12703. {
  12704. sstr[c] = loc[2+strlen("duration")+c];
  12705. c++;
  12706. }
  12707. sstr[c] = '\0';
  12708. tempdurationInt = atoi(sstr);
  12709. }
  12710. else
  12711. {
  12712. tempdurationInt = 0;
  12713. }
  12714. //**********startSchedule**********/
  12715. c = 0;
  12716. loc = strstr(sLineWord, "startSchedule");
  12717. memset(sstr ,0, sizeof(sstr) );
  12718. while (loc[3+strlen("startSchedule")+c] != '\"')
  12719. {
  12720. sstr[c] = loc[3+strlen("startSchedule")+c];
  12721. c++;
  12722. }
  12723. sstr[c] = '\0';
  12724. strcpy(tempstartScheduleStr, sstr);
  12725. strcpy(TxDefaultProfileScheduleStr, sstr);
  12726. //**********chargingRateUnit**********/
  12727. c = 0;
  12728. loc = strstr(sLineWord, "chargingRateUnit");
  12729. memset(sstr ,0, sizeof(sstr) );
  12730. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12731. {
  12732. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12733. c++;
  12734. }
  12735. sstr[c] = '\0';
  12736. strcpy(tempchargingRateUnitStr, sstr);
  12737. //**********minChargingRate*******/
  12738. c = 0;
  12739. loc = strstr(sLineWord, "minChargingRate");
  12740. if(loc != NULL)
  12741. {
  12742. memset(sstr ,0, sizeof(sstr) );
  12743. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12744. {
  12745. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12746. c++;
  12747. }
  12748. sstr[c] = '\0';
  12749. tempminChargingRateFloat = atof(sstr);
  12750. }
  12751. else
  12752. {
  12753. tempminChargingRateFloat = 0.0;
  12754. }
  12755. //
  12756. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12757. tp.tm_isdst = -1;
  12758. time_t utc = mktime(&tp);
  12759. time_t t = time(NULL);
  12760. diff_t = difftime(t, utc);
  12761. printf("diff between startScheduleStr and now =%f\n",diff_t);
  12762. //parsing strings to words
  12763. i = 0;
  12764. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12765. loc = loc+3+strlen("chargingSchedulePeriod");
  12766. pch = strtok(loc ,"{");
  12767. while (pch != NULL)
  12768. {
  12769. strcpy(SchedulePeriodList[i], pch);
  12770. pch = strtok (NULL, "{");
  12771. i = i + 1;
  12772. }
  12773. n_SchedulePeriods = i;
  12774. for(int i=0;i<n_SchedulePeriods;i++)
  12775. {
  12776. //*************startPeriod****************/
  12777. c = 0;
  12778. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12779. memset(sstr ,0, sizeof(sstr) );
  12780. while (loc[strlen("startPeriod")+2+c] != ',')
  12781. {
  12782. sstr[c] = loc[strlen("startPeriod")+2+c];
  12783. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12784. c++;
  12785. }
  12786. sstr[c] = '\0';
  12787. tempStartPeriodInt = atoi(sstr);
  12788. //*************limit****************/
  12789. c = 0;
  12790. loc = strstr(SchedulePeriodList[i], "limit");
  12791. memset(sstr ,0, sizeof(sstr) );
  12792. while (loc[strlen("limit")+2+c] != ',')
  12793. {
  12794. sstr[c] = loc[strlen("limit")+2+c];
  12795. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12796. c++;
  12797. }
  12798. sstr[c] = '\0';
  12799. tempLimitInt = atof(sstr);
  12800. //*************numberPhases****************/
  12801. c = 0;
  12802. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12803. memset(sstr ,0, sizeof(sstr) );
  12804. while (loc[strlen("numberPhases")+2+c] != '}')
  12805. {
  12806. sstr[c] = loc[strlen("numberPhases")+2+c];
  12807. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12808. c++;
  12809. }
  12810. sstr[c] = '\0';
  12811. tempNumberPhasesInt = atoi(sstr);
  12812. if(j == 0)
  12813. {
  12814. TxDefaultProfile.Duration = tempdurationInt;
  12815. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  12816. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  12817. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12818. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12819. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12820. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  12821. TxDefaultProfile_TEMP.TransactionId = 0;
  12822. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  12823. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12824. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12825. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12826. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12827. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12828. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12829. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12830. }
  12831. else
  12832. {
  12833. //other stack level charging Profile
  12834. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  12835. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  12836. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  12837. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  12838. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  12839. }
  12840. }
  12841. if(MinChargingRate < tempminChargingRateFloat)
  12842. {
  12843. MinChargingRate = tempminChargingRateFloat;
  12844. }
  12845. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12846. if(confirmPeriods < n_SchedulePeriods)
  12847. confirmPeriods = n_SchedulePeriods;
  12848. j = j + 1;
  12849. }
  12850. fclose(fptr1);
  12851. //Stacking Charging Profiles
  12852. for(int l=0; l <(j-1) ;l++)
  12853. {
  12854. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  12855. {
  12856. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  12857. {
  12858. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  12859. {
  12860. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  12861. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  12862. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  12863. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12864. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12865. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12866. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12867. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12868. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12869. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12870. }
  12871. else
  12872. {
  12873. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12874. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12875. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12876. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12877. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12878. }
  12879. }
  12880. }
  12881. }
  12882. //end of Stacking Charging Profiles
  12883. }
  12884. }// the end of ACCESS TxDefaultProfile
  12885. //****************************TxProfile************************************************/
  12886. switch(gunindex + 1)
  12887. {
  12888. case 0:
  12889. break;
  12890. case 1:
  12891. strcpy(fname, TxProfile_1_JSON );
  12892. break;
  12893. case 2:
  12894. strcpy(fname, TxProfile_2_JSON );
  12895. break;
  12896. default:
  12897. strcpy(fname, TxProfile_1_JSON );
  12898. break;
  12899. }
  12900. TxProfileIsNull=TRUE;
  12901. if((access(fname,F_OK))!=-1)
  12902. {
  12903. fptr1 = fopen(fname, "r");
  12904. c = 0;
  12905. c = fgetc(fptr1);
  12906. //DEBUG_INFO("c:%d\n",c);
  12907. rewind(fptr1);
  12908. if(c == EOF)
  12909. {
  12910. DEBUG_INFO("\n End of file reached.");
  12911. TxProfileIsNull=TRUE;
  12912. fclose(fptr1);
  12913. }
  12914. else
  12915. {
  12916. TxProfileIsNull=FALSE;
  12917. while(fscanf(fptr1, "%s", word) != EOF)
  12918. {
  12919. if(strcmp(word, "chargingProfileId") == 0)
  12920. {
  12921. n_chargingProfile = n_chargingProfile + 1;
  12922. }
  12923. }
  12924. rewind(fptr1);
  12925. //search Charging Profile Element
  12926. int i= 0;
  12927. int j= 0;
  12928. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12929. #if 0
  12930. /***********connectorId****************/
  12931. c = 0;
  12932. loc = strstr(sLineWord, "connectorId");
  12933. memset(sstr ,0, sizeof(sstr) );
  12934. while (loc[strlen("connectorId")+2+c] != ',')
  12935. {
  12936. sstr[c] = loc[strlen("connectorId")+2+c];
  12937. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12938. c++;
  12939. }
  12940. sstr[c] = '\0';
  12941. tempconnectorIdInt = atoi(sstr);
  12942. #endif
  12943. //***********chargingProfileId**************/
  12944. c = 0;
  12945. loc = strstr(sLineWord, "chargingProfileId");
  12946. memset(sstr ,0, sizeof(sstr) );
  12947. if(loc != NULL)
  12948. {
  12949. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12950. {
  12951. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12952. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12953. c++;
  12954. }
  12955. sstr[c] = '\0';
  12956. tempchargingProfileId = atoi(sstr);
  12957. }
  12958. else
  12959. {
  12960. tempchargingProfileId = 0;
  12961. }
  12962. //***********transactionId **************/
  12963. c = 0;
  12964. loc = strstr(sLineWord, "transactionId");
  12965. //DEBUG_INFO("loc=%s\n",loc);
  12966. memset(sstr ,0, sizeof(sstr) );
  12967. if(loc != NULL)
  12968. {
  12969. while (loc[2+strlen("transactionId")+c] != '\"')
  12970. {
  12971. sstr[c] = loc[2+strlen("transactionId")+c];
  12972. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12973. c++;
  12974. }
  12975. sstr[c] = '\0';
  12976. temptransactionId = atoi(sstr);
  12977. }
  12978. else
  12979. {
  12980. temptransactionId = 0;
  12981. }
  12982. //***********stackLevel**************/
  12983. c = 0;
  12984. loc = strstr(sLineWord, "stackLevel");
  12985. //DEBUG_INFO("loc=%s\n",loc);
  12986. memset(sstr ,0, sizeof(sstr) );
  12987. if(loc != NULL)
  12988. {
  12989. while (loc[2+strlen("stackLevel")+c] != '\"')
  12990. {
  12991. sstr[c] = loc[2+strlen("stackLevel")+c];
  12992. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12993. c++;
  12994. }
  12995. sstr[c] = '\0';
  12996. tempstackLevel = atoi(sstr);
  12997. }
  12998. else
  12999. {
  13000. tempstackLevel = 0;
  13001. }
  13002. //***********chargingProfilePurpose **************/
  13003. c = 0;
  13004. loc = strstr(sLineWord, "chargingProfilePurpose");
  13005. //DEBUG_INFO("loc=%s\n",loc);
  13006. memset(sstr ,0, sizeof(sstr) );
  13007. if(loc != NULL)
  13008. {
  13009. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13010. {
  13011. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13012. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13013. c++;
  13014. }
  13015. sstr[c] = '\0';
  13016. strcpy(tempchargingProfilePurposeStr,sstr);
  13017. }
  13018. else
  13019. {
  13020. strcpy(tempchargingProfilePurposeStr,"");
  13021. }
  13022. //***********chargingProfileKind **************/
  13023. c = 0;
  13024. loc = strstr(sLineWord, "chargingProfileKind");
  13025. //DEBUG_INFO("loc=%s\n",loc);
  13026. memset(sstr ,0, sizeof(sstr) );
  13027. if(loc != NULL)
  13028. {
  13029. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13030. {
  13031. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13032. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13033. c++;
  13034. }
  13035. sstr[c] = '\0';
  13036. strcpy(tempchargingProfileKindStr,sstr);
  13037. }
  13038. else
  13039. {
  13040. strcpy(tempchargingProfileKindStr,"");
  13041. }
  13042. //***********recurrencyKind **************/
  13043. c = 0;
  13044. loc = strstr(sLineWord, "recurrencyKind");
  13045. //DEBUG_INFO("loc=%s\n",loc);
  13046. memset(sstr ,0, sizeof(sstr) );
  13047. if(loc != NULL)
  13048. {
  13049. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13050. {
  13051. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13052. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13053. c++;
  13054. }
  13055. sstr[c] = '\0';
  13056. strcpy(temprecurrencyKindStr,sstr);
  13057. }
  13058. else
  13059. {
  13060. strcpy(temprecurrencyKindStr,"");
  13061. }
  13062. //***********validFrom**************/
  13063. c = 0;
  13064. loc = strstr(sLineWord, "validFrom");
  13065. if(loc != NULL)
  13066. {
  13067. memset(sstr ,0, sizeof(sstr) );
  13068. while (loc[3+strlen("validFrom")+c] != '\"')
  13069. {
  13070. sstr[c] = loc[3+strlen("validFrom")+c];
  13071. c++;
  13072. }
  13073. sstr[c] = '\0';
  13074. strcpy(tempvalidFromStr,sstr);
  13075. }
  13076. else
  13077. {
  13078. strcpy(tempvalidFromStr,"");
  13079. }
  13080. //***********duration**************/
  13081. c = 0;
  13082. loc = strstr(sLineWord, "duration");
  13083. //DEBUG_INFO("loc=%s\n",loc);
  13084. memset(sstr ,0, sizeof(sstr) );
  13085. if(loc != NULL)
  13086. {
  13087. while (loc[2+strlen("duration")+c] != '\"')
  13088. {
  13089. sstr[c] = loc[2+strlen("duration")+c];
  13090. c++;
  13091. }
  13092. sstr[c] = '\0';
  13093. tempdurationInt = atoi(sstr);
  13094. }
  13095. else
  13096. {
  13097. tempdurationInt = 0;
  13098. }
  13099. //**********startSchedule**********/
  13100. c = 0;
  13101. loc = strstr(sLineWord, "startSchedule");
  13102. memset(sstr ,0, sizeof(sstr) );
  13103. while (loc[3+strlen("startSchedule")+c] != '\"')
  13104. {
  13105. sstr[c] = loc[3+strlen("startSchedule")+c];
  13106. c++;
  13107. }
  13108. sstr[c] = '\0';
  13109. strcpy(tempstartScheduleStr, sstr);
  13110. strcpy(TxProfileScheduleStr, sstr);
  13111. //**********chargingRateUnit**********/
  13112. c = 0;
  13113. loc = strstr(sLineWord, "chargingRateUnit");
  13114. memset(sstr ,0, sizeof(sstr) );
  13115. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13116. {
  13117. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13118. c++;
  13119. }
  13120. sstr[c] = '\0';
  13121. strcpy(tempchargingRateUnitStr, sstr);
  13122. //**********minChargingRate*******/
  13123. c = 0;
  13124. loc = strstr(sLineWord, "minChargingRate");
  13125. if(loc != NULL)
  13126. {
  13127. memset(sstr ,0, sizeof(sstr) );
  13128. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13129. {
  13130. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13131. c++;
  13132. }
  13133. sstr[c] = '\0';
  13134. tempminChargingRateFloat = atof(sstr);
  13135. }
  13136. else
  13137. {
  13138. tempminChargingRateFloat = 0.0;
  13139. }
  13140. //
  13141. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13142. tp.tm_isdst = -1;
  13143. time_t utc = mktime(&tp);
  13144. time_t t = time(NULL);
  13145. diff_t = difftime(t, utc);
  13146. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13147. //parsing strings to words
  13148. i = 0;
  13149. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13150. loc = loc+3+strlen("chargingSchedulePeriod");
  13151. pch = strtok(loc ,"{");
  13152. while (pch != NULL)
  13153. {
  13154. strcpy(SchedulePeriodList[i], pch);
  13155. pch = strtok (NULL, "{");
  13156. i = i + 1;
  13157. }
  13158. n_SchedulePeriods = i;
  13159. for(int i=0;i<n_SchedulePeriods;i++)
  13160. {
  13161. //*************startPeriod****************/
  13162. c = 0;
  13163. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13164. memset(sstr ,0, sizeof(sstr) );
  13165. while (loc[strlen("startPeriod")+2+c] != ',')
  13166. {
  13167. sstr[c] = loc[strlen("startPeriod")+2+c];
  13168. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13169. c++;
  13170. }
  13171. sstr[c] = '\0';
  13172. tempStartPeriodInt = atoi(sstr);
  13173. //*************limit****************/
  13174. c = 0;
  13175. loc = strstr(SchedulePeriodList[i], "limit");
  13176. memset(sstr ,0, sizeof(sstr) );
  13177. while (loc[strlen("limit")+2+c] != ',')
  13178. {
  13179. sstr[c] = loc[strlen("limit")+2+c];
  13180. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13181. c++;
  13182. }
  13183. sstr[c] = '\0';
  13184. tempLimitInt = atof(sstr);
  13185. //*************numberPhases****************/
  13186. c = 0;
  13187. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13188. memset(sstr ,0, sizeof(sstr) );
  13189. while (loc[strlen("numberPhases")+2+c] != '}')
  13190. {
  13191. sstr[c] = loc[strlen("numberPhases")+2+c];
  13192. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13193. c++;
  13194. }
  13195. sstr[c] = '\0';
  13196. tempNumberPhasesInt = atoi(sstr);
  13197. //TxProfile.Duration = durationInt;
  13198. TxProfile.TotalPeriod = n_SchedulePeriods;
  13199. TxProfile.Period[i].Limit = tempLimitInt;
  13200. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13201. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13202. }
  13203. if(MinChargingRate < tempminChargingRateFloat)
  13204. {
  13205. MinChargingRate = tempminChargingRateFloat;
  13206. }
  13207. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13208. if(confirmPeriods < n_SchedulePeriods)
  13209. confirmPeriods = n_SchedulePeriods;
  13210. if(j == 0)
  13211. {
  13212. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13213. TxProfile_TEMP.StackLevel = tempstackLevel;
  13214. TxProfile_TEMP.TransactionId = 0;
  13215. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13216. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13217. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13218. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13219. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13220. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13221. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13222. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13223. }
  13224. }
  13225. fclose(fptr1);
  13226. }
  13227. }// the end of ACCESS TxProfile
  13228. //CompositeSchedule
  13229. int period=0;
  13230. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13231. {
  13232. //TxProfile
  13233. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13234. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13235. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13236. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13237. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13238. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13239. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13240. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13241. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13242. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13243. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13244. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13245. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13246. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13247. {
  13248. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13249. {
  13250. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13251. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13252. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13253. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13254. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13255. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13256. period = period + 1;
  13257. }
  13258. else
  13259. {
  13260. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13261. {
  13262. }
  13263. else
  13264. {
  13265. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13266. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13267. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13268. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13269. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13270. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13271. period = period + 1;
  13272. }
  13273. }
  13274. }
  13275. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13276. {
  13277. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  13278. {
  13279. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13280. {
  13281. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13282. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13283. }
  13284. else
  13285. {
  13286. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13287. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13288. }
  13289. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13290. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13291. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13292. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13293. period = period + 1;
  13294. }
  13295. }
  13296. }
  13297. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13298. {
  13299. //TxDefaultProfile
  13300. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13301. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13302. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13303. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13304. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  13305. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13306. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13307. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13308. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13309. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13310. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13311. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13312. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13313. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13314. {
  13315. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13316. {
  13317. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13318. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13319. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13320. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13321. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13322. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13323. period = period + 1;
  13324. }
  13325. else
  13326. {
  13327. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13328. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13329. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13330. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13331. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13332. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13333. period = period + 1;
  13334. }
  13335. }
  13336. }
  13337. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  13338. {
  13339. //TxDefaultProfile
  13340. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13341. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13342. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13343. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13344. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  13345. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13346. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13347. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13348. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13349. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13350. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13351. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13352. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13353. {
  13354. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13355. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13356. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13357. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13358. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13359. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13360. period = period + 1;
  13361. }
  13362. }
  13363. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13364. {
  13365. //ChargePointMaxProfile
  13366. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  13367. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  13368. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13369. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  13370. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  13371. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13372. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  13373. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  13374. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  13375. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  13376. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  13377. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  13378. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  13379. {
  13380. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  13381. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  13382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  13383. period = period + 1;
  13384. }
  13385. }
  13386. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  13387. {
  13388. //TxProfile
  13389. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13390. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13391. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13392. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13394. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13395. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13396. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13397. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13398. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13399. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13400. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13401. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13402. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13403. {
  13404. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  13405. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  13406. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  13407. }
  13408. }
  13409. confirmPeriods = period;
  13410. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  13411. 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,"
  13412. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  13413. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  13414. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  13415. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  13416. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  13417. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  13418. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  13419. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  13420. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  13421. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  13422. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  13423. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  13424. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  13425. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  13426. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  13427. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  13428. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  13429. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  13430. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  13431. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  13432. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  13433. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  13434. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  13435. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  13436. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  13437. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  13438. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  13439. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  13440. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  13441. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  13442. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  13443. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  13444. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  13445. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  13446. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  13447. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  13448. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  13449. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  13450. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  13451. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  13452. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  13453. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  13454. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  13455. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  13456. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  13457. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  13458. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  13459. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  13460. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  13461. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  13462. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  13463. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  13464. }
  13465. void LWS_Send(char * str)
  13466. {
  13467. //=====================================================
  13468. // Check InternetConn 0: disconnected, 1: connected
  13469. //====================================================
  13470. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13471. {
  13472. DEBUG_INFO("\n offline now !!!\n");
  13473. return;
  13474. }
  13475. pthread_mutex_lock(&lock);
  13476. memset(SendBuffer,0,SendBufLen);
  13477. sprintf((char *)SendBuffer, "%s", str);
  13478. pthread_mutex_unlock(&lock);
  13479. lws_callback_on_writable(wsi_client);
  13480. lws_service(context, 10000);//timeout_ms
  13481. }