MessageHandler.c 571 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795
  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. else if((server_sign == FALSE) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  1088. {
  1089. sendAuthorizeRequest(0);
  1090. }
  1091. //===============================
  1092. // CSU Trigger Smart Charging Profilw
  1093. //===============================
  1094. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1095. {
  1096. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1097. GetChargingProfileRequest(gun_index);
  1098. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1099. }
  1100. //==============================================
  1101. // Charger start transaction
  1102. //==============================================
  1103. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1104. {
  1105. sendStartTransactionRequest(gun_index);
  1106. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1107. clientTime.StartTransaction = time((time_t*)NULL);
  1108. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1109. }
  1110. //==============================================
  1111. // Charger stop transaction
  1112. //==============================================
  1113. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1114. {
  1115. sendStopTransactionRequest(gun_index);
  1116. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1117. clientTime.StopTransaction = time((time_t*)NULL);
  1118. }
  1119. //==============================================
  1120. // Charger status report
  1121. //==============================================
  1122. /* Check Mode Change */
  1123. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1124. {
  1125. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1126. {
  1127. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1128. {
  1129. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1130. {
  1131. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1132. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1133. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1134. statusModeChage[gun_index] = TRUE;
  1135. }
  1136. }
  1137. }
  1138. for (int index = 0; index < CCS_QUANTITY; index++)
  1139. {
  1140. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1141. {
  1142. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1143. {
  1144. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1145. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1146. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1147. statusModeChage[gun_index] = TRUE;
  1148. }
  1149. }
  1150. }
  1151. for (int index = 0; index < GB_QUANTITY; index++)
  1152. {
  1153. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1154. {
  1155. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1156. {
  1157. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1158. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1159. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1160. statusModeChage[gun_index] = TRUE;
  1161. }
  1162. }
  1163. }
  1164. }
  1165. else //AC
  1166. {
  1167. for (int index = 0; index < AC_QUANTITY; index++)
  1168. {
  1169. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1170. {
  1171. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1172. {
  1173. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1174. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1175. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1176. statusModeChage[gun_index] = TRUE;
  1177. }
  1178. }
  1179. }// END OF FOR
  1180. }// END OF ELSE
  1181. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1182. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1183. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1184. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1185. {
  1186. if(SystemInitial != 0)
  1187. SystemInitial = SystemInitial -1;
  1188. sendStatusNotificationRequest(gun_index);
  1189. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1190. statusModeChage[gun_index] = FALSE;
  1191. }
  1192. //==============================================
  1193. // Meter report
  1194. //==============================================
  1195. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1196. {
  1197. //check Transaction active
  1198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1199. {
  1200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1201. {
  1202. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1203. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1204. {
  1205. meterValueSend[gun_index] =1;
  1206. }
  1207. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1208. {
  1209. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1210. if((access(filenmae,F_OK))!=-1)
  1211. {
  1212. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1213. sprintf(str,"rm -f %s",filenmae);
  1214. system(str);
  1215. }
  1216. }
  1217. }// End for CHAdeMO
  1218. for (int index = 0; index < CCS_QUANTITY; index++)
  1219. {
  1220. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1221. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1222. {
  1223. meterValueSend[gun_index] =1;
  1224. }
  1225. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1226. {
  1227. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1228. if((access(filenmae,F_OK))!=-1)
  1229. {
  1230. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1231. sprintf(str,"rm -f %s",filenmae);
  1232. system(str);
  1233. }
  1234. }
  1235. } // End for CCS
  1236. for (int index = 0; index < GB_QUANTITY; index++)
  1237. {
  1238. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1239. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1240. {
  1241. meterValueSend[gun_index] =1;
  1242. }
  1243. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1244. {
  1245. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1246. if((access(filenmae,F_OK))!=-1)
  1247. {
  1248. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1249. sprintf(str,"rm -f %s",filenmae);
  1250. system(str);
  1251. }
  1252. }
  1253. }// End for GB
  1254. }
  1255. else
  1256. {
  1257. for (int index = 0; index < AC_QUANTITY; index++)
  1258. {
  1259. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1260. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1261. {
  1262. meterValueSend[gun_index] =1;
  1263. }
  1264. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1265. {
  1266. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1267. if((access(filenmae,F_OK))!=-1)
  1268. {
  1269. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1270. sprintf(str,"rm -f %s",filenmae);
  1271. system(str);
  1272. }
  1273. }
  1274. }//End for AC
  1275. }//END OF ELSE
  1276. // sleep(1);
  1277. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1278. if(meterValueSend[gun_index] == 1)
  1279. sendMeterValuesRequest(gun_index);
  1280. }
  1281. //==============================================
  1282. // Check Connector reserved
  1283. //==============================================
  1284. //===============================
  1285. // Check if Reserve is expired
  1286. //===============================
  1287. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1288. {
  1289. double diff_t;
  1290. struct tm tp;
  1291. // current time
  1292. time_t t = time(NULL);
  1293. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1294. tp.tm_isdst = -1;
  1295. time_t utc = mktime(&tp);
  1296. diff_t = difftime(utc, t);
  1297. if(diff_t <= 0)
  1298. {
  1299. DEBUG_INFO("reserve expired !!! \n");
  1300. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1301. }
  1302. }//END OF Check if Reserve is expired
  1303. //==========================================
  1304. // csu trigger FirmwareStatusNotificationReq
  1305. //==========================================
  1306. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1307. {
  1308. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1309. }
  1310. //==========================================
  1311. // csu trigger CancelReservationConf
  1312. //==========================================
  1313. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1314. {
  1315. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1316. }
  1317. //==========================================
  1318. // csu trigger ChangeAvailabilityConf
  1319. //==========================================
  1320. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1321. {
  1322. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1323. }
  1324. //==========================================
  1325. // csu trigger UnlockConnectorConf
  1326. //==========================================
  1327. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1328. {
  1329. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1330. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1331. }
  1332. //==========================================
  1333. // csu trigger ReserveNowConf
  1334. //==========================================
  1335. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1336. {
  1337. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1338. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1339. }
  1340. //==========================================
  1341. // csu trigger DataTransferReq
  1342. //==========================================
  1343. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1344. {
  1345. sendDataTransferRequest(gun_index);
  1346. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1347. }
  1348. }
  1349. }
  1350. //==========================================
  1351. // send request routine
  1352. //==========================================
  1353. int sendAuthorizeRequest(int gun_index)
  1354. {
  1355. mtrace();
  1356. int result = FAIL;
  1357. char message[100]={0};
  1358. char guid[37];
  1359. char tempdata[65]={0};
  1360. DEBUG_INFO("sendAuthorizeRequest \n");
  1361. //Local Authorize
  1362. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))
  1363. {
  1364. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1365. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1366. {
  1367. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1368. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1369. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1370. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1371. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1372. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1373. authorizeRetryTimes = 0;
  1374. return result;
  1375. }
  1376. else
  1377. {
  1378. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1379. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1380. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1381. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1382. result = PASS;
  1383. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1384. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1385. authorizeRetryTimes = 0;
  1386. return result;
  1387. }
  1388. }
  1389. //initailize struct Authorize
  1390. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1391. //get data from shared memory
  1392. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1393. random_uuid(guid);
  1394. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1395. LWS_Send(message);
  1396. sprintf(tempdata, "Authorize,%d", gun_index);
  1397. if(hashmap_operation(0, guid, tempdata) == 1)
  1398. {
  1399. result = PASS;
  1400. DEBUG_ERROR("Authorize mapItem pass\n");
  1401. }
  1402. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1403. return result;
  1404. }
  1405. int sendBootNotificationRequest(void)
  1406. {
  1407. mtrace();
  1408. int result = FAIL;
  1409. char message[500]={0}, payload[700]={0};
  1410. char guid[37]={0};
  1411. char tempdata[65]={0};
  1412. int IsGunCharging = FALSE;
  1413. //check Transaction active
  1414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1415. {
  1416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1417. {
  1418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1419. {
  1420. IsGunCharging = TRUE;
  1421. }
  1422. }
  1423. for (int index = 0; index < CCS_QUANTITY; index++)
  1424. {
  1425. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1426. {
  1427. IsGunCharging = TRUE;
  1428. }
  1429. }
  1430. for (int index = 0; index < GB_QUANTITY; index++)
  1431. {
  1432. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1433. {
  1434. IsGunCharging = TRUE;
  1435. }
  1436. }
  1437. }
  1438. else
  1439. {
  1440. for (int index = 0; index < AC_QUANTITY; index++)
  1441. {
  1442. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1443. {
  1444. IsGunCharging = TRUE;
  1445. }
  1446. }
  1447. }
  1448. if(IsGunCharging == TRUE)
  1449. {
  1450. server_sign = TRUE;
  1451. return result;
  1452. }
  1453. // Fill BootNotification fields
  1454. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1455. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1456. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1457. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1458. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1459. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1460. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1461. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1462. ShmOCPP16Data->ChargeBoxId
  1463. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1464. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1465. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1466. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1467. ,ShmOCPP16Data->BootNotification.CpIccid
  1468. ,ShmOCPP16Data->BootNotification.CpImsi
  1469. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1470. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1471. random_uuid(guid);
  1472. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1473. LWS_Send(message);
  1474. sprintf(tempdata, "BootNotification,0");
  1475. 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*/)
  1476. {
  1477. result = PASS;
  1478. }
  1479. memset(queuedata, 0, sizeof(queuedata));
  1480. strcpy(queuedata,message);
  1481. HeartBeatCount = 0;
  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. pthread_t t; // pthread 變數
  5372. system("exec /root/logPackTools 'log' 6");
  5373. #if 0
  5374. //char buffer [128];
  5375. time (&rawtime);
  5376. //printf("%ld\n", rawtime);
  5377. timeinfo = localtime (&rawtime);
  5378. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5379. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5380. if((access(fnamePlusPath,F_OK))!=-1)
  5381. {
  5382. DEBUG_INFO("fnamePlusPath exist.\n");
  5383. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5384. }
  5385. else
  5386. {
  5387. DEBUG_INFO("fnamePlusPath not exist!\n");
  5388. }
  5389. #endif
  5390. checkUploadLog();
  5391. memset(GetDiagnosticspayloadData, 0, 300);
  5392. strcpy(GetDiagnosticspayloadData, payload);
  5393. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5394. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5395. return result;
  5396. }
  5397. void* GetDiagnosticsProcess(void* data)
  5398. {
  5399. pthread_detach(pthread_self());
  5400. mtrace();
  5401. int retriesInt=0, retryIntervalInt=0;
  5402. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5403. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5404. 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};
  5405. int port=0;
  5406. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5407. int c = 0;
  5408. char *loc;
  5409. int isSuccess = FALSE;
  5410. char ftpbuf[200]={0};
  5411. //char temp[100]={0};
  5412. char * pch;
  5413. // [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"}]
  5414. char str[300]={ 0 };
  5415. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5416. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5417. DEBUG_INFO("GetDiagnosticsProcess\n");
  5418. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5419. //****************location*******************/
  5420. c = 0;
  5421. memset(sstr ,0, sizeof(sstr) );
  5422. loc = strstr(str, "location");
  5423. while (loc[3+strlen("location")+c] != '\"')
  5424. {
  5425. sstr[c] = loc[3+strlen("location")+c];
  5426. c++;
  5427. }
  5428. sstr[c] = '\0';
  5429. strcpy(locationstr,sstr);
  5430. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5431. if(strcmp(locationstr,"")==0)
  5432. {
  5433. DEBUG_INFO("location is <Empty>!\n");
  5434. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5435. goto end;
  5436. }
  5437. //****************retries*******************/
  5438. c = 0;
  5439. loc = strstr(str, "retries");
  5440. if(loc == NULL)
  5441. {
  5442. retriesIsNULL = TRUE;
  5443. }
  5444. else
  5445. {
  5446. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5447. {
  5448. sstr[c] = loc[strlen("retries")+2+c];
  5449. c++;
  5450. }
  5451. sstr[c] = '\0';
  5452. retriesInt = atoi(sstr);
  5453. }
  5454. if(retriesIsNULL == TRUE)
  5455. {
  5456. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5457. }
  5458. //****************retryInterval*******************/
  5459. c = 0;
  5460. loc = strstr(str, "retryInterval");
  5461. if(loc == NULL)
  5462. {
  5463. retryIntervalIsNULL = TRUE;
  5464. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5465. }
  5466. else
  5467. {
  5468. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5469. {
  5470. sstr[c] = loc[strlen("retryInterval")+2+c];
  5471. c++;
  5472. }
  5473. sstr[c] = '\0';
  5474. retryIntervalInt = atoi(sstr);
  5475. }
  5476. //****************startTime*******************/
  5477. c = 0;
  5478. memset(sstr ,0, sizeof(sstr) );
  5479. loc = strstr(str, "startTime");
  5480. if(loc == NULL)
  5481. {
  5482. startTimeIsNULL = TRUE;
  5483. }
  5484. else
  5485. {
  5486. while (loc[3+strlen("startTime")+c] != '\"')
  5487. {
  5488. sstr[c] = loc[3+strlen("startTime")+c];
  5489. c++;
  5490. }
  5491. sstr[c] = '\0';
  5492. strcpy(startTimestr,sstr);
  5493. }
  5494. //****************stopTime*******************/
  5495. c = 0;
  5496. memset(sstr ,0, sizeof(sstr) );
  5497. loc = strstr(str, "stopTime");
  5498. if(loc == NULL)
  5499. {
  5500. stopTimeIsNULL = TRUE;
  5501. }
  5502. else
  5503. {
  5504. while (loc[3+strlen("stopTime")+c] != '\"')
  5505. {
  5506. sstr[c] = loc[3+strlen("stopTime")+c];
  5507. c++;
  5508. }
  5509. sstr[c] = '\0';
  5510. strcpy(stopTimestr,sstr);
  5511. }
  5512. memset(protocol, 0, sizeof(protocol));
  5513. memset(user, 0, sizeof(user) );
  5514. memset(password, 0, sizeof(password));
  5515. memset(host, 0, sizeof(host));
  5516. memset(path, 0, sizeof(path));
  5517. memset(ftppath, 0, sizeof(ftppath));
  5518. memset(host1, 0, sizeof(host1));
  5519. memset(path1, 0, sizeof(path1));
  5520. /*location: ftp://user:password@host:port/path*/
  5521. #if 0
  5522. time_t rawtime;
  5523. struct tm * timeinfo;
  5524. //char buffer [128];
  5525. time (&rawtime);
  5526. //printf("%ld\n", rawtime);
  5527. timeinfo = localtime (&rawtime);
  5528. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5529. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5530. #endif
  5531. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5532. if((access(fnamePlusPath,F_OK))!=-1)
  5533. {
  5534. DEBUG_INFO("fnamePlusPath exist.\n");
  5535. }
  5536. else
  5537. {
  5538. DEBUG_INFO("fnamePlusPath not exist!\n");
  5539. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5540. goto end;
  5541. }
  5542. pch=strchr(locationstr,'@');
  5543. if(pch==NULL)
  5544. {
  5545. sscanf(locationstr,
  5546. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5547. protocol, host, &port, path);
  5548. strcpy(user,"anonymous");
  5549. strcpy(password,"");
  5550. }
  5551. else
  5552. {
  5553. //DEBUG_INFO("pch=%s\n", pch);
  5554. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5555. protocol, user, password, host, &port, path);
  5556. }
  5557. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5558. {
  5559. DEBUG_INFO("protocol is not ftp/http ! \n");
  5560. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5561. goto end;
  5562. }
  5563. if(strncmp(locationstr,"http", 4) == 0)
  5564. {
  5565. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  5566. sprintf(ftppath,"/%s", path);
  5567. do{
  5568. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5569. sleep(retryIntervalInt);
  5570. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5571. if(!isSuccess)
  5572. {
  5573. DEBUG_INFO("Diagnostics fail.\n");
  5574. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5575. }
  5576. else
  5577. {
  5578. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5579. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5580. }
  5581. }
  5582. else
  5583. {
  5584. sscanf(host,"%[^/]%s",host1, path1);
  5585. sprintf(ftppath,"%s", path1);
  5586. int ftppathlen=strlen(ftppath);
  5587. int i=1;
  5588. char filenametemp[50];
  5589. while(i < ftppathlen)
  5590. {
  5591. int len=ftppathlen-i;
  5592. if(ftppath[len]== 47) // '/' ascll code: 47
  5593. {
  5594. DEBUG_INFO("find '/' all right\n");
  5595. break;
  5596. }
  5597. i=i+1;
  5598. }
  5599. memset(filenametemp, 0, sizeof(filenametemp));
  5600. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5601. filenametemp[i+1] = 0;
  5602. memset(ftpbuf, 0, sizeof(ftpbuf));
  5603. if(port == 0)
  5604. port = 21;
  5605. do{
  5606. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  5607. sleep(retryIntervalInt);
  5608. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5609. if(!isSuccess)
  5610. {
  5611. DEBUG_INFO("Diagnostics fail.\n");
  5612. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5613. }
  5614. else
  5615. {
  5616. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5617. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5618. }
  5619. }
  5620. end:
  5621. DiagnosticsStatusNotificationStatus = 0; //Idle
  5622. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5623. }
  5624. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5625. {
  5626. mtrace();
  5627. int result = FAIL;
  5628. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5629. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5630. {
  5631. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5632. localversion = -1;
  5633. }
  5634. else
  5635. {
  5636. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5637. OCPP_getListVerion();
  5638. }
  5639. //from db.OCPP_getListVerion
  5640. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5641. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5642. sendGetLocalListVersionConfirmation(uuid,"");
  5643. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5644. return result;
  5645. }
  5646. int handleRemoteStartRequest(char *uuid, char *payload)
  5647. {
  5648. mtrace();
  5649. int result = FAIL;
  5650. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5651. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5652. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5653. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5654. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5655. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5656. int chargingSchedulePeriodCount = 0;
  5657. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5658. int c = 0;
  5659. char *loc;
  5660. char comfirmstr[20]={0};
  5661. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5662. if(server_pending == TRUE)
  5663. {
  5664. return 0;
  5665. }
  5666. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5667. //**********connectorId****************/
  5668. c = 0;
  5669. memset(sstr ,0, sizeof(sstr) );
  5670. loc = strstr(payload, "connectorId");
  5671. if(loc == NULL)
  5672. {
  5673. connectorIdIsNULL = TRUE;
  5674. }
  5675. else
  5676. {
  5677. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5678. {
  5679. sstr[c] = loc[strlen("connectorId")+2+c];
  5680. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5681. c++;
  5682. }
  5683. sstr[c] = '\0';
  5684. connectorIdInt = atoi(sstr);
  5685. }
  5686. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  5687. {
  5688. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5689. goto end;
  5690. }
  5691. //****************idTag*******************/
  5692. c = 0;
  5693. memset(sstr ,0, sizeof(sstr) );
  5694. loc = strstr(payload, "idTag");
  5695. while (loc[3+strlen("idTag")+c] != '\"')
  5696. {
  5697. sstr[c] = loc[3+strlen("idTag")+c];
  5698. c++;
  5699. }
  5700. sstr[c] = '\0';
  5701. strcpy(idTagstr,sstr);
  5702. //****************chargingProfile*******************/
  5703. c = 0;
  5704. memset(sstr ,0, sizeof(sstr) );
  5705. loc = strstr(payload, "chargingProfile");
  5706. if(loc == NULL)
  5707. {
  5708. chargingProfileIsNULL = TRUE;
  5709. }
  5710. else
  5711. {
  5712. //****************chargingProfileId*******************/
  5713. c=0;
  5714. loc = strstr(payload, "chargingProfileId");
  5715. memset(sstr ,0, sizeof(sstr) );
  5716. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5717. {
  5718. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5719. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5720. c++;
  5721. }
  5722. sstr[c] = '\0';
  5723. chargingProfileIdInt = atoi(sstr);
  5724. //****************transactionId*******************/
  5725. loc = strstr(payload, "transactionId");
  5726. if(loc == NULL)
  5727. {
  5728. transactionIdIsNULL = TRUE;
  5729. }
  5730. else
  5731. {
  5732. c=0;
  5733. memset(sstr ,0, sizeof(sstr) );
  5734. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5735. {
  5736. sstr[c] = loc[strlen("transactionId")+2+c];
  5737. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5738. c++;
  5739. }
  5740. sstr[c] = '\0';
  5741. transactionIdInt = atoi(sstr);
  5742. }
  5743. //****************stackLevel*******************/
  5744. c=0;
  5745. loc = strstr(payload, "stackLevel");
  5746. memset(sstr ,0, sizeof(sstr) );
  5747. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5748. {
  5749. sstr[c] = loc[strlen("stackLevel")+2+c];
  5750. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5751. c++;
  5752. }
  5753. sstr[c] = '\0';
  5754. stackLevelInt = atoi(sstr);
  5755. //****************chargingProfilePurpose*******************/
  5756. c = 0;
  5757. memset(sstr ,0, sizeof(sstr) );
  5758. loc = strstr(payload, "chargingProfilePurpose");
  5759. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5760. {
  5761. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5762. c++;
  5763. }
  5764. sstr[c] = '\0';
  5765. strcpy(chargingProfilePurposestr,sstr);
  5766. //****************chargingProfileKind*******************/
  5767. c = 0;
  5768. memset(sstr ,0, sizeof(sstr) );
  5769. loc = strstr(payload, "chargingProfileKind");
  5770. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5771. {
  5772. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5773. c++;
  5774. }
  5775. sstr[c] = '\0';
  5776. strcpy(chargingProfileKindstr,sstr);
  5777. //****************recurrencyKind*******************/
  5778. loc = strstr(payload, "recurrencyKind");
  5779. if(loc == NULL)
  5780. {
  5781. recurrencyKindIsNULL = TRUE;
  5782. }
  5783. else
  5784. {
  5785. c = 0;
  5786. memset(sstr ,0, sizeof(sstr) );
  5787. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5788. {
  5789. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5790. c++;
  5791. }
  5792. sstr[c] = '\0';
  5793. strcpy(recurrencyKindstr,sstr);
  5794. }
  5795. //****************validFrom*******************/
  5796. loc = strstr(payload, "validFrom");
  5797. if(loc == NULL)
  5798. {
  5799. validFromIsNULL = TRUE;
  5800. }
  5801. else
  5802. {
  5803. c = 0;
  5804. memset(sstr ,0, sizeof(sstr) );
  5805. while (loc[3+strlen("validFrom")+c] != '\"')
  5806. {
  5807. sstr[c] = loc[3+strlen("validFrom")+c];
  5808. c++;
  5809. }
  5810. sstr[c] = '\0';
  5811. strcpy(validFromstr,sstr);
  5812. }
  5813. //****************validTo*******************/
  5814. loc = strstr(payload, "validTo");
  5815. if(loc == NULL)
  5816. {
  5817. validToIsNULL = TRUE;
  5818. }
  5819. else
  5820. {
  5821. c = 0;
  5822. memset(sstr ,0, sizeof(sstr) );
  5823. while (loc[3+strlen("validTo")+c] != '\"')
  5824. {
  5825. sstr[c] = loc[3+strlen("validTo")+c];
  5826. c++;
  5827. }
  5828. sstr[c] = '\0';
  5829. strcpy(validTostr,sstr);
  5830. }
  5831. //****************chargingSchedule*******************/
  5832. loc = strstr(payload, "chargingSchedule");
  5833. if(loc != NULL)
  5834. {
  5835. //****************duration*******************/
  5836. loc = strstr(payload, "duration");
  5837. if(loc == NULL)
  5838. {
  5839. durationIsNULL = TRUE;
  5840. }
  5841. else
  5842. {
  5843. c=0;
  5844. memset(sstr ,0, sizeof(sstr) );
  5845. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5846. {
  5847. sstr[c] = loc[strlen("duration")+2+c];
  5848. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5849. c++;
  5850. }
  5851. sstr[c] = '\0';
  5852. durationInt = atoi(sstr);
  5853. }
  5854. //****************startSchedule******************/
  5855. loc = strstr(payload, "startSchedule");
  5856. if(loc == NULL)
  5857. {
  5858. startScheduleIsNULL = TRUE;
  5859. }
  5860. else
  5861. {
  5862. c = 0;
  5863. memset(sstr ,0, sizeof(sstr) );
  5864. while (loc[3+strlen("startSchedule")+c] != '\"')
  5865. {
  5866. sstr[c] = loc[3+strlen("startSchedule")+c];
  5867. c++;
  5868. }
  5869. sstr[c] = '\0';
  5870. strcpy(startSchedulestr,sstr);
  5871. }
  5872. //****************chargingRateUnit*******************/
  5873. c = 0;
  5874. memset(sstr ,0, sizeof(sstr) );
  5875. loc = strstr(payload, "chargingRateUnit");
  5876. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5877. {
  5878. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5879. c++;
  5880. }
  5881. sstr[c] = '\0';
  5882. strcpy(chargingRateUnitstr,sstr);
  5883. //****************minChargingRate*******************/
  5884. loc = strstr(payload, "minChargingRate");
  5885. if(loc == NULL)
  5886. {
  5887. minChargingRateIsNULL = TRUE;
  5888. }
  5889. else
  5890. {
  5891. c=0;
  5892. memset(sstr ,0, sizeof(sstr) );
  5893. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5894. {
  5895. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5896. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5897. c++;
  5898. }
  5899. sstr[c] = '\0';
  5900. minChargingRateflaot = atof(sstr);
  5901. }
  5902. //****************chargingSchedulePeriod count*******************/
  5903. int what_len = strlen("startPeriod");
  5904. char *where = payload;
  5905. while ((where = strstr(where, "startPeriod"))) {
  5906. where += what_len;
  5907. chargingSchedulePeriodCount++;
  5908. }
  5909. where = payload;
  5910. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5911. {
  5912. //****************startPeriod*******************/
  5913. c=0;
  5914. loc = strstr(where, "startPeriod");
  5915. memset(sstr ,0, sizeof(sstr) );
  5916. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5917. {
  5918. sstr[c] = loc[strlen("startPeriod")+2+c];
  5919. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5920. c++;
  5921. }
  5922. sstr[c] = '\0';
  5923. startPeriodInt[periodNums] = atoi(sstr);
  5924. //****************limit*******************/
  5925. c=0;
  5926. loc = strstr(where, "limit");
  5927. memset(sstr ,0, sizeof(sstr) );
  5928. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5929. {
  5930. sstr[c] = loc[strlen("limit")+2+c];
  5931. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5932. c++;
  5933. }
  5934. sstr[c] = '\0';
  5935. limitflaot[periodNums] = atof(sstr);
  5936. //****************numberPhases*******************/
  5937. loc = strstr(where, "numberPhases");
  5938. if(loc == NULL)
  5939. {
  5940. numberPhasesIsNULL = TRUE;
  5941. }
  5942. else
  5943. {
  5944. c=0;
  5945. memset(sstr ,0, sizeof(sstr) );
  5946. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  5947. {
  5948. sstr[c] = loc[strlen("numberPhases")+2+c];
  5949. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5950. c++;
  5951. }
  5952. sstr[c] = '\0';
  5953. numberPhasesInt[periodNums] = atoi(sstr);
  5954. }
  5955. where = loc;
  5956. }
  5957. }
  5958. }
  5959. /*
  5960. enum _SYSTEM_STATUS
  5961. {
  5962. S_BOOTING = 0,
  5963. S_IDLE, = 1
  5964. S_AUTHORIZING, =2
  5965. S_REASSIGN_CHECK, =3
  5966. S_REASSIGN, =4
  5967. S_PRECHARGE, =5
  5968. S_PREPARING_FOR_EV, =6
  5969. S_PREPARING_FOR_EVSE, =7
  5970. S_CHARGING, =8
  5971. S_TERMINATING, =9
  5972. S_COMPLETE, =10
  5973. S_ALARM, =11
  5974. S_FAULT =12
  5975. }
  5976. */
  5977. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  5978. {
  5979. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  5980. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  5981. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  5982. //check Transaction active
  5983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5984. {
  5985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5986. {
  5987. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  5988. {
  5989. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  5990. {
  5991. //Reserved
  5992. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  5993. }
  5994. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  5995. {
  5996. //Reserved
  5997. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  5998. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5999. goto end;
  6000. }
  6001. else
  6002. {
  6003. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6004. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6005. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6006. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6007. {
  6008. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6009. goto end;
  6010. }
  6011. }//END FOR ELSE
  6012. }
  6013. }// END FOR CHAdeMO_QUANTITY
  6014. for (int index = 0; index < CCS_QUANTITY; index++)
  6015. {
  6016. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6017. {
  6018. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6019. {
  6020. //Reserved
  6021. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6022. }
  6023. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6024. {
  6025. //Reserved
  6026. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6027. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6028. goto end;
  6029. }
  6030. else
  6031. {
  6032. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6033. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6034. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6035. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6036. {
  6037. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6038. goto end;
  6039. }
  6040. }// END FOR ELSE
  6041. }
  6042. }// END FOR CCS_QUANTITY
  6043. for (int index = 0; index < GB_QUANTITY; index++)
  6044. {
  6045. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6046. {
  6047. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6048. {
  6049. //Reserved
  6050. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6051. }
  6052. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6053. {
  6054. //Reserved
  6055. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6056. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6057. goto end;
  6058. }
  6059. else
  6060. {
  6061. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6062. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6063. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6064. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6065. {
  6066. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6067. goto end;
  6068. }
  6069. }// END FOR ELSE
  6070. }
  6071. } // END FOR GB_QUANTITY
  6072. }
  6073. else
  6074. {
  6075. for (int index = 0; index < AC_QUANTITY; index++)
  6076. {
  6077. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6078. {
  6079. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6080. {
  6081. //Reserved
  6082. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6083. }
  6084. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6085. {
  6086. //Reserved
  6087. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6088. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6089. goto end;
  6090. }
  6091. else
  6092. {
  6093. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6094. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6095. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6096. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6097. {
  6098. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6099. goto end;
  6100. }
  6101. }//END FOR ELSE
  6102. }
  6103. }// END FOR AC_QUANTITY
  6104. }
  6105. if(chargingProfileIsNULL == FALSE)
  6106. {
  6107. //ChargingProfile
  6108. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6109. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6110. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6111. if(recurrencyKindIsNULL == FALSE) //OPTION
  6112. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6113. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6114. if(transactionIdIsNULL == FALSE) // OPTION
  6115. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6116. if(validFromIsNULL == FALSE) // OPTION
  6117. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6118. if(validToIsNULL == FALSE) //OPTION
  6119. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6120. //ChargingSchedule
  6121. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6122. if(durationIsNULL == FALSE) //OPTION
  6123. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6124. if(minChargingRateIsNULL == FALSE) //OPTION
  6125. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6126. if(startScheduleIsNULL == FALSE) //OPTION
  6127. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6128. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6129. {
  6130. //ChargingSchedulePeriod
  6131. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6132. if(numberPhasesIsNULL == FALSE)
  6133. {
  6134. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6135. }
  6136. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6137. }
  6138. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6139. {
  6140. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6141. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6142. //memset idTag
  6143. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6144. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6145. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6146. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6147. }
  6148. else
  6149. {
  6150. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6151. }
  6152. }
  6153. else
  6154. {
  6155. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6156. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6157. //memset idTag
  6158. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6159. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6160. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6161. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6162. }
  6163. }
  6164. else
  6165. {
  6166. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6167. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6168. }
  6169. end:
  6170. if(connectorIdIsNULL == FALSE)
  6171. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6172. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6173. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6174. //OCPP send RemoteStartConfirmation by first.
  6175. sendRemoteStartConfirmation(uuid, comfirmstr);
  6176. return result;
  6177. }
  6178. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6179. {
  6180. mtrace();
  6181. int result = FAIL;
  6182. int match = FALSE;
  6183. int GunNO = 0;
  6184. int transactionIdInt=0;
  6185. int transactionIdIsNULL= FALSE;
  6186. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6187. int c = 0;
  6188. char *loc;
  6189. char comfirmstr[20];
  6190. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6191. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6192. if(server_pending == TRUE)
  6193. {
  6194. return 0;
  6195. }
  6196. c=0;
  6197. loc = strstr(payload, "transactionId");
  6198. if(loc == NULL)
  6199. {
  6200. transactionIdIsNULL= TRUE;
  6201. }
  6202. else
  6203. {
  6204. memset(sstr ,0, sizeof(sstr) );
  6205. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6206. {
  6207. sstr[c] = loc[strlen("transactionId")+2+c];
  6208. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6209. c++;
  6210. }
  6211. sstr[c] = '\0';
  6212. transactionIdInt = atoi(sstr);
  6213. }
  6214. if(transactionIdIsNULL == FALSE)
  6215. {
  6216. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6217. {
  6218. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6219. {
  6220. //check Transaction active
  6221. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6222. {
  6223. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6224. {
  6225. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6226. {
  6227. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6228. {
  6229. match = TRUE;
  6230. GunNO = gun_index;
  6231. }
  6232. }
  6233. }// END FOR CHAdeMO_QUANTITY
  6234. for (int index = 0; index < CCS_QUANTITY; index++)
  6235. {
  6236. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6237. {
  6238. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6239. {
  6240. match = TRUE;
  6241. GunNO = gun_index;
  6242. }
  6243. }
  6244. }// END FOR CCS_QUANTITY
  6245. for (int index = 0; index < GB_QUANTITY; index++)
  6246. {
  6247. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6248. {
  6249. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6250. {
  6251. match = TRUE;
  6252. GunNO = gun_index;
  6253. }
  6254. }
  6255. }// END FOR GB_QUANTITY
  6256. }
  6257. else
  6258. {
  6259. for (int index = 0; index < AC_QUANTITY; index++)
  6260. {
  6261. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6262. {
  6263. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6264. {
  6265. match = TRUE;
  6266. GunNO = gun_index;
  6267. }
  6268. }
  6269. }// END FOR CHAdeMO_QUANTITY
  6270. }// END FOR AC ELSE
  6271. }// CHECK IF ResponseTransactionId == transactionIdInt
  6272. }//END FOR
  6273. if( match == TRUE)
  6274. {
  6275. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6276. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6277. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6278. }
  6279. else
  6280. {
  6281. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6282. }
  6283. }
  6284. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6285. return result;
  6286. }
  6287. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6288. {
  6289. mtrace();
  6290. int result = FAIL;
  6291. int connectorIdInt=0, reservationIdInt=0;
  6292. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6293. char comfirmstr[20]={0};
  6294. char sstr[180]={ 0 };
  6295. int c = 0;
  6296. char *loc;
  6297. //char *ptr;
  6298. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6299. //***(1)connectorId ****/
  6300. c=0;
  6301. loc = strstr(payload, "connectorId");
  6302. memset(sstr ,0, sizeof(sstr) );
  6303. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6304. {
  6305. sstr[c] = loc[strlen("connectorId")+2+c];
  6306. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6307. c++;
  6308. }
  6309. sstr[c] = '\0';
  6310. connectorIdInt = atoi(sstr);
  6311. //***(2)expiryDate ****/
  6312. loc = strstr(payload, "expiryDate");
  6313. memset(sstr ,0, sizeof(sstr) );
  6314. c = 0;
  6315. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6316. {
  6317. sstr[c] = loc[3+strlen("expiryDate")+c];
  6318. c++;
  6319. }
  6320. sstr[c] = '\0';
  6321. strcpy(expiryDatestr, sstr);
  6322. //***(3)idTag ****/
  6323. loc = strstr(payload, "idTag");
  6324. memset(sstr ,0, sizeof(sstr) );
  6325. c = 0;
  6326. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6327. {
  6328. sstr[c] = loc[3+strlen("idTag")+c];
  6329. c++;
  6330. }
  6331. sstr[c] = '\0';
  6332. strcpy(idTagstr, sstr);
  6333. //***(4)parentIdTag ****/
  6334. loc = strstr(payload, "parentIdTag");
  6335. memset(sstr ,0, sizeof(sstr) );
  6336. c = 0;
  6337. if(loc == NULL)
  6338. {
  6339. strcpy(parentIdTagstr, "");
  6340. }
  6341. else
  6342. {
  6343. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6344. {
  6345. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6346. c++;
  6347. }
  6348. sstr[c] = '\0';
  6349. strcpy(parentIdTagstr, sstr);
  6350. }
  6351. //***(5)reservationId ****/
  6352. c=0;
  6353. loc = strstr(payload, "reservationId");
  6354. memset(sstr ,0, sizeof(sstr) );
  6355. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6356. {
  6357. sstr[c] = loc[strlen("reservationId")+2+c];
  6358. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6359. c++;
  6360. }
  6361. sstr[c] = '\0';
  6362. reservationIdInt = atoi(sstr);
  6363. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6364. /*
  6365. enum SYSTEM_STATUS
  6366. {
  6367. SYS_MODE_BOOTING = 0,
  6368. SYS_MODE_IDLE = 1,
  6369. SYS_MODE_AUTHORIZING = 2,
  6370. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6371. SYS_MODE_REASSIGN = 4,
  6372. SYS_MODE_PREPARING = 5,
  6373. SYS_MODE_PREPARE_FOR_EV = 6,
  6374. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6375. SYS_MODE_CHARGING = 8,
  6376. SYS_MODE_TERMINATING = 9,
  6377. SYS_MODE_COMPLETE = 10,
  6378. SYS_MODE_ALARM = 11,
  6379. SYS_MODE_FAULT = 12,
  6380. SYS_MODE_RESERVATION = 13,
  6381. SYS_MODE_BOOKING = 14,
  6382. SYS_MODE_MAINTAIN = 15,
  6383. SYS_MODE_DEBUG = 16,
  6384. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6385. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6386. SYS_MODE_UPDATE = 19
  6387. };
  6388. */
  6389. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6390. {
  6391. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6392. goto end;
  6393. }
  6394. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6395. {
  6396. //check Transaction active
  6397. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6398. {
  6399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6400. {
  6401. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6402. {
  6403. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6404. {
  6405. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6406. {
  6407. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6408. {
  6409. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6410. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6411. }
  6412. 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'))
  6413. {
  6414. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6415. }
  6416. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6417. {
  6418. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6419. }
  6420. else
  6421. {
  6422. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6423. }
  6424. }
  6425. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6426. {
  6427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6428. }
  6429. }
  6430. else
  6431. {
  6432. //replace reservation
  6433. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6434. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6435. }
  6436. }
  6437. } // END FOR CHAdeMO_QUANTITY
  6438. for (int index = 0; index < CCS_QUANTITY; index++)
  6439. {
  6440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6441. {
  6442. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6443. {
  6444. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6445. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6446. {
  6447. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6448. {
  6449. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6450. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6451. }
  6452. 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'))
  6453. {
  6454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6455. }
  6456. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6457. {
  6458. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6459. }
  6460. else
  6461. {
  6462. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6463. }
  6464. }
  6465. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6466. {
  6467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6468. }
  6469. }
  6470. else
  6471. {
  6472. //replace reservation
  6473. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6475. }
  6476. }
  6477. } // END FOR CCS_QUANTITY
  6478. for (int index = 0; index < GB_QUANTITY; index++)
  6479. {
  6480. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6481. {
  6482. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6483. {
  6484. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6485. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6486. {
  6487. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6488. {
  6489. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6491. }
  6492. 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'))
  6493. {
  6494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6495. }
  6496. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6497. {
  6498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6499. }
  6500. else
  6501. {
  6502. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6503. }
  6504. }
  6505. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6506. {
  6507. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6508. }
  6509. }
  6510. else
  6511. {
  6512. //replace reservation
  6513. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6514. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6515. }
  6516. }
  6517. }// END FOR GB_QUANTITY
  6518. }
  6519. else
  6520. {
  6521. for (int index = 0; index < AC_QUANTITY; index++)
  6522. {
  6523. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6524. {
  6525. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6526. {
  6527. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6528. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6529. {
  6530. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6531. {
  6532. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6533. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6534. }
  6535. 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'))
  6536. {
  6537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6538. }
  6539. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6540. {
  6541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6542. }
  6543. else
  6544. {
  6545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6546. }
  6547. }
  6548. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6549. {
  6550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6551. }
  6552. }
  6553. else
  6554. {
  6555. //replace reservation
  6556. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6557. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6558. }
  6559. }
  6560. } // END FOR AC_QUANTITY
  6561. }//END FOR AC ELSE
  6562. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6563. }
  6564. else if(connectorIdInt == 0)
  6565. {
  6566. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6567. {
  6568. //check Transaction active
  6569. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6570. {
  6571. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6572. {
  6573. 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'))
  6574. {
  6575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6576. goto end;
  6577. }
  6578. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6579. {
  6580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6581. goto end;
  6582. }
  6583. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6584. {
  6585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6586. goto end;
  6587. }
  6588. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6589. {
  6590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6591. goto end;
  6592. }
  6593. }
  6594. }// END FOR CHAdeMO_QUANTITY
  6595. for (int index = 0; index < CCS_QUANTITY; index++)
  6596. {
  6597. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6598. {
  6599. 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'))
  6600. {
  6601. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6602. }
  6603. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6604. {
  6605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6606. }
  6607. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6608. {
  6609. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6610. }
  6611. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6612. {
  6613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6614. }
  6615. }
  6616. } // END FOR CCS_QUANTITY
  6617. for (int index = 0; index < GB_QUANTITY; index++)
  6618. {
  6619. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6620. {
  6621. 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'))
  6622. {
  6623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6624. }
  6625. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6626. {
  6627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6628. }
  6629. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6630. {
  6631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6632. }
  6633. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6634. {
  6635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6636. }
  6637. }
  6638. } // END FOR GB_QUANTITY
  6639. }
  6640. else
  6641. {
  6642. for (int index = 0; index < AC_QUANTITY; index++)
  6643. {
  6644. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6645. {
  6646. 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'))
  6647. {
  6648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6649. goto end;
  6650. }
  6651. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6652. {
  6653. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6654. goto end;
  6655. }
  6656. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6657. {
  6658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6659. goto end;
  6660. }
  6661. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6662. {
  6663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6664. goto end;
  6665. }
  6666. }
  6667. }// END FOR AC_QUANTITY
  6668. }
  6669. //The connectorId is 0
  6670. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6672. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6673. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6674. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6675. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6676. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6677. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6678. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6679. result = TRUE;
  6680. return result;
  6681. }
  6682. else
  6683. {
  6684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6685. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6686. }
  6687. if(strcmp(comfirmstr,"Accepted") == 0)
  6688. {
  6689. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6690. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6691. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6692. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6693. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6694. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6695. result = TRUE;
  6696. return result;
  6697. }
  6698. end:
  6699. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6700. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6701. return result;
  6702. }
  6703. int handleResetRequest(char *uuid, char *payload)
  6704. {
  6705. mtrace();
  6706. int result = FAIL;
  6707. char sstr[10]={0};
  6708. char typestr[10]={0};
  6709. char comfirmstr[20]={0};
  6710. int c = 0;
  6711. char *loc;
  6712. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6713. DEBUG_INFO("handleResetRequest ...\n");
  6714. loc = strstr(payload, "type");
  6715. memset(sstr ,0, sizeof(sstr) );
  6716. c = 0;
  6717. while (loc[3+strlen("type")+c] != '\"')
  6718. {
  6719. sstr[c] = loc[3+strlen("type")+c];
  6720. c++;
  6721. }
  6722. sstr[c] = '\0';
  6723. strcpy(typestr,sstr);
  6724. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6725. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6726. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6727. {
  6728. //check Transaction active
  6729. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6730. {
  6731. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6732. {
  6733. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6734. {
  6735. //0: unplug, 1: Plug-in
  6736. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6737. }
  6738. }
  6739. for (int index = 0; index < CCS_QUANTITY; index++)
  6740. {
  6741. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6742. {
  6743. //0: unplug, 1: Plug-in
  6744. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6745. }
  6746. }
  6747. for (int index = 0; index < GB_QUANTITY; index++)
  6748. {
  6749. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6750. {
  6751. //0: unplug, 1: Plug-in
  6752. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6753. }
  6754. }
  6755. }
  6756. else
  6757. {
  6758. for (int index = 0; index < AC_QUANTITY; index++)
  6759. {
  6760. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6761. {
  6762. //0: unplug, 1: Plug-in
  6763. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6764. }
  6765. }
  6766. }// END FOR AC ELSE
  6767. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6768. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6769. result = TRUE;
  6770. return result;
  6771. }
  6772. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6773. {
  6774. //check Transaction active
  6775. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6776. {
  6777. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6778. {
  6779. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6780. {
  6781. //0: unplug, 1: Plug-in
  6782. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6783. }
  6784. }
  6785. for (int index = 0; index < CCS_QUANTITY; index++)
  6786. {
  6787. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6788. {
  6789. //0: unplug, 1: Plug-in
  6790. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6791. }
  6792. }
  6793. for (int index = 0; index < GB_QUANTITY; index++)
  6794. {
  6795. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6796. {
  6797. //0: unplug, 1: Plug-in
  6798. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6799. }
  6800. }
  6801. }
  6802. else
  6803. {
  6804. for (int index = 0; index < AC_QUANTITY; index++)
  6805. {
  6806. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6807. {
  6808. //0: unplug, 1: Plug-in
  6809. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6810. }
  6811. }
  6812. }// END FOR AC ELSE
  6813. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6814. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6815. result = TRUE;
  6816. return result;
  6817. }
  6818. else
  6819. {
  6820. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6821. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6822. goto errorend;
  6823. }
  6824. errorend:
  6825. sendResetConfirmation(uuid, comfirmstr);
  6826. return result;
  6827. }
  6828. int handleSendLocalListRequest(char *uuid, char *payload)
  6829. {
  6830. mtrace();
  6831. int result = FAIL;
  6832. int listVersionInt;
  6833. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6834. char listsearch[]="listVersion";
  6835. char updateTypesearch[]="updateType";
  6836. char localAuthorizationListsearch[]="localAuthorizationList";
  6837. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6838. char CardList[500][160]={0};
  6839. char updateTypestr[15]={0};
  6840. char idTagstr[20]={0};
  6841. char parentIdTag[20]={0};
  6842. char expiryDate[30]={0};
  6843. char idTagstatus[16]={0};
  6844. int c = 0;
  6845. int i = 0;
  6846. char *delim1 = "}";
  6847. char * pch;
  6848. char *loc;
  6849. //char *ptr;
  6850. char comfirmstr[20];
  6851. //int n_localAuthorizations = 0;
  6852. int checkState_Faulted = FALSE;
  6853. DEBUG_INFO("handleSendLocalListRequest\n");
  6854. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6855. {
  6856. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6857. goto end;
  6858. }
  6859. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6860. {
  6861. //check Charge Point state
  6862. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6863. {
  6864. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6865. {
  6866. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6867. }
  6868. }
  6869. for (int index = 0; index < CCS_QUANTITY; index++)
  6870. {
  6871. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6872. {
  6873. checkState_Faulted = TRUE; //OCPP Status
  6874. }
  6875. }
  6876. for (int index = 0; index < GB_QUANTITY; index++)
  6877. {
  6878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6879. {
  6880. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6881. }
  6882. }
  6883. }
  6884. else
  6885. {
  6886. //check Charge Point state
  6887. for (int index = 0; index < AC_QUANTITY; index++)
  6888. {
  6889. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6890. {
  6891. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6892. }
  6893. }
  6894. }// END FOR AC ELSE
  6895. if(checkState_Faulted == TRUE)
  6896. {
  6897. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6898. goto end;
  6899. }
  6900. //listVersion
  6901. c = 0;
  6902. loc = strstr(payload, listsearch);
  6903. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  6904. {
  6905. sstr[c] = loc[strlen("listVersion")+2+c];
  6906. c++;
  6907. }
  6908. sstr[c] = '\0';
  6909. listVersionInt = atoi(sstr);
  6910. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6911. //updateType
  6912. loc = strstr(payload, updateTypesearch);
  6913. c = 0;
  6914. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6915. {
  6916. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6917. c++;
  6918. }
  6919. sstr[c] = '\0';
  6920. strcpy(updateTypestr, sstr);
  6921. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6922. //localAuthorizationList
  6923. memset(sstr ,0, sizeof(sstr) );
  6924. loc = strstr(payload, localAuthorizationListsearch);
  6925. if(loc != NULL) // localAuthorizationList is not NULL
  6926. {
  6927. //Check UpdateType
  6928. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6929. {
  6930. //Local list full update
  6931. printf("Local list full update.\n");
  6932. OCPP_cleanLocalList();
  6933. }
  6934. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6935. {
  6936. //Local list different update
  6937. printf("Local list different update.\n");
  6938. OCPP_getListVerion();
  6939. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6940. {
  6941. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6942. goto end;
  6943. }
  6944. }
  6945. else
  6946. {
  6947. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6948. goto end;
  6949. }
  6950. c = 0;
  6951. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6952. {
  6953. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6954. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6955. c++;
  6956. }
  6957. sstr[c] = '\0';
  6958. //DEBUG_INFO("sstr=%s\n", sstr);
  6959. //parsing strings to words
  6960. i = 0;
  6961. pch = strtok(sstr,delim1);
  6962. while (pch != NULL)
  6963. {
  6964. strcpy(CardList[i], pch);
  6965. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  6966. pch = strtok (NULL, delim1);
  6967. i = i + 1;
  6968. }
  6969. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  6970. //local Authorizations List Numbers
  6971. //n_localAuthorizations = i;
  6972. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6973. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  6974. c= 0;
  6975. while(c < i)
  6976. {
  6977. //Search "IdToken"
  6978. memset(sstr ,0, sizeof(sstr) );
  6979. loc = strstr(CardList[c], "idTag");
  6980. int j = 0;
  6981. while (loc[3+strlen("idTag")+j] != '\"')
  6982. {
  6983. sstr[j] = loc[3+strlen("idTag")+j];
  6984. //printf("i=%d sstr=%c\n",c, sstr[j]);
  6985. j++;
  6986. }
  6987. sstr[j] = '\0';
  6988. strcpy(idTagstr, sstr);
  6989. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  6990. //Search "expiryDate"
  6991. memset(sstr ,0, sizeof(sstr) );
  6992. loc = strstr(CardList[c], "expiryDate");
  6993. j = 0;
  6994. if(loc != NULL)
  6995. {
  6996. while (loc[3+strlen("expiryDate")+j] != '\"')
  6997. {
  6998. sstr[j] = loc[3+strlen("expiryDate")+j];
  6999. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7000. j++;
  7001. }
  7002. sstr[j] = '\0';
  7003. strcpy(expiryDate, sstr);
  7004. }
  7005. else
  7006. {
  7007. strcpy(expiryDate, "");
  7008. }
  7009. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7010. //Search "parentIdTag"
  7011. memset(sstr ,0, sizeof(sstr) );
  7012. loc = strstr(CardList[c], "parentIdTag");
  7013. j = 0;
  7014. if(loc != NULL)
  7015. {
  7016. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7017. {
  7018. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7019. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7020. j++;
  7021. }
  7022. sstr[j] = '\0';
  7023. strcpy(parentIdTag, sstr);
  7024. }
  7025. else
  7026. {
  7027. strcpy(parentIdTag, "");
  7028. }
  7029. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7030. //Search "status"
  7031. memset(sstr ,0, sizeof(sstr) );
  7032. loc = strstr(CardList[c], "status");
  7033. j = 0;
  7034. while (loc[3+strlen("status")+j] != '\"')
  7035. {
  7036. sstr[j] = loc[3+strlen("status")+j];
  7037. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7038. j++;
  7039. }
  7040. sstr[j] = '\0';
  7041. strcpy(idTagstatus, sstr);
  7042. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7043. OCPP_getIdTag(idTagstr);
  7044. //OCPP_getIdTag("test"); For Test
  7045. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7046. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7047. {
  7048. //Local list full update
  7049. DEBUG_INFO("Local list full update.\n");
  7050. // update list
  7051. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7052. OCPP_get_TableAuthlocalAllData();
  7053. }
  7054. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7055. {
  7056. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7057. {
  7058. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7059. }
  7060. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7061. {
  7062. OCPP_deleteIdTag(idTagstr);
  7063. }
  7064. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7065. {
  7066. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7067. }
  7068. }
  7069. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7070. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7071. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7072. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7073. c++;
  7074. }
  7075. }
  7076. else
  7077. {
  7078. //Check UpdateType
  7079. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7080. {
  7081. //Local list full update
  7082. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7083. OCPP_cleanLocalList();
  7084. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7085. goto end;
  7086. }
  7087. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7088. {
  7089. //Local list different update
  7090. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7091. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7092. goto end;
  7093. }
  7094. }
  7095. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7096. end:
  7097. sendSendLocalListConfirmation(uuid, comfirmstr);
  7098. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7099. return result;
  7100. }
  7101. #define MAX 200
  7102. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7103. {
  7104. mtrace();
  7105. int result = FAIL;
  7106. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7107. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7108. char chargingProfilePurposeStr[30]={0};
  7109. char chargingProfileKindStr[16]={0};
  7110. char recurrencyKindStr[10]={0};
  7111. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7112. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7113. int chargingSchedulePeriodCount = 0;
  7114. //int updateflag = FALSE;
  7115. char comfirmstr[20]={0};
  7116. int meet= FALSE;
  7117. char sstr[10]={0};
  7118. int c = 0;
  7119. char *loc;
  7120. FILE *fptr1;//, *fptr2;
  7121. //int lno=0;//, linectr = 0;
  7122. //int modifyflag = FALSE;
  7123. char filename[MAX]={0};
  7124. char tempfile[] = "../Storage/OCPP/temp.json";
  7125. //int resultRename=0;
  7126. char rmFileCmd[50]={0};
  7127. char tempchargingProfilePurposeStr[30]={0};
  7128. //[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}}}]
  7129. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7130. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7131. //*********************connectorId***************************/
  7132. loc = strstr(payload, "connectorId");
  7133. c = 0;
  7134. memset(sstr ,0, sizeof(sstr) );
  7135. while (loc[strlen("connectorId")+2+c] != ',')
  7136. {
  7137. sstr[c] = loc[strlen("connectorId")+2+c];
  7138. c++;
  7139. }
  7140. sstr[c] = '\0';
  7141. connectorIdInt = atoi(sstr);
  7142. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7143. {
  7144. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7145. }
  7146. else
  7147. {
  7148. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7149. }
  7150. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7151. //*********************chargingProfileId***************************/
  7152. loc = strstr(payload, "chargingProfileId");
  7153. c = 0;
  7154. memset(sstr ,0, sizeof(sstr) );
  7155. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7156. {
  7157. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7158. c++;
  7159. }
  7160. sstr[c] = '\0';
  7161. chargingProfileIdInt = atoi(sstr);
  7162. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7163. {
  7164. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7165. }
  7166. else
  7167. {
  7168. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7169. }
  7170. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7171. //*********************transactionId***************************/
  7172. loc = strstr(payload, "transactionId");
  7173. if(loc != NULL)
  7174. {
  7175. c = 0;
  7176. memset(sstr ,0, sizeof(sstr) );
  7177. while (loc[strlen("transactionId")+2+c] != ',')
  7178. {
  7179. sstr[c] = loc[strlen("transactionId")+2+c];
  7180. c++;
  7181. }
  7182. sstr[c] = '\0';
  7183. transactionIdInt = atoi(sstr);
  7184. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7185. {
  7186. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7187. }
  7188. else
  7189. {
  7190. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7191. }
  7192. }
  7193. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7194. //*********************stackLevel***************************/
  7195. loc = strstr(payload, "stackLevel");
  7196. c = 0;
  7197. memset(sstr ,0, sizeof(sstr) );
  7198. while (loc[strlen("stackLevel")+2+c] != ',')
  7199. {
  7200. sstr[c] = loc[strlen("stackLevel")+2+c];
  7201. c++;
  7202. }
  7203. sstr[c] = '\0';
  7204. stackLevelInt = atoi(sstr);
  7205. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7206. {
  7207. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7208. }
  7209. else
  7210. {
  7211. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7212. }
  7213. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7214. //*********************chargingProfilePurpose***************************/
  7215. loc = strstr(payload, "chargingProfilePurpose");
  7216. c = 0;
  7217. memset(sstr ,0, sizeof(sstr) );
  7218. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7219. {
  7220. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7221. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7222. c++;
  7223. }
  7224. sstr[c] = '\0';
  7225. strcpy(chargingProfilePurposeStr,sstr);
  7226. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7227. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7228. {
  7229. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7230. }
  7231. else
  7232. {
  7233. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7234. }
  7235. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7236. //*********************chargingProfileKind***************************/
  7237. loc = strstr(payload, "chargingProfileKind");
  7238. c = 0;
  7239. memset(sstr ,0, sizeof(sstr) );
  7240. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7241. {
  7242. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7243. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7244. c++;
  7245. }
  7246. sstr[c] = '\0';
  7247. strcpy(chargingProfileKindStr,sstr);
  7248. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7249. {
  7250. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7251. }
  7252. else
  7253. {
  7254. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7255. }
  7256. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7257. //*********************recurrencyKind***************************/
  7258. loc = strstr(payload, "recurrencyKind");
  7259. if(loc != NULL)
  7260. {
  7261. c = 0;
  7262. memset(sstr ,0, sizeof(sstr) );
  7263. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7264. {
  7265. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7266. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7267. c++;
  7268. }
  7269. sstr[c] = '\0';
  7270. strcpy(recurrencyKindStr,sstr);
  7271. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7272. {
  7273. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7274. }
  7275. else
  7276. {
  7277. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7278. }
  7279. }
  7280. else
  7281. {
  7282. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7283. {
  7284. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7285. }
  7286. else
  7287. {
  7288. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7289. }
  7290. }
  7291. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7292. //*********************validFrom***************************/
  7293. loc = strstr(payload, "validFrom");
  7294. if(loc != NULL)
  7295. {
  7296. c = 0;
  7297. memset(sstr ,0, sizeof(sstr) );
  7298. while (loc[3+strlen("validFrom")+c] != '\"')
  7299. {
  7300. sstr[c] = loc[3+strlen("validFrom")+c];
  7301. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7302. c++;
  7303. }
  7304. sstr[c] = '\0';
  7305. strcpy(validFromStr,sstr);
  7306. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7307. {
  7308. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7309. }
  7310. else
  7311. {
  7312. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7313. }
  7314. }
  7315. else
  7316. {
  7317. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7318. {
  7319. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7320. }
  7321. else
  7322. {
  7323. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7324. }
  7325. }
  7326. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7327. //*********************validTo***************************/
  7328. loc = strstr(payload, "validTo");
  7329. if(loc != NULL)
  7330. {
  7331. c = 0;
  7332. memset(sstr ,0, sizeof(sstr) );
  7333. while (loc[3+strlen("validTo")+c] != '\"')
  7334. {
  7335. sstr[c] = loc[3+strlen("validTo")+c];
  7336. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7337. c++;
  7338. }
  7339. sstr[c] = '\0';
  7340. strcpy(validToStr,sstr);
  7341. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7342. {
  7343. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7344. }
  7345. else
  7346. {
  7347. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7348. }
  7349. }
  7350. else
  7351. {
  7352. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7353. {
  7354. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7355. }
  7356. else
  7357. {
  7358. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7359. }
  7360. }
  7361. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7362. //*********************duration***************************/
  7363. loc = strstr(payload, "duration");
  7364. if(loc != NULL)
  7365. {
  7366. c = 0;
  7367. memset(sstr ,0, sizeof(sstr) );
  7368. while (loc[strlen("duration")+2+c] != ',')
  7369. {
  7370. sstr[c] = loc[strlen("duration")+2+c];
  7371. c++;
  7372. }
  7373. sstr[c] = '\0';
  7374. durationInt = atoi(sstr);
  7375. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7376. {
  7377. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7378. }
  7379. else
  7380. {
  7381. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7382. }
  7383. }
  7384. else
  7385. {
  7386. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7387. {
  7388. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7389. }
  7390. else
  7391. {
  7392. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7393. }
  7394. }
  7395. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7396. //*********************startSchedule***************************/
  7397. loc = strstr(payload, "startSchedule");
  7398. if(loc != NULL)
  7399. {
  7400. c = 0;
  7401. memset(sstr ,0, sizeof(sstr) );
  7402. while (loc[3+strlen("startSchedule")+c] != '\"')
  7403. {
  7404. sstr[c] = loc[3+strlen("startSchedule")+c];
  7405. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7406. c++;
  7407. }
  7408. sstr[c] = '\0';
  7409. strcpy(startScheduleStr,sstr);
  7410. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7411. {
  7412. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7413. }
  7414. else
  7415. {
  7416. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7417. }
  7418. }
  7419. else
  7420. {
  7421. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7422. {
  7423. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7424. }
  7425. else
  7426. {
  7427. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7428. }
  7429. }
  7430. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7431. //*********************chargingRateUnit***************************/
  7432. loc = strstr(payload, "chargingRateUnit");
  7433. if(loc != NULL)
  7434. {
  7435. c = 0;
  7436. memset(sstr ,0, sizeof(sstr) );
  7437. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7438. {
  7439. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7440. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7441. c++;
  7442. }
  7443. sstr[c] = '\0';
  7444. strcpy(chargingRateUnitStr,sstr);
  7445. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7446. {
  7447. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7448. }
  7449. else
  7450. {
  7451. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7452. }
  7453. }
  7454. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7455. //****************chargingSchedulePeriod count start*******************/
  7456. int what_len = strlen("startPeriod");
  7457. char tempChargingProfile[1000]={0};
  7458. strcpy(tempChargingProfile,(const char*)payload);
  7459. char *where = tempChargingProfile;
  7460. if (what_len)
  7461. {
  7462. while ((where = strstr(where, "startPeriod"))) {
  7463. where += what_len;
  7464. chargingSchedulePeriodCount++;
  7465. }
  7466. }
  7467. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7468. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7469. //where = payload;
  7470. int templength = 0;
  7471. //int searchstart = 0;
  7472. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7473. {
  7474. //****************startPeriod*******************/
  7475. c=0;
  7476. loc = strstr(tempChargingProfile + templength, "startPeriod");
  7477. memset(sstr ,0, sizeof(sstr) );
  7478. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7479. {
  7480. sstr[c] = loc[strlen("startPeriod")+2+c];
  7481. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7482. c++;
  7483. }
  7484. sstr[c] = '\0';
  7485. startPeriodInt[periodNums] = atoi(sstr);
  7486. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7487. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7488. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7489. {
  7490. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7491. }
  7492. else
  7493. {
  7494. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7495. }
  7496. templength = strlen("startPeriod")+2+c;
  7497. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7498. //****************limit*******************/
  7499. c=0;
  7500. loc = strstr(tempChargingProfile + templength, "limit");
  7501. memset(sstr ,0, sizeof(sstr) );
  7502. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7503. {
  7504. sstr[c] = loc[strlen("limit")+2+c];
  7505. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7506. c++;
  7507. }
  7508. sstr[c] = '\0';
  7509. limitflaot[periodNums] = atof(sstr);
  7510. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7511. {
  7512. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7513. }
  7514. else
  7515. {
  7516. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7517. }
  7518. templength = templength + strlen("limit")+2+c;
  7519. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7520. //****************numberPhases*******************/
  7521. loc = strstr(tempChargingProfile + templength, "numberPhases");
  7522. if(loc != NULL)
  7523. {
  7524. c=0;
  7525. memset(sstr ,0, sizeof(sstr) );
  7526. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7527. {
  7528. sstr[c] = loc[strlen("numberPhases")+2+c];
  7529. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7530. c++;
  7531. }
  7532. sstr[c] = '\0';
  7533. numberPhasesInt[periodNums] = atoi(sstr);
  7534. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7535. {
  7536. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7537. }
  7538. else
  7539. {
  7540. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7541. }
  7542. templength = templength + strlen("numberPhases")+2+c;
  7543. }
  7544. //where = loc;
  7545. }
  7546. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7547. //****************chargingSchedulePeriod count end*******************/
  7548. //*********************minChargingRate***************************/
  7549. loc = strstr(payload, "minChargingRate");
  7550. if(loc != NULL)
  7551. {
  7552. c = 0;
  7553. memset(sstr ,0, sizeof(sstr) );
  7554. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7555. {
  7556. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7557. c++;
  7558. }
  7559. sstr[c] = '\0';
  7560. minChargingRateFloat = atof(sstr);
  7561. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7562. {
  7563. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7564. }
  7565. else
  7566. {
  7567. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7568. }
  7569. }
  7570. else
  7571. {
  7572. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7573. {
  7574. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7575. }
  7576. else
  7577. {
  7578. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7579. }
  7580. }
  7581. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7582. {
  7583. //printf("set chargingProfile 1-2\n");
  7584. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7585. if(connectorIdInt != 0)
  7586. {
  7587. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7588. goto end;
  7589. }
  7590. strcpy(filename, ChargePointMaxProfile_JSON );
  7591. fptr1 = fopen(filename, "r");
  7592. if (!fptr1)
  7593. {
  7594. //file not exist
  7595. DEBUG_INFO("Unable to open the input file!!\n");
  7596. fptr1 = fopen(filename, "w+");
  7597. }
  7598. fclose(fptr1);
  7599. }
  7600. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7601. {
  7602. //printf("set chargingProfile 1-3\n");
  7603. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7604. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7605. {
  7606. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7607. goto end;
  7608. }
  7609. switch(connectorIdInt)
  7610. {
  7611. case 0:
  7612. strcpy(filename, TxDefaultProfile_0_JSON );
  7613. break;
  7614. case 1:
  7615. strcpy(filename, TxDefaultProfile_1_JSON );
  7616. break;
  7617. case 2:
  7618. strcpy(filename, TxDefaultProfile_2_JSON );
  7619. break;
  7620. default:
  7621. strcpy(filename, TxDefaultProfile_0_JSON );
  7622. break;
  7623. }
  7624. fptr1 = fopen(filename, "r");
  7625. if (!fptr1)
  7626. {
  7627. //file not exist
  7628. //DEBUG_INFO("Unable to open the input file!!\n");
  7629. fptr1 = fopen(filename, "w+");
  7630. }
  7631. fclose(fptr1);
  7632. }
  7633. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7634. {
  7635. //printf("set chargingProfile 1-4\n");
  7636. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7637. //check Transaction active
  7638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7639. {
  7640. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7641. {
  7642. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7643. {
  7644. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7645. {
  7646. meet = TRUE;
  7647. break;
  7648. }
  7649. }
  7650. }
  7651. }
  7652. for (int index = 0; index < CCS_QUANTITY; index++)
  7653. {
  7654. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7655. {
  7656. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7657. {
  7658. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7659. {
  7660. meet = TRUE;
  7661. break;
  7662. }
  7663. }
  7664. }
  7665. }
  7666. for (int index = 0; index < GB_QUANTITY; index++)
  7667. {
  7668. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7669. {
  7670. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7671. {
  7672. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7673. {
  7674. meet = TRUE;
  7675. break;
  7676. }
  7677. }
  7678. }
  7679. }
  7680. if(meet == FALSE)
  7681. {
  7682. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7683. goto end;
  7684. }
  7685. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7686. {
  7687. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7688. goto end;
  7689. }
  7690. switch(connectorIdInt)
  7691. {
  7692. case 0:
  7693. break;
  7694. case 1:
  7695. strcpy(filename, TxProfile_1_JSON);
  7696. break;
  7697. case 2:
  7698. strcpy(filename, TxProfile_2_JSON);
  7699. break;
  7700. default:
  7701. strcpy(filename, TxProfile_1_JSON);
  7702. break;
  7703. }
  7704. fptr1 = fopen(filename, "r");
  7705. if (!fptr1)
  7706. {
  7707. //file not exist
  7708. DEBUG_INFO("Unable to open the input file!!\n");
  7709. fptr1 = fopen(filename, "w+");
  7710. }
  7711. fclose(fptr1);
  7712. }
  7713. //**********************************Write to File********************************************************/
  7714. FILE *infile;
  7715. FILE *outfile;
  7716. // open file for writing
  7717. infile = fopen (filename, "r");
  7718. outfile = fopen (tempfile, "w");
  7719. int d =0;
  7720. d = fgetc(infile);
  7721. //DEBUG_INFO("d:%d\n",d);
  7722. rewind(infile);
  7723. //*检测到文件结束标识返回1,否则返回0。*/
  7724. if(d == EOF)
  7725. {
  7726. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7727. fprintf(outfile,"%s\n",payload);
  7728. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7729. fclose(infile);
  7730. fclose(outfile);
  7731. sprintf(rmFileCmd,"rm -f %s",filename);
  7732. system(rmFileCmd);
  7733. rename(tempfile, filename);
  7734. #if 0
  7735. resultRename = rename(tempfile, filename);
  7736. if(resultRename == 0)
  7737. {
  7738. DEBUG_INFO("File chargingProfile renamed successfully");
  7739. }
  7740. else
  7741. {
  7742. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7743. }
  7744. #endif
  7745. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7746. //system(rmFileCmd);
  7747. }
  7748. else
  7749. {
  7750. char buf[1000]={0};
  7751. int ChargingProfileAdded = FALSE;
  7752. while (fgets(buf, sizeof(buf), infile) != NULL)
  7753. {
  7754. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7755. //*************************tempconnectorIdInt*********************************/
  7756. loc = strstr(buf, "connectorId");
  7757. c = 0;
  7758. memset(sstr ,0, sizeof(sstr) );
  7759. while (loc[strlen("connectorId")+2+c] != ',')
  7760. {
  7761. sstr[c] = loc[strlen("connectorId")+2+c];
  7762. c++;
  7763. }
  7764. sstr[c] = '\0';
  7765. tempconnectorIdInt = atoi(sstr);
  7766. //*************************tempchargingProfileIdInt*********************************/
  7767. loc = strstr(buf, "chargingProfileId");
  7768. c = 0;
  7769. memset(sstr ,0, sizeof(sstr) );
  7770. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7771. {
  7772. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7773. c++;
  7774. }
  7775. sstr[c] = '\0';
  7776. tempchargingProfileIdInt = atoi(sstr);
  7777. //*************************tempstackLevelInt*********************************/
  7778. loc = strstr(buf, "stackLevel");
  7779. c = 0;
  7780. memset(sstr ,0, sizeof(sstr) );
  7781. while (loc[strlen("stackLevel")+2+c] != ',')
  7782. {
  7783. sstr[c] = loc[strlen("stackLevel")+2+c];
  7784. c++;
  7785. }
  7786. sstr[c] = '\0';
  7787. tempstackLevelInt = atoi(sstr);
  7788. //*************************tempchargingProfilePurposeStr*********************************/
  7789. loc = strstr(payload, "chargingProfilePurpose");
  7790. c = 0;
  7791. memset(sstr ,0, sizeof(sstr) );
  7792. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7793. {
  7794. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7795. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7796. c++;
  7797. }
  7798. sstr[c] = '\0';
  7799. strcpy(tempchargingProfilePurposeStr,sstr);
  7800. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7801. {
  7802. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7803. {
  7804. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7805. if(ChargingProfileAdded == FALSE)
  7806. {
  7807. fprintf(outfile,"%s\n",payload);
  7808. ChargingProfileAdded = TRUE;
  7809. }
  7810. }
  7811. else
  7812. {
  7813. if(tempstackLevelInt < stackLevelInt)
  7814. {
  7815. if(ChargingProfileAdded == FALSE)
  7816. {
  7817. fprintf(outfile,"%s\n",payload);
  7818. ChargingProfileAdded = TRUE;
  7819. fprintf(outfile,"%s\n",buf);
  7820. }
  7821. else
  7822. {
  7823. fprintf(outfile,"%s\n",buf);
  7824. }
  7825. }
  7826. else
  7827. {
  7828. if(ChargingProfileAdded == FALSE)
  7829. {
  7830. fprintf(outfile,"%s\n",buf);
  7831. fprintf(outfile,"%s\n",payload);
  7832. ChargingProfileAdded = TRUE;
  7833. }
  7834. else
  7835. {
  7836. fprintf(outfile,"%s\n",buf);
  7837. }
  7838. }
  7839. }
  7840. }
  7841. else
  7842. {
  7843. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7844. {
  7845. if(ChargingProfileAdded == FALSE)
  7846. {
  7847. fprintf(outfile,"%s\n",payload);
  7848. ChargingProfileAdded = TRUE;
  7849. fprintf(outfile,"%s\n",buf);
  7850. }
  7851. else
  7852. {
  7853. fprintf(outfile,"%s\n",buf);
  7854. }
  7855. }
  7856. else if(tempstackLevelInt < stackLevelInt)
  7857. {
  7858. if(ChargingProfileAdded == FALSE)
  7859. {
  7860. fprintf(outfile,"%s\n",payload);
  7861. ChargingProfileAdded = TRUE;
  7862. fprintf(outfile,"%s\n",buf);
  7863. }
  7864. else
  7865. {
  7866. fprintf(outfile,"%s\n",buf);
  7867. }
  7868. }
  7869. else
  7870. {
  7871. if(ChargingProfileAdded == FALSE)
  7872. {
  7873. fprintf(outfile,"%s\n",buf);
  7874. fprintf(outfile,"%s\n",payload);
  7875. ChargingProfileAdded = TRUE;
  7876. }
  7877. else
  7878. {
  7879. fprintf(outfile,"%s\n",buf);
  7880. }
  7881. }
  7882. }
  7883. } // end of while loop
  7884. fclose(infile);
  7885. fclose(outfile);
  7886. sprintf(rmFileCmd,"rm -f %s",filename);
  7887. system(rmFileCmd);
  7888. rename(tempfile, filename);
  7889. #if 0
  7890. resultRename = rename(tempfile, filename);
  7891. if(resultRename == 0)
  7892. {
  7893. DEBUG_INFO("File chargingProfile renamed successfully");
  7894. }
  7895. else
  7896. {
  7897. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7898. }
  7899. #endif
  7900. result = TRUE;
  7901. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7902. }
  7903. end:
  7904. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7905. return result;
  7906. return result;
  7907. }
  7908. int handleTriggerMessageRequest(char *uuid, char *payload)
  7909. {
  7910. mtrace();
  7911. int result = FAIL;
  7912. int connectorIdIsNULL = FALSE;
  7913. int connectorIdInt =0;
  7914. char sstr[40]={0};
  7915. char requestedMessagestr[40]={0};
  7916. char comfirmstr[20]={0};
  7917. int c = 0;
  7918. char *loc;
  7919. DEBUG_INFO("handleTriggerMessageRequest\n");
  7920. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7921. c = 0;
  7922. loc = strstr(payload, "requestedMessage");
  7923. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7924. {
  7925. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7926. c++;
  7927. }
  7928. sstr[c] = '\0';
  7929. strcpy(requestedMessagestr, sstr);
  7930. c = 0;
  7931. loc = strstr(payload, "connectorId");
  7932. if(loc == NULL)
  7933. {
  7934. connectorIdIsNULL = TRUE;
  7935. }
  7936. else
  7937. {
  7938. memset(sstr ,0, sizeof(sstr) );
  7939. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7940. {
  7941. sstr[c] = loc[strlen("connectorId")+2+c];
  7942. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7943. c++;
  7944. }
  7945. sstr[c] = '\0';
  7946. connectorIdInt = atoi(sstr);
  7947. }
  7948. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7949. {
  7950. //connectorIdInt = json_object_get_int(connectorId);
  7951. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7952. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7953. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7954. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7955. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7956. }
  7957. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7958. {
  7959. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7960. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7961. return TRUE;
  7962. }
  7963. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7964. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7965. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7966. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7967. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7968. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7969. {
  7970. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7971. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7972. return TRUE;
  7973. }
  7974. else
  7975. {
  7976. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7977. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7978. }
  7979. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7980. {
  7981. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  7982. {
  7983. FirmwareStatusNotificationStatus = 3;
  7984. }
  7985. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7986. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7987. }
  7988. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7989. {
  7990. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7991. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7992. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7993. }
  7994. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7995. {
  7996. sendBootNotificationRequest();
  7997. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7998. }
  7999. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8000. {
  8001. sendHeartbeatRequest(connectorIdInt);
  8002. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8003. }
  8004. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8005. {
  8006. if(connectorIdIsNULL == FALSE)
  8007. {
  8008. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8009. {
  8010. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8011. sendMeterValuesRequest(connectorIdInt -1);
  8012. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8013. }
  8014. }
  8015. else
  8016. {
  8017. for(int idx=0;idx< gunTotalNumber;idx++)
  8018. {
  8019. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8020. sendMeterValuesRequest(idx);
  8021. }
  8022. }
  8023. }
  8024. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8025. {
  8026. if(connectorIdIsNULL == FALSE)
  8027. {
  8028. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8029. {
  8030. sendStatusNotificationRequest(connectorIdInt -1);
  8031. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8032. }
  8033. }
  8034. else
  8035. {
  8036. for(int idx=0;idx< gunTotalNumber;idx++)
  8037. sendStatusNotificationRequest(idx);
  8038. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8039. }
  8040. }
  8041. return result;
  8042. }
  8043. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8044. {
  8045. mtrace();
  8046. int result = FAIL;
  8047. char sstr[6]={0};
  8048. int connectorIdInt =0;
  8049. char comfirmstr[20]={0};
  8050. int c = 0;
  8051. char *loc;
  8052. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8053. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8054. c = 0;
  8055. loc = strstr(payload, "connectorId");
  8056. memset(sstr ,0, sizeof(sstr) );
  8057. while (loc[strlen("connectorId")+2+c] != '}')
  8058. {
  8059. sstr[c] = loc[strlen("connectorId")+2+c];
  8060. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8061. c++;
  8062. }
  8063. sstr[c] = '\0';
  8064. connectorIdInt = atoi(sstr);
  8065. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8066. if(gunTotalNumber == 0)
  8067. {
  8068. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8069. goto end;
  8070. }
  8071. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8072. {
  8073. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8074. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8075. goto end;
  8076. }
  8077. else
  8078. {
  8079. //check Transaction active
  8080. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8081. {
  8082. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8083. {
  8084. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8085. {
  8086. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8087. }
  8088. }
  8089. for (int index = 0; index < CCS_QUANTITY; index++)
  8090. {
  8091. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8092. {
  8093. //stop Transaction
  8094. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8095. }
  8096. }
  8097. for (int index = 0; index < GB_QUANTITY; index++)
  8098. {
  8099. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8100. {
  8101. //stop Transaction
  8102. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8103. }
  8104. }
  8105. }
  8106. else
  8107. {
  8108. for (int index = 0; index < AC_QUANTITY; index++)
  8109. {
  8110. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8111. {
  8112. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8113. }
  8114. }
  8115. }// END FOR AC ELSE
  8116. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8117. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8118. result = TRUE;
  8119. return result;
  8120. }
  8121. end:
  8122. //json_object_put(obj); --- remove temporally
  8123. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8124. return result;
  8125. }
  8126. static char UpdateFirmwarepayloadData[300]={0};
  8127. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8128. {
  8129. mtrace();
  8130. int result = FAIL;
  8131. pthread_t t;
  8132. sendUpdateFirmwareConfirmation(uuid);
  8133. memset(UpdateFirmwarepayloadData, 0, 300);
  8134. strcpy(UpdateFirmwarepayloadData, payload);
  8135. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8136. ////pthread_join(t, NULL); //
  8137. //pthread_detach(t);
  8138. //sendUpdateFirmwareConfirmation(uuid);
  8139. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8140. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8141. return result;
  8142. }
  8143. void *UpdateFirmwareProcess(void *data)
  8144. {
  8145. pthread_detach(pthread_self());
  8146. mtrace();
  8147. int retriesInt =0, retryIntervalInt=0;
  8148. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8149. int port=0;
  8150. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8151. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8152. //char comfirmstr[20];
  8153. int isSuccess = 0;
  8154. char ftpbuf[200];
  8155. char temp[100];
  8156. char * pch;
  8157. int retriesISNULL=FALSE;
  8158. int retryInterval=FALSE;
  8159. int c = 0;
  8160. //int i = 0;
  8161. char *loc;
  8162. char sstr[300]={ 0 };
  8163. char str[300]={ 0 };
  8164. //char *str = (char*) data; // ? ?輸入資 ?
  8165. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8166. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8167. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8168. //***************location **************/
  8169. loc = strstr(str, "location");
  8170. memset(sstr ,0, sizeof(sstr) );
  8171. c = 0;
  8172. while (loc[3+strlen("location")+c] != '\"')
  8173. {
  8174. sstr[c] = loc[3+strlen("location")+c];
  8175. c++;
  8176. }
  8177. sstr[c] = '\0';
  8178. strcpy(locationstr, sstr);
  8179. //***************retries**************/
  8180. c = 0;
  8181. loc = strstr(str, "retries");
  8182. if(loc == NULL)
  8183. {
  8184. retriesISNULL=TRUE;
  8185. }
  8186. else
  8187. {
  8188. memset(sstr ,0, sizeof(sstr) );
  8189. while (loc[strlen("retries")+2+c] != ',')
  8190. {
  8191. sstr[c] = loc[strlen("retries")+2+c];
  8192. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8193. c++;
  8194. }
  8195. sstr[c] = '\0';
  8196. }
  8197. if(retriesISNULL == FALSE)
  8198. {
  8199. retriesInt = atoi(sstr);
  8200. }
  8201. //***************retrieveDate **************/
  8202. loc = strstr(str, "retrieveDate");
  8203. memset(sstr ,0, sizeof(sstr) );
  8204. c = 0;
  8205. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8206. {
  8207. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8208. c++;
  8209. }
  8210. sstr[c] = '\0';
  8211. strcpy(retrieveDatestr, sstr);
  8212. //***************retryInterval **************/
  8213. c = 0;
  8214. loc = strstr(str, "retryInterval");
  8215. memset(sstr ,0, sizeof(sstr) );
  8216. if(loc == NULL)
  8217. {
  8218. retryInterval=TRUE;
  8219. }
  8220. else
  8221. {
  8222. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8223. {
  8224. sstr[c] = loc[strlen("retryInterval")+2+c];
  8225. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8226. c++;
  8227. }
  8228. sstr[c] = '\0';
  8229. }
  8230. if(retryInterval==FALSE)
  8231. {
  8232. retryIntervalInt = atoi(sstr);
  8233. }
  8234. memset(ftppath, 0, sizeof(ftppath));
  8235. memset(path, 0, sizeof(path));
  8236. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8237. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8238. if(strncmp(locationstr,"http", 4) == 0)
  8239. {
  8240. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8241. protocol, host, path);
  8242. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8243. // protocol, user, password, host, path);
  8244. sprintf(ftppath,"/%s", path);
  8245. //DEBUG_INFO("protocol =%s\n",protocol);
  8246. //DEBUG_INFO("host =%s\n",host);
  8247. //DEBUG_INFO("path =%s\n",path);
  8248. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8249. int ftppathlen=strlen(ftppath);
  8250. int i=1;
  8251. char filenametemp[50];
  8252. while(i < ftppathlen)
  8253. {
  8254. int len=ftppathlen-i;
  8255. if(ftppath[len]== 47) // '/' ascll code: 47
  8256. {
  8257. DEBUG_INFO("compare '/' all right\n");
  8258. break;
  8259. }
  8260. i=i+1;
  8261. }
  8262. memset(filenametemp, 0, sizeof(filenametemp));
  8263. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8264. filenametemp[i+1] = 0;
  8265. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8266. do{
  8267. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8268. sleep(retryIntervalInt);
  8269. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8270. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8271. if(!isSuccess)
  8272. {
  8273. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8274. }
  8275. else
  8276. {
  8277. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8278. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8279. isUpdateRequest = TRUE;
  8280. }
  8281. }
  8282. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8283. {
  8284. memset(ftpbuf, 0, sizeof(ftpbuf));
  8285. memset(temp, 0, sizeof(temp));
  8286. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8287. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8288. int ftppathlen=strlen(ftpbuf);
  8289. int i=1;
  8290. char filenametemp[50];
  8291. while(i < ftppathlen)
  8292. {
  8293. int len=ftppathlen-i;
  8294. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8295. {
  8296. DEBUG_INFO(" compare '/' all right\n");
  8297. break;
  8298. }
  8299. i=i+1;
  8300. }
  8301. memset(filenametemp, 0, sizeof(filenametemp));
  8302. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8303. filenametemp[i+1] = 0;
  8304. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8305. pch=strchr(temp,'@');
  8306. if(pch==NULL)
  8307. {
  8308. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8309. protocol, host, &port, path);
  8310. strcpy(user,"anonymous");
  8311. strcpy(password,"");
  8312. }
  8313. else
  8314. {
  8315. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8316. protocol, user, password, host, &port, path);
  8317. }
  8318. sscanf(host,"%[^/]%s",host1, path1);
  8319. sprintf(ftppath,"%s", path1);
  8320. //DEBUG_INFO("protocol =%s\n",protocol);
  8321. //DEBUG_INFO("user =%s\n",user);
  8322. //DEBUG_INFO("password =%s\n",password);
  8323. //DEBUG_INFO("host1 =%s\n",host1);
  8324. //DEBUG_INFO("port =%d\n",port);
  8325. //DEBUG_INFO("path1 =%s\n",path1);
  8326. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8327. //ftpFile(host, user, password, port, ftppath, fname);
  8328. //download firmware pthred
  8329. if(port == 0)
  8330. {
  8331. port = 21;
  8332. }
  8333. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8334. do{
  8335. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8336. sleep(retryIntervalInt);
  8337. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8338. if(!isSuccess)
  8339. {
  8340. //BulldogUtil.sleepMs(interval*1000);
  8341. DEBUG_INFO("Update firmware request and download file fail.\n");
  8342. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8343. }
  8344. else
  8345. {
  8346. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8347. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8348. isUpdateRequest = TRUE;
  8349. }
  8350. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8351. }
  8352. else
  8353. {
  8354. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8355. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8356. }
  8357. pthread_exit(NULL);
  8358. }
  8359. //==========================================
  8360. // Handle server response routine
  8361. //==========================================
  8362. void handleAuthorizeResponse(char *payload, int gun_index)
  8363. {
  8364. mtrace();
  8365. char expiryDatestr[30]={0};
  8366. char parentIdTagstr[20]={0};
  8367. char statusstr[20]={0};
  8368. char expiryDatestrtemp[30]={0};
  8369. char parentIdTagstrtemp[20]={0};
  8370. char IdTagstrtemp[20]={0};
  8371. char statusstrtemp[20]={0};
  8372. int expiryDateISNULL=FALSE;
  8373. int parentIdTagISNULL=FALSE;
  8374. char sstr[160]={ 0 };
  8375. char* filename = AuthorizationCache_JSON;
  8376. char tempfile[] = "../Storage/OCPP/temp.json";
  8377. int c = 0;
  8378. char *loc;
  8379. int resultRename=0;
  8380. int responseIdTagInfoAsZero= 0;
  8381. char rmFileCmd[50]={0};
  8382. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8383. //***********expiryDate*************/
  8384. loc = strstr(payload, "expiryDate");
  8385. memset(sstr ,0, sizeof(sstr) );
  8386. c = 0;
  8387. if(loc == NULL)
  8388. {
  8389. expiryDateISNULL = TRUE;
  8390. }
  8391. else
  8392. {
  8393. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8394. {
  8395. sstr[c] = loc[3+strlen("expiryDate")+c];
  8396. c++;
  8397. }
  8398. sstr[c] = '\0';
  8399. strcpy(expiryDatestr, sstr);
  8400. }
  8401. //***********parentIdTag*************/
  8402. loc = strstr(payload, "parentIdTag");
  8403. memset(sstr ,0, sizeof(sstr) );
  8404. c = 0;
  8405. if(loc == NULL)
  8406. {
  8407. parentIdTagISNULL = TRUE;
  8408. }
  8409. else
  8410. {
  8411. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8412. {
  8413. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8414. c++;
  8415. }
  8416. sstr[c] = '\0';
  8417. strcpy(parentIdTagstr, sstr);
  8418. }
  8419. //***********status*************/
  8420. loc = strstr(payload, "status");
  8421. memset(sstr ,0, sizeof(sstr) );
  8422. c = 0;
  8423. while (loc[3+strlen("status")+c] != '\"')
  8424. {
  8425. sstr[c] = loc[3+strlen("status")+c];
  8426. c++;
  8427. }
  8428. sstr[c] = '\0';
  8429. strcpy(statusstr, sstr);
  8430. if(expiryDateISNULL == FALSE)
  8431. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8432. if(parentIdTagISNULL == FALSE)
  8433. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8434. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8435. //Update idTag information to authorization cache if supproted
  8436. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8437. {
  8438. if((access(filename,F_OK))!=-1)
  8439. {
  8440. printf("AuthorizationCache exist.\n");
  8441. }
  8442. else
  8443. {
  8444. printf("AuthorizationCache not exist\n");
  8445. FILE *log = fopen(filename, "w+");
  8446. if(log == NULL)
  8447. {
  8448. printf("log is NULL\n");
  8449. goto out;
  8450. }
  8451. else
  8452. {
  8453. fclose(log);
  8454. }
  8455. }
  8456. FILE *infile;
  8457. FILE *outfile;
  8458. // open file for writing
  8459. infile = fopen (filename, "r");
  8460. outfile = fopen (tempfile, "w");
  8461. //*检测到文件结束标识返回1,否则返回0。*/
  8462. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8463. int c;
  8464. c = fgetc(infile);
  8465. //DEBUG_INFO("c:%d\n",c);
  8466. rewind(infile);
  8467. if(c == EOF)
  8468. {
  8469. DEBUG_INFO("Orignal File is NULL\n");
  8470. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8471. {
  8472. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8473. }
  8474. else
  8475. {
  8476. strcpy(expiryDatestrtemp, "");
  8477. }
  8478. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8479. {
  8480. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8481. }
  8482. else
  8483. {
  8484. //write Authorize IdTag
  8485. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8486. }
  8487. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8488. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8489. fclose(infile);
  8490. fclose(outfile);
  8491. sprintf(rmFileCmd,"rm -f %s",filename);
  8492. system(rmFileCmd);
  8493. resultRename = rename(tempfile, filename);
  8494. if(resultRename == 0)
  8495. {
  8496. printf("File renamed successfully");
  8497. }
  8498. else
  8499. {
  8500. printf("Error: unable to rename the file");
  8501. }
  8502. }
  8503. else
  8504. {
  8505. char buf[160]={0};
  8506. while (fgets(buf, sizeof(buf), infile) != NULL)
  8507. {
  8508. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8509. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8510. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8511. memset(statusstr, 0, sizeof(statusstrtemp));
  8512. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8513. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8514. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8515. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8516. //------------------IdTag-----------------------
  8517. loc = strstr(buf, "idTag");
  8518. memset(sstr ,0, sizeof(sstr) );
  8519. c = 0;
  8520. while (loc[3+strlen("idTag")+c] != '\"')
  8521. {
  8522. sstr[c] = loc[3+strlen("idTag")+c];
  8523. c++;
  8524. }
  8525. sstr[c] = '\0';
  8526. strcpy(IdTagstrtemp,sstr);
  8527. //*********************expiryDate***************/
  8528. loc = strstr(buf, "expiryDate");
  8529. memset(sstr ,0, sizeof(sstr) );
  8530. c = 0;
  8531. while (loc[3+strlen("expiryDate")+c] != '\"')
  8532. {
  8533. sstr[c] = loc[3+strlen("expiryDate")+c];
  8534. c++;
  8535. }
  8536. sstr[c] = '\0';
  8537. strcpy(expiryDatestr,sstr);
  8538. //*********************parentIdTag***************/
  8539. loc = strstr(buf, "parentIdTag");
  8540. memset(sstr ,0, sizeof(sstr) );
  8541. c = 0;
  8542. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8543. {
  8544. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8545. c++;
  8546. }
  8547. sstr[c] = '\0';
  8548. strcpy(parentIdTagstr,sstr);
  8549. //*********************status***************/
  8550. loc = strstr(buf, "status");
  8551. memset(sstr ,0, sizeof(sstr) );
  8552. c = 0;
  8553. while (loc[3+strlen("status")+c] != '\"')
  8554. {
  8555. sstr[c] = loc[3+strlen("status")+c];
  8556. c++;
  8557. }
  8558. sstr[c] = '\0';
  8559. strcpy(statusstr,sstr);
  8560. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8561. {
  8562. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8563. responseIdTagInfoAsZero = 1;
  8564. }
  8565. else
  8566. {
  8567. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8568. }
  8569. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8570. {
  8571. //modify item
  8572. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8573. {
  8574. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8575. }
  8576. else
  8577. {
  8578. strcpy(expiryDatestrtemp, "");
  8579. }
  8580. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8581. {
  8582. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8583. }
  8584. else
  8585. {
  8586. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8587. }
  8588. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8589. }
  8590. else
  8591. {
  8592. //wrie original item
  8593. strcpy(expiryDatestrtemp, expiryDatestr);
  8594. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8595. strcpy(statusstrtemp, statusstr);
  8596. }
  8597. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8598. }
  8599. fclose(infile);
  8600. fclose(outfile);
  8601. sprintf(rmFileCmd,"rm -f %s",filename);
  8602. system(rmFileCmd);
  8603. resultRename = rename(tempfile, filename);
  8604. if(resultRename == 0)
  8605. {
  8606. DEBUG_INFO("File renamed successfully");
  8607. }
  8608. else
  8609. {
  8610. DEBUG_INFO("Error: unable to rename the file");
  8611. }
  8612. }
  8613. }
  8614. out:
  8615. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8616. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8617. authorizeRetryTimes = 0;
  8618. }
  8619. void handleBootNotificationResponse(char *payload, int gun_index)
  8620. {
  8621. mtrace();
  8622. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8623. char statusStr[12]={0};
  8624. char currentTimeStr[30]={0};
  8625. char *loc;
  8626. int intervalInt = 0;
  8627. int c = 0;
  8628. //double diff_t;
  8629. struct tm tp;
  8630. char buf[28]={0};
  8631. char timebuf[50]={0};
  8632. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8633. //*** interval ****/
  8634. c = 0;
  8635. loc = strstr(payload, "interval");
  8636. //printf("loc=%s\n",loc);
  8637. memset(sstr ,0, sizeof(sstr) );
  8638. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8639. {
  8640. sstr[c] = loc[strlen("interval")+2+c];
  8641. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8642. c++;
  8643. }
  8644. sstr[c] = '\0';
  8645. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8646. intervalInt = atoi(sstr);
  8647. //***status ****/
  8648. loc = strstr(payload, "status");
  8649. memset(sstr ,0, sizeof(sstr) );
  8650. c = 0;
  8651. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8652. {
  8653. sstr[c] = loc[3+strlen("status")+c];
  8654. c++;
  8655. }
  8656. sstr[c] = '\0';
  8657. strcpy(statusStr, sstr);
  8658. //***currentTime ****/
  8659. loc = strstr(payload, "currentTime");
  8660. //printf("loc=%s\n",loc);
  8661. memset(sstr ,0, sizeof(sstr) );
  8662. c = 0;
  8663. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8664. {
  8665. sstr[c] = loc[3+strlen("currentTime")+c];
  8666. c++;
  8667. }
  8668. sstr[c] = '\0';
  8669. strcpy(currentTimeStr, sstr);
  8670. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8671. HeartBeatWaitTime = BootNotificationInterval;
  8672. clientTime.Heartbeat=time((time_t*)NULL);
  8673. //write back to ShmOCPP16Data->BootNotification
  8674. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8675. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8676. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8677. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8678. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8679. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8680. {
  8681. server_sign = TRUE;
  8682. server_pending =FALSE;
  8683. }
  8684. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8685. {
  8686. server_pending = TRUE;
  8687. }
  8688. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8689. tp.tm_isdst = -1;
  8690. //time_t utc = mktime(&tp);
  8691. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8692. memset(timebuf, 0, sizeof timebuf);
  8693. sprintf(timebuf,"date -s '%s'",buf);
  8694. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8695. system(timebuf);
  8696. //==============================================
  8697. // RTC sync
  8698. //==============================================
  8699. system("/sbin/hwclock -w --systohc");
  8700. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8701. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8702. }
  8703. void handleDataTransferResponse(char *payload, int gun_index)
  8704. {
  8705. char sstr[160]={0};//sstr[200]={ 0 };
  8706. int c = 0;
  8707. char *loc;
  8708. DEBUG_INFO("handleDataTransferResponse ...\n");
  8709. loc = strstr(payload, "status");
  8710. printf("loc=%s\n",loc);
  8711. c = 0;
  8712. while (loc[3+strlen("status")+c] != '\"')
  8713. {
  8714. sstr[c] = loc[3+strlen("status")+c];
  8715. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8716. c++;
  8717. }
  8718. sstr[c] = '\0';
  8719. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8720. }
  8721. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8722. {
  8723. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8724. //struct json_object *obj;
  8725. // obj = json_tokener_parse(payload);
  8726. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8727. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8728. //No fields are defined.
  8729. }
  8730. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8731. {
  8732. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8733. //struct json_object *obj;
  8734. // obj = json_tokener_parse(payload);
  8735. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8736. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8737. //No fields are defined.
  8738. }
  8739. void handleHeartbeatResponse(char *payload, int gun_index)
  8740. {
  8741. mtrace();
  8742. //double diff_t;
  8743. struct tm tp;
  8744. char buf[28]={0};
  8745. char timebuf[50]={0};
  8746. char sstr[30]={ 0 };
  8747. int c = 0;
  8748. char *loc;
  8749. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8750. if((HeartBeatCount%360) == 0)
  8751. {
  8752. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8753. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8754. }
  8755. HeartBeatCount = HeartBeatCount + 1;
  8756. c = 0;
  8757. loc = strstr(payload, "currentTime");
  8758. memset(sstr ,0, sizeof(sstr) );
  8759. while (loc[3+strlen("currentTime")+c] != '\"')
  8760. {
  8761. sstr[c] = loc[3+strlen("currentTime")+c];
  8762. c++;
  8763. }
  8764. sstr[c] = '\0';
  8765. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8766. // #ifdef SystemLogMessage
  8767. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8768. // #endif
  8769. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8770. tp.tm_isdst = -1;
  8771. //time_t utc = mktime(&tp);
  8772. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8773. memset(timebuf, 0, sizeof timebuf);
  8774. sprintf(timebuf,"date -s '%s'",buf);
  8775. system(timebuf);
  8776. //==============================================
  8777. // RTC sync
  8778. //==============================================
  8779. system("/sbin/hwclock -w --systohc");
  8780. if(FirstHeartBeat == 0)
  8781. {
  8782. FirstHeartBeat = 1;
  8783. }
  8784. HeartBeatWithNOResponse = 0;
  8785. }
  8786. void handleMeterValuesResponse(char *payload, int gun_index)
  8787. {
  8788. mtrace();
  8789. //struct json_object *obj;
  8790. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8791. //No fields are defined.
  8792. }
  8793. void handleStartTransactionResponse(char *payload, int gun_index)
  8794. {
  8795. mtrace();
  8796. char sstr[28]={ 0 };
  8797. int c = 0;
  8798. char *loc;
  8799. int transactionIdInt = 0;
  8800. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8801. DEBUG_INFO("handleStartTransactionResponse\n");
  8802. //****************expiryDate********************/
  8803. loc = strstr(payload, "expiryDate");
  8804. if(loc == NULL)
  8805. {
  8806. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8807. }
  8808. else
  8809. {
  8810. c = 0;
  8811. memset(sstr ,0, sizeof(sstr) );
  8812. while (loc[3+strlen("expiryDate")+c] != '\"')
  8813. {
  8814. sstr[c] = loc[3+strlen("expiryDate")+c];
  8815. c++;
  8816. }
  8817. sstr[c] = '\0';
  8818. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8819. }
  8820. //****************parentIdTag********************/
  8821. loc = strstr(payload, "parentIdTag");
  8822. if(loc == NULL)
  8823. {
  8824. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8825. }
  8826. else
  8827. {
  8828. c = 0;
  8829. memset(sstr ,0, sizeof(sstr) );
  8830. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8831. {
  8832. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8833. c++;
  8834. }
  8835. sstr[c] = '\0';
  8836. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8837. }
  8838. //****************status********************/
  8839. loc = strstr(payload, "status");
  8840. if(loc == NULL)
  8841. {
  8842. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8843. }
  8844. else
  8845. {
  8846. c = 0;
  8847. memset(sstr ,0, sizeof(sstr) );
  8848. while (loc[3+strlen("status")+c] != '\"')
  8849. {
  8850. sstr[c] = loc[3+strlen("status")+c];
  8851. c++;
  8852. }
  8853. sstr[c] = '\0';
  8854. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8855. }
  8856. //****************transactionId********************/
  8857. c=0;
  8858. loc = strstr(payload, "transactionId");
  8859. memset(sstr ,0, sizeof(sstr) );
  8860. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8861. {
  8862. sstr[c] = loc[strlen("transactionId")+2+c];
  8863. c++;
  8864. }
  8865. sstr[c] = '\0';
  8866. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8867. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8868. TransactionId[gun_index] = transactionIdInt;
  8869. DEBUG_INFO("gun_index: %d\n", gun_index);
  8870. DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  8871. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8872. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8873. #ifdef SystemLogMessage
  8874. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8875. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8876. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8877. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8878. #endif
  8879. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8880. {
  8881. //add Charging Record
  8882. SettingChargingRecord(gun_index, transactionIdInt);
  8883. }
  8884. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8885. }
  8886. void handleStatusNotificationResponse(char *payload, int gun_index)
  8887. {
  8888. mtrace();
  8889. printf("handleStatusNotificationResponse\n");
  8890. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8891. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8892. }
  8893. void handleStopTransactionnResponse(char *payload, int gun_index)
  8894. {
  8895. mtrace();
  8896. char sstr[30]={ 0 };
  8897. int c = 0;
  8898. char *loc;
  8899. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8900. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8901. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8902. loc = strstr(payload, "idTagInfo");
  8903. //***********************idTagInfo************************/
  8904. if(loc != NULL)
  8905. {
  8906. //***********************expiryDate************************/
  8907. loc = strstr(payload, "expiryDate");
  8908. if(loc != NULL)
  8909. {
  8910. memset(sstr ,0, sizeof(sstr) );
  8911. c = 0;
  8912. while (loc[3+strlen("expiryDate")+c] != '\"')
  8913. {
  8914. sstr[c] = loc[3+strlen("expiryDate")+c];
  8915. c++;
  8916. }
  8917. sstr[c] = '\0';
  8918. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8919. }
  8920. //***********************parentIdTag************************/
  8921. loc = strstr(payload, "parentIdTag");
  8922. if(loc != NULL)
  8923. {
  8924. memset(sstr ,0, sizeof(sstr) );
  8925. c = 0;
  8926. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8927. {
  8928. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8929. c++;
  8930. }
  8931. sstr[c] = '\0';
  8932. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8933. }
  8934. //***********************status************************/
  8935. loc = strstr(payload, "status");
  8936. memset(sstr ,0, sizeof(sstr) );
  8937. c = 0;
  8938. while (loc[3+strlen("status")+c] != '\"')
  8939. {
  8940. sstr[c] = loc[3+strlen("status")+c];
  8941. c++;
  8942. }
  8943. sstr[c] = '\0';
  8944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8945. }
  8946. #ifdef SystemLogMessage
  8947. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8948. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8949. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8950. #endif
  8951. }
  8952. //==========================================
  8953. // Handle Error routine
  8954. //==========================================
  8955. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8956. {
  8957. mtrace();
  8958. #ifdef SystemLogMessage
  8959. DEBUG_INFO("errorCode: %s\n", errorCode);
  8960. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8961. DEBUG_INFO("errorDetails: %s\n", payload);
  8962. #endif
  8963. }
  8964. //===============================================
  8965. // Common routine
  8966. //===============================================
  8967. int initialConfigurationTable(void)
  8968. {
  8969. FILE *fp;
  8970. FILE *outfile;
  8971. char str[200]={0};
  8972. char sstr[100]={0};
  8973. int c = 0;
  8974. char *loc;
  8975. printf("initialConfigurationTable \n");
  8976. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8977. if((access("../Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  8978. {
  8979. outfile = fopen("../Storage/OCPP/OCPPConfiguration" , "w+");
  8980. if(outfile == NULL) {
  8981. DEBUG_INFO("Error opening file");
  8982. return FALSE;
  8983. }
  8984. //outfile = fopen ("../Storage/OCPP/OCPPConfiguration", "a");
  8985. /*Core Profile*/
  8986. //AllowOfflineTxForUnknownId
  8987. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8988. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8991. //DEBUG_INFO("data=%s\n",data);
  8992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  8993. //AuthorizationCacheEnabled
  8994. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  8998. //AuthorizeRemoteTxRequests
  8999. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "TRUE");
  9003. //BlinkRepeat
  9004. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9008. //ClockAlignedDataInterval
  9009. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9013. //ConnectionTimeOut
  9014. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9018. //GetConfigurationMaxKeys
  9019. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9023. // HeartbeatInterval
  9024. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9028. // LightIntensity
  9029. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9033. // LocalAuthorizeOffline
  9034. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9038. // LocalPreAuthorize
  9039. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9043. // MaxEnergyOnInvalidId
  9044. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9047. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9049. // MeterValuesAlignedData
  9050. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9054. // MeterValuesAlignedDataMaxLength
  9055. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9059. // MeterValuesSampledData
  9060. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9064. // MeterValuesSampledDataMaxLength
  9065. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9069. // MeterValueSampleInterval
  9070. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9074. // MinimumStatusDuration
  9075. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9079. // NumberOfConnectors
  9080. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9083. {
  9084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9085. }
  9086. else
  9087. {
  9088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9089. }
  9090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9091. // ResetRetries
  9092. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9096. // ConnectorPhaseRotation
  9097. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9101. // ConnectorPhaseRotationMaxLength
  9102. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9106. // StopTransactionOnEVSideDisconnect
  9107. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9111. // StopTransactionOnInvalidId
  9112. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9116. // StopTxnAlignedData
  9117. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9121. // StopTxnAlignedDataMaxLength
  9122. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9126. // StopTxnSampledData
  9127. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Energy.Active.Import.Register");
  9131. // StopTxnSampledDataMaxLength
  9132. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", "0");
  9136. // SupportedFeatureProfiles
  9137. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "0");
  9141. // SupportedFeatureProfilesMaxLength
  9142. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9146. // TransactionMessageAttempts
  9147. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9150. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9152. // TransactionMessageRetryInterval
  9153. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9156. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9158. // UnlockConnectorOnEVSideDisconnect
  9159. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9163. // WebSocketPingInterval
  9164. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9168. //* Local Auth List Management Profile*/
  9169. #if 0
  9170. //For OCTT Test Case
  9171. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9174. #endif
  9175. #if 1
  9176. //LocalAuthListEnabled
  9177. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9181. #endif
  9182. //LocalAuthListMaxLength
  9183. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9187. //SendLocalListMaxLength
  9188. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9192. //ReserveConnectorZeroSupported
  9193. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9197. //* Smart Charging Profile */
  9198. //ChargeProfileMaxStackLevel
  9199. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9203. // ChargingScheduleAllowedChargingRateUnit
  9204. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9208. // ChargingScheduleMaxPeriods
  9209. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9213. // ConnectorSwitch3to1PhaseSupported
  9214. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9218. // MaxChargingProfilesInstalled
  9219. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9223. fclose(outfile);
  9224. }
  9225. else
  9226. {
  9227. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9228. char keystr[60]={0};
  9229. char readonlystr[10]={0};
  9230. char valuestr[100]={0};
  9231. fp = fopen("../Storage/OCPP/OCPPConfiguration" , "r");
  9232. if(fp == NULL) {
  9233. DEBUG_INFO("Error opening file");
  9234. return FALSE;
  9235. }
  9236. while( fgets (str, sizeof(str), fp)!=NULL )
  9237. {
  9238. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9239. //*************************key*********************************/
  9240. loc = strstr(str, "key");
  9241. c = 0;
  9242. memset(sstr ,0, sizeof(sstr) );
  9243. while (loc[strlen("key")+3+c] != '\"')
  9244. {
  9245. sstr[c] = loc[strlen("key")+3+c];
  9246. c++;
  9247. }
  9248. sstr[c] = '\0';
  9249. strcpy(keystr,sstr);
  9250. //*************************readonly*********************************/
  9251. loc = strstr(str, "readonly");
  9252. c = 0;
  9253. memset(sstr ,0, sizeof(sstr) );
  9254. while (loc[strlen("readonly")+2+c] != ',')
  9255. {
  9256. sstr[c] = loc[strlen("readonly")+2+c];
  9257. c++;
  9258. }
  9259. sstr[c] = '\0';
  9260. strcpy(readonlystr,sstr);
  9261. //*************************value*********************************/
  9262. loc = strstr(str, "value");
  9263. c = 0;
  9264. memset(sstr ,0, sizeof(sstr) );
  9265. while (loc[strlen("value")+3+c] != '\"')
  9266. {
  9267. sstr[c] = loc[strlen("value")+3+c];
  9268. c++;
  9269. }
  9270. sstr[c] = '\0';
  9271. strcpy(valuestr,sstr);
  9272. // DEBUG_INFO("keystr=%s\n",keystr);
  9273. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9274. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9275. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9276. {
  9277. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9278. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9280. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9281. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9282. }
  9283. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9284. {
  9285. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9286. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9288. }
  9289. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9290. {
  9291. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9293. }
  9294. if(strcmp(keystr, "BlinkRepeat") == 0)
  9295. {
  9296. //Charger.BlinkRepeat = Integer.parseInt(value);
  9297. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9299. }
  9300. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9301. {
  9302. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9304. }
  9305. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9306. {
  9307. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9309. }
  9310. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9311. {
  9312. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9314. }
  9315. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9316. {
  9317. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9319. HeartBeatWaitTime = atoi(valuestr);
  9320. }
  9321. if(strcmp(keystr, "LightIntensity") == 0)
  9322. {
  9323. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9325. }
  9326. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9327. {
  9328. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9330. }
  9331. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9332. {
  9333. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9335. }
  9336. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9337. {
  9338. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9340. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9341. }
  9342. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9343. {
  9344. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9346. }
  9347. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9348. {
  9349. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9351. }
  9352. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9353. {
  9354. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9356. }
  9357. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9358. {
  9359. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9361. }
  9362. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9363. {
  9364. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9366. }
  9367. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9368. {
  9369. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9371. }
  9372. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9373. {
  9374. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9376. }
  9377. if(strcmp(keystr, "ResetRetries") == 0)
  9378. {
  9379. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9380. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9381. }
  9382. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9383. {
  9384. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9386. }
  9387. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9388. {
  9389. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9391. }
  9392. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  9393. {
  9394. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  9396. }
  9397. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  9398. {
  9399. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  9401. }
  9402. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  9403. {
  9404. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  9406. }
  9407. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  9408. {
  9409. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9411. }
  9412. if(strcmp(keystr, "StopTxnSampledData") == 0)
  9413. {
  9414. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  9416. }
  9417. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  9418. {
  9419. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9421. }
  9422. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  9423. {
  9424. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  9426. }
  9427. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  9428. {
  9429. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  9431. }
  9432. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  9433. {
  9434. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  9436. TransactionMessageAttemptsValue = atoi(valuestr);
  9437. }
  9438. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  9439. {
  9440. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  9442. TransactionMessageRetryIntervalValue = atoi(valuestr);
  9443. }
  9444. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  9445. {
  9446. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  9448. }
  9449. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  9450. {
  9451. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  9453. }
  9454. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  9455. {
  9456. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  9458. }
  9459. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  9460. {
  9461. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  9463. }
  9464. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  9465. {
  9466. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  9468. }
  9469. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  9470. {
  9471. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  9473. }
  9474. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  9475. {
  9476. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  9478. }
  9479. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  9480. {
  9481. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  9483. }
  9484. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  9485. {
  9486. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  9488. }
  9489. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  9490. {
  9491. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  9493. }
  9494. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  9495. {
  9496. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  9498. }
  9499. }
  9500. fclose(fp);
  9501. }
  9502. return 0;
  9503. }
  9504. void StoreConfigurationTable(void)
  9505. {
  9506. FILE *outfile;
  9507. outfile = fopen("../Storage/OCPP/OCPPConfiguration" , "w+");
  9508. if(outfile == NULL)
  9509. {
  9510. DEBUG_INFO("Error opening file");
  9511. return ;
  9512. }
  9513. /*Core Profile*/
  9514. //AllowOfflineTxForUnknownId
  9515. /*
  9516. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9517. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9520. */
  9521. //DEBUG_INFO("data=%s\n",data);
  9522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9523. //AuthorizationCacheEnabled
  9524. /*
  9525. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9528. */
  9529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9530. //AuthorizeRemoteTxRequests
  9531. /*
  9532. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9535. */
  9536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9537. //BlinkRepeat
  9538. /*
  9539. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9542. */
  9543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9544. //ClockAlignedDataInterval
  9545. /*
  9546. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9549. */
  9550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9551. //ConnectionTimeOut
  9552. /*
  9553. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9556. */
  9557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9558. //GetConfigurationMaxKeys
  9559. /*
  9560. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9563. */
  9564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9565. // HeartbeatInterval
  9566. /*
  9567. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9570. */
  9571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9572. // LightIntensity
  9573. /*
  9574. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9577. */
  9578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9579. // LocalAuthorizeOffline
  9580. /*
  9581. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9584. */
  9585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9586. // LocalPreAuthorize
  9587. /*
  9588. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9591. */
  9592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9593. // MaxEnergyOnInvalidId
  9594. /*
  9595. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9598. */
  9599. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9601. // MeterValuesAlignedData
  9602. /*
  9603. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9606. */
  9607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9608. // MeterValuesAlignedDataMaxLength
  9609. /*
  9610. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9613. */
  9614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9615. // MeterValuesSampledData
  9616. /*
  9617. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9620. */
  9621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9622. // MeterValuesSampledDataMaxLength
  9623. /*
  9624. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9627. */
  9628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9629. // MeterValueSampleInterval
  9630. /*
  9631. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9634. */
  9635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9636. // MinimumStatusDuration
  9637. /*
  9638. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9641. */
  9642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9643. // NumberOfConnectors
  9644. /*
  9645. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9648. {
  9649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9650. }
  9651. else
  9652. {
  9653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9654. }
  9655. */
  9656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9657. // ResetRetries
  9658. /*
  9659. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9662. */
  9663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9664. // ConnectorPhaseRotation
  9665. /*
  9666. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9669. */
  9670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9671. // ConnectorPhaseRotationMaxLength
  9672. /*
  9673. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9676. */
  9677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9678. // StopTransactionOnEVSideDisconnect
  9679. /*
  9680. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9683. */
  9684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9685. // StopTransactionOnInvalidId
  9686. /*
  9687. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9690. */
  9691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9692. // StopTxnAlignedData
  9693. /*
  9694. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9697. */
  9698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9699. // StopTxnAlignedDataMaxLength
  9700. /*
  9701. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9704. */
  9705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9706. // StopTxnSampledData
  9707. /*
  9708. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9711. */
  9712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9713. // StopTxnSampledDataMaxLength
  9714. /*
  9715. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9718. */
  9719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9720. // SupportedFeatureProfiles
  9721. /*
  9722. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9725. */
  9726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  9727. // SupportedFeatureProfilesMaxLength
  9728. /*
  9729. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9732. */
  9733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  9734. // TransactionMessageAttempts
  9735. /*
  9736. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9739. */
  9740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9741. // TransactionMessageRetryInterval
  9742. /*
  9743. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9746. */
  9747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9748. // UnlockConnectorOnEVSideDisconnect
  9749. /*
  9750. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9753. */
  9754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  9755. // WebSocketPingInterval
  9756. /*
  9757. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9760. */
  9761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  9762. //* Local Auth List Management Profile*/
  9763. //LocalAuthListEnabled
  9764. /*
  9765. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9768. */
  9769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9770. //LocalAuthListMaxLength
  9771. /*
  9772. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9775. */
  9776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  9777. //SendLocalListMaxLength
  9778. /*
  9779. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9782. */
  9783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  9784. //ReserveConnectorZeroSupported
  9785. /*
  9786. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9789. */
  9790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9791. //* Smart Charging Profile */
  9792. //ChargeProfileMaxStackLevel
  9793. /*
  9794. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9797. */
  9798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9799. // ChargingScheduleAllowedChargingRateUnit
  9800. /*
  9801. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9804. */
  9805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9806. // ChargingScheduleMaxPeriods
  9807. /*
  9808. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9811. */
  9812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9813. // ConnectorSwitch3to1PhaseSupported
  9814. /*
  9815. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9818. */
  9819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9820. // MaxChargingProfilesInstalled
  9821. /*
  9822. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9825. */
  9826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9827. fclose(outfile);
  9828. }
  9829. void getKeyValue(char *keyReq)
  9830. {
  9831. int isEmpty = FALSE;
  9832. int isKnowKey = FALSE;
  9833. //int unKnowIndex = 0;
  9834. DEBUG_INFO("getKeyValue \n");
  9835. DEBUG_INFO("keyReq=%s \n",keyReq);
  9836. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9837. isEmpty = TRUE;
  9838. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9839. {
  9840. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  9841. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9844. {
  9845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9846. }
  9847. else
  9848. {
  9849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9850. }
  9851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9852. isKnowKey = TRUE;
  9853. }
  9854. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9855. {
  9856. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9859. {
  9860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9861. }
  9862. else
  9863. {
  9864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9865. }
  9866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9867. isKnowKey = TRUE;
  9868. }
  9869. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9870. {
  9871. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9874. {
  9875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9876. }
  9877. else
  9878. {
  9879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9880. }
  9881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9882. isKnowKey = TRUE;
  9883. }
  9884. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9885. {
  9886. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9889. {
  9890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9891. }
  9892. else
  9893. {
  9894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9895. }
  9896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9897. isKnowKey = TRUE;
  9898. }
  9899. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9900. {
  9901. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9904. {
  9905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9906. }
  9907. else
  9908. {
  9909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9910. }
  9911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9912. isKnowKey = TRUE;
  9913. }
  9914. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9915. {
  9916. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9919. {
  9920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9921. }
  9922. else
  9923. {
  9924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9925. }
  9926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9927. isKnowKey = TRUE;
  9928. }
  9929. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9930. {
  9931. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9934. {
  9935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9936. }
  9937. else
  9938. {
  9939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9940. }
  9941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9942. isKnowKey = TRUE;
  9943. }
  9944. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9945. {
  9946. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9949. {
  9950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9951. }
  9952. else
  9953. {
  9954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9955. }
  9956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9957. isKnowKey = TRUE;
  9958. }
  9959. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9960. {
  9961. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9964. {
  9965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9966. }
  9967. else
  9968. {
  9969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9970. }
  9971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9972. isKnowKey = TRUE;
  9973. }
  9974. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9975. {
  9976. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9979. {
  9980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9981. }
  9982. else
  9983. {
  9984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9985. }
  9986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9987. isKnowKey = TRUE;
  9988. }
  9989. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9990. {
  9991. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9994. {
  9995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9996. }
  9997. else
  9998. {
  9999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10000. }
  10001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10002. isKnowKey = TRUE;
  10003. }
  10004. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10005. {
  10006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10009. {
  10010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10011. }
  10012. else
  10013. {
  10014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10015. }
  10016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10017. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10018. isKnowKey = TRUE;
  10019. }
  10020. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10021. {
  10022. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10025. {
  10026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10027. }
  10028. else
  10029. {
  10030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10031. }
  10032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10033. isKnowKey = TRUE;
  10034. }
  10035. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10036. {
  10037. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10039. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10040. {
  10041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10042. }
  10043. else
  10044. {
  10045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10046. }
  10047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10048. isKnowKey = TRUE;
  10049. }
  10050. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10051. {
  10052. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10055. {
  10056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10057. }
  10058. else
  10059. {
  10060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10061. }
  10062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10063. isKnowKey = TRUE;
  10064. }
  10065. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10066. {
  10067. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10070. {
  10071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10072. }
  10073. else
  10074. {
  10075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10076. }
  10077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10078. isKnowKey = TRUE;
  10079. }
  10080. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10081. {
  10082. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10085. {
  10086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10087. }
  10088. else
  10089. {
  10090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10091. }
  10092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10093. isKnowKey = TRUE;
  10094. }
  10095. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10096. {
  10097. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10099. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10100. {
  10101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10102. }
  10103. else
  10104. {
  10105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10106. }
  10107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10108. isKnowKey = TRUE;
  10109. }
  10110. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10111. {
  10112. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10115. {
  10116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10117. }
  10118. else
  10119. {
  10120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10121. }
  10122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10123. isKnowKey = TRUE;
  10124. }
  10125. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10126. {
  10127. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10129. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10130. {
  10131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10132. }
  10133. else
  10134. {
  10135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10136. }
  10137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10138. isKnowKey = TRUE;
  10139. }
  10140. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10141. {
  10142. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10145. {
  10146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10147. }
  10148. else
  10149. {
  10150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10151. }
  10152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10153. isKnowKey = TRUE;
  10154. }
  10155. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10156. {
  10157. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10160. {
  10161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10162. }
  10163. else
  10164. {
  10165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10166. }
  10167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10168. isKnowKey = TRUE;
  10169. }
  10170. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10171. {
  10172. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10174. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10175. {
  10176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10177. }
  10178. else
  10179. {
  10180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10181. }
  10182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10183. isKnowKey = TRUE;
  10184. }
  10185. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10186. {
  10187. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10190. {
  10191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10192. }
  10193. else
  10194. {
  10195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10196. }
  10197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10198. isKnowKey = TRUE;
  10199. }
  10200. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10201. {
  10202. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10204. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10205. {
  10206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10207. }
  10208. else
  10209. {
  10210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10211. }
  10212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10213. isKnowKey = TRUE;
  10214. }
  10215. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10216. {
  10217. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10219. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10220. {
  10221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10222. }
  10223. else
  10224. {
  10225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10226. }
  10227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10228. isKnowKey = TRUE;
  10229. }
  10230. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10231. {
  10232. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10234. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10235. {
  10236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10237. }
  10238. else
  10239. {
  10240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10241. }
  10242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10243. isKnowKey = TRUE;
  10244. }
  10245. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10246. {
  10247. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10250. {
  10251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10252. }
  10253. else
  10254. {
  10255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10256. }
  10257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10258. isKnowKey = TRUE;
  10259. }
  10260. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10261. {
  10262. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10264. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10265. {
  10266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10267. }
  10268. else
  10269. {
  10270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10271. }
  10272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10273. isKnowKey = TRUE;
  10274. }
  10275. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10276. {
  10277. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10280. {
  10281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10282. }
  10283. else
  10284. {
  10285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10286. }
  10287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10288. isKnowKey = TRUE;
  10289. }
  10290. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10291. {
  10292. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10295. {
  10296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10297. }
  10298. else
  10299. {
  10300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10301. }
  10302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10303. isKnowKey = TRUE;
  10304. }
  10305. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10306. {
  10307. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10309. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10310. {
  10311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10312. }
  10313. else
  10314. {
  10315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10316. }
  10317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10318. isKnowKey = TRUE;
  10319. }
  10320. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10321. {
  10322. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10324. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10325. {
  10326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10327. }
  10328. else
  10329. {
  10330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10331. }
  10332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10333. isKnowKey = TRUE;
  10334. }
  10335. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10336. {
  10337. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10340. {
  10341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10342. }
  10343. else
  10344. {
  10345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10346. }
  10347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10348. isKnowKey = TRUE;
  10349. }
  10350. #if 0
  10351. //For OCTT Test Case
  10352. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10353. {
  10354. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10356. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10357. {
  10358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10359. }
  10360. else
  10361. {
  10362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10363. }
  10364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10365. isKnowKey = TRUE;
  10366. }
  10367. #endif
  10368. #if 1
  10369. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10370. {
  10371. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10373. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10374. {
  10375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10376. }
  10377. else
  10378. {
  10379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10380. }
  10381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10382. isKnowKey = TRUE;
  10383. }
  10384. #endif
  10385. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10386. {
  10387. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10389. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10390. {
  10391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10392. }
  10393. else
  10394. {
  10395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10396. }
  10397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  10398. isKnowKey = TRUE;
  10399. }
  10400. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  10401. {
  10402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  10403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  10404. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  10405. {
  10406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10407. }
  10408. else
  10409. {
  10410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10411. }
  10412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  10413. isKnowKey = TRUE;
  10414. }
  10415. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  10416. {
  10417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  10418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  10419. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  10420. {
  10421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  10422. }
  10423. else
  10424. {
  10425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  10426. }
  10427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10428. isKnowKey = TRUE;
  10429. }
  10430. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  10431. {
  10432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  10433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  10434. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  10435. {
  10436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  10437. }
  10438. else
  10439. {
  10440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  10441. }
  10442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10443. isKnowKey = TRUE;
  10444. }
  10445. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  10446. {
  10447. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  10448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  10449. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  10450. {
  10451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  10452. }
  10453. else
  10454. {
  10455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  10456. }
  10457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10458. isKnowKey = TRUE;
  10459. }
  10460. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  10461. {
  10462. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  10463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  10464. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  10465. {
  10466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  10467. }
  10468. else
  10469. {
  10470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  10471. }
  10472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10473. isKnowKey = TRUE;
  10474. }
  10475. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  10476. {
  10477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  10478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  10479. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  10480. {
  10481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  10482. }
  10483. else
  10484. {
  10485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  10486. }
  10487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10488. isKnowKey = TRUE;
  10489. }
  10490. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  10491. {
  10492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  10493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  10494. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  10495. {
  10496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  10497. }
  10498. else
  10499. {
  10500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  10501. }
  10502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10503. isKnowKey = TRUE;
  10504. }
  10505. //=========================================================
  10506. if(!isEmpty && !isKnowKey)
  10507. {
  10508. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  10509. strcpy(unknownkey[UnknownKeynum], keyReq);
  10510. UnknownKeynum = UnknownKeynum + 1;
  10511. }
  10512. }
  10513. void processUnkownKey(void)
  10514. {
  10515. DEBUG_INFO("processUnkownKey\n");
  10516. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  10517. for(int index=0; index < UnknownKeynum; index++)
  10518. {
  10519. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  10520. {
  10521. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  10522. }
  10523. }
  10524. }
  10525. int setKeyValue(char *key, char *value)
  10526. {
  10527. int isSuccess = NotSupported;
  10528. int check_ascii=0;
  10529. char str[10]={0};
  10530. #ifdef Debug
  10531. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  10532. #endif
  10533. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  10534. {
  10535. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10537. {
  10538. strcpy(str, (const char*)value);
  10539. for(int i = 0; str[i]; i++){
  10540. str[i] = tolower(str[i]);
  10541. }
  10542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10543. isSuccess = ConfigurationStatus_Accepted;
  10544. }
  10545. else
  10546. {
  10547. isSuccess = ConfigurationStatus_Rejected;
  10548. }
  10549. }
  10550. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  10551. {
  10552. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10554. {
  10555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  10556. isSuccess = ConfigurationStatus_Accepted;
  10557. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  10558. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  10559. }
  10560. else
  10561. {
  10562. isSuccess = ConfigurationStatus_Rejected;
  10563. }
  10564. }
  10565. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  10566. {
  10567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10568. {
  10569. strcpy(str, (const char*)value);
  10570. for(int i = 0; str[i]; i++)
  10571. {
  10572. str[i] = tolower(str[i]);
  10573. }
  10574. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  10575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10576. isSuccess = ConfigurationStatus_Accepted;
  10577. }
  10578. else
  10579. {
  10580. isSuccess = ConfigurationStatus_Rejected;
  10581. }
  10582. }
  10583. if(strcmp(key, "BlinkRepeat") == 0)
  10584. {
  10585. //Charger.BlinkRepeat = Integer.parseInt(value);
  10586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10587. {
  10588. check_ascii = value[0];
  10589. if( (check_ascii < 48) || (check_ascii > 57) )
  10590. {
  10591. isSuccess = ConfigurationStatus_Rejected;
  10592. }
  10593. else
  10594. {
  10595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  10596. isSuccess = ConfigurationStatus_Accepted;
  10597. }
  10598. }
  10599. else
  10600. {
  10601. isSuccess = ConfigurationStatus_Rejected;
  10602. }
  10603. }
  10604. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  10605. {
  10606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10607. {
  10608. check_ascii = value[0];
  10609. if( (check_ascii < 48) || (check_ascii > 57) )
  10610. {
  10611. isSuccess = ConfigurationStatus_Rejected;
  10612. }
  10613. else
  10614. {
  10615. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  10616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  10617. isSuccess = ConfigurationStatus_Accepted;
  10618. }
  10619. }
  10620. else
  10621. {
  10622. isSuccess = ConfigurationStatus_Rejected;
  10623. }
  10624. }
  10625. if(strcmp(key, "ConnectionTimeOut") == 0 )
  10626. {
  10627. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10628. {
  10629. check_ascii = value[0];
  10630. if( (check_ascii < 48) || (check_ascii > 57) )
  10631. {
  10632. isSuccess = ConfigurationStatus_Rejected;
  10633. }
  10634. else
  10635. {
  10636. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  10637. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  10638. isSuccess = ConfigurationStatus_Accepted;
  10639. }
  10640. }
  10641. else
  10642. {
  10643. isSuccess = ConfigurationStatus_Rejected;
  10644. }
  10645. }
  10646. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  10647. {
  10648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10649. {
  10650. check_ascii = value[0];
  10651. if( (check_ascii < 48) || (check_ascii > 57) )
  10652. {
  10653. isSuccess = ConfigurationStatus_Rejected;
  10654. }
  10655. else
  10656. {
  10657. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  10659. isSuccess = ConfigurationStatus_Accepted;
  10660. }
  10661. }
  10662. else
  10663. {
  10664. isSuccess = ConfigurationStatus_Rejected;
  10665. }
  10666. }
  10667. if(strcmp(key, "HeartbeatInterval") == 0)
  10668. {
  10669. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10670. {
  10671. check_ascii = value[0];
  10672. if( (check_ascii < 48) || (check_ascii > 57) )
  10673. {
  10674. isSuccess = ConfigurationStatus_Rejected;
  10675. }
  10676. else
  10677. {
  10678. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  10680. HeartBeatWaitTime = atoi(value);
  10681. isSuccess = ConfigurationStatus_Accepted;
  10682. }
  10683. }
  10684. else
  10685. {
  10686. isSuccess = ConfigurationStatus_Rejected;
  10687. }
  10688. }
  10689. if(strcmp(key, "LightIntensity") == 0)
  10690. {
  10691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10692. {
  10693. check_ascii = value[0];
  10694. if( (check_ascii < 48) || (check_ascii > 57) )
  10695. {
  10696. isSuccess = ConfigurationStatus_Rejected;
  10697. }
  10698. else
  10699. {
  10700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10701. isSuccess = ConfigurationStatus_Accepted;
  10702. }
  10703. }
  10704. else
  10705. {
  10706. isSuccess = ConfigurationStatus_Rejected;
  10707. }
  10708. }
  10709. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10710. {
  10711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10712. {
  10713. strcpy(str, (const char*)value);
  10714. for(int i = 0; str[i]; i++)
  10715. {
  10716. str[i] = tolower(str[i]);
  10717. }
  10718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10719. isSuccess = ConfigurationStatus_Accepted;
  10720. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10721. }
  10722. else
  10723. {
  10724. isSuccess = ConfigurationStatus_Rejected;
  10725. }
  10726. }
  10727. if(strcmp(key, "LocalPreAuthorize") == 0)
  10728. {
  10729. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10730. {
  10731. strcpy(str, (const char*)value);
  10732. for(int i = 0; str[i]; i++)
  10733. {
  10734. str[i] = tolower(str[i]);
  10735. }
  10736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10737. isSuccess = ConfigurationStatus_Accepted;
  10738. }
  10739. else
  10740. {
  10741. isSuccess = ConfigurationStatus_Rejected;
  10742. }
  10743. }
  10744. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10745. {
  10746. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10747. {
  10748. check_ascii = value[0];
  10749. if( (check_ascii < 48) || (check_ascii > 57) )
  10750. {
  10751. isSuccess = ConfigurationStatus_Rejected;
  10752. }
  10753. else
  10754. {
  10755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10756. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  10757. isSuccess = ConfigurationStatus_Accepted;
  10758. }
  10759. }
  10760. else
  10761. {
  10762. isSuccess = ConfigurationStatus_Rejected;
  10763. }
  10764. }
  10765. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10766. {
  10767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10768. {
  10769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10770. isSuccess = ConfigurationStatus_Accepted;
  10771. }
  10772. else
  10773. {
  10774. isSuccess = ConfigurationStatus_Rejected;
  10775. }
  10776. }
  10777. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  10778. {
  10779. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10780. {
  10781. check_ascii = value[0];
  10782. if( (check_ascii < 48) || (check_ascii > 57) )
  10783. {
  10784. isSuccess = ConfigurationStatus_Rejected;
  10785. }
  10786. else
  10787. {
  10788. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  10790. isSuccess = ConfigurationStatus_Accepted;
  10791. }
  10792. }
  10793. else
  10794. {
  10795. isSuccess = ConfigurationStatus_Rejected;
  10796. }
  10797. }
  10798. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10799. {
  10800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10801. {
  10802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10803. isSuccess = ConfigurationStatus_Accepted;
  10804. }
  10805. else
  10806. {
  10807. isSuccess = ConfigurationStatus_Rejected;
  10808. }
  10809. }
  10810. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  10811. {
  10812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10813. {
  10814. check_ascii = value[0];
  10815. if( (check_ascii < 48) || (check_ascii > 57) )
  10816. {
  10817. isSuccess = ConfigurationStatus_Rejected;
  10818. }
  10819. else
  10820. {
  10821. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  10823. isSuccess = ConfigurationStatus_Accepted;
  10824. }
  10825. }
  10826. else
  10827. {
  10828. isSuccess = ConfigurationStatus_Rejected;
  10829. }
  10830. }
  10831. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10832. {
  10833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10834. {
  10835. check_ascii = value[0];
  10836. if( (check_ascii < 48) || (check_ascii > 57) )
  10837. {
  10838. isSuccess = ConfigurationStatus_Rejected;
  10839. }
  10840. else
  10841. {
  10842. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10844. isSuccess = ConfigurationStatus_Accepted;
  10845. }
  10846. }
  10847. else
  10848. {
  10849. isSuccess = ConfigurationStatus_Rejected;
  10850. }
  10851. }
  10852. if(strcmp(key, "MinimumStatusDuration") == 0)
  10853. {
  10854. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10855. {
  10856. check_ascii = value[0];
  10857. if( (check_ascii < 48) || (check_ascii > 57) )
  10858. {
  10859. isSuccess = ConfigurationStatus_Rejected;
  10860. }
  10861. else
  10862. {
  10863. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10865. isSuccess = ConfigurationStatus_Accepted;
  10866. }
  10867. }
  10868. else
  10869. {
  10870. isSuccess = ConfigurationStatus_Rejected;
  10871. }
  10872. }
  10873. if(strcmp(key, "NumberOfConnectors") == 0)
  10874. {
  10875. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10876. {
  10877. check_ascii = value[0];
  10878. if( (check_ascii < 48) || (check_ascii > 57) )
  10879. {
  10880. isSuccess = ConfigurationStatus_Rejected;
  10881. }
  10882. else
  10883. {
  10884. //Charger.ResetRetries = Integer.parseInt(value);
  10885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  10886. isSuccess = ConfigurationStatus_Accepted;
  10887. }
  10888. }
  10889. else
  10890. {
  10891. isSuccess = ConfigurationStatus_Rejected;
  10892. }
  10893. }
  10894. if(strcmp(key, "ResetRetries") == 0)
  10895. {
  10896. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10897. {
  10898. check_ascii = value[0];
  10899. if( (check_ascii < 48) || (check_ascii > 57) )
  10900. {
  10901. isSuccess = ConfigurationStatus_Rejected;
  10902. }
  10903. else
  10904. {
  10905. //Charger.ResetRetries = Integer.parseInt(value);
  10906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10907. isSuccess = ConfigurationStatus_Accepted;
  10908. }
  10909. }
  10910. else
  10911. {
  10912. isSuccess = ConfigurationStatus_Rejected;
  10913. }
  10914. }
  10915. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10916. {
  10917. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10918. {
  10919. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10920. isSuccess = ConfigurationStatus_Accepted;
  10921. }
  10922. else
  10923. {
  10924. isSuccess = ConfigurationStatus_Rejected;
  10925. }
  10926. }
  10927. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  10928. {
  10929. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10930. {
  10931. check_ascii = value[0];
  10932. if( (check_ascii < 48) || (check_ascii > 57) )
  10933. {
  10934. isSuccess = ConfigurationStatus_Rejected;
  10935. }
  10936. else
  10937. {
  10938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  10939. isSuccess = ConfigurationStatus_Accepted;
  10940. }
  10941. }
  10942. else
  10943. {
  10944. isSuccess = ConfigurationStatus_Rejected;
  10945. }
  10946. }
  10947. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10948. {
  10949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10950. {
  10951. strcpy(str, (const char*)value);
  10952. for(int i = 0; str[i]; i++)
  10953. {
  10954. str[i] = tolower(str[i]);
  10955. }
  10956. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10958. isSuccess = ConfigurationStatus_Accepted;
  10959. }
  10960. else
  10961. {
  10962. isSuccess = ConfigurationStatus_Rejected;
  10963. }
  10964. }
  10965. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10966. {
  10967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10968. {
  10969. strcpy(str, (const char*)value);
  10970. for(int i = 0; str[i]; i++)
  10971. {
  10972. str[i] = tolower(str[i]);
  10973. }
  10974. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10976. isSuccess = ConfigurationStatus_Accepted;
  10977. }
  10978. else
  10979. {
  10980. isSuccess = ConfigurationStatus_Rejected;
  10981. }
  10982. }
  10983. if(strcmp(key, "StopTxnAlignedData") == 0)
  10984. {
  10985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10986. {
  10987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10988. isSuccess = ConfigurationStatus_Accepted;
  10989. }
  10990. else
  10991. {
  10992. isSuccess = ConfigurationStatus_Rejected;
  10993. }
  10994. }
  10995. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  10996. {
  10997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10998. {
  10999. check_ascii = value[0];
  11000. if( (check_ascii < 48) || (check_ascii > 57) )
  11001. {
  11002. isSuccess = ConfigurationStatus_Rejected;
  11003. }
  11004. else
  11005. {
  11006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11007. isSuccess = ConfigurationStatus_Accepted;
  11008. }
  11009. }
  11010. else
  11011. {
  11012. isSuccess = ConfigurationStatus_Rejected;
  11013. }
  11014. }
  11015. if(strcmp(key, "StopTxnSampledData") == 0)
  11016. {
  11017. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11018. {
  11019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11020. isSuccess = ConfigurationStatus_Accepted;
  11021. }
  11022. else
  11023. {
  11024. isSuccess = ConfigurationStatus_Rejected;
  11025. }
  11026. }
  11027. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11028. {
  11029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11030. {
  11031. check_ascii = value[0];
  11032. if( (check_ascii < 48) || (check_ascii > 57) )
  11033. {
  11034. isSuccess = ConfigurationStatus_Rejected;
  11035. }
  11036. else
  11037. {
  11038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11039. isSuccess = ConfigurationStatus_Accepted;
  11040. }
  11041. }
  11042. else
  11043. {
  11044. isSuccess = ConfigurationStatus_Rejected;
  11045. }
  11046. }
  11047. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11048. {
  11049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11050. {
  11051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11052. isSuccess = ConfigurationStatus_Accepted;
  11053. }
  11054. else
  11055. {
  11056. isSuccess = ConfigurationStatus_Rejected;
  11057. }
  11058. }
  11059. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11060. {
  11061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11062. {
  11063. check_ascii = value[0];
  11064. if( (check_ascii < 48) || (check_ascii > 57) )
  11065. {
  11066. isSuccess = ConfigurationStatus_Rejected;
  11067. }
  11068. else
  11069. {
  11070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11071. isSuccess = ConfigurationStatus_Accepted;
  11072. }
  11073. }
  11074. else
  11075. {
  11076. isSuccess = ConfigurationStatus_Rejected;
  11077. }
  11078. }
  11079. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11080. {
  11081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11082. {
  11083. check_ascii = value[0];
  11084. if( (check_ascii < 48) || (check_ascii > 57) )
  11085. {
  11086. isSuccess = ConfigurationStatus_Rejected;
  11087. }
  11088. else
  11089. {
  11090. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11092. TransactionMessageAttemptsValue = atoi(value);
  11093. isSuccess = ConfigurationStatus_Accepted;
  11094. }
  11095. }
  11096. else
  11097. {
  11098. isSuccess = ConfigurationStatus_Rejected;
  11099. }
  11100. }
  11101. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11102. {
  11103. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11104. {
  11105. check_ascii = value[0];
  11106. if( (check_ascii < 48) || (check_ascii > 57) )
  11107. {
  11108. isSuccess = ConfigurationStatus_Rejected;
  11109. }
  11110. else
  11111. {
  11112. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11114. TransactionMessageRetryIntervalValue = atoi(value);
  11115. isSuccess = ConfigurationStatus_Accepted;
  11116. }
  11117. }
  11118. else
  11119. {
  11120. isSuccess = ConfigurationStatus_Rejected;
  11121. }
  11122. }
  11123. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11124. {
  11125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11126. {
  11127. strcpy(str, (const char*)value);
  11128. for(int i = 0; str[i]; i++)
  11129. {
  11130. str[i] = tolower(str[i]);
  11131. }
  11132. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11134. isSuccess = ConfigurationStatus_Accepted;
  11135. }
  11136. else
  11137. {
  11138. isSuccess = ConfigurationStatus_Rejected;
  11139. }
  11140. }
  11141. if(strcmp(key, "WebSocketPingInterval") == 0)
  11142. {
  11143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11144. {
  11145. check_ascii = value[0];
  11146. if( (check_ascii < 48) || (check_ascii > 57) )
  11147. {
  11148. isSuccess = ConfigurationStatus_Rejected;
  11149. }
  11150. else
  11151. {
  11152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11153. isSuccess = ConfigurationStatus_Accepted;
  11154. }
  11155. }
  11156. else
  11157. {
  11158. isSuccess = ConfigurationStatus_Rejected;
  11159. }
  11160. }
  11161. #if 0
  11162. //For OCPP Test Case
  11163. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11164. {
  11165. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11166. {
  11167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11168. isSuccess = ConfigurationStatus_Accepted;
  11169. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11170. }
  11171. else
  11172. {
  11173. isSuccess = ConfigurationStatus_Rejected;
  11174. }
  11175. }
  11176. #endif
  11177. #if 1
  11178. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11179. {
  11180. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11181. {
  11182. strcpy(str, (const char*)value);
  11183. for(int i = 0; str[i]; i++)
  11184. {
  11185. str[i] = tolower(str[i]);
  11186. }
  11187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11188. isSuccess = ConfigurationStatus_Accepted;
  11189. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11190. }
  11191. else
  11192. {
  11193. isSuccess = ConfigurationStatus_Rejected;
  11194. }
  11195. }
  11196. #endif
  11197. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11198. {
  11199. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11200. {
  11201. check_ascii = value[0];
  11202. if( (check_ascii < 48) || (check_ascii > 57) )
  11203. {
  11204. isSuccess = ConfigurationStatus_Rejected;
  11205. }
  11206. else
  11207. {
  11208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11209. isSuccess = ConfigurationStatus_Accepted;
  11210. }
  11211. }
  11212. else
  11213. {
  11214. isSuccess = ConfigurationStatus_Rejected;
  11215. }
  11216. }
  11217. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11218. {
  11219. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11220. {
  11221. check_ascii = value[0];
  11222. if( (check_ascii < 48) || (check_ascii > 57) )
  11223. {
  11224. isSuccess = ConfigurationStatus_Rejected;
  11225. }
  11226. else
  11227. {
  11228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11229. isSuccess = ConfigurationStatus_Accepted;
  11230. }
  11231. }
  11232. else
  11233. {
  11234. isSuccess = ConfigurationStatus_Rejected;
  11235. }
  11236. }
  11237. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11238. {
  11239. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11240. {
  11241. strcpy(str, (const char*)value);
  11242. for(int i = 0; str[i]; i++)
  11243. {
  11244. str[i] = tolower(str[i]);
  11245. }
  11246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11247. isSuccess = ConfigurationStatus_Accepted;
  11248. }
  11249. else
  11250. {
  11251. isSuccess = ConfigurationStatus_Rejected;
  11252. }
  11253. }
  11254. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11255. {
  11256. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11257. {
  11258. check_ascii = value[0];
  11259. if( (check_ascii < 48) || (check_ascii > 57) )
  11260. {
  11261. isSuccess = ConfigurationStatus_Rejected;
  11262. }
  11263. else
  11264. {
  11265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11266. isSuccess = ConfigurationStatus_Accepted;
  11267. }
  11268. }
  11269. else
  11270. {
  11271. isSuccess = ConfigurationStatus_Rejected;
  11272. }
  11273. }
  11274. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11275. {
  11276. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11277. {
  11278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11279. isSuccess = ConfigurationStatus_Accepted;
  11280. }
  11281. else
  11282. {
  11283. isSuccess = ConfigurationStatus_Rejected;
  11284. }
  11285. }
  11286. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11287. {
  11288. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11289. {
  11290. check_ascii = value[0];
  11291. if( (check_ascii < 48) || (check_ascii > 57) )
  11292. {
  11293. isSuccess = ConfigurationStatus_Rejected;
  11294. }
  11295. else
  11296. {
  11297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11298. isSuccess = ConfigurationStatus_Accepted;
  11299. }
  11300. }
  11301. else
  11302. {
  11303. isSuccess = ConfigurationStatus_Rejected;
  11304. }
  11305. }
  11306. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11307. {
  11308. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11309. {
  11310. strcpy(str, (const char*)value);
  11311. for(int i = 0; str[i]; i++)
  11312. {
  11313. str[i] = tolower(str[i]);
  11314. }
  11315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11316. isSuccess = ConfigurationStatus_Accepted;
  11317. }
  11318. else
  11319. {
  11320. isSuccess = ConfigurationStatus_Rejected;
  11321. }
  11322. }
  11323. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11324. {
  11325. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11326. {
  11327. check_ascii = value[0];
  11328. if( (check_ascii < 48) || (check_ascii > 57) )
  11329. {
  11330. isSuccess = ConfigurationStatus_Rejected;
  11331. }
  11332. else
  11333. {
  11334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11335. isSuccess = ConfigurationStatus_Accepted;
  11336. }
  11337. }
  11338. else
  11339. {
  11340. isSuccess = ConfigurationStatus_Rejected;
  11341. }
  11342. }
  11343. return isSuccess;
  11344. }
  11345. int updateSetting(char *key, char *value)
  11346. {
  11347. mtrace();
  11348. int isSuccess = FALSE;
  11349. char string[1000]={0}, buffer[1000]={0};
  11350. char strtemp[50]={0};
  11351. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11352. int pos, c = 0;
  11353. char *loc;
  11354. int pos1=0;
  11355. FILE *f = fopen("/var/www/settings1", "r");
  11356. if(f == NULL)
  11357. {
  11358. #ifdef Debug
  11359. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11360. #endif
  11361. return isSuccess;
  11362. }
  11363. fseek(f, 0, SEEK_END);
  11364. long fsize = ftell(f);
  11365. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11366. fread(string, 1, fsize, f);
  11367. fclose(f);
  11368. string[fsize] = 0;
  11369. loc = strstr(string, key);
  11370. if(loc != NULL)
  11371. {
  11372. DEBUG_INFO("key exist!\n");
  11373. pos = loc - string-1;
  11374. f = fopen("/var/www/settings1", "w");
  11375. strncpy(buffer, string, pos);
  11376. fprintf(f, "%s", buffer);
  11377. memset(sstr ,0, sizeof(sstr) );
  11378. c = 0;
  11379. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11380. {
  11381. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11382. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11383. c++;
  11384. }
  11385. sstr[c] = '\0';
  11386. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11387. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11388. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11389. memset(buffer ,0, sizeof(buffer) );
  11390. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11391. //printf("buffer=%s",buffer);
  11392. fprintf(f, "%s", buffer);
  11393. fclose(f);
  11394. }
  11395. else
  11396. {
  11397. printf("key not exist!\n");
  11398. f = fopen("/var/www/settings1", "w+");
  11399. fputs(string, f);
  11400. fseek(f, -1, SEEK_CUR);
  11401. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  11402. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  11403. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  11404. fclose(f);
  11405. }
  11406. isSuccess = TRUE;
  11407. return isSuccess;
  11408. }
  11409. int TransactionMessageAttemptsGet(void)
  11410. {
  11411. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11412. }
  11413. int FirstHeartBeatResponse(void)
  11414. {
  11415. return FirstHeartBeat;
  11416. }
  11417. int TransactionMessageRetryIntervalGet(void)
  11418. {
  11419. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11420. }
  11421. #define SA struct sockaddr
  11422. #define MAXBUF 1024
  11423. //static int m_socket_data;
  11424. //static int sockfd;
  11425. int ReadHttpStatus(int sock){
  11426. //char c;
  11427. char buff[1024]="",*ptr=buff+1;
  11428. int bytes_received, status;
  11429. DEBUG_INFO("Begin Response ..\n");
  11430. while((bytes_received = recv(sock, ptr, 1, 0))){
  11431. if(bytes_received==-1){
  11432. perror("ReadHttpStatus");
  11433. exit(1);
  11434. }
  11435. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  11436. ptr++;
  11437. }
  11438. *ptr=0;
  11439. ptr=buff+1;
  11440. sscanf(ptr,"%*s %d ", &status);
  11441. DEBUG_INFO("%s\n",ptr);
  11442. DEBUG_INFO("status=%d\n",status);
  11443. DEBUG_INFO("End Response ..\n");
  11444. return (bytes_received>0)?status:0;
  11445. }
  11446. //the only filed that it parsed is 'Content-Length'
  11447. int ParseHeader(int sock){
  11448. //char c;
  11449. char buff[1024]="",*ptr=buff+4;
  11450. int bytes_received;
  11451. DEBUG_INFO("Begin HEADER ..\n");
  11452. while((bytes_received = recv(sock, ptr, 1, 0))){
  11453. if(bytes_received==-1){
  11454. perror("Parse Header");
  11455. exit(1);
  11456. }
  11457. if(
  11458. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  11459. (ptr[-1]=='\r') && (*ptr=='\n' )
  11460. ) break;
  11461. ptr++;
  11462. }
  11463. *ptr=0;
  11464. ptr=buff+4;
  11465. //printf("%s",ptr);
  11466. if(bytes_received){
  11467. ptr=strstr(ptr,"Content-Length:");
  11468. if(ptr){
  11469. sscanf(ptr,"%*s %d",&bytes_received);
  11470. }else
  11471. bytes_received=-1; //unknown size
  11472. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  11473. }
  11474. DEBUG_INFO("End HEADER ..\n");
  11475. return bytes_received ;
  11476. }
  11477. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  11478. {
  11479. char rmFileCmd[100]={0};
  11480. char FilePath[100]={0};
  11481. char ftpbuf[200];
  11482. int systemresult;
  11483. //DEBUG_INFO("filename=%s\n",filename);
  11484. //DEBUG_INFO("url=%s\n",url);
  11485. sprintf(FilePath,"../mnt/%s",filename);
  11486. if((access(FilePath,F_OK))!=-1)
  11487. {
  11488. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11489. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11490. system(rmFileCmd);
  11491. }
  11492. memset(ftpbuf, 0, sizeof(ftpbuf));
  11493. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11494. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11495. systemresult = system(ftpbuf);
  11496. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11497. if(systemresult != 0)
  11498. {
  11499. DEBUG_INFO("http DownLoad error!\n");
  11500. return FALSE;
  11501. }
  11502. return TRUE;
  11503. }
  11504. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  11505. {
  11506. char rmFileCmd[100]={0};
  11507. char FilePath[100]={0};
  11508. char ftpbuf[200];
  11509. int systemresult;
  11510. //char temp[100];
  11511. #if 0
  11512. struct hostent* server;
  11513. char *IPbuffer;
  11514. server = gethostbyname(location);
  11515. // To convert an Internet network
  11516. // address into ASCII string
  11517. IPbuffer = inet_ntoa(*((struct in_addr*)
  11518. server->h_addr_list[0]));
  11519. #endif
  11520. sprintf(FilePath,"../mnt/%s",filename);
  11521. if((access(FilePath,F_OK))!=-1)
  11522. {
  11523. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11524. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11525. system(rmFileCmd);
  11526. }
  11527. memset(ftpbuf, 0, sizeof(ftpbuf));
  11528. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11529. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  11530. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11531. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11532. systemresult = system(ftpbuf);
  11533. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11534. if(systemresult != 0)
  11535. {
  11536. printf("wget error!\n");
  11537. return FALSE;
  11538. }
  11539. return TRUE;
  11540. }
  11541. int httpUploadFile(char *location, char *path, char *filename,char *url)
  11542. {
  11543. char rmFileCmd[100]={0};
  11544. char FilePath[100]={0};
  11545. char ftpbuf[200];
  11546. char filenametemp[60]={0};
  11547. int systemresult;
  11548. //DEBUG_INFO("filename=%s\n",filename);
  11549. //DEBUG_INFO("url=%s\n",url);
  11550. sprintf(FilePath,"%s","../mnt/upload_file.txt");
  11551. if((access(FilePath,F_OK))!=-1)
  11552. {
  11553. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11554. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11555. system(rmFileCmd);
  11556. }
  11557. FILE *fp = fopen("../mnt/upload_file.txt", "w+");
  11558. if(fp == NULL)
  11559. {
  11560. DEBUG_INFO("log is NULL\n");
  11561. return FALSE;
  11562. }
  11563. else
  11564. {
  11565. fprintf(fp, "%s\n", url);
  11566. sscanf(filename, "%*2[.]%s", filenametemp);
  11567. fprintf(fp, "%s\n", filenametemp);
  11568. fclose(fp);
  11569. }
  11570. memset(ftpbuf, 0, sizeof(ftpbuf));
  11571. sprintf(ftpbuf, "%s","../bin/php-cgi /var/www/ocpp_upload.php");
  11572. systemresult = system(ftpbuf);
  11573. DEBUG_INFO("systemresult=%d\n",systemresult);
  11574. if(systemresult != 0)
  11575. {
  11576. DEBUG_INFO("http upload error!\n");
  11577. return FALSE;
  11578. }
  11579. return TRUE;
  11580. }
  11581. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  11582. {
  11583. struct hostent* server;
  11584. char *IPbuffer;
  11585. char ftpbuf[200];
  11586. int systemresult;
  11587. // To retrieve host information
  11588. server = gethostbyname(location);
  11589. // To convert an Internet network
  11590. // address into ASCII string
  11591. IPbuffer = inet_ntoa(*((struct in_addr*)
  11592. server->h_addr_list[0]));
  11593. memset(ftpbuf, 0, sizeof(ftpbuf));
  11594. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  11595. /* format : ftpput -u username -p passwd IP target source*/
  11596. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  11597. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11598. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11599. systemresult = system(ftpbuf);
  11600. DEBUG_INFO("systemresult=%d\n",systemresult);
  11601. if(systemresult != 0)
  11602. {
  11603. DEBUG_INFO("ftpput error!\n");
  11604. return FALSE;
  11605. }
  11606. return TRUE;
  11607. }
  11608. int SettingChargingRecord(int target, int transactionId)
  11609. {
  11610. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11611. {
  11612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11613. {
  11614. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11615. {
  11616. addBuff(target, transactionId, 0);
  11617. return TRUE;
  11618. }
  11619. }
  11620. for (int index = 0; index < CCS_QUANTITY; index++)
  11621. {
  11622. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11623. {
  11624. addBuff(target, transactionId, 0);
  11625. return TRUE;
  11626. }
  11627. }
  11628. for (int index = 0; index < GB_QUANTITY; index++)
  11629. {
  11630. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11631. {
  11632. addBuff(target, transactionId, 0);
  11633. return TRUE;
  11634. }
  11635. }
  11636. }
  11637. else
  11638. {
  11639. for (int index = 0; index < AC_QUANTITY; index++)
  11640. {
  11641. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11642. {
  11643. addBuff(target, transactionId, 0);
  11644. return TRUE;
  11645. }
  11646. }
  11647. }
  11648. return FALSE;
  11649. }
  11650. int addBuff(int gun_idx, int user_id, int cmd_sn)
  11651. {
  11652. int isSuccess = FALSE;
  11653. //char *query = NULL;
  11654. sqlite3_stmt *stmt;
  11655. int rc; // return code
  11656. char str[20];
  11657. sprintf(str,"%d",user_id);
  11658. 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 */
  11659. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  11660. rc = sqlite3_step(stmt); /* 3 */
  11661. if (rc != SQLITE_DONE) {
  11662. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  11663. goto out;
  11664. }
  11665. sqlite3_finalize(stmt);
  11666. // free(query);
  11667. out:
  11668. //----------------------
  11669. // close SQLite database
  11670. //----------------------
  11671. sqlite3_close(db);
  11672. printf("database closed.\n");
  11673. return isSuccess;
  11674. }
  11675. /**
  11676. * Place the contents of the specified file into a memory buffer
  11677. *
  11678. * @param[in] filename The path and name of the file to read
  11679. * @param[out] filebuffer A pointer to the contents in memory
  11680. * @return status 0 success, 1 on failure
  11681. */
  11682. int get_file_contents(const char* filename, char** outbuffer) {
  11683. FILE* file = NULL;
  11684. long filesize;
  11685. const int blocksize = 1;
  11686. size_t readsize;
  11687. char* filebuffer;
  11688. // Open the file
  11689. file = fopen(filename, "r");
  11690. if (NULL == file)
  11691. {
  11692. printf("'%s' not opened\n", filename);
  11693. exit(EXIT_FAILURE);
  11694. }
  11695. // Determine the file size
  11696. fseek(file, 0, SEEK_END);
  11697. filesize = ftell(file);
  11698. rewind (file);
  11699. // Allocate memory for the file contents
  11700. filebuffer = (char*) malloc(sizeof(char) * filesize);
  11701. *outbuffer = filebuffer;
  11702. if (filebuffer == NULL)
  11703. {
  11704. fputs ("malloc out-of-memory", stderr);
  11705. exit(EXIT_FAILURE);
  11706. }
  11707. // Read in the file
  11708. readsize = fread(filebuffer, blocksize, filesize, file);
  11709. if (readsize != filesize)
  11710. {
  11711. fputs ("didn't read file completely",stderr);
  11712. exit(EXIT_FAILURE);
  11713. }
  11714. // Clean exit
  11715. fclose(file);
  11716. return EXIT_SUCCESS;
  11717. }
  11718. static int selectSqlCount = 0;
  11719. static int callback(void *data, int argc, char **argv, char **azColName){
  11720. int i;
  11721. printf("%s: ", (const char*)data);
  11722. selectSqlCount = argc;
  11723. for(i = 0; i<argc; i++){
  11724. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  11725. }
  11726. printf("\n");
  11727. return 0;
  11728. }
  11729. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  11730. //int i;
  11731. //printf("%s:\n", (const char*)data);
  11732. localversion = argv[5] ? atoi(argv[5]) : 0;
  11733. printf("localversion=%d\n", localversion);
  11734. return 0;
  11735. }
  11736. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  11737. //int i;
  11738. //printf("%s:\n", (const char*)data);
  11739. //idTag
  11740. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  11741. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  11742. //parentIdTag
  11743. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  11744. //expir_date
  11745. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  11746. //status
  11747. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  11748. //version
  11749. idTagQuery.listVersionInt = atoi(argv[5]);
  11750. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  11751. return 0;
  11752. }
  11753. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  11754. int i;
  11755. //printf("%s:\n", (const char*)data);
  11756. #if 1
  11757. for(i=0; i<argc; i++){
  11758. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  11759. }
  11760. //printf("");
  11761. #endif
  11762. // localversion = argv[5] ? atoi(argv[5]) : 0;
  11763. // printf("localversion=%d\n", localversion);
  11764. return 0;
  11765. }
  11766. /** sqlite3_exec的回调。
  11767. *
  11768. * 向控制台打印查询的结果。
  11769. *
  11770. * @param in data 传递给回调函数的数据。
  11771. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  11772. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  11773. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  11774. * @return 状态码。
  11775. */
  11776. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  11777. {
  11778. for (int i = 0; i < n_columns; i++)
  11779. {
  11780. DEBUG_INFO("%s/t", col_values[i]);
  11781. }
  11782. DEBUG_INFO("/n");
  11783. return 0;
  11784. }
  11785. void OCPP_getListVerion()
  11786. {
  11787. int rc = 0;
  11788. // const char* data = "Callback function called";
  11789. char sql[100];
  11790. char zErrMsg[100];
  11791. memset(sql, 0, 100);
  11792. memset(zErrMsg, 0, 100);
  11793. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  11794. /* Execute SQL statement */
  11795. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  11796. DEBUG_INFO("rc=%d\n",rc);
  11797. if( rc != SQLITE_OK ){
  11798. DEBUG_INFO("SQL error: %s", zErrMsg);
  11799. //sqlite3_free(zErrMsg);
  11800. }else{
  11801. DEBUG_INFO("Operation done successfully");
  11802. }
  11803. }
  11804. void OCPP_getIdTag(char *idTag)
  11805. {
  11806. int rc = 0;
  11807. // const char* data = "Callback function called";
  11808. char sql[100];
  11809. char zErrMsg[100];
  11810. memset(sql, 0, 100);
  11811. memset(zErrMsg, 0, 100);
  11812. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  11813. memset(&idTagQuery, 0, sizeof(idTagQuery));
  11814. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11815. /* Execute SQL statement */
  11816. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  11817. if( rc != SQLITE_OK ){
  11818. DEBUG_INFO("SQL error: %s", zErrMsg);
  11819. //sqlite3_free(zErrMsg);
  11820. }else{
  11821. printf("Operation done successfully");
  11822. }
  11823. //return ver;
  11824. }
  11825. void OCPP_get_TableAuthlocalAllData(void)
  11826. {
  11827. int rc = 0;
  11828. // const char* data = "Callback function called";
  11829. char sql[100];
  11830. char zErrMsg[100];
  11831. memset(sql, 0, 100);
  11832. memset(zErrMsg, 0, 100);
  11833. sprintf(sql,"select * from ocpp_auth_local ");
  11834. /* Execute SQL statement */
  11835. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  11836. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  11837. if( rc != SQLITE_OK ){
  11838. DEBUG_INFO("SQL error: %s", zErrMsg);
  11839. //sqlite3_free(zErrMsg);
  11840. }else{
  11841. DEBUG_INFO("Operation done successfully");
  11842. }
  11843. //return ver;
  11844. }
  11845. int OCPP_cleanLocalList()
  11846. {
  11847. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  11848. char *errMsg = 0;
  11849. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  11850. if (SQLITE_OK != rc)
  11851. {
  11852. DEBUG_INFO("%s\n",errMsg);
  11853. return FALSE;
  11854. }
  11855. else
  11856. {
  11857. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  11858. }
  11859. return TRUE;
  11860. }
  11861. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11862. {
  11863. int isSuccess = FALSE;
  11864. int ret = 0;
  11865. //const char* data = "Callback function called";
  11866. char sql[200];
  11867. char zErrMsg[100];
  11868. memset(sql, 0, 200);
  11869. memset(zErrMsg, 0, 100);
  11870. 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);
  11871. //* Execute SQL statement */
  11872. //zErrMsg = 0;
  11873. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  11874. if( ret != SQLITE_OK ){
  11875. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  11876. // free(zErrMsg);
  11877. // free(sql);
  11878. return isSuccess;
  11879. }
  11880. DEBUG_INFO("successfully Insert records created\n");
  11881. isSuccess = TRUE;
  11882. return isSuccess;
  11883. }
  11884. void OCPP_deleteIdTag(char *idTag)
  11885. {
  11886. //int ver = 0;
  11887. //int isSuccess = FALSE;
  11888. int rc = 0;
  11889. char sql[100];
  11890. char zErrMsg[100];
  11891. memset(sql, 0, 100);
  11892. memset(zErrMsg, 0, 100);
  11893. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  11894. //* Execute SQL statement */
  11895. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  11896. if( rc != SQLITE_OK ){
  11897. DEBUG_INFO("SQL error: %s", zErrMsg);
  11898. //sqlite3_free(zErrMsg);
  11899. }else{
  11900. DEBUG_INFO("Operation done successfully");
  11901. }
  11902. }
  11903. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11904. {
  11905. int isSuccess = FALSE;
  11906. int ret = 0;
  11907. const char* data = "Callback function called";
  11908. char sql[200];
  11909. char zErrMsg[100];
  11910. memset(sql, 0, 200);
  11911. memset(zErrMsg, 0, 100);
  11912. //* selectFromTable */
  11913. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  11914. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11915. //* Execute SQL statement */
  11916. selectSqlCount = 0;
  11917. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11918. if( ret != SQLITE_OK ){
  11919. printf("Error SQL: %s\n", zErrMsg);
  11920. }
  11921. printf("successfully select operation done\n");
  11922. memset(sql, 0, 200);
  11923. memset(zErrMsg, 0, 100);
  11924. if(selectSqlCount == 0)
  11925. {
  11926. //Insert
  11927. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  11928. 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);
  11929. DEBUG_INFO("sql:%s\n", sql);
  11930. //* Execute SQL statement */
  11931. //zErrMsg = 0;
  11932. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  11933. if( ret != SQLITE_OK ){
  11934. printf("SQL error: %s\n", zErrMsg);
  11935. return isSuccess;
  11936. }
  11937. DEBUG_INFO("successfully Insert records created\n");
  11938. isSuccess = TRUE;
  11939. }
  11940. else
  11941. {
  11942. //Update
  11943. //* Create merged SQL statement */
  11944. 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);
  11945. /* Execute SQL statement */
  11946. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11947. if( ret != SQLITE_OK ){
  11948. printf("SQL error: %s\n", zErrMsg);
  11949. //sqlite3_free(zErrMsg);
  11950. //sqlite3_free(sql);
  11951. return isSuccess;
  11952. }
  11953. DEBUG_INFO("Successfully operation done \n");
  11954. isSuccess = TRUE;
  11955. }
  11956. return isSuccess;
  11957. }
  11958. int GetOcppServerURL()
  11959. {
  11960. int result = FALSE;
  11961. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  11962. memset(OcppHost, 0, sizeof(OcppHost));
  11963. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  11964. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  11965. {
  11966. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  11967. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  11968. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11969. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  11970. result = TRUE;
  11971. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  11972. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  11973. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  11974. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  11975. goto End;
  11976. }
  11977. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  11978. {
  11979. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  11980. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  11981. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11982. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  11983. result = TRUE;
  11984. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  11985. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  11986. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  11987. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  11988. goto End;
  11989. }
  11990. else
  11991. {
  11992. strcpy(OcppHost,"");
  11993. }
  11994. End:
  11995. return result;
  11996. }
  11997. int GetOcppPath()
  11998. {
  11999. int result = FALSE;
  12000. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12001. {
  12002. if(OcppTempPath == NULL)
  12003. {
  12004. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12005. }
  12006. else
  12007. {
  12008. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12009. }
  12010. result = TRUE;
  12011. goto End;
  12012. }
  12013. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12014. {
  12015. if(OcppTempPath == NULL)
  12016. {
  12017. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12018. }
  12019. else
  12020. {
  12021. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12022. }
  12023. result = TRUE;
  12024. goto End;
  12025. }
  12026. else
  12027. {
  12028. strcpy(OcppPath,"");
  12029. }
  12030. End:
  12031. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12032. return result;
  12033. }
  12034. int GetOcppPort()
  12035. {
  12036. return OcppPort;
  12037. }
  12038. int GetOcppConnStatus(void)
  12039. {
  12040. return ShmOCPP16Data->OcppConnStatus;
  12041. }
  12042. void SetOcppConnStatus(uint8_t status)
  12043. {
  12044. ShmOCPP16Data->OcppConnStatus = status;
  12045. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12046. if(status == FALSE)
  12047. {
  12048. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12049. {
  12050. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12051. }
  12052. else
  12053. {
  12054. SystemInitial = AC_QUANTITY;
  12055. }
  12056. }
  12057. }
  12058. int GetHeartBeatWithNOResponse(void)
  12059. {
  12060. return HeartBeatWithNOResponse;
  12061. }
  12062. void SetHeartBeatWithNOResponse(void)
  12063. {
  12064. HeartBeatWithNOResponse = 0;
  12065. }
  12066. int GetTransactionId(int gunindex)
  12067. {
  12068. return TransactionId[gunindex];
  12069. }
  12070. void SetTransactionIdZero(int gunindex)
  12071. {
  12072. TransactionId[gunindex] = 0;
  12073. }
  12074. int InternetDisconnect(void)
  12075. {
  12076. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12077. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12078. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12079. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12080. }
  12081. void GetChargingProfileRequest(int gunindex)
  12082. {
  12083. mtrace();
  12084. //int connectorIdInt, durationInt;
  12085. //char chargingRateUnitStr[4]={0};
  12086. int tempdurationInt = 0;
  12087. int tempchargingProfileId = 0;
  12088. int tempstackLevel = 0;
  12089. int temptransactionId = 0;
  12090. float tempminChargingRateFloat = 0.0;
  12091. char tempchargingProfilePurposeStr[24]={0};
  12092. char tempchargingProfileKindStr[12]={0};
  12093. char temprecurrencyKindStr[8]={0};
  12094. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12095. char tempvalidToStr[28]={0};
  12096. int tempStartPeriodInt = 0;
  12097. float tempLimitInt = 0.0;//0.1;
  12098. int tempNumberPhasesInt=0;
  12099. char fname[200];
  12100. //char comfirmstr[20];
  12101. float MinChargingRate =0.0;
  12102. double diff_t;
  12103. struct tm tp;
  12104. FILE *fptr1;//, *fptr2;
  12105. int c = 0;
  12106. char * pch;
  12107. char *loc;
  12108. char sstr[200]={ 0 };
  12109. int n_chargingProfile = 0;
  12110. int n_SchedulePeriods = 0;
  12111. char SchedulePeriodList[10][200]={0};
  12112. char sLineWord[800]={0};
  12113. char word[1000]={0};
  12114. int confirmPeriods = 0;
  12115. struct StructProfile ChargePointMaxProfile;
  12116. struct StructProfile TxDefaultProfile;
  12117. struct StructProfile TxProfile;
  12118. struct StructProfile TxDefaultProfiletemp[2]={0};
  12119. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12120. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12121. struct StructChargingProfile TxProfile_TEMP={0};
  12122. int TxDefaultProfileFileIsNull=FALSE;
  12123. int ChargePointMaxProfileIsNull=FALSE;
  12124. int TxProfileIsNull=FALSE;
  12125. // int CompositeSceduleIndex = 0;
  12126. char ChargePointMaxProfileScheduleStr[30]={0};
  12127. char TxDefaultProfileScheduleStr[30]={0};
  12128. char TxProfileScheduleStr[30]={0};
  12129. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12130. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12131. memset(&TxProfile,0,sizeof(struct StructProfile));
  12132. DEBUG_INFO("GetChargingProfileRequest\n");
  12133. //*****************************ChargePointMaxProfile******************************************/
  12134. strcpy(fname, ChargePointMaxProfile_JSON);
  12135. ChargePointMaxProfileIsNull=TRUE;
  12136. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12137. {
  12138. fptr1 = fopen(fname, "r");
  12139. int c;
  12140. c = fgetc(fptr1);
  12141. //DEBUG_INFO("c:%d\n",c);
  12142. rewind(fptr1);
  12143. if(c == EOF)
  12144. {
  12145. DEBUG_INFO("\n End of file reached.");
  12146. ChargePointMaxProfileIsNull=TRUE;
  12147. fclose(fptr1);
  12148. }
  12149. else
  12150. {
  12151. ChargePointMaxProfileIsNull=FALSE;
  12152. while(fscanf(fptr1, "%s", word) != EOF)
  12153. {
  12154. if(strcmp(word, "chargingProfileId") == 0)
  12155. {
  12156. n_chargingProfile = n_chargingProfile + 1;
  12157. }
  12158. }
  12159. rewind(fptr1);
  12160. //search Charging Profile Element
  12161. int i = 0;
  12162. int j = 0;
  12163. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12164. //***********chargingProfileId**************/
  12165. c = 0;
  12166. loc = strstr(sLineWord, "chargingProfileId");
  12167. //DEBUG_INFO("loc=%s\n",loc);
  12168. memset(sstr ,0, sizeof(sstr) );
  12169. if(loc != NULL)
  12170. {
  12171. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12172. {
  12173. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12174. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12175. c++;
  12176. }
  12177. sstr[c] = '\0';
  12178. tempchargingProfileId = atoi(sstr);
  12179. }
  12180. else
  12181. {
  12182. tempchargingProfileId = 0;
  12183. }
  12184. //***********stackLevel**************/
  12185. c = 0;
  12186. loc = strstr(sLineWord, "stackLevel");
  12187. //DEBUG_INFO("loc=%s\n",loc);
  12188. memset(sstr ,0, sizeof(sstr) );
  12189. if(loc != NULL)
  12190. {
  12191. while (loc[2+strlen("stackLevel")+c] != '\"')
  12192. {
  12193. sstr[c] = loc[2+strlen("stackLevel")+c];
  12194. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12195. c++;
  12196. }
  12197. sstr[c] = '\0';
  12198. tempstackLevel = atoi(sstr);
  12199. }
  12200. else
  12201. {
  12202. tempstackLevel = 0;
  12203. }
  12204. //***********chargingProfilePurpose **************/
  12205. c = 0;
  12206. loc = strstr(sLineWord, "chargingProfilePurpose");
  12207. //DEBUG_INFO("loc=%s\n",loc);
  12208. memset(sstr ,0, sizeof(sstr) );
  12209. if(loc != NULL)
  12210. {
  12211. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12212. {
  12213. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12214. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12215. c++;
  12216. }
  12217. sstr[c] = '\0';
  12218. strcpy(tempchargingProfilePurposeStr,sstr);
  12219. }
  12220. else
  12221. {
  12222. strcpy(tempchargingProfilePurposeStr,"");
  12223. }
  12224. //***********chargingProfileKind **************/
  12225. c = 0;
  12226. loc = strstr(sLineWord, "chargingProfileKind");
  12227. //DEBUG_INFO("loc=%s\n",loc);
  12228. memset(sstr ,0, sizeof(sstr) );
  12229. if(loc != NULL)
  12230. {
  12231. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12232. {
  12233. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12234. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12235. c++;
  12236. }
  12237. sstr[c] = '\0';
  12238. strcpy(tempchargingProfileKindStr,sstr);
  12239. }
  12240. else
  12241. {
  12242. strcpy(tempchargingProfileKindStr,"");
  12243. }
  12244. //***********recurrencyKind **************/
  12245. c = 0;
  12246. loc = strstr(sLineWord, "recurrencyKind");
  12247. //DEBUG_INFO("loc=%s\n",loc);
  12248. memset(sstr ,0, sizeof(sstr) );
  12249. if(loc != NULL)
  12250. {
  12251. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12252. {
  12253. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12254. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12255. c++;
  12256. }
  12257. sstr[c] = '\0';
  12258. strcpy(temprecurrencyKindStr,sstr);
  12259. }
  12260. else
  12261. {
  12262. strcpy(temprecurrencyKindStr,"");
  12263. }
  12264. //***********validFrom**************/
  12265. c = 0;
  12266. loc = strstr(sLineWord, "validFrom");
  12267. //DEBUG_INFO("loc=%s\n",loc);
  12268. memset(sstr ,0, sizeof(sstr) );
  12269. if(loc != NULL)
  12270. {
  12271. while (loc[3+strlen("validFrom")+c] != '\"')
  12272. {
  12273. sstr[c] = loc[3+strlen("validFrom")+c];
  12274. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12275. c++;
  12276. }
  12277. sstr[c] = '\0';
  12278. strcpy(tempvalidFromStr,sstr);
  12279. }
  12280. else
  12281. {
  12282. strcpy(tempvalidFromStr,"");
  12283. }
  12284. //***********validTo **************/
  12285. c = 0;
  12286. loc = strstr(sLineWord, "validTo");
  12287. //DEBUG_INFO("loc=%s\n",loc);
  12288. memset(sstr ,0, sizeof(sstr) );
  12289. if(loc != NULL)
  12290. {
  12291. while (loc[3+strlen("validTo")+c] != '\"')
  12292. {
  12293. sstr[c] = loc[3+strlen("validTo")+c];
  12294. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12295. c++;
  12296. }
  12297. sstr[c] = '\0';
  12298. strcpy(tempvalidToStr,sstr);
  12299. }
  12300. else
  12301. {
  12302. strcpy(tempvalidToStr,"");
  12303. }
  12304. //***********validFrom**************/
  12305. c = 0;
  12306. loc = strstr(sLineWord, "validFrom");
  12307. if(loc != NULL)
  12308. {
  12309. memset(sstr ,0, sizeof(sstr) );
  12310. while (loc[3+strlen("validFrom")+c] != '\"')
  12311. {
  12312. sstr[c] = loc[3+strlen("validFrom")+c];
  12313. c++;
  12314. }
  12315. sstr[c] = '\0';
  12316. strcpy(tempvalidFromStr,sstr);
  12317. }
  12318. else
  12319. {
  12320. strcpy(tempvalidFromStr,"");
  12321. }
  12322. //***********duration**************/
  12323. c = 0;
  12324. loc = strstr(sLineWord, "duration");
  12325. if(loc != NULL)
  12326. {
  12327. memset(sstr ,0, sizeof(sstr) );
  12328. while (loc[2+strlen("duration")+c] != ',')
  12329. {
  12330. sstr[c] = loc[2+strlen("duration")+c];
  12331. c++;
  12332. }
  12333. sstr[c] = '\0';
  12334. tempdurationInt = atoi(sstr);
  12335. }
  12336. else
  12337. {
  12338. tempdurationInt = 0;
  12339. }
  12340. //**********startSchedule**********/
  12341. c = 0;
  12342. loc = strstr(sLineWord, "startSchedule");
  12343. memset(sstr ,0, sizeof(sstr) );
  12344. while (loc[3+strlen("startSchedule")+c] != '\"')
  12345. {
  12346. sstr[c] = loc[3+strlen("startSchedule")+c];
  12347. c++;
  12348. }
  12349. sstr[c] = '\0';
  12350. strcpy(tempstartScheduleStr, sstr);
  12351. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  12352. //**********chargingRateUnit**********/
  12353. c = 0;
  12354. loc = strstr(sLineWord, "chargingRateUnit");
  12355. memset(sstr ,0, sizeof(sstr) );
  12356. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12357. {
  12358. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12359. c++;
  12360. }
  12361. sstr[c] = '\0';
  12362. strcpy(tempchargingRateUnitStr, sstr);
  12363. //**********minChargingRate*******/
  12364. c = 0;
  12365. loc = strstr(sLineWord, "minChargingRate");
  12366. if(loc != NULL)
  12367. {
  12368. memset(sstr ,0, sizeof(sstr) );
  12369. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12370. {
  12371. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12372. c++;
  12373. }
  12374. sstr[c] = '\0';
  12375. tempminChargingRateFloat = atof(sstr);
  12376. }
  12377. else
  12378. {
  12379. tempminChargingRateFloat = 0.0;
  12380. }
  12381. //
  12382. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12383. tp.tm_isdst = -1;
  12384. time_t utc = mktime(&tp);
  12385. time_t t = time(NULL);
  12386. diff_t = difftime(t, utc);
  12387. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12388. //parsing strings to words
  12389. i = 0;
  12390. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12391. loc = loc+3+strlen("chargingSchedulePeriod");
  12392. pch = strtok(loc ,"{");
  12393. while (pch != NULL)
  12394. {
  12395. strcpy(SchedulePeriodList[i], pch);
  12396. pch = strtok (NULL, "{");
  12397. i = i + 1;
  12398. }
  12399. n_SchedulePeriods = i;
  12400. for(int i=0;i<n_SchedulePeriods;i++)
  12401. {
  12402. //*************startPeriod****************/
  12403. c = 0;
  12404. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12405. memset(sstr ,0, sizeof(sstr) );
  12406. while (loc[strlen("startPeriod")+2+c] != ',')
  12407. {
  12408. sstr[c] = loc[strlen("startPeriod")+2+c];
  12409. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12410. c++;
  12411. }
  12412. sstr[c] = '\0';
  12413. tempStartPeriodInt = atoi(sstr);
  12414. //*************limit****************/
  12415. c = 0;
  12416. loc = strstr(SchedulePeriodList[i], "limit");
  12417. memset(sstr ,0, sizeof(sstr) );
  12418. while (loc[strlen("limit")+2+c] != ',')
  12419. {
  12420. sstr[c] = loc[strlen("limit")+2+c];
  12421. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12422. c++;
  12423. }
  12424. sstr[c] = '\0';
  12425. tempLimitInt = atof(sstr);
  12426. //*************numberPhases****************/
  12427. c = 0;
  12428. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12429. memset(sstr ,0, sizeof(sstr) );
  12430. while (loc[strlen("numberPhases")+2+c] != '}')
  12431. {
  12432. sstr[c] = loc[strlen("numberPhases")+2+c];
  12433. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12434. c++;
  12435. }
  12436. sstr[c] = '\0';
  12437. tempNumberPhasesInt = atoi(sstr);
  12438. if(j == 0)
  12439. {
  12440. ChargePointMaxProfile.Duration = tempdurationInt;
  12441. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  12442. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  12443. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12444. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12445. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12446. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  12447. ChargePointMaxProfile_TEMP.TransactionId = 0;
  12448. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12449. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12450. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12451. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12452. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12453. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12454. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12455. }
  12456. }
  12457. if(MinChargingRate < tempminChargingRateFloat)
  12458. {
  12459. MinChargingRate = tempminChargingRateFloat;
  12460. }
  12461. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12462. if(confirmPeriods < n_SchedulePeriods)
  12463. {
  12464. confirmPeriods = n_SchedulePeriods;
  12465. }
  12466. j = j + 1;
  12467. }
  12468. fclose(fptr1);
  12469. }
  12470. }// the end of access file ChargePointMaxProfile
  12471. //****************************TxDefaultProfile************************************************/
  12472. switch(gunindex + 1)
  12473. {
  12474. case 0:
  12475. break;
  12476. case 1:
  12477. strcpy(fname, TxDefaultProfile_1_JSON );
  12478. break;
  12479. case 2:
  12480. strcpy(fname, TxDefaultProfile_2_JSON );
  12481. break;
  12482. default:
  12483. strcpy(fname, TxDefaultProfile_1_JSON );
  12484. break;
  12485. }
  12486. TxDefaultProfileFileIsNull=TRUE;
  12487. if((access(fname,F_OK))!=-1)
  12488. {
  12489. fptr1 = fopen(fname, "r");
  12490. c = 0;
  12491. c = fgetc(fptr1);
  12492. //DEBUG_INFO("c:%d\n",c);
  12493. rewind(fptr1);
  12494. if(c == EOF)
  12495. {
  12496. DEBUG_INFO("\n End of file reached.");
  12497. TxDefaultProfileFileIsNull=TRUE;
  12498. fclose(fptr1);
  12499. }
  12500. else
  12501. {
  12502. TxDefaultProfileFileIsNull=FALSE;
  12503. while(fscanf(fptr1, "%s", word) != EOF)
  12504. {
  12505. if(strcmp(word, "chargingProfileId") == 0)
  12506. {
  12507. n_chargingProfile = n_chargingProfile + 1;
  12508. }
  12509. }
  12510. rewind(fptr1);
  12511. //search Charging Profile Element
  12512. int i = 0;
  12513. int j = 0;
  12514. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12515. #if 0
  12516. /***********connectorId****************/
  12517. c = 0;
  12518. loc = strstr(sLineWord, "connectorId");
  12519. memset(sstr ,0, sizeof(sstr) );
  12520. while (loc[strlen("connectorId")+2+c] != ',')
  12521. {
  12522. sstr[c] = loc[strlen("connectorId")+2+c];
  12523. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12524. c++;
  12525. }
  12526. sstr[c] = '\0';
  12527. tempconnectorIdInt = atoi(sstr);
  12528. #endif
  12529. //***********chargingProfileId**************/
  12530. c = 0;
  12531. loc = strstr(sLineWord, "chargingProfileId");
  12532. //DEBUG_INFO("loc=%s\n",loc);
  12533. memset(sstr ,0, sizeof(sstr) );
  12534. if(loc != NULL)
  12535. {
  12536. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12537. {
  12538. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12539. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12540. c++;
  12541. }
  12542. sstr[c] = '\0';
  12543. tempchargingProfileId = atoi(sstr);
  12544. }
  12545. else
  12546. {
  12547. tempchargingProfileId = 0;
  12548. }
  12549. //***********stackLevel**************/
  12550. c = 0;
  12551. loc = strstr(sLineWord, "stackLevel");
  12552. //DEBUG_INFO("loc=%s\n",loc);
  12553. memset(sstr ,0, sizeof(sstr) );
  12554. if(loc != NULL)
  12555. {
  12556. while (loc[2+strlen("stackLevel")+c] != '\"')
  12557. {
  12558. sstr[c] = loc[2+strlen("stackLevel")+c];
  12559. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12560. c++;
  12561. }
  12562. sstr[c] = '\0';
  12563. tempstackLevel = atoi(sstr);
  12564. }
  12565. else
  12566. {
  12567. tempstackLevel = 0;
  12568. }
  12569. //***********chargingProfilePurpose **************/
  12570. c = 0;
  12571. loc = strstr(sLineWord, "chargingProfilePurpose");
  12572. //DEBUG_INFO("loc=%s\n",loc);
  12573. memset(sstr ,0, sizeof(sstr) );
  12574. if(loc != NULL)
  12575. {
  12576. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12577. {
  12578. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12579. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12580. c++;
  12581. }
  12582. sstr[c] = '\0';
  12583. strcpy(tempchargingProfilePurposeStr,sstr);
  12584. }
  12585. else
  12586. {
  12587. strcpy(tempchargingProfilePurposeStr,"");
  12588. }
  12589. //***********chargingProfileKind **************/
  12590. c = 0;
  12591. loc = strstr(sLineWord, "chargingProfileKind");
  12592. //DEBUG_INFO("loc=%s\n",loc);
  12593. memset(sstr ,0, sizeof(sstr) );
  12594. if(loc != NULL)
  12595. {
  12596. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12597. {
  12598. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12599. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12600. c++;
  12601. }
  12602. sstr[c] = '\0';
  12603. strcpy(tempchargingProfileKindStr,sstr);
  12604. }
  12605. else
  12606. {
  12607. strcpy(tempchargingProfileKindStr,"");
  12608. }
  12609. //***********recurrencyKind **************/
  12610. c = 0;
  12611. loc = strstr(sLineWord, "recurrencyKind");
  12612. //DEBUG_INFO("loc=%s\n",loc);
  12613. memset(sstr ,0, sizeof(sstr) );
  12614. if(loc != NULL)
  12615. {
  12616. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12617. {
  12618. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12619. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12620. c++;
  12621. }
  12622. sstr[c] = '\0';
  12623. strcpy(temprecurrencyKindStr,sstr);
  12624. }
  12625. else
  12626. {
  12627. strcpy(temprecurrencyKindStr,"");
  12628. }
  12629. //***********validFrom**************/
  12630. c = 0;
  12631. loc = strstr(sLineWord, "validFrom");
  12632. if(loc != NULL)
  12633. {
  12634. memset(sstr ,0, sizeof(sstr) );
  12635. while (loc[3+strlen("validFrom")+c] != '\"')
  12636. {
  12637. sstr[c] = loc[3+strlen("validFrom")+c];
  12638. c++;
  12639. }
  12640. sstr[c] = '\0';
  12641. strcpy(tempvalidFromStr,sstr);
  12642. }
  12643. else
  12644. {
  12645. strcpy(tempvalidFromStr,"");
  12646. }
  12647. //***********validFrom**************/
  12648. c = 0;
  12649. loc = strstr(sLineWord, "duration");
  12650. if(loc != NULL)
  12651. {
  12652. memset(sstr ,0, sizeof(sstr) );
  12653. while (loc[2+strlen("duration")+c] != ',')
  12654. {
  12655. sstr[c] = loc[2+strlen("duration")+c];
  12656. c++;
  12657. }
  12658. sstr[c] = '\0';
  12659. tempdurationInt = atoi(sstr);
  12660. }
  12661. else
  12662. {
  12663. tempdurationInt = 0;
  12664. }
  12665. //**********startSchedule**********/
  12666. c = 0;
  12667. loc = strstr(sLineWord, "startSchedule");
  12668. memset(sstr ,0, sizeof(sstr) );
  12669. while (loc[3+strlen("startSchedule")+c] != '\"')
  12670. {
  12671. sstr[c] = loc[3+strlen("startSchedule")+c];
  12672. c++;
  12673. }
  12674. sstr[c] = '\0';
  12675. strcpy(tempstartScheduleStr, sstr);
  12676. strcpy(TxDefaultProfileScheduleStr, sstr);
  12677. //**********chargingRateUnit**********/
  12678. c = 0;
  12679. loc = strstr(sLineWord, "chargingRateUnit");
  12680. memset(sstr ,0, sizeof(sstr) );
  12681. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12682. {
  12683. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12684. c++;
  12685. }
  12686. sstr[c] = '\0';
  12687. strcpy(tempchargingRateUnitStr, sstr);
  12688. //**********minChargingRate*******/
  12689. c = 0;
  12690. loc = strstr(sLineWord, "minChargingRate");
  12691. if(loc != NULL)
  12692. {
  12693. memset(sstr ,0, sizeof(sstr) );
  12694. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12695. {
  12696. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12697. c++;
  12698. }
  12699. sstr[c] = '\0';
  12700. tempminChargingRateFloat = atof(sstr);
  12701. }
  12702. else
  12703. {
  12704. tempminChargingRateFloat = 0.0;
  12705. }
  12706. //
  12707. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12708. tp.tm_isdst = -1;
  12709. time_t utc = mktime(&tp);
  12710. time_t t = time(NULL);
  12711. diff_t = difftime(t, utc);
  12712. printf("diff between startScheduleStr and now =%f\n",diff_t);
  12713. //parsing strings to words
  12714. i = 0;
  12715. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12716. loc = loc+3+strlen("chargingSchedulePeriod");
  12717. pch = strtok(loc ,"{");
  12718. while (pch != NULL)
  12719. {
  12720. strcpy(SchedulePeriodList[i], pch);
  12721. pch = strtok (NULL, "{");
  12722. i = i + 1;
  12723. }
  12724. n_SchedulePeriods = i;
  12725. for(int i=0;i<n_SchedulePeriods;i++)
  12726. {
  12727. //*************startPeriod****************/
  12728. c = 0;
  12729. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12730. memset(sstr ,0, sizeof(sstr) );
  12731. while (loc[strlen("startPeriod")+2+c] != ',')
  12732. {
  12733. sstr[c] = loc[strlen("startPeriod")+2+c];
  12734. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12735. c++;
  12736. }
  12737. sstr[c] = '\0';
  12738. tempStartPeriodInt = atoi(sstr);
  12739. //*************limit****************/
  12740. c = 0;
  12741. loc = strstr(SchedulePeriodList[i], "limit");
  12742. memset(sstr ,0, sizeof(sstr) );
  12743. while (loc[strlen("limit")+2+c] != ',')
  12744. {
  12745. sstr[c] = loc[strlen("limit")+2+c];
  12746. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12747. c++;
  12748. }
  12749. sstr[c] = '\0';
  12750. tempLimitInt = atof(sstr);
  12751. //*************numberPhases****************/
  12752. c = 0;
  12753. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12754. memset(sstr ,0, sizeof(sstr) );
  12755. while (loc[strlen("numberPhases")+2+c] != '}')
  12756. {
  12757. sstr[c] = loc[strlen("numberPhases")+2+c];
  12758. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12759. c++;
  12760. }
  12761. sstr[c] = '\0';
  12762. tempNumberPhasesInt = atoi(sstr);
  12763. if(j == 0)
  12764. {
  12765. TxDefaultProfile.Duration = tempdurationInt;
  12766. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  12767. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  12768. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12769. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12770. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12771. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  12772. TxDefaultProfile_TEMP.TransactionId = 0;
  12773. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  12774. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12775. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12776. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12777. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12778. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12779. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12780. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12781. }
  12782. else
  12783. {
  12784. //other stack level charging Profile
  12785. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  12786. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  12787. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  12788. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  12789. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  12790. }
  12791. }
  12792. if(MinChargingRate < tempminChargingRateFloat)
  12793. {
  12794. MinChargingRate = tempminChargingRateFloat;
  12795. }
  12796. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12797. if(confirmPeriods < n_SchedulePeriods)
  12798. confirmPeriods = n_SchedulePeriods;
  12799. j = j + 1;
  12800. }
  12801. fclose(fptr1);
  12802. //Stacking Charging Profiles
  12803. for(int l=0; l <(j-1) ;l++)
  12804. {
  12805. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  12806. {
  12807. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  12808. {
  12809. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  12810. {
  12811. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  12812. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  12813. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  12814. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12815. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12816. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12817. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12818. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12819. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12820. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12821. }
  12822. else
  12823. {
  12824. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12825. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12826. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12827. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12828. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12829. }
  12830. }
  12831. }
  12832. }
  12833. //end of Stacking Charging Profiles
  12834. }
  12835. }// the end of ACCESS TxDefaultProfile
  12836. //****************************TxProfile************************************************/
  12837. switch(gunindex + 1)
  12838. {
  12839. case 0:
  12840. break;
  12841. case 1:
  12842. strcpy(fname, TxProfile_1_JSON );
  12843. break;
  12844. case 2:
  12845. strcpy(fname, TxProfile_2_JSON );
  12846. break;
  12847. default:
  12848. strcpy(fname, TxProfile_1_JSON );
  12849. break;
  12850. }
  12851. TxProfileIsNull=TRUE;
  12852. if((access(fname,F_OK))!=-1)
  12853. {
  12854. fptr1 = fopen(fname, "r");
  12855. c = 0;
  12856. c = fgetc(fptr1);
  12857. //DEBUG_INFO("c:%d\n",c);
  12858. rewind(fptr1);
  12859. if(c == EOF)
  12860. {
  12861. DEBUG_INFO("\n End of file reached.");
  12862. TxProfileIsNull=TRUE;
  12863. fclose(fptr1);
  12864. }
  12865. else
  12866. {
  12867. TxProfileIsNull=FALSE;
  12868. while(fscanf(fptr1, "%s", word) != EOF)
  12869. {
  12870. if(strcmp(word, "chargingProfileId") == 0)
  12871. {
  12872. n_chargingProfile = n_chargingProfile + 1;
  12873. }
  12874. }
  12875. rewind(fptr1);
  12876. //search Charging Profile Element
  12877. int i= 0;
  12878. int j= 0;
  12879. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12880. #if 0
  12881. /***********connectorId****************/
  12882. c = 0;
  12883. loc = strstr(sLineWord, "connectorId");
  12884. memset(sstr ,0, sizeof(sstr) );
  12885. while (loc[strlen("connectorId")+2+c] != ',')
  12886. {
  12887. sstr[c] = loc[strlen("connectorId")+2+c];
  12888. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12889. c++;
  12890. }
  12891. sstr[c] = '\0';
  12892. tempconnectorIdInt = atoi(sstr);
  12893. #endif
  12894. //***********chargingProfileId**************/
  12895. c = 0;
  12896. loc = strstr(sLineWord, "chargingProfileId");
  12897. memset(sstr ,0, sizeof(sstr) );
  12898. if(loc != NULL)
  12899. {
  12900. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12901. {
  12902. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12903. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12904. c++;
  12905. }
  12906. sstr[c] = '\0';
  12907. tempchargingProfileId = atoi(sstr);
  12908. }
  12909. else
  12910. {
  12911. tempchargingProfileId = 0;
  12912. }
  12913. //***********transactionId **************/
  12914. c = 0;
  12915. loc = strstr(sLineWord, "transactionId");
  12916. //DEBUG_INFO("loc=%s\n",loc);
  12917. memset(sstr ,0, sizeof(sstr) );
  12918. if(loc != NULL)
  12919. {
  12920. while (loc[2+strlen("transactionId")+c] != '\"')
  12921. {
  12922. sstr[c] = loc[2+strlen("transactionId")+c];
  12923. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12924. c++;
  12925. }
  12926. sstr[c] = '\0';
  12927. temptransactionId = atoi(sstr);
  12928. }
  12929. else
  12930. {
  12931. temptransactionId = 0;
  12932. }
  12933. //***********stackLevel**************/
  12934. c = 0;
  12935. loc = strstr(sLineWord, "stackLevel");
  12936. //DEBUG_INFO("loc=%s\n",loc);
  12937. memset(sstr ,0, sizeof(sstr) );
  12938. if(loc != NULL)
  12939. {
  12940. while (loc[2+strlen("stackLevel")+c] != '\"')
  12941. {
  12942. sstr[c] = loc[2+strlen("stackLevel")+c];
  12943. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12944. c++;
  12945. }
  12946. sstr[c] = '\0';
  12947. tempstackLevel = atoi(sstr);
  12948. }
  12949. else
  12950. {
  12951. tempstackLevel = 0;
  12952. }
  12953. //***********chargingProfilePurpose **************/
  12954. c = 0;
  12955. loc = strstr(sLineWord, "chargingProfilePurpose");
  12956. //DEBUG_INFO("loc=%s\n",loc);
  12957. memset(sstr ,0, sizeof(sstr) );
  12958. if(loc != NULL)
  12959. {
  12960. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12961. {
  12962. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12963. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12964. c++;
  12965. }
  12966. sstr[c] = '\0';
  12967. strcpy(tempchargingProfilePurposeStr,sstr);
  12968. }
  12969. else
  12970. {
  12971. strcpy(tempchargingProfilePurposeStr,"");
  12972. }
  12973. //***********chargingProfileKind **************/
  12974. c = 0;
  12975. loc = strstr(sLineWord, "chargingProfileKind");
  12976. //DEBUG_INFO("loc=%s\n",loc);
  12977. memset(sstr ,0, sizeof(sstr) );
  12978. if(loc != NULL)
  12979. {
  12980. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12981. {
  12982. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12983. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12984. c++;
  12985. }
  12986. sstr[c] = '\0';
  12987. strcpy(tempchargingProfileKindStr,sstr);
  12988. }
  12989. else
  12990. {
  12991. strcpy(tempchargingProfileKindStr,"");
  12992. }
  12993. //***********recurrencyKind **************/
  12994. c = 0;
  12995. loc = strstr(sLineWord, "recurrencyKind");
  12996. //DEBUG_INFO("loc=%s\n",loc);
  12997. memset(sstr ,0, sizeof(sstr) );
  12998. if(loc != NULL)
  12999. {
  13000. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13001. {
  13002. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13003. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13004. c++;
  13005. }
  13006. sstr[c] = '\0';
  13007. strcpy(temprecurrencyKindStr,sstr);
  13008. }
  13009. else
  13010. {
  13011. strcpy(temprecurrencyKindStr,"");
  13012. }
  13013. //***********validFrom**************/
  13014. c = 0;
  13015. loc = strstr(sLineWord, "validFrom");
  13016. if(loc != NULL)
  13017. {
  13018. memset(sstr ,0, sizeof(sstr) );
  13019. while (loc[3+strlen("validFrom")+c] != '\"')
  13020. {
  13021. sstr[c] = loc[3+strlen("validFrom")+c];
  13022. c++;
  13023. }
  13024. sstr[c] = '\0';
  13025. strcpy(tempvalidFromStr,sstr);
  13026. }
  13027. else
  13028. {
  13029. strcpy(tempvalidFromStr,"");
  13030. }
  13031. //***********duration**************/
  13032. c = 0;
  13033. loc = strstr(sLineWord, "duration");
  13034. //DEBUG_INFO("loc=%s\n",loc);
  13035. memset(sstr ,0, sizeof(sstr) );
  13036. if(loc != NULL)
  13037. {
  13038. while (loc[2+strlen("duration")+c] != '\"')
  13039. {
  13040. sstr[c] = loc[2+strlen("duration")+c];
  13041. c++;
  13042. }
  13043. sstr[c] = '\0';
  13044. tempdurationInt = atoi(sstr);
  13045. }
  13046. else
  13047. {
  13048. tempdurationInt = 0;
  13049. }
  13050. //**********startSchedule**********/
  13051. c = 0;
  13052. loc = strstr(sLineWord, "startSchedule");
  13053. memset(sstr ,0, sizeof(sstr) );
  13054. while (loc[3+strlen("startSchedule")+c] != '\"')
  13055. {
  13056. sstr[c] = loc[3+strlen("startSchedule")+c];
  13057. c++;
  13058. }
  13059. sstr[c] = '\0';
  13060. strcpy(tempstartScheduleStr, sstr);
  13061. strcpy(TxProfileScheduleStr, sstr);
  13062. //**********chargingRateUnit**********/
  13063. c = 0;
  13064. loc = strstr(sLineWord, "chargingRateUnit");
  13065. memset(sstr ,0, sizeof(sstr) );
  13066. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13067. {
  13068. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13069. c++;
  13070. }
  13071. sstr[c] = '\0';
  13072. strcpy(tempchargingRateUnitStr, sstr);
  13073. //**********minChargingRate*******/
  13074. c = 0;
  13075. loc = strstr(sLineWord, "minChargingRate");
  13076. if(loc != NULL)
  13077. {
  13078. memset(sstr ,0, sizeof(sstr) );
  13079. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13080. {
  13081. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13082. c++;
  13083. }
  13084. sstr[c] = '\0';
  13085. tempminChargingRateFloat = atof(sstr);
  13086. }
  13087. else
  13088. {
  13089. tempminChargingRateFloat = 0.0;
  13090. }
  13091. //
  13092. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13093. tp.tm_isdst = -1;
  13094. time_t utc = mktime(&tp);
  13095. time_t t = time(NULL);
  13096. diff_t = difftime(t, utc);
  13097. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13098. //parsing strings to words
  13099. i = 0;
  13100. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13101. loc = loc+3+strlen("chargingSchedulePeriod");
  13102. pch = strtok(loc ,"{");
  13103. while (pch != NULL)
  13104. {
  13105. strcpy(SchedulePeriodList[i], pch);
  13106. pch = strtok (NULL, "{");
  13107. i = i + 1;
  13108. }
  13109. n_SchedulePeriods = i;
  13110. for(int i=0;i<n_SchedulePeriods;i++)
  13111. {
  13112. //*************startPeriod****************/
  13113. c = 0;
  13114. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13115. memset(sstr ,0, sizeof(sstr) );
  13116. while (loc[strlen("startPeriod")+2+c] != ',')
  13117. {
  13118. sstr[c] = loc[strlen("startPeriod")+2+c];
  13119. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13120. c++;
  13121. }
  13122. sstr[c] = '\0';
  13123. tempStartPeriodInt = atoi(sstr);
  13124. //*************limit****************/
  13125. c = 0;
  13126. loc = strstr(SchedulePeriodList[i], "limit");
  13127. memset(sstr ,0, sizeof(sstr) );
  13128. while (loc[strlen("limit")+2+c] != ',')
  13129. {
  13130. sstr[c] = loc[strlen("limit")+2+c];
  13131. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13132. c++;
  13133. }
  13134. sstr[c] = '\0';
  13135. tempLimitInt = atof(sstr);
  13136. //*************numberPhases****************/
  13137. c = 0;
  13138. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13139. memset(sstr ,0, sizeof(sstr) );
  13140. while (loc[strlen("numberPhases")+2+c] != '}')
  13141. {
  13142. sstr[c] = loc[strlen("numberPhases")+2+c];
  13143. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13144. c++;
  13145. }
  13146. sstr[c] = '\0';
  13147. tempNumberPhasesInt = atoi(sstr);
  13148. //TxProfile.Duration = durationInt;
  13149. TxProfile.TotalPeriod = n_SchedulePeriods;
  13150. TxProfile.Period[i].Limit = tempLimitInt;
  13151. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13152. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13153. }
  13154. if(MinChargingRate < tempminChargingRateFloat)
  13155. {
  13156. MinChargingRate = tempminChargingRateFloat;
  13157. }
  13158. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13159. if(confirmPeriods < n_SchedulePeriods)
  13160. confirmPeriods = n_SchedulePeriods;
  13161. if(j == 0)
  13162. {
  13163. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13164. TxProfile_TEMP.StackLevel = tempstackLevel;
  13165. TxProfile_TEMP.TransactionId = 0;
  13166. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13167. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13168. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13169. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13170. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13171. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13172. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13173. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13174. }
  13175. }
  13176. fclose(fptr1);
  13177. }
  13178. }// the end of ACCESS TxProfile
  13179. //CompositeSchedule
  13180. int period=0;
  13181. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13182. {
  13183. //TxProfile
  13184. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13185. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13186. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13187. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13188. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13189. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13190. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13191. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13192. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13193. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13194. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13195. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13196. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13197. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13198. {
  13199. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13200. {
  13201. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13202. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13203. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13204. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13205. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13206. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13207. period = period + 1;
  13208. }
  13209. else
  13210. {
  13211. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13212. {
  13213. }
  13214. else
  13215. {
  13216. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13217. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13218. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13219. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13220. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13221. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13222. period = period + 1;
  13223. }
  13224. }
  13225. }
  13226. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13227. {
  13228. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  13229. {
  13230. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13231. {
  13232. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13233. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13234. }
  13235. else
  13236. {
  13237. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13238. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13239. }
  13240. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13241. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13242. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13243. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13244. period = period + 1;
  13245. }
  13246. }
  13247. }
  13248. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13249. {
  13250. //TxDefaultProfile
  13251. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13252. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13253. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13254. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13255. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  13256. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13257. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13258. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13259. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13260. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13261. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13262. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13263. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13264. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13265. {
  13266. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13267. {
  13268. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13269. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13270. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13271. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13272. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13273. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13274. period = period + 1;
  13275. }
  13276. else
  13277. {
  13278. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13279. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13280. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13281. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13282. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13283. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13284. period = period + 1;
  13285. }
  13286. }
  13287. }
  13288. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  13289. {
  13290. //TxDefaultProfile
  13291. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13292. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13293. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13294. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13295. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  13296. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13297. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13298. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13299. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13300. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13301. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13302. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13303. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13304. {
  13305. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13306. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13307. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13308. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13309. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13310. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13311. period = period + 1;
  13312. }
  13313. }
  13314. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13315. {
  13316. //ChargePointMaxProfile
  13317. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  13318. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  13319. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13320. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  13321. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  13322. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13323. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  13324. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  13325. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  13326. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  13327. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  13328. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  13329. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  13330. {
  13331. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  13332. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  13333. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  13334. period = period + 1;
  13335. }
  13336. }
  13337. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  13338. {
  13339. //TxProfile
  13340. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13341. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13342. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13343. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13344. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13345. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13346. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13347. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13348. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13349. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13350. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13351. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13352. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13353. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13354. {
  13355. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  13356. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  13357. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  13358. }
  13359. }
  13360. confirmPeriods = period;
  13361. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  13362. 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,"
  13363. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  13364. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  13365. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  13366. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  13367. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  13368. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  13369. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  13370. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  13371. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  13372. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  13373. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  13374. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  13375. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  13376. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  13377. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  13378. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  13379. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  13380. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  13381. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  13382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  13383. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  13384. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  13385. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  13386. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  13387. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  13388. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  13389. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  13390. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  13391. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  13392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  13393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  13394. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  13395. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  13396. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  13397. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  13398. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  13399. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  13400. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  13401. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  13402. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  13403. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  13404. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  13405. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  13406. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  13407. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  13408. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  13409. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  13410. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  13411. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  13412. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  13413. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  13414. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  13415. }
  13416. void LWS_Send(char * str)
  13417. {
  13418. //=====================================================
  13419. // Check InternetConn 0: disconnected, 1: connected
  13420. //====================================================
  13421. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13422. {
  13423. DEBUG_INFO("\n offline now !!!\n");
  13424. return;
  13425. }
  13426. pthread_mutex_lock(&lock);
  13427. memset(SendBuffer,0,SendBufLen);
  13428. sprintf((char *)SendBuffer, "%s", str);
  13429. pthread_mutex_unlock(&lock);
  13430. lws_callback_on_writable(wsi_client);
  13431. lws_service(context, 10000);//timeout_ms
  13432. }