MessageHandler.c 571 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "hashmap.h"
  21. #include "ShareMemory.h"
  22. #include "TransactionQueue.h"
  23. #include "define.h"
  24. #include "SystemLogMessage.h"
  25. //#include "config.h"
  26. #include <sys/socket.h>
  27. #include <netinet/in.h>
  28. #include <stdlib.h>
  29. /*for sendfile()*/
  30. #include <sys/sendfile.h>
  31. /*for O_RDONLY*/
  32. #include <fcntl.h>
  33. #include "sqlite3.h"
  34. #include <arpa/inet.h>
  35. //#define _GNU_SOURCE
  36. #include <time.h>
  37. #include "MessageHandler.h"
  38. #include <assert.h>
  39. #include <pthread.h>
  40. #include <mcheck.h>
  41. #define PASS 1
  42. #define FAIL -1
  43. #define FALSE 0
  44. #define TRUE 1 // Option 1
  45. //ChargePointMaxProfile
  46. #define ChargePointMaxProfile_JSON "../Storage/OCPP/ChargePointMaxProfile.json"
  47. //TxDefaultProfile
  48. #define TxDefaultProfile_0_JSON "../Storage/OCPP/TxDefaultProfile_0.json"
  49. #define TxDefaultProfile_1_JSON "../Storage/OCPP/TxDefaultProfile_1.json"
  50. #define TxDefaultProfile_2_JSON "../Storage/OCPP/TxDefaultProfile_2.json"
  51. //TxProfile
  52. #define TxProfile_1_JSON "../Storage/OCPP/TxProfile_1.json"
  53. #define TxProfile_2_JSON "../Storage/OCPP/TxProfile_2.json"
  54. #define ChargingProfile_0_JSON "../Storage/OCPP/chargingprofile_0.json"
  55. #define ChargingProfile_1_JSON "../Storage/OCPP/chargingprofile_1.json"
  56. #define ChargingProfile_2_JSON "../Storage/OCPP/chargingprofile_2.json"
  57. #define AuthorizationCache_JSON "../Storage/OCPP/AuthorizationCache.json"
  58. #define LocalAuthorizationList_JSON "../Storage/OCPP/LocalAuthorizationList.json"
  59. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  60. struct StatusCodeData *ShmStatusCodeData;
  61. struct PsuData *ShmPsuData ;
  62. struct OCPP16Data *ShmOCPP16Data;
  63. // define Macro
  64. #define SystemLogMessage
  65. // OCPP Message Type
  66. #define MESSAGE_TYPE_CALL 2
  67. #define MESSAGE_TYPE_CALLRESULT 3
  68. #define MESSAGE_TYPE_CALLERROR 4
  69. //
  70. #define server_cycle_Status 120
  71. #define MACROSTR(k) #k
  72. //ConfigurationMaxKeys
  73. #define GetConfigurationMaxKeysNUM 43
  74. //char guid[37];
  75. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  76. char queuedata[2600]={0};
  77. //===============================
  78. // Configuration: unknownkey
  79. //===============================
  80. static char unknownkey[10][20]={0};
  81. static int UnknownKeynum = 0;
  82. //===============================
  83. // Gun Total Numbers
  84. //===============================
  85. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  86. static int gunTotalNumber=0;
  87. //===============================
  88. // Local List Version
  89. //===============================
  90. static int localversion=0;
  91. static char idTagAuthorization[32]={0};
  92. //===============================
  93. // OCPP Path
  94. //===============================
  95. extern char OcppPath[160];
  96. extern char OcppProtocol[10];
  97. extern char OcppHost[50];
  98. extern char OcppTempPath[50];
  99. int OcppPort=0;
  100. //===============================
  101. // OCPP sign variable
  102. //===============================
  103. int server_sign = FALSE;
  104. int server_pending = FALSE;
  105. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  106. int BootNotificationInterval = 0;
  107. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  108. //===============================
  109. // OCPP auth variable
  110. //===============================
  111. int authenrequest = FALSE;
  112. int authorizeRetryTimes = 0; //number of Retry times
  113. //===============================
  114. // OCPP StartTransaction transactionId variables
  115. //===============================
  116. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  117. //===============================
  118. // OCPP other variables
  119. //===============================
  120. int isUpdateRequest = FALSE;
  121. static int HeartBeatWaitTime = 10;
  122. static int FirstHeartBeat = 0;
  123. static int FirmwareStatusNotificationStatus = 3; // Idle
  124. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  125. static char CurrentChargingProfileScheduleStr[30]={0};
  126. //========================================
  127. // OCPP status/previous related variables
  128. //========================================
  129. static int GunStatusInterval = 10;
  130. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  131. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  132. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  133. static int GbPreviousSystemStatus[GB_QUANTITY];
  134. static int AcPreviousSystemStatus[AC_QUANTITY];
  135. int TransactionMessageAttemptsValue = 0;
  136. int TransactionMessageRetryIntervalValue = 0;
  137. static struct OCPPAuthLocalElemet
  138. {
  139. int listVersionInt;
  140. char idTagstr[20];
  141. char parentIdTag[20];
  142. char expiryDate[30];
  143. char idTagstatus[16];
  144. }idTagQuery;
  145. //=============================================
  146. // OCPP HeartBeat Response Not Receive Counts
  147. //============================================
  148. static int HeartBeatWithNOResponse = 0;
  149. static int HeartBeatCount = 0;
  150. extern struct lws *wsi_client;
  151. extern struct lws_context *context;
  152. extern unsigned char SendBuffer[4096];
  153. extern int SendBufLen;
  154. extern char *random_uuid( char buf[37] );
  155. extern void split(char **arr, char *str, const char *del);
  156. extern pthread_mutex_t mutex1;
  157. extern struct Charger_Info Charger;
  158. extern sqlite3 *db;
  159. int TransactionMessageAttemptsGet(void);
  160. int TransactionMessageRetryIntervalGet(void);
  161. int GetOcppConnStatus(void);
  162. void SetOcppConnStatus(uint8_t status);
  163. int updateSetting(char *key, char *value);
  164. int setKeyValue(char *key, char *value);
  165. void OCPP_get_TableAuthlocalAllData(void);
  166. void processUnkownKey(void);
  167. struct StructOCPPMeterValue
  168. {
  169. unsigned char TimeStamp[28];
  170. struct StructSampledValue SampledValue[10];
  171. };
  172. struct ClientTime
  173. {
  174. unsigned int Heartbeat;
  175. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  176. unsigned int StartTransaction;
  177. unsigned int StopTransaction;
  178. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  179. }clientTime;
  180. typedef union
  181. {
  182. //Operations Initiated by Central System
  183. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  184. struct
  185. {
  186. //CsMsgValue[0]
  187. unsigned char StatusNotificationReq :1; //bit 0,
  188. unsigned char StatusNotificationConf :1; //bit 0,
  189. unsigned char :6; //bit 2~7
  190. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  191. }CpinitiateMsg;
  192. CpinitiateMsg cpinitateMsg;
  193. //==========================================
  194. // Init all Enumeration & Mapping String
  195. //==========================================
  196. /*ChargePointErrorCode*/
  197. typedef enum {
  198. ConnectorLockFailure,
  199. EVCommunicationError,
  200. GroundFailure,
  201. HighTemperature,
  202. InternalError,
  203. LocalListConflict,
  204. NoError,
  205. OtherError,
  206. OverCurrentFailure,
  207. OverVoltage,
  208. PowerMeterFailure,
  209. PowerSwitchFailure,
  210. ReaderFailure,
  211. ResetFailure,
  212. UnderVoltage,
  213. WeakSignal
  214. } ChargePointErrorCode;
  215. #if 0
  216. static char *ChargePointErrorCodeStr[] = {
  217. MACROSTR(ConnectorLockFailure),
  218. MACROSTR(EVCommunicationError),
  219. MACROSTR(GroundFailure),
  220. MACROSTR(HighTemperature),
  221. MACROSTR(InternalError),
  222. MACROSTR(LocalListConflict),
  223. MACROSTR(NoError),
  224. MACROSTR(OtherError),
  225. MACROSTR(OverCurrentFailure),
  226. MACROSTR(OverVoltage),
  227. MACROSTR(PowerMeterFailure),
  228. MACROSTR(PowerSwitchFailure),
  229. MACROSTR(ReaderFailure),
  230. MACROSTR(ResetFailure),
  231. MACROSTR(UnderVoltage),
  232. MACROSTR(WeakSignal)
  233. };
  234. #endif
  235. /*ChargePointStatus*/
  236. typedef enum {
  237. Available =0,
  238. Preparing,
  239. Charging,
  240. SuspendedEVSE,
  241. SuspendedEV,
  242. Finishing,
  243. Reserved,
  244. Unavailable,
  245. Faulted
  246. } ChargePointStatus;
  247. static char * ChargePointStatusStr[] = {
  248. MACROSTR(Available),
  249. MACROSTR(Preparing),
  250. MACROSTR(Charging),
  251. MACROSTR(SuspendedEVSE),
  252. MACROSTR(SuspendedEV),
  253. MACROSTR(Finishing),
  254. MACROSTR(Reserved),
  255. MACROSTR(Unavailable),
  256. MACROSTR(Faulted)
  257. };
  258. /*AvailabilityType*/
  259. typedef enum {
  260. RegistrationStatus_Accepted,
  261. RegistrationStatus_Pending,
  262. RegistrationStatus_Rejected
  263. } RegistrationStatus;
  264. static char *RegistrationStatusStr[] = {
  265. MACROSTR(Accepted),
  266. MACROSTR(Pending),
  267. MACROSTR(Rejected)
  268. };
  269. /*AvailabilityType*/
  270. typedef enum {
  271. Inoperative,
  272. Operative
  273. } AvailabilityType;
  274. static char *AvailabilityTypeStr[] = {
  275. MACROSTR(Inoperative),
  276. MACROSTR(Operative)
  277. };
  278. /*AvailabilityStatus*/
  279. typedef enum {
  280. Accepted,
  281. Rejected,
  282. Scheduled
  283. } AvailabilityStatus;
  284. static char *AvailabilityStatusStr[] = {
  285. MACROSTR(Accepted),
  286. MACROSTR(Rejected),
  287. MACROSTR(Scheduled)
  288. };
  289. /*ConfigurationStatus*/
  290. typedef enum {
  291. ConfigurationStatus_Accepted,
  292. ConfigurationStatus_Rejected,
  293. RebootRequired,
  294. NotSupported
  295. } ConfigurationStatus;
  296. static char *ConfigurationStatusStr[] = {
  297. MACROSTR(Accepted),
  298. MACROSTR(Rejected),
  299. MACROSTR(RebootRequired),
  300. MACROSTR(NotSupported)
  301. };
  302. /*ClearCacheStatus*/
  303. typedef enum {
  304. ClearCacheStatus_Accepted,
  305. ClearCacheStatus_Rejected
  306. } ClearCacheStatus;
  307. static char *ClearCacheStatusStr[] = {
  308. MACROSTR(Accepted),
  309. MACROSTR(Rejected)
  310. };
  311. /*ChargingProfilePurposeType*/
  312. typedef enum {
  313. ChargePointMaxProfile,
  314. TxDefaultProfile,
  315. TxProfile
  316. } ChargingProfilePurposeType;
  317. static char *ChargingProfilePurposeTypeStr[] = {
  318. MACROSTR(ChargePointMaxProfile),
  319. MACROSTR(TxDefaultProfile),
  320. MACROSTR(TxProfile)
  321. };
  322. /*ChargingProfileStatus*/
  323. typedef enum {
  324. ChargingProfileStatus_Accepted,
  325. ChargingProfileStatus_Rejected,
  326. ChargingProfileStatus_NotSupported
  327. } ChargingProfileStatus;
  328. static char *ChargingProfileStatusStr[] = {
  329. MACROSTR(Accepted),
  330. MACROSTR(Rejected),
  331. MACROSTR(NotSupported)
  332. };
  333. /*ClearChargingProfileStatus*/
  334. typedef enum {
  335. ClearChargingProfileStatus_Accepted,
  336. ClearChargingProfileStatus_Unknown
  337. } ClearChargingProfileStatus;
  338. static char *ClearChargingProfileStatusStr[] = {
  339. MACROSTR(Accepted),
  340. MACROSTR(Unknown)
  341. };
  342. /*GetCompositeScheduleStatus*/
  343. typedef enum {
  344. GetCompositeScheduleStatus_Accepted,
  345. GetCompositeScheduleStatus_Rejected
  346. } GetCompositeScheduleStatus;
  347. static char *GetCompositeScheduleStatusStr[] = {
  348. MACROSTR(Accepted),
  349. MACROSTR(Rejected)
  350. };
  351. /*ChargingRateUnitType*/
  352. typedef enum {
  353. ChargingRateUnitType_W,
  354. ChargingRateUnitType_A
  355. } ChargingRateUnitType;
  356. /*AuthorizationStatus*/
  357. typedef enum {
  358. AuthorizationStatus_Accepted ,
  359. AuthorizationStatus_Blocked ,
  360. AuthorizationStatus_Expired ,
  361. AuthorizationStatus_Invalid ,
  362. AuthorizationStatus_ConcurrentTx
  363. } AuthorizationStatus;
  364. /*UpdateType*/
  365. typedef enum {
  366. Differential ,
  367. Full
  368. } UpdateType;
  369. static char *UpdateTypeStr[] = {
  370. MACROSTR(Differential),
  371. MACROSTR(Full)
  372. };
  373. /*UpdateStatus*/
  374. typedef enum {
  375. UpdateStatus_Accepted ,
  376. UpdateStatus_Failed ,
  377. UpdateStatus_NotSupported ,
  378. UpdateStatus_VersionMismatch
  379. } UpdateStatus;
  380. static char *UpdateStatusStr[] = {
  381. MACROSTR(Accepted),
  382. MACROSTR(Failed),
  383. MACROSTR(NotSupported),
  384. MACROSTR(VersionMismatch)
  385. };
  386. /*RemoteStartStopStatus*/
  387. typedef enum {
  388. RemoteStartStopStatus_Accepted,
  389. RemoteStartStopStatus_Rejected
  390. } RemoteStartStopStatus;
  391. static char *RemoteStartStopStatusStr[] = {
  392. MACROSTR(Accepted),
  393. MACROSTR(Rejected)
  394. };
  395. /*ReservationStatus*/
  396. typedef enum {
  397. ReservationStatus_Accepted,
  398. ReservationStatus_Faulted,
  399. ReservationStatus_Occupied,
  400. ReservationStatus_Rejected,
  401. ReservationStatus_Unavailable
  402. } ReservationStatus;
  403. static char *ReservationStatusStr[] = {
  404. MACROSTR(Accepted),
  405. MACROSTR(Faulted),
  406. MACROSTR(Occupied),
  407. MACROSTR(Rejected),
  408. MACROSTR(Unavailable)
  409. };
  410. /*ResetType*/
  411. typedef enum {
  412. Hard,
  413. Soft
  414. } ResetType;
  415. static char *ResetTypeStr[] = {
  416. MACROSTR(Hard),
  417. MACROSTR(Soft)
  418. };
  419. /*ResetStatus*/
  420. typedef enum {
  421. ResetStatus_Accepted,
  422. ResetStatus_Rejected
  423. } ResetStatus;
  424. static char *ResetStatusStr[] = {
  425. MACROSTR(Accepted),
  426. MACROSTR(Rejected)
  427. };
  428. /*DiagnosticsStatus*/
  429. typedef enum {
  430. DiagnosticsStatus_Idle,
  431. DiagnosticsStatus_Uploaded,
  432. DiagnosticsStatus_UploadFailed,
  433. DiagnosticsStatus_Uploading
  434. } DiagnosticsStatus;
  435. static char * DiagnosticsStatusStr[] = {
  436. MACROSTR(Idle),
  437. MACROSTR(Uploaded),
  438. MACROSTR(UploadFailed),
  439. MACROSTR(Uploading)
  440. };
  441. /*FirmwareStatus*/
  442. typedef enum {
  443. FirmwareStatus_Downloaded,
  444. FirmwareStatus_DownloadFailed,
  445. FirmwareStatus_Downloading,
  446. FirmwareStatus_Idle,
  447. FirmwareStatus_InstallationFailed,
  448. FirmwareStatus_Installing,
  449. FirmwareStatus_Installed
  450. } FirmwareStatus;
  451. static char * FirmwareStatusStr[] = {
  452. MACROSTR(Downloaded),
  453. MACROSTR(DownloadFailed),
  454. MACROSTR(Downloading),
  455. MACROSTR(Idle),
  456. MACROSTR(InstallationFailed),
  457. MACROSTR(Installing),
  458. MACROSTR(Installed)
  459. };
  460. /*MessageTrigger*/
  461. typedef enum {
  462. BootNotification,
  463. DiagnosticsStatusNotification,
  464. FirmwareStatusNotification,
  465. Heartbeat,
  466. MeterValues,
  467. StatusNotification
  468. } MessageTrigger;
  469. static char * MessageTriggerStr[] = {
  470. MACROSTR(BootNotification),
  471. MACROSTR(DiagnosticsStatusNotification),
  472. MACROSTR(FirmwareStatusNotification),
  473. MACROSTR(Heartbeat),
  474. MACROSTR(MeterValues),
  475. MACROSTR(StatusNotification)
  476. };
  477. /*TriggerMessageStatus*/
  478. typedef enum {
  479. TriggerMessageStatus_Accepted ,
  480. TriggerMessageStatus_Rejected ,
  481. TriggerMessageStatus_NotImplemented
  482. } TriggerMessageStatus;
  483. static char * TriggerMessageStatusStr[] = {
  484. MACROSTR(Accepted),
  485. MACROSTR(Rejected),
  486. MACROSTR(NotImplemented)
  487. };
  488. /*UnlockStatus*/
  489. typedef enum {
  490. Unlocked,
  491. UnlockFailed,
  492. UnlockStatus_NotSupported
  493. } UnlockStatus;
  494. static char * UnlockStatusStr[] = {
  495. MACROSTR(Unlocked),
  496. MACROSTR(UnlockFailed),
  497. MACROSTR(NotSupported)
  498. };
  499. /*StopTransactionReason*/
  500. typedef enum {
  501. EmergencyStop,
  502. EVDisconnected,
  503. HardReset,
  504. Local,
  505. Other,
  506. PowerLoss,
  507. Reboot,
  508. Remote,
  509. SoftReset,
  510. UnlockCommand,
  511. DeAuthorized
  512. } StopTransactionReason;
  513. #if 0
  514. static char * StopTransactionReasonStr[] = {
  515. MACROSTR(EmergencyStop),
  516. MACROSTR(EVDisconnected),
  517. MACROSTR(HardReset),
  518. MACROSTR(Local),
  519. MACROSTR(Other),
  520. MACROSTR(PowerLoss),
  521. MACROSTR(Reboot),
  522. MACROSTR(Remote),
  523. MACROSTR(SoftReset),
  524. MACROSTR(UnlockCommand),
  525. MACROSTR(DeAuthorized)
  526. };
  527. #endif
  528. /*CancelReservationStatus*/
  529. typedef enum {
  530. CancelReservationStatus_Accepted,
  531. CancelReservationStatus_Rejected
  532. } CancelReservationStatus;
  533. static char * CancelReservationStatusStr[] = {
  534. MACROSTR(Accepted),
  535. MACROSTR(Rejected)
  536. };
  537. /*ReadingContext*/
  538. typedef enum {
  539. ReadingContext_Interruption_Begin,
  540. ReadingContext_Interruption_End,
  541. ReadingContext_Other,
  542. ReadingContext_Sample_Clock,
  543. ReadingContext_Sample_Periodic ,
  544. ReadingContext_Transaction_Begin ,
  545. ReadingContext_Transaction_End,
  546. ReadingContext_Trigger
  547. } ReadingContext;
  548. static char * ReadingContextStr[] = {
  549. MACROSTR(Interruption.Begin),
  550. MACROSTR(Interruption.End),
  551. MACROSTR(Other),
  552. MACROSTR(Sample.Clock),
  553. MACROSTR(Sample.Periodic),
  554. MACROSTR(Transaction.Begin),
  555. MACROSTR(Transaction.End),
  556. MACROSTR(Trigger)
  557. };
  558. /*ValueFormat*/
  559. typedef enum {
  560. Raw,
  561. SignedData
  562. } ValueFormat;
  563. static char * ValueFormatStr[] = {
  564. MACROSTR(Raw),
  565. MACROSTR(SignedData)
  566. };
  567. /*Measurand*/
  568. typedef enum {
  569. Current_Export ,
  570. Current_Import,
  571. Current_Offered,
  572. Energy_Active_Export_Register,
  573. Energy_Active_Import_Register,
  574. Energy_Reactive_Export_Register,
  575. Energy_Reactive_Import_Register,
  576. Energy_Active_Export_Interval,
  577. Energy_Active_Import_Interval,
  578. Energy_Reactive_Export_Interval,
  579. Energy_Reactive_Import_Interval,
  580. Frequency,
  581. Power_Active_Export ,
  582. Power_Active_Import,
  583. Power_Factor,
  584. Power_Offered,
  585. Power_Reactive_Export,
  586. Power_Reactive_Import,
  587. RPM,
  588. SoC,
  589. Temperature ,
  590. Voltage
  591. } Measurand;
  592. static char * MeasurandStr[] = {
  593. MACROSTR(Current.Export),
  594. MACROSTR(Current.Import),
  595. MACROSTR(Current.Offered),
  596. MACROSTR(Energy.Active.Export.Register),
  597. MACROSTR(Energy.Active.Import.Register),
  598. MACROSTR(Energy.Reactive.Export.Register),
  599. MACROSTR(Energy.Reactive.Import.Register),
  600. MACROSTR(Energy.Active.Export.Interval),
  601. MACROSTR(Energy.Active.Import.Interval),
  602. MACROSTR(Energy.Reactive.Export.Interval),
  603. MACROSTR(Energy.Reactive.Import.Interval),
  604. MACROSTR(Frequency),
  605. MACROSTR(Power.Active.Export),
  606. MACROSTR(Power.Active.Import),
  607. MACROSTR(Power.Factor),
  608. MACROSTR(Power.Offered),
  609. MACROSTR(Power.Reactive.ExportMACROSTR),
  610. MACROSTR(Power.Reactive.Import),
  611. MACROSTR(RPM),
  612. MACROSTR(SoC),
  613. MACROSTR(Temperature),
  614. MACROSTR(Voltage)
  615. };
  616. /*Location*/
  617. typedef enum {
  618. Location_Body,
  619. Location_Cable,
  620. Location_EV,
  621. Location_Inlet ,
  622. Location_Outlet
  623. } Location;
  624. static char * LocationStr[] = {
  625. MACROSTR(Body),
  626. MACROSTR(Cable),
  627. MACROSTR(EV),
  628. MACROSTR(Inlet),
  629. MACROSTR(Outlet)
  630. };
  631. /*Phase*/
  632. typedef enum {
  633. L1,
  634. L2,
  635. L3,
  636. N,
  637. L1_N,
  638. L2_N,
  639. L3_N,
  640. L1_L2,
  641. L2_L3,
  642. L3_L1
  643. } Phase;
  644. static char * PhaseStr[] = {
  645. MACROSTR(L1),
  646. MACROSTR(L2),
  647. MACROSTR(L3),
  648. MACROSTR(N),
  649. MACROSTR(L1-N),
  650. MACROSTR(L2-N),
  651. MACROSTR(L3-N),
  652. MACROSTR(L1-L2),
  653. MACROSTR(L2-L3),
  654. MACROSTR(L3-L1)
  655. };
  656. /*UnitOfMeasure*/
  657. typedef enum {
  658. UnitOfMeasure_Wh,
  659. UnitOfMeasure_kWh ,
  660. UnitOfMeasure_varh ,
  661. UnitOfMeasure_kvarh ,
  662. UnitOfMeasure_W ,
  663. UnitOfMeasure_kW ,
  664. UnitOfMeasure_VA ,
  665. UnitOfMeasure_kVA ,
  666. UnitOfMeasure_var ,
  667. UnitOfMeasure_kvar ,
  668. UnitOfMeasure_A ,
  669. UnitOfMeasure_V ,
  670. UnitOfMeasure_Celsius ,
  671. UnitOfMeasure_Fahrenheit ,
  672. UnitOfMeasure_K ,
  673. UnitOfMeasure_Percent
  674. } UnitOfMeasure;
  675. static char * UnitOfMeasureStr[] = {
  676. MACROSTR(Wh),
  677. MACROSTR(kWh),
  678. MACROSTR(varh),
  679. MACROSTR(kvarh),
  680. MACROSTR(W),
  681. MACROSTR(kW),
  682. MACROSTR(VA),
  683. MACROSTR(kVA),
  684. MACROSTR(var),
  685. MACROSTR(kvar),
  686. MACROSTR(A),
  687. MACROSTR(V),
  688. MACROSTR(Celsius),
  689. MACROSTR(Fahrenheit),
  690. MACROSTR(K),
  691. MACROSTR(Percent)
  692. };
  693. #if 0
  694. /*Configuration enum*/
  695. enum CoreProfile {
  696. AllowOfflineTxForUnknownId=0,
  697. AuthorizationCacheEnabled,
  698. AuthorizeRemoteTxRequests,
  699. BlinkRepeat,
  700. ClockAlignedDataInterval,
  701. ConnectionTimeOut,
  702. GetConfigurationMaxKeys,
  703. HeartbeatInterval,
  704. LightIntensity,
  705. LocalAuthorizeOffline,
  706. LocalPreAuthorize,
  707. MaxEnergyOnInvalidId,
  708. MeterValuesAlignedData,
  709. MeterValuesAlignedDataMaxLength,
  710. MeterValuesSampledData,
  711. MeterValuesSampledDataMaxLength,
  712. MeterValueSampleInterval,
  713. MinimumStatusDuration,
  714. NumberOfConnectors,
  715. ResetRetries,
  716. ConnectorPhaseRotation,
  717. ConnectorPhaseRotationMaxLength,
  718. StopTransactionOnEVSideDisconnect,
  719. StopTransactionOnInvalidId,
  720. StopTxnAlignedData,
  721. StopTxnAlignedDataMaxLength,
  722. StopTxnSampledData,
  723. StopTxnSampledDataMaxLength,
  724. SupportedFeatureProfiles,
  725. SupportedFeatureProfilesMaxLength,
  726. TransactionMessageAttempts,
  727. TransactionMessageRetryInterval,
  728. UnlockConnectorOnEVSideDisconnect,
  729. WebSocketPingInterval,
  730. _CoreProfile_CNT
  731. };
  732. #endif
  733. enum LocalAuthListManagementProfile{
  734. LocalAuthListEnabled=0,
  735. LocalAuthListMaxLength,
  736. SendLocalListMaxLength,
  737. _LocalAuthListManagementProfile_CNT
  738. };
  739. enum ReservationProfile{
  740. ReserveConnectorZeroSupported
  741. };
  742. enum SmartChargingProfile{
  743. ChargeProfileMaxStackLevel,
  744. ChargingScheduleAllowedChargingRateUnit,
  745. ChargingScheduleMaxPeriods,
  746. ConnectorSwitch3to1PhaseSupported,
  747. MaxChargingProfilesInstalled
  748. };
  749. enum ChargerSystemStatus{
  750. ChargerSystemStatus_Booting,
  751. ChargerSystemStatus_Idle,
  752. ChargerSystemStatus_Authorizing,
  753. ChargerSystemStatus_Preparing,
  754. ChargerSystemStatus_Charging,
  755. ChargerSystemStatus_Terminating,
  756. ChargerSystemStatus_Alarm,
  757. ChargerSystemStatus_Fault
  758. };
  759. enum GetConfigurationKey {
  760. GetConfiguration_AllowOfflineTxForUnknownId=0,
  761. GetConfiguration_AuthorizationCacheEnabled,
  762. GetConfiguration_AuthorizeRemoteTxRequests,
  763. GetConfiguration_BlinkRepeat,
  764. GetConfiguration_ClockAlignedDataInterval,
  765. GetConfiguration_ConnectionTimeOut,
  766. GetConfiguration_GetConfigurationMaxKeys,
  767. GetConfiguration_HeartbeatInterval,
  768. GetConfiguration_LightIntensity,
  769. GetConfiguration_LocalAuthorizeOffline,
  770. GetConfiguration_LocalPreAuthorize,
  771. GetConfiguration_MaxEnergyOnInvalidId,
  772. GetConfiguration_MeterValuesAlignedData,
  773. GetConfiguration_MeterValuesAlignedDataMaxLength,
  774. GetConfiguration_MeterValuesSampledData,
  775. GetConfiguration_MeterValuesSampledDataMaxLength,
  776. GetConfiguration_MeterValueSampleInterval,
  777. GetConfiguration_MinimumStatusDuration,
  778. GetConfiguration_NumberOfConnectors,
  779. GetConfiguration_ResetRetries,
  780. GetConfiguration_ConnectorPhaseRotation,
  781. GetConfiguration_ConnectorPhaseRotationMaxLength,
  782. GetConfiguration_StopTransactionOnEVSideDisconnect,
  783. GetConfiguration_StopTransactionOnInvalidId,
  784. GetConfiguration_StopTxnAlignedData,
  785. GetConfiguration_StopTxnAlignedDataMaxLength,
  786. GetConfiguration_StopTxnSampledData,
  787. GetConfiguration_StopTxnSampledDataMaxLength,
  788. GetConfiguration_SupportedFeatureProfiles,
  789. GetConfiguration_SupportedFeatureProfilesMaxLength,
  790. GetConfiguration_TransactionMessageAttempts,
  791. GetConfiguration_TransactionMessageRetryInterval,
  792. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  793. GetConfiguration_WebSocketPingInterval,
  794. GetConfiguration_LocalAuthListEnabled,
  795. GetConfiguration_LocalAuthListMaxLength,
  796. GetConfiguration_SendLocalListMaxLength,
  797. GetConfiguration_ReserveConnectorZeroSupported,
  798. GetConfiguration_ChargeProfileMaxStackLevel,
  799. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  800. GetConfiguration_ChargingScheduleMaxPeriods,
  801. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  802. GetConfiguration_MaxChargingProfilesInstalled,
  803. };
  804. //GetConfiguration Array
  805. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  806. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  807. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  808. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  809. //==========================================
  810. // Init all share memory
  811. //==========================================
  812. int InitShareMemory()
  813. {
  814. int result = PASS;
  815. int MeterSMId;
  816. //creat ShmSysConfigAndInfo
  817. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  818. {
  819. #ifdef SystemLogMessage
  820. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  821. #endif
  822. result = FAIL;
  823. }
  824. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  825. {
  826. #ifdef SystemLogMessage
  827. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  828. #endif
  829. result = FAIL;
  830. }
  831. else
  832. {}
  833. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  834. {
  835. #ifdef SystemLogMessage
  836. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  837. #endif
  838. result = FAIL;
  839. }
  840. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  841. {
  842. #ifdef SystemLogMessage
  843. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  844. #endif
  845. result = FAIL;
  846. }
  847. else
  848. {}
  849. //creat ShmPsuData
  850. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  851. {
  852. #ifdef SystemLogMessage
  853. DEBUG_ERROR("shmget ShmPsuData NG\n");
  854. #endif
  855. result = FAIL;
  856. }
  857. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  858. {
  859. #ifdef SystemLogMessage
  860. DEBUG_ERROR("shmat ShmPsuData NG\n");
  861. #endif
  862. result = FAIL;
  863. }
  864. else
  865. {}
  866. //creat ShmOCPP16Data
  867. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  868. {
  869. #ifdef SystemLogMessage
  870. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  871. #endif
  872. result = FAIL;
  873. }
  874. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  875. {
  876. #ifdef SystemLogMessage
  877. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  878. #endif
  879. result = FAIL;
  880. }
  881. else
  882. {}
  883. /****************************** For Initial Settings************************************************/
  884. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  885. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  886. {
  887. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  888. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  889. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  890. }
  891. // Charger PRE_SYS_MODE
  892. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  893. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  894. clientTime.Heartbeat=time((time_t*)NULL);
  895. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  896. {
  897. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  898. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  899. }
  900. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  901. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  902. // allocate Configuration memory address
  903. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  904. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  905. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  906. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  908. {
  909. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  910. DEBUG_INFO("DC ...\n");
  911. }
  912. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  913. {
  914. SystemInitial = AC_QUANTITY;
  915. DEBUG_INFO("AC ...\n");
  916. }
  917. //Status Setting
  918. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  919. {
  920. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  921. }
  922. for (int index = 0; index < CCS_QUANTITY; index++)
  923. {
  924. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  925. }
  926. for (int index = 0; index < GB_QUANTITY; index++)
  927. {
  928. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  929. }
  930. for (int index = 0; index < AC_QUANTITY; index++)
  931. {
  932. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  933. }
  934. return result;
  935. }
  936. int ProcessShareMemory()
  937. {
  938. if(InitShareMemory() == FAIL)
  939. {
  940. #ifdef SystemLogMessage
  941. DEBUG_ERROR("InitShareMemory NG\n");
  942. #endif
  943. if(ShmStatusCodeData!=NULL)
  944. {
  945. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  946. }
  947. sleep(5);
  948. return FAIL;
  949. }
  950. return PASS;
  951. }
  952. //---------------------------------------------
  953. // new:
  954. // enum SYSTEM_STATUS
  955. // {
  956. // SYS_MODE_BOOTING = 0,
  957. // SYS_MODE_IDLE = 1,
  958. // SYS_MODE_AUTHORIZING = 2,
  959. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  960. // SYS_MODE_REASSIGN = 4,
  961. // SYS_MODE_PREPARING = 5,
  962. // SYS_MODE_PREPARE_FOR_EV = 6,
  963. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  964. // SYS_MODE_CHARGING = 8,
  965. // SYS_MODE_TERMINATING = 9,
  966. // SYS_MODE_COMPLETE = 10,
  967. // SYS_MODE_ALARM = 11,
  968. // SYS_MODE_FAULT = 12,
  969. // SYS_MODE_RESERVATION = 13,
  970. // SYS_MODE_BOOKING = 14,
  971. // SYS_MODE_MAINTAIN = 15,
  972. // SYS_MODE_DEBUG = 16,
  973. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  974. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  975. // SYS_MODE_UPDATE = 19
  976. // };
  977. //
  978. //
  979. //-----------------------------------------
  980. void CheckSystemValue(void)
  981. {
  982. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  983. int IdleModeCnt = 0;
  984. char filenmae[100]={0};
  985. char str[100]={0};
  986. //===============================
  987. // send Heartbeat
  988. //===============================
  989. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  990. {
  991. printf("Heartbeat !!!\n");
  992. //parameter for test
  993. sendHeartbeatRequest(0);
  994. //==============================================
  995. // Reset Waiting Time
  996. //==============================================
  997. clientTime.Heartbeat=time((time_t*)NULL);
  998. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  999. }
  1000. //==============================================
  1001. // Update firmware request
  1002. //==============================================
  1003. if(isUpdateRequest == TRUE )
  1004. {
  1005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1006. {
  1007. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1008. {
  1009. //check SystemStatus
  1010. /*************************DC*******************************/
  1011. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1012. {
  1013. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1014. {
  1015. IdleModeCnt = IdleModeCnt + 1;
  1016. }
  1017. }
  1018. for (int index = 0; index < CCS_QUANTITY; index++)
  1019. {
  1020. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1021. {
  1022. IdleModeCnt = IdleModeCnt + 1;
  1023. }
  1024. }
  1025. for (int index = 0; index < GB_QUANTITY; index++)
  1026. {
  1027. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1028. {
  1029. IdleModeCnt = IdleModeCnt + 1;
  1030. }
  1031. }
  1032. }
  1033. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1034. {
  1035. isUpdateRequest = FALSE;
  1036. }
  1037. }
  1038. else
  1039. {
  1040. /*************************AC*******************************/
  1041. for (int index = 0; index < AC_QUANTITY; index++)
  1042. {
  1043. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1044. {
  1045. IdleModeCnt = IdleModeCnt + 1;
  1046. }
  1047. }
  1048. if(IdleModeCnt == AC_QUANTITY)
  1049. {
  1050. isUpdateRequest = FALSE;
  1051. }
  1052. }
  1053. }
  1054. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1055. {
  1056. //===============================
  1057. // CSU Trigger Reset Conf
  1058. //===============================
  1059. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1060. {
  1061. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1062. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1063. {
  1064. server_sign = FALSE;
  1065. }
  1066. }
  1067. //===============================
  1068. // CSU Trigger Authorize Request
  1069. //===============================
  1070. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1071. {
  1072. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1073. {
  1074. sendAuthorizeRequest(0);
  1075. authorizeRetryTimes = authorizeRetryTimes + 1;
  1076. // authenrequest = TRUE
  1077. if(authorizeRetryTimes < 3)
  1078. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1079. }
  1080. }
  1081. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1082. {
  1083. authorizeRetryTimes = 0;
  1084. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1085. server_sign = FALSE;
  1086. }
  1087. //===============================
  1088. // CSU Trigger Smart Charging Profilw
  1089. //===============================
  1090. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1091. {
  1092. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1093. GetChargingProfileRequest(gun_index);
  1094. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1095. }
  1096. //==============================================
  1097. // Charger start transaction
  1098. //==============================================
  1099. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1100. {
  1101. sendStartTransactionRequest(gun_index);
  1102. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1103. clientTime.StartTransaction = time((time_t*)NULL);
  1104. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1105. }
  1106. //==============================================
  1107. // Charger stop transaction
  1108. //==============================================
  1109. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1110. {
  1111. sendStopTransactionRequest(gun_index);
  1112. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1113. clientTime.StopTransaction = time((time_t*)NULL);
  1114. }
  1115. //==============================================
  1116. // Charger status report
  1117. //==============================================
  1118. /* Check Mode Change */
  1119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1120. {
  1121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1122. {
  1123. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1124. {
  1125. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1126. {
  1127. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1128. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1129. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1130. statusModeChage[gun_index] = TRUE;
  1131. }
  1132. }
  1133. }
  1134. for (int index = 0; index < CCS_QUANTITY; index++)
  1135. {
  1136. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1137. {
  1138. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1139. {
  1140. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1141. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1142. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1143. statusModeChage[gun_index] = TRUE;
  1144. }
  1145. }
  1146. }
  1147. for (int index = 0; index < GB_QUANTITY; index++)
  1148. {
  1149. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1150. {
  1151. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1152. {
  1153. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1154. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1155. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1156. statusModeChage[gun_index] = TRUE;
  1157. }
  1158. }
  1159. }
  1160. }
  1161. else //AC
  1162. {
  1163. for (int index = 0; index < AC_QUANTITY; index++)
  1164. {
  1165. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1166. {
  1167. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1168. {
  1169. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1170. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1171. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1172. statusModeChage[gun_index] = TRUE;
  1173. }
  1174. }
  1175. }// END OF FOR
  1176. }// END OF ELSE
  1177. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1178. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1179. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1180. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1181. {
  1182. if(SystemInitial != 0)
  1183. SystemInitial = SystemInitial -1;
  1184. sendStatusNotificationRequest(gun_index);
  1185. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1186. statusModeChage[gun_index] = FALSE;
  1187. }
  1188. //==============================================
  1189. // Meter report
  1190. //==============================================
  1191. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1192. {
  1193. //check Transaction active
  1194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1195. {
  1196. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1197. {
  1198. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1199. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1200. {
  1201. meterValueSend[gun_index] =1;
  1202. }
  1203. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1204. {
  1205. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1206. if((access(filenmae,F_OK))!=-1)
  1207. {
  1208. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1209. sprintf(str,"rm -f %s",filenmae);
  1210. system(str);
  1211. }
  1212. }
  1213. }// End for CHAdeMO
  1214. for (int index = 0; index < CCS_QUANTITY; index++)
  1215. {
  1216. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1217. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1218. {
  1219. meterValueSend[gun_index] =1;
  1220. }
  1221. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1222. {
  1223. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1224. if((access(filenmae,F_OK))!=-1)
  1225. {
  1226. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1227. sprintf(str,"rm -f %s",filenmae);
  1228. system(str);
  1229. }
  1230. }
  1231. } // End for CCS
  1232. for (int index = 0; index < GB_QUANTITY; index++)
  1233. {
  1234. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1235. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1236. {
  1237. meterValueSend[gun_index] =1;
  1238. }
  1239. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1240. {
  1241. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1242. if((access(filenmae,F_OK))!=-1)
  1243. {
  1244. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1245. sprintf(str,"rm -f %s",filenmae);
  1246. system(str);
  1247. }
  1248. }
  1249. }// End for GB
  1250. }
  1251. else
  1252. {
  1253. for (int index = 0; index < AC_QUANTITY; index++)
  1254. {
  1255. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1256. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1257. {
  1258. meterValueSend[gun_index] =1;
  1259. }
  1260. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1261. {
  1262. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1263. if((access(filenmae,F_OK))!=-1)
  1264. {
  1265. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1266. sprintf(str,"rm -f %s",filenmae);
  1267. system(str);
  1268. }
  1269. }
  1270. }//End for AC
  1271. }//END OF ELSE
  1272. // sleep(1);
  1273. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1274. if(meterValueSend[gun_index] == 1)
  1275. sendMeterValuesRequest(gun_index);
  1276. }
  1277. //==============================================
  1278. // Check Connector reserved
  1279. //==============================================
  1280. //===============================
  1281. // Check if Reserve is expired
  1282. //===============================
  1283. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1284. {
  1285. double diff_t;
  1286. struct tm tp;
  1287. // current time
  1288. time_t t = time(NULL);
  1289. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1290. tp.tm_isdst = -1;
  1291. time_t utc = mktime(&tp);
  1292. diff_t = difftime(utc, t);
  1293. if(diff_t <= 0)
  1294. {
  1295. DEBUG_INFO("reserve expired !!! \n");
  1296. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1297. }
  1298. }//END OF Check if Reserve is expired
  1299. //==========================================
  1300. // csu trigger FirmwareStatusNotificationReq
  1301. //==========================================
  1302. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1303. {
  1304. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1305. }
  1306. //==========================================
  1307. // csu trigger CancelReservationConf
  1308. //==========================================
  1309. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1310. {
  1311. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1312. }
  1313. //==========================================
  1314. // csu trigger ChangeAvailabilityConf
  1315. //==========================================
  1316. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1317. {
  1318. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1319. }
  1320. //==========================================
  1321. // csu trigger UnlockConnectorConf
  1322. //==========================================
  1323. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1324. {
  1325. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1326. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1327. }
  1328. //==========================================
  1329. // csu trigger ReserveNowConf
  1330. //==========================================
  1331. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1332. {
  1333. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1334. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1335. }
  1336. //==========================================
  1337. // csu trigger DataTransferReq
  1338. //==========================================
  1339. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1340. {
  1341. sendDataTransferRequest(gun_index);
  1342. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1343. }
  1344. }
  1345. }
  1346. //==========================================
  1347. // send request routine
  1348. //==========================================
  1349. int sendAuthorizeRequest(int gun_index)
  1350. {
  1351. mtrace();
  1352. int result = FAIL;
  1353. char message[100]={0};
  1354. char guid[37];
  1355. char tempdata[65]={0};
  1356. DEBUG_INFO("sendAuthorizeRequest \n");
  1357. //Local Authorize
  1358. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))
  1359. {
  1360. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1361. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1362. {
  1363. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1364. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1365. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1366. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1367. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1368. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1369. authorizeRetryTimes = 0;
  1370. return result;
  1371. }
  1372. else
  1373. {
  1374. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1375. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1376. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1377. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1378. result = PASS;
  1379. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1380. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1381. authorizeRetryTimes = 0;
  1382. return result;
  1383. }
  1384. }
  1385. //initailize struct Authorize
  1386. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1387. //get data from shared memory
  1388. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1389. random_uuid(guid);
  1390. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1391. LWS_Send(message);
  1392. sprintf(tempdata, "Authorize,%d", gun_index);
  1393. if(hashmap_operation(0, guid, tempdata) == 1)
  1394. {
  1395. result = PASS;
  1396. DEBUG_ERROR("Authorize mapItem pass\n");
  1397. }
  1398. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1399. return result;
  1400. }
  1401. int sendBootNotificationRequest(void)
  1402. {
  1403. mtrace();
  1404. int result = FAIL;
  1405. char message[500]={0}, payload[700]={0};
  1406. char guid[37]={0};
  1407. char tempdata[65]={0};
  1408. int IsGunCharging = FALSE;
  1409. //check Transaction active
  1410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1411. {
  1412. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1413. {
  1414. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1415. {
  1416. IsGunCharging = TRUE;
  1417. }
  1418. }
  1419. for (int index = 0; index < CCS_QUANTITY; index++)
  1420. {
  1421. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1422. {
  1423. IsGunCharging = TRUE;
  1424. }
  1425. }
  1426. for (int index = 0; index < GB_QUANTITY; index++)
  1427. {
  1428. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1429. {
  1430. IsGunCharging = TRUE;
  1431. }
  1432. }
  1433. }
  1434. else
  1435. {
  1436. for (int index = 0; index < AC_QUANTITY; index++)
  1437. {
  1438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1439. {
  1440. IsGunCharging = TRUE;
  1441. }
  1442. }
  1443. }
  1444. if(IsGunCharging == TRUE)
  1445. {
  1446. server_sign = TRUE;
  1447. return result;
  1448. }
  1449. // Fill BootNotification fields
  1450. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1451. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1452. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1453. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1454. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1455. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1456. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1457. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1458. ShmOCPP16Data->ChargeBoxId
  1459. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1460. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1461. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1462. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1463. ,ShmOCPP16Data->BootNotification.CpIccid
  1464. ,ShmOCPP16Data->BootNotification.CpImsi
  1465. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1466. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1467. random_uuid(guid);
  1468. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1469. LWS_Send(message);
  1470. sprintf(tempdata, "BootNotification,0");
  1471. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1472. {
  1473. result = PASS;
  1474. }
  1475. memset(queuedata, 0, sizeof(queuedata));
  1476. strcpy(queuedata,message);
  1477. HeartBeatCount = 0;
  1478. //#ifdef SystemLogMessage
  1479. //DEBUG_INFO(">>>>>BootNotification request\n");
  1480. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1481. //#endif
  1482. return result;
  1483. }
  1484. int sendDataTransferRequest(int gun_index)
  1485. {
  1486. mtrace();
  1487. char message[1000]={0};
  1488. char guid[37]={0};
  1489. char tempdata[65]={0};
  1490. int result = FAIL;
  1491. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1492. random_uuid(guid);
  1493. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1494. MESSAGE_TYPE_CALL,
  1495. guid,
  1496. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1497. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1498. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1499. LWS_Send(message);
  1500. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1501. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1502. {
  1503. result = PASS;
  1504. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1505. }
  1506. return result;
  1507. }
  1508. int sendDiagnosticsStatusNotificationRequest(char *status)
  1509. {
  1510. mtrace();
  1511. int result = FAIL;
  1512. char message[110]={0};
  1513. char guid[37]={0};
  1514. char tempdata[65]={0};
  1515. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1516. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1517. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1518. random_uuid(guid);
  1519. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1520. LWS_Send(message);
  1521. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1522. if(hashmap_operation(0, guid, tempdata) == 1)
  1523. {
  1524. result = PASS;
  1525. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1526. }
  1527. //#ifdef SystemLogMessage
  1528. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1529. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1530. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1531. //#endif
  1532. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1533. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1534. //record status
  1535. if(strcmp(status,"Idle")==0)
  1536. {
  1537. DiagnosticsStatusNotificationStatus = 0;
  1538. }
  1539. else if(strcmp(status,"Uploaded")==0)
  1540. {
  1541. DiagnosticsStatusNotificationStatus = 1;
  1542. }
  1543. else if(strcmp(status,"UploadFailed")==0)
  1544. {
  1545. DiagnosticsStatusNotificationStatus = 2;
  1546. }
  1547. else if(strcmp(status,"Uploading")==0)
  1548. {
  1549. DiagnosticsStatusNotificationStatus = 3;
  1550. }
  1551. return result;
  1552. }
  1553. int sendFirmwareStatusNotificationRequest(char *status)
  1554. {
  1555. mtrace();
  1556. int result = FAIL;
  1557. char message[110]={0};
  1558. char guid[37]={0};
  1559. char tempdata[65]={0};
  1560. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1561. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1562. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1563. random_uuid(guid);
  1564. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1565. LWS_Send(message);
  1566. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1567. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1568. {
  1569. result = PASS;
  1570. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1571. }
  1572. //#ifdef SystemLogMessage
  1573. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1574. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1575. //#endif
  1576. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1577. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1578. //record status
  1579. if(strcmp(status,"Downloaded")==0)
  1580. {
  1581. FirmwareStatusNotificationStatus = 0;
  1582. }
  1583. else if(strcmp(status,"DownloadFailed")==0)
  1584. {
  1585. FirmwareStatusNotificationStatus = 1;
  1586. }
  1587. else if(strcmp(status,"Downloading")==0)
  1588. {
  1589. FirmwareStatusNotificationStatus = 2;
  1590. }
  1591. else if(strcmp(status,"Idle")==0)
  1592. {
  1593. FirmwareStatusNotificationStatus = 3;
  1594. }
  1595. else if(strcmp(status,"InstallationFailed")==0)
  1596. {
  1597. FirmwareStatusNotificationStatus = 4;
  1598. }
  1599. else if(strcmp(status,"Installing")==0)
  1600. {
  1601. FirmwareStatusNotificationStatus = 5;
  1602. }
  1603. else if(strcmp(status,"Installed")==0)
  1604. {
  1605. FirmwareStatusNotificationStatus = 6;
  1606. }
  1607. return result;
  1608. }
  1609. int sendHeartbeatRequest(int gun_index)
  1610. {
  1611. mtrace();
  1612. int result = FAIL;
  1613. char message[80]={0};
  1614. char guid[37]={0};
  1615. char tempdata[65]={0};
  1616. random_uuid(guid);
  1617. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1618. , MESSAGE_TYPE_CALL
  1619. , guid );
  1620. LWS_Send(message);
  1621. sprintf(tempdata, "Heartbeat,%d", 0);
  1622. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1623. {
  1624. result = PASS;
  1625. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1626. }
  1627. return result;
  1628. }
  1629. int sendStartTransactionRequest(int gun_index)
  1630. {
  1631. mtrace();
  1632. int result = FAIL;
  1633. char message[250]={0};
  1634. char guid[37]={0};
  1635. struct timeval tmnow;
  1636. struct tm *tm;
  1637. char buf[28];//, usec_buf[6];
  1638. char tempdata[65]={0};
  1639. DEBUG_INFO("sendStartTransactionRequest...");
  1640. gettimeofday(&tmnow, NULL);
  1641. time_t t;
  1642. t = time(NULL);
  1643. /*UTC time and date*/
  1644. tm = gmtime(&t);
  1645. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1646. #if 0 // remove temporally
  1647. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1648. strcat(buf,".");
  1649. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1650. strcat(buf,usec_buf);
  1651. #endif
  1652. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1653. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1654. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1656. {
  1657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1658. {
  1659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1660. {
  1661. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1662. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1663. }
  1664. }
  1665. for (int index = 0; index < CCS_QUANTITY; index++)
  1666. {
  1667. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1668. {
  1669. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1670. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1671. }
  1672. }
  1673. for (int index = 0; index < GB_QUANTITY; index++)
  1674. {
  1675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1676. {
  1677. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1678. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1679. }
  1680. }
  1681. }
  1682. else
  1683. {
  1684. for (int index = 0; index < AC_QUANTITY; index++)
  1685. {
  1686. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1687. {
  1688. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1689. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1690. }
  1691. }
  1692. }//END OF ELSE
  1693. random_uuid(guid);
  1694. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1695. , MESSAGE_TYPE_CALL
  1696. , guid
  1697. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1698. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1699. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1700. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1701. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1702. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1703. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1704. {
  1705. result = PASS;
  1706. }
  1707. strcpy(queuedata, message);
  1708. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1709. LWS_Send(message);
  1710. #if 0
  1711. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1712. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1713. {
  1714. result = PASS;
  1715. }
  1716. strcpy(queuedata, message);
  1717. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1718. #endif
  1719. //#ifdef SystemLogMessage
  1720. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1721. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1722. //#endif
  1723. return result;
  1724. }
  1725. int sendStatusNotificationRequest(int gun_index)
  1726. {
  1727. mtrace();
  1728. int result = FAIL;
  1729. char message[600]={0};
  1730. char guid[37];
  1731. int currentStatus = 0;
  1732. struct timeval tmnow;
  1733. struct tm *tm;
  1734. char buf[28];//, usec_buf[6];
  1735. char tempdata[65]={0};
  1736. gettimeofday(&tmnow, NULL);
  1737. time_t t;
  1738. t = time(NULL);
  1739. /*UTC time and date*/
  1740. tm = gmtime(&t);
  1741. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1742. #if 0 // remove temporally
  1743. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1744. strcat(buf,".");
  1745. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1746. strcat(buf,usec_buf);
  1747. #endif
  1748. printf("%s",buf);
  1749. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1750. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1751. // it's option
  1752. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1753. /*
  1754. enum _SYSTEM_STATUS
  1755. {
  1756. S_BOOTING = 0,
  1757. S_IDLE, = 1
  1758. S_AUTHORIZING, =2
  1759. S_REASSIGN_CHECK, =3
  1760. S_REASSIGN, =4
  1761. S_PRECHARGE, =5
  1762. S_PREPARING_FOR_EV, =6
  1763. S_PREPARING_FOR_EVSE, =7
  1764. S_CHARGING, =8
  1765. S_TERMINATING, =9
  1766. S_COMPLETE, =10
  1767. S_ALARM, =11
  1768. S_FAULT =12
  1769. }
  1770. */
  1771. //check Transaction active
  1772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1773. {
  1774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1775. {
  1776. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1777. {
  1778. currentStatus = 0; //OCPP Status: Available
  1779. }
  1780. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1781. {
  1782. currentStatus = 1; //OCPP Status: Preparing
  1783. }
  1784. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1785. {
  1786. currentStatus = 2; //OCPP Status: Charging
  1787. }
  1788. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1789. {
  1790. currentStatus = 5; //OCPP Status: Finishing
  1791. }
  1792. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1793. {
  1794. currentStatus = 4; //OCPP Status: SuspendedEV
  1795. }
  1796. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE) )) // ---> Unavailable
  1797. {
  1798. currentStatus = 7; //OCPP Status: Unavailable
  1799. }
  1800. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1801. {
  1802. currentStatus = 8; //OCPP Status: Faulted
  1803. }
  1804. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1805. {
  1806. currentStatus = 6; //OCPP Status: Reserved
  1807. }
  1808. }//end of for CHAdeMO_QUANTITY
  1809. for (int index = 0; index < CCS_QUANTITY; index++)
  1810. {
  1811. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1812. {
  1813. currentStatus = 0; //OCPP Status: Available
  1814. }
  1815. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1816. {
  1817. currentStatus = 1; //OCPP Status: Preparing
  1818. }
  1819. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1820. {
  1821. currentStatus = 2; //OCPP Status: Charging
  1822. }
  1823. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1824. {
  1825. currentStatus = 5; //OCPP Status: Finishing
  1826. }
  1827. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM ,S_TERMINATING ---> SuspendedEV
  1828. {
  1829. currentStatus = 4; //OCPP Status: SuspendedEV
  1830. }
  1831. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1832. {
  1833. currentStatus = 7; //OCPP Status : Unavailable
  1834. }
  1835. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1836. {
  1837. currentStatus = 8; //OCPP Status: Faulted
  1838. }
  1839. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1840. {
  1841. currentStatus = 6; //OCPP Status: Reserved
  1842. }
  1843. }
  1844. for (int index = 0; index < GB_QUANTITY; index++)
  1845. {
  1846. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1847. {
  1848. currentStatus = 0; //OCPP Status: Available
  1849. }
  1850. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1851. {
  1852. currentStatus = 1; //OCPP Status: Preparing
  1853. }
  1854. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1855. {
  1856. currentStatus = 2; //OCPP Status: Charging
  1857. }
  1858. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1859. {
  1860. currentStatus = 5; //OCPP Status: Finishing
  1861. }
  1862. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM , S_TERMINATING ---> SuspendedEV
  1863. {
  1864. currentStatus = 4; //OCPP Status: SuspendedEV
  1865. }
  1866. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1867. {
  1868. currentStatus = 7; //OCPP Status: Unavailable
  1869. }
  1870. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1871. {
  1872. currentStatus = 8; //OCPP Status: Faulted
  1873. }
  1874. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1875. {
  1876. currentStatus = 6; //OCPP Status: Reserved
  1877. }
  1878. }
  1879. }
  1880. else
  1881. {
  1882. for (int index = 0; index < AC_QUANTITY; index++)
  1883. {
  1884. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1885. {
  1886. currentStatus = 0; //OCPP Status: Available
  1887. }
  1888. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1889. {
  1890. currentStatus = 1; //OCPP Status: Preparing
  1891. }
  1892. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1893. {
  1894. currentStatus = 2; //OCPP Status: Charging
  1895. }
  1896. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1897. {
  1898. currentStatus = 5; //OCPP Status: Finishing
  1899. }
  1900. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1901. {
  1902. currentStatus = 4; //OCPP Status: SuspendedEV
  1903. }
  1904. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1905. {
  1906. currentStatus = 7; //OCPP Status: Unavailable
  1907. }
  1908. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1909. {
  1910. currentStatus = 8; //OCPP Status: Faulted
  1911. }
  1912. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1913. {
  1914. currentStatus = 6; //OCPP Status: Reserved
  1915. }
  1916. }//end of for AC_QUANTITY
  1917. }//END OF ELSE
  1918. //it's option
  1919. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1920. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1921. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1922. random_uuid(guid);
  1923. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1924. , MESSAGE_TYPE_CALL
  1925. , guid
  1926. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1927. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1928. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1929. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1930. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1931. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1932. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1933. LWS_Send(message);
  1934. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1935. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1936. {
  1937. //DEBUG_ERROR("statusNotification mapitem pass");
  1938. result = PASS;
  1939. }
  1940. return result;
  1941. }
  1942. int sendStopTransactionRequest(int gun_index)
  1943. {
  1944. mtrace();
  1945. int result = FAIL;
  1946. //char message[1500]={0};
  1947. char guid[37]={0};
  1948. char tempdata[65]={0};
  1949. //int idx_sample=0;
  1950. DEBUG_ERROR("sendStopTransactionRequest \n");
  1951. memset(queuedata, 0, sizeof(queuedata));
  1952. //ENERGY_ACTIVE_IMPORT_REGISTER
  1953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1954. {
  1955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1956. {
  1957. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1958. {
  1959. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1960. }
  1961. }// END OF CHAdeMO_QUANTITY
  1962. for (int index = 0; index < CCS_QUANTITY; index++)
  1963. {
  1964. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1965. {
  1966. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1967. }
  1968. }// END OF CCS_QUANTITY
  1969. for (int index = 0; index < GB_QUANTITY; index++)
  1970. {
  1971. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1972. {
  1973. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1974. }
  1975. }// END OF GB_QUANTITY
  1976. }
  1977. else
  1978. {
  1979. for (int index = 0; index < AC_QUANTITY; index++)
  1980. {
  1981. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1982. {
  1983. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1984. }
  1985. }// END OF AC_QUANTITY
  1986. }//END OF ELSE
  1987. //Stop Transaction Time
  1988. struct timeval tmnow;
  1989. struct tm *tm;
  1990. char buf[28];//, usec_buf[6];
  1991. gettimeofday(&tmnow, NULL);
  1992. time_t t;
  1993. t = time(NULL);
  1994. /*UTC time and date*/
  1995. tm = gmtime(&t);
  1996. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  1998. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  1999. random_uuid(guid);
  2000. /***********************************transactionData******************************************************/
  2001. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2003. //=================================
  2004. // Transaction_Begin
  2005. //=================================
  2006. // Energy.Active.Export.Interval
  2007. //idx_sample=0;
  2008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Export_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2013. {
  2014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2015. }
  2016. else
  2017. {
  2018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2019. }
  2020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2022. //=================================
  2023. // Transaction_End
  2024. //=================================
  2025. //Current.Export
  2026. //idx_sample=1;
  2027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2028. {
  2029. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2030. {
  2031. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2032. {
  2033. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2034. }
  2035. }
  2036. for (int index = 0; index < CCS_QUANTITY; index++)
  2037. {
  2038. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2039. {
  2040. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2041. }
  2042. }
  2043. for (int index = 0; index < GB_QUANTITY; index++)
  2044. {
  2045. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2046. {
  2047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2048. }
  2049. }
  2050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2051. }
  2052. else
  2053. {
  2054. for (int index = 0; index < AC_QUANTITY; index++)
  2055. {
  2056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2057. {
  2058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2059. }
  2060. }
  2061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2062. }// END FOR AC ELSE
  2063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2066. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2069. //Energy.Active.Export.Interval
  2070. //idx_sample=2;
  2071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2072. {
  2073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2074. {
  2075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2076. {
  2077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2078. }
  2079. }
  2080. for (int index = 0; index < CCS_QUANTITY; index++)
  2081. {
  2082. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2083. {
  2084. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2085. }
  2086. }
  2087. for (int index = 0; index < GB_QUANTITY; index++)
  2088. {
  2089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2090. {
  2091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2092. }
  2093. }
  2094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2095. }
  2096. else
  2097. {
  2098. for (int index = 0; index < AC_QUANTITY; index++)
  2099. {
  2100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2101. {
  2102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2103. }
  2104. }
  2105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2106. }// END FOR AC ELSE
  2107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2110. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2113. //Power.Active.Export
  2114. //idx_sample=3;
  2115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2116. {
  2117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2118. {
  2119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2120. {
  2121. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2122. }
  2123. }
  2124. for (int index = 0; index < CCS_QUANTITY; index++)
  2125. {
  2126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2127. {
  2128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2129. }
  2130. }
  2131. for (int index = 0; index < GB_QUANTITY; index++)
  2132. {
  2133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2134. {
  2135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2136. }
  2137. }
  2138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2139. }
  2140. else
  2141. {
  2142. for (int index = 0; index < AC_QUANTITY; index++)
  2143. {
  2144. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2145. {
  2146. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2147. }
  2148. }
  2149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2150. }// END FOR AC ELSE
  2151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2154. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2157. //Voltage
  2158. //idx_sample=4;
  2159. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2160. {
  2161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2162. {
  2163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2164. {
  2165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2166. }
  2167. }
  2168. for (int index = 0; index < CCS_QUANTITY; index++)
  2169. {
  2170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2171. {
  2172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2173. }
  2174. }
  2175. for (int index = 0; index < GB_QUANTITY; index++)
  2176. {
  2177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2178. {
  2179. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2180. }
  2181. }
  2182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2183. }
  2184. else
  2185. {
  2186. for (int index = 0; index < AC_QUANTITY; index++)
  2187. {
  2188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2189. {
  2190. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2191. }
  2192. }
  2193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2194. }// END FOR AC ELSE
  2195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2198. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2201. //SoC
  2202. //idx_sample=5;
  2203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2204. {
  2205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2206. {
  2207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2208. {
  2209. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2210. }
  2211. }
  2212. for (int index = 0; index < CCS_QUANTITY; index++)
  2213. {
  2214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2215. {
  2216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2217. }
  2218. }
  2219. for (int index = 0; index < GB_QUANTITY; index++)
  2220. {
  2221. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2222. {
  2223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2224. }
  2225. }
  2226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2232. } // END FOR DC CASE
  2233. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2234. {
  2235. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" } ] } ] } ]"
  2236. ,MESSAGE_TYPE_CALL
  2237. ,guid
  2238. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2239. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2240. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2241. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2242. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2243. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2244. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2245. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2246. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2247. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2248. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2249. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2250. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2251. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2252. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2253. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2254. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2255. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2256. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2257. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2258. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2259. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2260. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2261. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2262. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2263. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2264. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2265. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2266. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2267. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2268. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2269. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2270. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2271. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2272. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2273. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2274. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2275. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2276. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2277. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2278. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2279. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2280. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2281. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2282. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2283. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2284. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2285. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2286. );
  2287. }
  2288. else
  2289. {
  2290. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" } ] } ] } ]"
  2291. ,MESSAGE_TYPE_CALL
  2292. ,guid
  2293. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2294. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2295. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2296. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2297. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2298. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2299. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2304. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2334. );
  2335. }
  2336. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2337. if(hashmap_operation(0, guid, tempdata) == 1)
  2338. {
  2339. result = PASS;
  2340. DEBUG_INFO("StopTransaction mapitem pass\n");
  2341. }
  2342. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2343. LWS_Send(queuedata);
  2344. #if 0
  2345. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2346. if(hashmap_operation(0, guid, tempdata) == 1)
  2347. {
  2348. result = PASS;
  2349. DEBUG_INFO("StopTransaction mapitem pass\n");
  2350. }
  2351. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2352. #endif
  2353. //for test
  2354. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2355. return result;
  2356. }
  2357. int sendMeterValuesRequest(int gun_index)
  2358. {
  2359. mtrace();
  2360. int result = FAIL;
  2361. // char message[1500]={0};
  2362. char guid[37]={0};
  2363. //int idx_sample=0;
  2364. //int length = 0;
  2365. char tempdata[65]={0};
  2366. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2367. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2368. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2369. {
  2370. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2371. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2372. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2373. return result;
  2374. }
  2375. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2376. {
  2377. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2378. }
  2379. memset(queuedata, 0, sizeof(queuedata));
  2380. //set value
  2381. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2382. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2383. random_uuid(guid);
  2384. //UTC Date time
  2385. struct timeval tmnow;
  2386. struct tm *tm;
  2387. char buf[28];//, usec_buf[6];
  2388. gettimeofday(&tmnow, NULL);
  2389. time_t t;
  2390. t = time(NULL);
  2391. /*UTC time and date*/
  2392. tm = gmtime(&t);
  2393. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2395. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2396. //idx_sample=0;
  2397. //********************************(1)Current.Export************************************************/
  2398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2399. {
  2400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2401. {
  2402. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2403. {
  2404. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2405. }
  2406. }
  2407. for (int index = 0; index < CCS_QUANTITY; index++)
  2408. {
  2409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2410. {
  2411. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2412. }
  2413. }
  2414. for (int index = 0; index < GB_QUANTITY; index++)
  2415. {
  2416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2417. {
  2418. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2419. }
  2420. }
  2421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2422. }
  2423. else
  2424. {
  2425. for (int index = 0; index < AC_QUANTITY; index++)
  2426. {
  2427. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2428. {
  2429. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2430. }
  2431. }
  2432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2433. }// END FOR AC ELSE
  2434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2437. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2438. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2440. //idx_sample=1;
  2441. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2443. {
  2444. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2445. {
  2446. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2447. {
  2448. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2449. }
  2450. }
  2451. for (int index = 0; index < CCS_QUANTITY; index++)
  2452. {
  2453. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2454. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2455. {
  2456. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2457. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2458. }
  2459. }
  2460. for (int index = 0; index < GB_QUANTITY; index++)
  2461. {
  2462. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2463. {
  2464. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2465. }
  2466. }
  2467. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2468. }
  2469. else
  2470. {
  2471. for (int index = 0; index < AC_QUANTITY; index++)
  2472. {
  2473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2474. {
  2475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2476. }
  2477. }
  2478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2479. }//END FOR AC ELSE
  2480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2483. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2486. //idx_sample=2;
  2487. //********************************(4)Power.Active.Export************************************************/
  2488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2489. {
  2490. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2491. {
  2492. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2493. {
  2494. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2495. }
  2496. }
  2497. for (int index = 0; index < CCS_QUANTITY; index++)
  2498. {
  2499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2500. {
  2501. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2502. }
  2503. }
  2504. for (int index = 0; index < GB_QUANTITY; index++)
  2505. {
  2506. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2507. {
  2508. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2509. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2510. }
  2511. }
  2512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2513. }
  2514. else
  2515. {
  2516. for (int index = 0; index < AC_QUANTITY; index++)
  2517. {
  2518. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2519. {
  2520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2521. }
  2522. }
  2523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2524. }// END FOR AC ELSE
  2525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2527. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2528. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2529. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2531. //idx_sample=3;
  2532. //***********************************************(5)VOLTAGE******************************************************/
  2533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2534. {
  2535. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2536. {
  2537. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2538. {
  2539. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2540. }
  2541. }
  2542. for (int index = 0; index < CCS_QUANTITY; index++)
  2543. {
  2544. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2545. {
  2546. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2547. }
  2548. }
  2549. for (int index = 0; index < GB_QUANTITY; index++)
  2550. {
  2551. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2552. {
  2553. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2554. }
  2555. }
  2556. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2557. }
  2558. else
  2559. {
  2560. for (int index = 0; index < AC_QUANTITY; index++)
  2561. {
  2562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2563. {
  2564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2565. }
  2566. }
  2567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2568. }//END FOR AC ELSE
  2569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2570. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2572. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2576. {
  2577. //idx_sample=4;
  2578. //sampledValue = NULL;
  2579. //***********************************************(6)SOC******************************************************/
  2580. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2581. {
  2582. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2583. {
  2584. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2585. }
  2586. }
  2587. for (int index = 0; index < CCS_QUANTITY; index++)
  2588. {
  2589. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2590. {
  2591. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2592. }
  2593. }
  2594. for (int index = 0; index < GB_QUANTITY; index++)
  2595. {
  2596. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2597. {
  2598. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2599. }
  2600. }
  2601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2607. }
  2608. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2609. {
  2610. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2611. ,MESSAGE_TYPE_CALL
  2612. ,guid
  2613. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2614. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2615. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2616. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2617. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2618. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2619. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2620. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2621. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2622. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2623. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2624. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2651. );
  2652. }
  2653. else
  2654. {
  2655. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2656. ,MESSAGE_TYPE_CALL
  2657. ,guid
  2658. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2659. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2660. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2662. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2663. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2664. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2689. );
  2690. }
  2691. // Put request guid to hash map
  2692. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2693. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2694. {
  2695. result = PASS;
  2696. DEBUG_INFO("MeterValues mapitem pass\n");
  2697. }
  2698. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2699. LWS_Send(queuedata);
  2700. #if 0
  2701. // Put request guid to hash map
  2702. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2703. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2704. {
  2705. result = PASS;
  2706. DEBUG_INFO("MeterValues mapitem pass\n");
  2707. }
  2708. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2709. #endif
  2710. return result;
  2711. }
  2712. //==========================================
  2713. // send confirm routine
  2714. //==========================================
  2715. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2716. {
  2717. mtrace();
  2718. int result = FAIL;
  2719. char message[100]={0};
  2720. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2721. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2722. LWS_Send(message);
  2723. result = TRUE;
  2724. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2725. return result;
  2726. }
  2727. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2728. {
  2729. mtrace();
  2730. int result = FAIL;
  2731. char message[100]={0};
  2732. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2733. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2734. LWS_Send(message);
  2735. result = TRUE;
  2736. return result;
  2737. }
  2738. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2739. {
  2740. mtrace();
  2741. int result = FAIL;
  2742. char message[100]={0};
  2743. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2744. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2745. LWS_Send(message);
  2746. result = TRUE;
  2747. return result;
  2748. }
  2749. int sendClearCacheConfirmation(char *uuid,char *payload)
  2750. {
  2751. mtrace();
  2752. int result = FAIL;
  2753. char message[500]={0};
  2754. // int count = 0;
  2755. // int gun_index = 0;
  2756. // char guid[37];
  2757. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2758. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2759. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2760. LWS_Send(message);
  2761. return result;
  2762. }
  2763. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2764. {
  2765. mtrace();
  2766. int result = FAIL;
  2767. char message[500]={0};
  2768. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2769. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2770. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2771. LWS_Send(message);
  2772. return result;
  2773. }
  2774. int sendDataTransferConfirmation(char *uuid,char *payload)
  2775. {
  2776. mtrace();
  2777. char statusStr[20]={0};
  2778. char dataStr[10]={0};
  2779. char sstr[20]={0};
  2780. int c = 0;
  2781. char *loc;
  2782. int result = FAIL;
  2783. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2784. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2785. /**********************status**************************/
  2786. loc = strstr(payload, "status");
  2787. memset(sstr ,0, sizeof(sstr) );
  2788. c = 0;
  2789. while (loc[3+strlen("status")+c] != '\"')
  2790. {
  2791. sstr[c] = loc[3+strlen("status")+c];
  2792. c++;
  2793. }
  2794. sstr[c] = '\0';
  2795. strcpy(statusStr, sstr);
  2796. /**********************data**************************/
  2797. loc = strstr(payload, "data");
  2798. memset(sstr ,0, sizeof(sstr) );
  2799. c = 0;
  2800. while (loc[3+strlen("data")+c] != '\"')
  2801. {
  2802. sstr[c] = loc[3+strlen("data")+c];
  2803. c++;
  2804. }
  2805. sstr[c] = '\0';
  2806. strcpy(dataStr, sstr);
  2807. return result;
  2808. }
  2809. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2810. {
  2811. mtrace();
  2812. int result = FAIL;
  2813. char message[1000]={0};
  2814. double diff_f = 0.0;
  2815. int diff_i = 0;
  2816. int diffSeconds = 0;
  2817. struct tm tp;
  2818. int TimeZero = FALSE;
  2819. int CompositeScheduleIndex = 0;
  2820. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2821. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2822. {
  2823. TimeZero = TRUE;
  2824. }
  2825. else
  2826. {
  2827. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2828. }
  2829. if(TimeZero == FALSE)
  2830. {
  2831. tp.tm_isdst = -1;
  2832. time_t utc = mktime(&tp);
  2833. time_t t = time(NULL);
  2834. diff_f = difftime(t, utc);
  2835. diff_i = (int)diff_f;
  2836. diffSeconds = diff_i % 86400;//86400 seconds/day
  2837. }
  2838. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2839. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2840. #if 0 //remove temporally
  2841. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":6.0,\"numberPhases\":3},{\"startPeriod\":40,\"limit\":10.0,\"numberPhases\":3},{\"startPeriod\":100,\"limit\":8.0,\"numberPhases\":3}"
  2842. ,MESSAGE_TYPE_CALLRESULT
  2843. ,uuid
  2844. ,payload
  2845. ,connectorIdInt
  2846. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2847. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2848. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2849. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2850. #endif
  2851. if(nPeriod == 0)
  2852. {
  2853. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2854. ,MESSAGE_TYPE_CALLRESULT
  2855. ,uuid
  2856. ,payload
  2857. ,connectorIdInt
  2858. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2859. }
  2860. else
  2861. {
  2862. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2863. ,MESSAGE_TYPE_CALLRESULT
  2864. ,uuid
  2865. ,payload
  2866. ,connectorIdInt
  2867. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2868. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2869. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2870. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2871. int len = nPeriod;
  2872. //Last Period StartPriod is less than diffSeconds
  2873. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2874. {
  2875. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2876. , 0
  2877. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2878. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2879. }
  2880. else
  2881. {
  2882. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2883. {
  2884. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2885. {
  2886. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2887. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2888. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2889. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2890. }
  2891. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2892. {
  2893. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2894. , (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)) //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
  2895. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2896. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2897. }
  2898. }
  2899. }
  2900. sprintf(message + strlen(message), "]}}]");
  2901. }
  2902. LWS_Send(message);
  2903. result = TRUE;
  2904. return result;
  2905. }
  2906. int sendGetConfigurationConfirmation(char *uuid)
  2907. {
  2908. mtrace();
  2909. int result = FAIL;
  2910. int MaxKeySupported = 0;
  2911. int sentConfigurationNumber= 0;
  2912. int sentunConfigurationNumber= 0;
  2913. char message[4000]={0};
  2914. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2915. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2916. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2917. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  2918. ,MESSAGE_TYPE_CALLRESULT
  2919. ,uuid );
  2920. //configuration key
  2921. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2922. {
  2923. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2924. {
  2925. if (sentConfigurationNumber == 0)
  2926. {
  2927. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  2928. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2929. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2930. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2931. }
  2932. else
  2933. {
  2934. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2935. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2936. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2937. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2938. }
  2939. sentConfigurationNumber = sentConfigurationNumber + 1;
  2940. }
  2941. }
  2942. sprintf(message + strlen(message), "]");
  2943. if(UnknownKeynum != 0)
  2944. {
  2945. sprintf(message + strlen(message), ",\"unknownKey\":[");
  2946. //unkown key
  2947. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  2948. {
  2949. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  2950. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  2951. if(sentunConfigurationNumber == 0)
  2952. {
  2953. sprintf(message + strlen(message), "\"%s\""
  2954. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2955. }
  2956. else
  2957. {
  2958. sprintf(message + strlen(message), ",\"%s\""
  2959. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2960. }
  2961. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  2962. }
  2963. sprintf(message + strlen(message), "]");
  2964. }
  2965. sprintf(message + strlen(message), "} ]");
  2966. LWS_Send(message);
  2967. return result;
  2968. }
  2969. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  2970. {
  2971. mtrace();
  2972. int result = FAIL;
  2973. char message[400]={0};
  2974. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  2975. if(strcmp(payload,"")==0)
  2976. {
  2977. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  2978. }
  2979. else
  2980. {
  2981. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  2982. }
  2983. LWS_Send(message);
  2984. result = TRUE;
  2985. return result;
  2986. }
  2987. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  2988. {
  2989. mtrace();
  2990. int result = FAIL;
  2991. char message[80]={0};
  2992. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  2993. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  2994. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  2995. LWS_Send(message);
  2996. result = TRUE;
  2997. return result;
  2998. }
  2999. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3000. {
  3001. mtrace();
  3002. int result = FAIL;
  3003. char message[80]={0};
  3004. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3005. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3006. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3007. LWS_Send(message);
  3008. result = TRUE;
  3009. return result;
  3010. }
  3011. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3012. {
  3013. mtrace();
  3014. int result = FAIL;
  3015. char message[80]={0};
  3016. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3017. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3018. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3019. LWS_Send(message);
  3020. result = TRUE;
  3021. return result;
  3022. }
  3023. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3024. {
  3025. mtrace();
  3026. int result = FAIL;
  3027. char message[80]={0};
  3028. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3029. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3030. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3031. LWS_Send(message);
  3032. result = TRUE;
  3033. return result;
  3034. }
  3035. int sendResetConfirmation(char *uuid,char *payload)
  3036. {
  3037. mtrace();
  3038. int result = FAIL;
  3039. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3040. char message[80]={0};
  3041. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3042. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3043. LWS_Send(message);
  3044. result = TRUE;
  3045. return result;
  3046. }
  3047. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3048. {
  3049. mtrace();
  3050. int result = FAIL;
  3051. char message[500]={0};
  3052. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3053. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3054. LWS_Send(message);
  3055. result = TRUE;
  3056. return result;
  3057. }
  3058. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3059. {
  3060. mtrace();
  3061. int result = FAIL;
  3062. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3063. char message[80]={0};
  3064. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3065. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3066. LWS_Send(message);
  3067. result = TRUE;
  3068. return result;
  3069. }
  3070. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3071. {
  3072. mtrace();
  3073. int result = FAIL;
  3074. char message[80]={0};
  3075. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3076. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3077. LWS_Send(message);
  3078. result = TRUE;
  3079. return result;
  3080. }
  3081. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3082. {
  3083. mtrace();
  3084. int result = FAIL;
  3085. char message[80]={0};
  3086. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3087. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3088. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3089. LWS_Send(message);
  3090. result = TRUE;
  3091. return result;
  3092. }
  3093. int sendUpdateFirmwareConfirmation(char *uuid)
  3094. {
  3095. mtrace();
  3096. int result = FAIL;
  3097. char message[60]={0};
  3098. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3099. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3100. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3101. LWS_Send(message);
  3102. result = TRUE;
  3103. return result;
  3104. }
  3105. //==========================================
  3106. // send CallError routine
  3107. //==========================================
  3108. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3109. {
  3110. mtrace();
  3111. //int result = FAIL;
  3112. char message[220]={0};
  3113. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3114. #ifdef SystemLogMessage
  3115. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3116. uniqueId, action, errorCode, errorDescription);
  3117. #endif
  3118. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3119. LWS_Send(message);
  3120. //result = TRUE;
  3121. }
  3122. //==========================================
  3123. // Handle server request routine Start
  3124. //==========================================
  3125. #define GUN_NUM 1
  3126. int handleCancelReservationRequest(char *uuid, char *payload)
  3127. {
  3128. mtrace();
  3129. int result = FAIL;
  3130. int gunNO = 0;
  3131. int reservationIdInt =0;
  3132. char comfirmstr[20];
  3133. int c = 0;
  3134. char *loc;
  3135. char sstr[100]={0};
  3136. DEBUG_INFO("handle CancelReservationRequest\n");
  3137. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3138. c = 0;
  3139. loc = strstr(payload, "reservationId");
  3140. memset(sstr ,0, sizeof(sstr) );
  3141. while (loc[strlen("reservationId")+2+c] != '}')
  3142. {
  3143. sstr[c] = loc[strlen("reservationId")+2+c];
  3144. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3145. c++;
  3146. }
  3147. sstr[c] = '\0';
  3148. reservationIdInt = atoi(sstr);
  3149. memset(comfirmstr, 0, sizeof comfirmstr);
  3150. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3151. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3152. //check Transaction active
  3153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3154. {
  3155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3156. {
  3157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3158. {
  3159. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3160. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3161. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3162. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3163. goto end;
  3164. }
  3165. }
  3166. for (int index = 0; index < CCS_QUANTITY; index++)
  3167. {
  3168. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3169. {
  3170. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3171. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3172. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3173. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3174. goto end;
  3175. }
  3176. }
  3177. for (int index = 0; index < GB_QUANTITY; index++)
  3178. {
  3179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3180. {
  3181. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3182. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3183. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3184. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3185. goto end;
  3186. }
  3187. }
  3188. }
  3189. else
  3190. {
  3191. for (int index = 0; index < AC_QUANTITY; index++)
  3192. {
  3193. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3194. {
  3195. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3196. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3197. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3198. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3199. goto end;
  3200. }
  3201. }
  3202. }// END FOR AC ELSE
  3203. //The reservationId does NOT match the reservationId
  3204. sendCancelReservationConfirmation(uuid, comfirmstr);
  3205. end:
  3206. // Fill in ocpp packet uuid
  3207. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3208. return result;
  3209. }
  3210. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3211. {
  3212. mtrace();
  3213. int result = FAIL;
  3214. int gunIndex = 0;
  3215. char sstr[90]={0};
  3216. char typeStr[16]={0};
  3217. char comfirmstr[20];
  3218. int specificId = FALSE;
  3219. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3220. char *loc;
  3221. //int intervalInt = 0;
  3222. int c = 0;
  3223. /*** connectorId ****/
  3224. c = 0;
  3225. loc = strstr(payload, "connectorId");
  3226. memset(sstr ,0, sizeof(sstr) );
  3227. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3228. {
  3229. sstr[c] = loc[strlen("connectorId")+2+c];
  3230. c++;
  3231. }
  3232. sstr[c] = '\0';
  3233. gunIndex = atoi(sstr);
  3234. /***type ****/
  3235. loc = strstr(payload, "type");
  3236. memset(sstr ,0, sizeof(sstr) );
  3237. c = 0;
  3238. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3239. {
  3240. sstr[c] = loc[3+strlen("type")+c];
  3241. c++;
  3242. }
  3243. sstr[c] = '\0';
  3244. strcpy(typeStr, sstr);
  3245. if(gunIndex != 0)
  3246. {
  3247. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3248. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3249. }
  3250. else
  3251. {
  3252. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3253. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3254. }
  3255. memset(comfirmstr, 0, sizeof comfirmstr);
  3256. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3257. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3258. {
  3259. specificId = TRUE;
  3260. }
  3261. if(specificId == FALSE)
  3262. goto end;
  3263. if(gunIndex != 0)
  3264. {
  3265. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3266. }
  3267. else
  3268. {
  3269. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3270. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3271. }
  3272. /*
  3273. enum SYSTEM_STATUS
  3274. {
  3275. SYS_MODE_BOOTING = 0,
  3276. SYS_MODE_IDLE = 1,
  3277. SYS_MODE_AUTHORIZING = 2,
  3278. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3279. SYS_MODE_REASSIGN = 4,
  3280. SYS_MODE_PREPARING = 5,
  3281. SYS_MODE_PREPARE_FOR_EV = 6,
  3282. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3283. SYS_MODE_CHARGING = 8,
  3284. SYS_MODE_TERMINATING = 9,
  3285. SYS_MODE_COMPLETE = 10,
  3286. SYS_MODE_ALARM = 11,
  3287. SYS_MODE_FAULT = 12,
  3288. SYS_MODE_RESERVATION = 13,
  3289. SYS_MODE_BOOKING = 14,
  3290. SYS_MODE_MAINTAIN = 15,
  3291. SYS_MODE_DEBUG = 16,
  3292. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3293. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3294. SYS_MODE_UPDATE = 19
  3295. };
  3296. */
  3297. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3298. {
  3299. //check Transaction active
  3300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3301. {
  3302. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3303. {
  3304. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3305. {
  3306. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3307. {
  3308. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3309. }
  3310. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3311. {
  3312. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3313. }
  3314. else
  3315. {
  3316. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3317. }
  3318. goto end;
  3319. }
  3320. }//END FOR CHAdeMO_QUANTITY
  3321. for (int index = 0; index < CCS_QUANTITY; index++)
  3322. {
  3323. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3324. {
  3325. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3326. {
  3327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3328. }
  3329. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3330. {
  3331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3332. }
  3333. else
  3334. {
  3335. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3336. }
  3337. goto end;
  3338. }
  3339. }//END FOR CCS_QUANTITY
  3340. for (int index = 0; index < GB_QUANTITY; index++)
  3341. {
  3342. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3343. {
  3344. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3345. {
  3346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3347. }
  3348. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3349. {
  3350. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3351. }
  3352. else
  3353. {
  3354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3355. }
  3356. goto end;
  3357. }
  3358. }// END FOR GB_QUANTITY
  3359. }
  3360. else
  3361. {
  3362. for (int index = 0; index < AC_QUANTITY; index++)
  3363. {
  3364. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3365. {
  3366. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3367. {
  3368. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3369. }
  3370. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3371. {
  3372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3373. }
  3374. else
  3375. {
  3376. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3377. }
  3378. goto end;
  3379. }
  3380. }//END FOR AC_QUANTITY
  3381. }// END FOR AC ELSE
  3382. }//END FOR AvailabilityTypeStr[Inoperative]
  3383. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3384. {
  3385. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3386. //check Transaction active
  3387. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3388. {
  3389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3390. {
  3391. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3392. {
  3393. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3394. goto end;
  3395. }
  3396. }//END FOR CHAdeMO_QUANTITY
  3397. for (int index = 0; index < CCS_QUANTITY; index++)
  3398. {
  3399. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3400. {
  3401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3402. goto end;
  3403. }
  3404. }//END FOR CCS_QUANTITY
  3405. for (int index = 0; index < GB_QUANTITY; index++)
  3406. {
  3407. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3408. {
  3409. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3410. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3411. goto end;
  3412. }
  3413. }// END FOR GB_QUANTITY
  3414. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3415. }
  3416. else
  3417. {
  3418. for (int index = 0; index < AC_QUANTITY; index++)
  3419. {
  3420. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3421. {
  3422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3423. goto end;
  3424. }
  3425. }//END FOR CHAdeMO_QUANTITY
  3426. }//END FOR AC ELSE
  3427. }//END FOR AvailabilityTypeStr[Operative]
  3428. end:
  3429. if(gunIndex != 0)
  3430. {
  3431. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3432. }
  3433. else
  3434. {
  3435. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3436. }
  3437. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3438. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3439. return result;
  3440. }
  3441. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3442. {
  3443. mtrace();
  3444. int result = FAIL;
  3445. char sstr[100]={0};
  3446. char keystr[40]={0};
  3447. char valuestr[100]={0};
  3448. char *loc;
  3449. int c = 0;
  3450. char comfirmstr[20]={0};
  3451. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3452. /***key ****/
  3453. loc = strstr(payload, "key");
  3454. memset(sstr ,0, sizeof(sstr) );
  3455. c = 0;
  3456. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3457. {
  3458. sstr[c] = loc[3+strlen("key")+c];
  3459. c++;
  3460. }
  3461. sstr[c] = '\0';
  3462. strcpy(keystr, sstr);
  3463. //DEBUG_INFO( "keystr=%s\n",keystr);
  3464. /***value ****/
  3465. loc = strstr(payload, "value");
  3466. memset(sstr ,0, sizeof(sstr) );
  3467. c = 0;
  3468. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3469. {
  3470. sstr[c] = loc[3+strlen("value")+c];
  3471. c++;
  3472. }
  3473. sstr[c] = '\0';
  3474. strcpy(valuestr, sstr);
  3475. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3476. if((uuid==NULL) || (payload ==NULL) )
  3477. {
  3478. #ifdef Debug
  3479. DEBUG_INFO("payload is null\n");
  3480. #endif
  3481. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3482. }
  3483. else
  3484. {
  3485. int status = setKeyValue(keystr, valuestr);
  3486. switch(status)
  3487. {
  3488. case ConfigurationStatus_Accepted:
  3489. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3490. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3491. StoreConfigurationTable();
  3492. break;
  3493. case ConfigurationStatus_Rejected:
  3494. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3495. break;
  3496. case RebootRequired:
  3497. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3498. StoreConfigurationTable();
  3499. break;
  3500. case NotSupported:
  3501. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3502. break;
  3503. default:
  3504. break;
  3505. }
  3506. }
  3507. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3508. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3509. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3510. return result;
  3511. }
  3512. int handleClearCacheRequest(char *uuid, char *payload)
  3513. {
  3514. mtrace();
  3515. int result = FAIL;
  3516. char comfirmstr[20];
  3517. int fd;
  3518. char rmFileCmd[100]={0};
  3519. struct stat stats;
  3520. DEBUG_INFO("handle ClearCacheRequest\n");
  3521. stat("../Storage/OCPP", &stats);
  3522. // Check for directory existence
  3523. if (S_ISDIR(stats.st_mode) == 1)
  3524. {
  3525. //DEBUG_ERROR("\n OCPP directory exist \n");
  3526. }
  3527. else
  3528. {
  3529. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3530. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3531. system(rmFileCmd);
  3532. }
  3533. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3534. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3535. {
  3536. DEBUG_INFO("AuthorizationCache file exist.\n");
  3537. }
  3538. else
  3539. {
  3540. DEBUG_INFO("AuthorizationCache file not exist\n");
  3541. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3542. if(log == NULL)
  3543. {
  3544. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3545. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3546. goto end;
  3547. }
  3548. else
  3549. {
  3550. fclose(log);
  3551. }
  3552. }
  3553. fd = open(AuthorizationCache_JSON,O_RDWR);
  3554. if(fd < 0)
  3555. {
  3556. DEBUG_INFO("open AuthorizationCache file failed\n");
  3557. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3558. }
  3559. else
  3560. {
  3561. DEBUG_INFO("open AuthorizationCache file successful\n");
  3562. //* 清空? 件 */
  3563. ftruncate(fd,0);
  3564. //* ? 新设置? 件? 移??*/
  3565. lseek(fd,0,SEEK_SET);
  3566. close(fd);
  3567. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3568. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3569. }
  3570. end:
  3571. sendClearCacheConfirmation(uuid, comfirmstr);
  3572. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3573. return result;
  3574. }
  3575. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3576. {
  3577. mtrace();
  3578. int result = FAIL;
  3579. int resultRename;
  3580. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3581. char chargingProfilePurposeStr[26]={0};
  3582. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3583. char tempchargingProfilePurposeStr[26]={0};
  3584. char sstr[160]={0};//sstr[200]={ 0 };
  3585. char str[100]={0};
  3586. int c = 0;
  3587. //int i = 0;
  3588. //char * pch;
  3589. char *loc;
  3590. char fname[200];
  3591. char comfirmstr[20]={0};
  3592. char word[1000]={0};
  3593. int clearflag = FALSE;
  3594. int chargingProfileIdIsNULL = FALSE;
  3595. int connectorIsNULL = FALSE;
  3596. int chargingProfilePurposeIsNULL = FALSE;
  3597. int stackLevelIsNULL = FALSE;
  3598. FILE *fptr1, *fptr2;
  3599. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3600. int n_chargingProfile=0;
  3601. char sLineWord[1060]={0};
  3602. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3603. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3604. //***id ****/
  3605. c = 0;
  3606. loc = strstr(payload, "id");
  3607. memset(sstr ,0, sizeof(sstr) );
  3608. if(loc == NULL)
  3609. {
  3610. chargingProfileIdIsNULL = TRUE;
  3611. }
  3612. else
  3613. {
  3614. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3615. {
  3616. sstr[c] = loc[strlen("id")+2+c];
  3617. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3618. c++;
  3619. }
  3620. sstr[c] = '\0';
  3621. chargingProfileIdInt = atoi(sstr);
  3622. }
  3623. //***connectorId ****/
  3624. c=0;
  3625. loc = strstr(payload, "connectorId");
  3626. memset(sstr ,0, sizeof(sstr) );
  3627. if(loc == NULL)
  3628. {
  3629. connectorIsNULL = TRUE;
  3630. }
  3631. else
  3632. {
  3633. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3634. {
  3635. sstr[c] = loc[strlen("connectorId")+2+c];
  3636. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3637. c++;
  3638. }
  3639. sstr[c] = '\0';
  3640. connectorIdInt = atoi(sstr);
  3641. }
  3642. //***chargingProfilePurpose ****/
  3643. loc = strstr(payload, "chargingProfilePurpose");
  3644. memset(sstr ,0, sizeof(sstr) );
  3645. c = 0;
  3646. if(loc == NULL)
  3647. {
  3648. chargingProfilePurposeIsNULL = TRUE;
  3649. }
  3650. else
  3651. {
  3652. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3653. {
  3654. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3655. c++;
  3656. }
  3657. sstr[c] = '\0';
  3658. strcpy(chargingProfilePurposeStr, sstr);
  3659. }
  3660. //***stackLevel ****/
  3661. c=0;
  3662. loc = strstr(payload, "stackLevel");
  3663. memset(sstr ,0, sizeof(sstr) );
  3664. if(loc == NULL)
  3665. {
  3666. stackLevelIsNULL = TRUE;
  3667. }
  3668. else
  3669. {
  3670. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3671. {
  3672. sstr[c] = loc[strlen("stackLevel")+2+c];
  3673. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3674. c++;
  3675. }
  3676. sstr[c] = '\0';
  3677. stackLevelInt = atoi(sstr);
  3678. }
  3679. if(connectorIsNULL == FALSE)
  3680. {
  3681. switch(connectorIdInt)
  3682. {
  3683. case 0:
  3684. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3685. {
  3686. strcpy(fname, ChargePointMaxProfile_JSON);
  3687. }
  3688. // else
  3689. // {
  3690. // strcpy(fname, TxDefaultProfile_0_JSON);
  3691. // }
  3692. break;
  3693. case 1:
  3694. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3695. {
  3696. strcpy(fname, TxDefaultProfile_1_JSON);
  3697. }
  3698. // else
  3699. // {
  3700. // strcpy(fname, TxProfile_1_JSON);
  3701. // }
  3702. break;
  3703. case 2:
  3704. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3705. {
  3706. strcpy(fname, TxDefaultProfile_2_JSON);
  3707. }
  3708. // else
  3709. // {
  3710. // strcpy(fname, TxProfile_2_JSON);
  3711. // }
  3712. break;
  3713. default:
  3714. strcpy(fname, ChargePointMaxProfile_JSON );
  3715. break;
  3716. }
  3717. }
  3718. else
  3719. {
  3720. strcpy(fname, ChargePointMaxProfile_JSON );
  3721. }
  3722. fptr1 = fopen(fname, "r");
  3723. if (!fptr1)
  3724. {
  3725. //file not exist
  3726. DEBUG_INFO("Unable to open the input file!!\n");
  3727. fptr1 = fopen(fname, "w+");
  3728. }
  3729. fclose(fptr1);
  3730. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3731. {
  3732. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3733. goto end;
  3734. }
  3735. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3736. {
  3737. //clear the whole contents of a file in C
  3738. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3739. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3740. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3741. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3742. fclose(fopen(TxProfile_1_JSON, "w"));
  3743. fclose(fopen(TxProfile_2_JSON, "w"));
  3744. #if 0
  3745. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3746. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3747. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3748. #endif
  3749. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3750. }
  3751. else
  3752. {
  3753. fptr1 = fopen(fname, "r");
  3754. fptr2 = fopen(temp, "w+");
  3755. while(fscanf(fptr1, "%s", word) != EOF)
  3756. {
  3757. //DEBUG_INFO("word=%s\n",word);
  3758. if(strcmp(word, "chargingProfileId") == 0)
  3759. {
  3760. n_chargingProfile = n_chargingProfile + 1;
  3761. DEBUG_INFO("chargingProfileId Found\n");
  3762. }
  3763. }
  3764. rewind(fptr1);
  3765. //search Charging Profile Element
  3766. //int i= 0;
  3767. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3768. {
  3769. //*************************tempconnectorIdInt*********************************/
  3770. loc = strstr(sLineWord, "connectorId");
  3771. c = 0;
  3772. memset(sstr ,0, sizeof(sstr) );
  3773. while (loc[strlen("connectorId")+2+c] != ',')
  3774. {
  3775. sstr[c] = loc[strlen("connectorId")+2+c];
  3776. c++;
  3777. }
  3778. sstr[c] = '\0';
  3779. tempconnectorIdInt = atoi(sstr);
  3780. //chargingProfileId
  3781. c = 0;
  3782. loc = strstr(sLineWord, "chargingProfileId");
  3783. memset(sstr ,0, sizeof(sstr) );
  3784. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3785. {
  3786. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3787. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3788. c++;
  3789. }
  3790. sstr[c] = '\0';
  3791. tempchargingProfileIdInt = atoi(sstr);
  3792. //stackLevel
  3793. c = 0;
  3794. loc = strstr(sLineWord, "stackLevel");
  3795. memset(sstr ,0, sizeof(sstr) );
  3796. while (loc[strlen("stackLevel")+2+c] != ',')
  3797. {
  3798. sstr[c] = loc[strlen("stackLevel")+2+c];
  3799. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3800. c++;
  3801. }
  3802. sstr[c] = '\0';
  3803. tempstackLevelInt = atoi(sstr);
  3804. c = 0;
  3805. loc = strstr(sLineWord, "chargingProfilePurpose");
  3806. memset(sstr ,0, sizeof(sstr) );
  3807. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3808. {
  3809. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3810. c++;
  3811. }
  3812. sstr[c] = '\0';
  3813. strcpy(tempchargingProfilePurposeStr, sstr);
  3814. if(chargingProfileIdIsNULL == FALSE)
  3815. {
  3816. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3817. {
  3818. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3819. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3820. clearflag = TRUE;
  3821. continue;
  3822. }
  3823. else
  3824. {
  3825. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3826. //json_object_array_add(newHeatMap, jsonitem);
  3827. fprintf(fptr2, sLineWord);//writing data into file
  3828. }
  3829. }
  3830. else
  3831. {
  3832. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3833. {
  3834. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3835. {
  3836. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3837. clearflag = TRUE;
  3838. continue;
  3839. }
  3840. }
  3841. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3842. {
  3843. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3844. {
  3845. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3846. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3847. {
  3848. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3849. clearflag = TRUE;
  3850. continue;
  3851. }
  3852. }
  3853. }
  3854. else
  3855. {
  3856. //json_object_array_add(newHeatMap, jsonitem);
  3857. fprintf(fptr2, sLineWord);//writing data into file
  3858. }
  3859. }
  3860. memset(sLineWord, 0, sizeof sLineWord);
  3861. }
  3862. if(clearflag == FALSE)
  3863. {
  3864. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3865. goto end;
  3866. }
  3867. fclose(fptr1);
  3868. fclose(fptr2);
  3869. sprintf(str,"rm -f %s",fname);
  3870. system(str);
  3871. resultRename = rename(temp, fname);
  3872. if(resultRename == 0)
  3873. {
  3874. DEBUG_INFO("File ChargingProfile renamed successfully");
  3875. }
  3876. else
  3877. {
  3878. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  3879. }
  3880. }
  3881. end:
  3882. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3883. return result;
  3884. }
  3885. int handleDataTransferRequest(char *uuid, char *payload)
  3886. {
  3887. mtrace();
  3888. int result = FAIL;
  3889. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  3890. char tempvendorId[255]={0};
  3891. char tempmessageId[50]={0};
  3892. char tempdata[50]={0};
  3893. char sstr[160]={0};//sstr[200]={ 0 };
  3894. char message[80]={0};
  3895. int c = 0;
  3896. char *loc;
  3897. DEBUG_INFO("handle DataTransferRequest\n");
  3898. if((uuid != NULL) && (payload != NULL))
  3899. {
  3900. //===============================
  3901. // vendorId
  3902. //===============================
  3903. c = 0;
  3904. loc = strstr(payload, "vendorId");
  3905. while (loc[strlen("vendorId")+3+c] != '\"')
  3906. {
  3907. sstr[c] = loc[strlen("vendorId")+3+c];
  3908. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3909. c++;
  3910. }
  3911. sstr[c] = '\0';
  3912. strcpy(tempvendorId,sstr);
  3913. //===============================
  3914. // messageId
  3915. //===============================
  3916. memset(sstr ,0, sizeof(sstr) );
  3917. c = 0;
  3918. loc = strstr(payload, "messageId");
  3919. while (loc[strlen("messageId")+3+c] != '\"')
  3920. {
  3921. sstr[c] = loc[strlen("messageId")+3+c];
  3922. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3923. c++;
  3924. }
  3925. sstr[c] = '\0';
  3926. strcpy(tempmessageId,sstr);
  3927. //===============================
  3928. // data
  3929. //===============================
  3930. memset(sstr ,0, sizeof(sstr) );
  3931. c = 0;
  3932. loc = strstr(payload, "data");
  3933. printf("loc=%s\n",loc);
  3934. while (loc[strlen("data")+3+c] != '\"')
  3935. {
  3936. sstr[c] = loc[strlen("data")+3+c];
  3937. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3938. c++;
  3939. }
  3940. sstr[c] = '\0';
  3941. strcpy(tempdata,sstr);
  3942. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  3943. }
  3944. else
  3945. {
  3946. char guid[37]={0};
  3947. random_uuid(guid);
  3948. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  3949. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  3950. }
  3951. LWS_Send(message);
  3952. return result;
  3953. }
  3954. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  3955. {
  3956. mtrace();
  3957. int result = FAIL;
  3958. int connectorIdInt, durationInt;
  3959. char chargingRateUnitStr[4]={0};
  3960. //int tempconnectorIdInt,
  3961. int tempdurationInt;
  3962. float tempminChargingRateFloat = 0.0;
  3963. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  3964. int tempStartPeriodInt=0;
  3965. float tempLimitInt=0.0;//0.1;
  3966. int tempNumberPhasesInt=0;
  3967. char fname[200];
  3968. char comfirmstr[20];
  3969. //float totallimit =0.0;
  3970. float MinChargingRate =0.0;
  3971. //double diff_t;
  3972. //struct tm tp;
  3973. FILE *fptr1;
  3974. int c = 0;
  3975. //int i = 0;
  3976. char * pch;
  3977. char *loc;
  3978. char sstr[200]={ 0 };
  3979. int n_chargingProfile = 0;
  3980. int n_SchedulePeriods = 0;
  3981. char SchedulePeriodList[10][200]={0};
  3982. char sLineWord[800]={0};
  3983. //int n_periods = 0;
  3984. char word[1000]={0};
  3985. int confirmPeriods = 0;
  3986. struct StructProfile ChargePointMaxProfile;
  3987. struct StructProfile TxDefaultProfile;
  3988. struct StructProfile TxProfile;
  3989. struct StructProfile TxDefaultProfiletemp[2]={0};
  3990. int TxDefaultProfileFileIsNull=FALSE;
  3991. int ChargePointMaxProfileIsNull=FALSE;
  3992. int TxProfileIsNull=FALSE;
  3993. int CompositeSceduleIndex = 0;
  3994. char ChargePointMaxProfileScheduleStr[30]={0};
  3995. char TxDefaultProfileScheduleStr[30]={0};
  3996. char TxProfileScheduleStr[30]={0};
  3997. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  3998. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  3999. memset(&TxProfile,0,sizeof(struct StructProfile));
  4000. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4001. c=0;
  4002. loc = strstr(payload, "connectorId");
  4003. memset(sstr ,0, sizeof(sstr) );
  4004. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4005. {
  4006. sstr[c] = loc[strlen("connectorId")+2+c];
  4007. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4008. c++;
  4009. }
  4010. sstr[c] = '\0';
  4011. connectorIdInt = atoi(sstr);
  4012. c=0;
  4013. loc = strstr(payload, "duration");
  4014. memset(sstr ,0, sizeof(sstr) );
  4015. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4016. {
  4017. sstr[c] = loc[strlen("duration")+2+c];
  4018. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4019. c++;
  4020. }
  4021. sstr[c] = '\0';
  4022. durationInt = atoi(sstr);
  4023. c = 0;
  4024. loc = strstr(payload, "chargingRateUnit");
  4025. memset(sstr ,0, sizeof(sstr) );
  4026. if(loc == NULL)
  4027. {
  4028. }
  4029. else
  4030. {
  4031. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4032. {
  4033. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4034. c++;
  4035. }
  4036. sstr[c] = '\0';
  4037. strcpy(chargingRateUnitStr, sstr);
  4038. }
  4039. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4040. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4041. if(connectorIdInt==0) // connectorId is 0
  4042. {
  4043. //******************************ChargePointMaxProfile*****************************************************/
  4044. strcpy(fname, ChargePointMaxProfile_JSON );
  4045. char word[30]={0};
  4046. char sLineWord[1060]={0};
  4047. int n_chargingProfile=0;
  4048. ChargePointMaxProfileIsNull=TRUE;
  4049. if((access(fname,F_OK))!=-1)
  4050. {
  4051. fptr1 = fopen(fname, "r");
  4052. int c;
  4053. c = fgetc(fptr1);
  4054. //DEBUG_INFO("c:%d\n",c);
  4055. rewind(fptr1);
  4056. if(c == EOF)
  4057. {
  4058. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4059. ChargePointMaxProfileIsNull=TRUE;
  4060. fclose(fptr1);
  4061. }
  4062. else
  4063. {
  4064. ChargePointMaxProfileIsNull=FALSE;
  4065. while(fscanf(fptr1, "%s", word) != EOF)
  4066. {
  4067. if(strcmp(word, "chargingProfileId") == 0)
  4068. {
  4069. n_chargingProfile = n_chargingProfile + 1;
  4070. printf("Found\n");
  4071. }
  4072. }
  4073. rewind(fptr1);
  4074. //search Charging Profile Element
  4075. int i= 0;
  4076. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4077. #if 0
  4078. /***********connectorId****************/
  4079. c = 0;
  4080. loc = strstr(sLineWord, "connectorId");
  4081. // printf("loc=%s\n",loc);
  4082. memset(sstr ,0, sizeof(sstr) );
  4083. while (loc[strlen("connectorId")+2+c] != ',')
  4084. {
  4085. sstr[c] = loc[strlen("connectorId")+2+c];
  4086. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4087. c++;
  4088. }
  4089. sstr[c] = '\0';
  4090. tempconnectorIdInt = atoi(sstr);
  4091. #endif
  4092. //***********validFrom**************/
  4093. c = 0;
  4094. loc = strstr(sLineWord, "validFrom");
  4095. //DEBUG_INFO("loc=%s\n",loc);
  4096. memset(sstr ,0, sizeof(sstr) );
  4097. if(loc != NULL)
  4098. {
  4099. while (loc[3+strlen("validFrom")+c] != '\"')
  4100. {
  4101. sstr[c] = loc[3+strlen("validFrom")+c];
  4102. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4103. c++;
  4104. }
  4105. sstr[c] = '\0';
  4106. DEBUG_INFO("validFrom=%s\n",sstr);
  4107. strcpy(tempvalidFromStr,sstr);
  4108. }
  4109. else
  4110. {
  4111. strcpy(tempvalidFromStr,"");
  4112. }
  4113. //**********startSchedule**********/
  4114. c = 0;
  4115. loc = strstr(sLineWord, "startSchedule");
  4116. //DEBUG_INFO("loc=%s\n",loc);
  4117. memset(sstr ,0, sizeof(sstr) );
  4118. while (loc[3+strlen("startSchedule")+c] != '\"')
  4119. {
  4120. sstr[c] = loc[3+strlen("startSchedule")+c];
  4121. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4122. c++;
  4123. }
  4124. sstr[c] = '\0';
  4125. strcpy(tempstartScheduleStr, sstr);
  4126. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4127. //**********chargingRateUnit**********/
  4128. c = 0;
  4129. loc = strstr(sLineWord, "chargingRateUnit");
  4130. memset(sstr ,0, sizeof(sstr) );
  4131. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4132. {
  4133. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4134. c++;
  4135. }
  4136. sstr[c] = '\0';
  4137. strcpy(tempchargingRateUnitStr, sstr);
  4138. //**********minChargingRate*******/
  4139. c = 0;
  4140. loc = strstr(sLineWord, "minChargingRate");
  4141. //printf("loc=%s\n",loc);
  4142. if(loc != NULL)
  4143. {
  4144. memset(sstr ,0, sizeof(sstr) );
  4145. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4146. {
  4147. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4148. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4149. c++;
  4150. }
  4151. sstr[c] = '\0';
  4152. tempminChargingRateFloat = atof(sstr);
  4153. }
  4154. else
  4155. {
  4156. tempminChargingRateFloat = 0.0;
  4157. }
  4158. //
  4159. #if 0
  4160. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4161. tp.tm_isdst = -1;
  4162. time_t utc = mktime(&tp);
  4163. // current time
  4164. time_t t = time(NULL);
  4165. #endif
  4166. //diff_t = difftime(t, utc);
  4167. //parsing strings to words
  4168. i = 0;
  4169. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4170. loc = loc+3+strlen("chargingSchedulePeriod");
  4171. pch = strtok(loc ,"{");
  4172. while (pch != NULL)
  4173. {
  4174. strcpy(SchedulePeriodList[i], pch);
  4175. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4176. //printf ("%s\n",pch);
  4177. pch = strtok (NULL, "{");
  4178. i = i + 1;
  4179. }
  4180. n_SchedulePeriods = i;
  4181. for(int i=0;i<n_SchedulePeriods;i++)
  4182. {
  4183. //*************startPeriod****************/
  4184. c = 0;
  4185. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4186. memset(sstr ,0, sizeof(sstr) );
  4187. while (loc[strlen("startPeriod")+2+c] != ',')
  4188. {
  4189. sstr[c] = loc[strlen("startPeriod")+2+c];
  4190. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4191. c++;
  4192. }
  4193. sstr[c] = '\0';
  4194. tempStartPeriodInt = atoi(sstr);
  4195. //*************limit****************/
  4196. c = 0;
  4197. loc = strstr(SchedulePeriodList[i], "limit");
  4198. memset(sstr ,0, sizeof(sstr) );
  4199. while (loc[strlen("limit")+2+c] != ',')
  4200. {
  4201. sstr[c] = loc[strlen("limit")+2+c];
  4202. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4203. c++;
  4204. }
  4205. sstr[c] = '\0';
  4206. tempLimitInt = atof(sstr);
  4207. //*************numberPhases****************/
  4208. c = 0;
  4209. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4210. memset(sstr ,0, sizeof(sstr) );
  4211. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4212. {
  4213. sstr[c] = loc[strlen("numberPhases")+2+c];
  4214. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4215. c++;
  4216. }
  4217. sstr[c] = '\0';
  4218. tempNumberPhasesInt = atoi(sstr);
  4219. ChargePointMaxProfile.Duration = durationInt;
  4220. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4221. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4222. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4223. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4224. }
  4225. if(MinChargingRate < tempminChargingRateFloat)
  4226. MinChargingRate = tempminChargingRateFloat;
  4227. }
  4228. }// End of file ChargingProfile
  4229. } //THE END OF ACCESS ChargePointMaxProfile
  4230. //******************************TxDefaultProfile***********************************************/
  4231. strcpy(fname, TxDefaultProfile_0_JSON);
  4232. memset(word, 0, 30);
  4233. memset(sLineWord, 0, 1060);
  4234. //char word[30]={0};
  4235. //char sLineWord[1060]={0};
  4236. n_chargingProfile=0;
  4237. TxDefaultProfileFileIsNull=TRUE;
  4238. if((access(fname,F_OK))!=-1)
  4239. {
  4240. fptr1 = fopen(fname, "r");
  4241. c = 0;
  4242. c = fgetc(fptr1);
  4243. //DEBUG_INFO("c:%d\n",c);
  4244. rewind(fptr1);
  4245. if(c == EOF)
  4246. {
  4247. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4248. TxDefaultProfileFileIsNull=TRUE;
  4249. fclose(fptr1);
  4250. }
  4251. else
  4252. {
  4253. TxDefaultProfileFileIsNull=FALSE;
  4254. while(fscanf(fptr1, "%s", word) != EOF)
  4255. {
  4256. if(strcmp(word, "chargingProfileId") == 0)
  4257. {
  4258. n_chargingProfile = n_chargingProfile + 1;
  4259. printf("Found\n");
  4260. }
  4261. }
  4262. rewind(fptr1);
  4263. //search Charging Profile Element
  4264. int i= 0;
  4265. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4266. #if 0
  4267. /***********connectorId****************/
  4268. c = 0;
  4269. loc = strstr(sLineWord, "connectorId");
  4270. // printf("loc=%s\n",loc);
  4271. memset(sstr ,0, sizeof(sstr) );
  4272. while (loc[strlen("connectorId")+2+c] != ',')
  4273. {
  4274. sstr[c] = loc[strlen("connectorId")+2+c];
  4275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4276. c++;
  4277. }
  4278. sstr[c] = '\0';
  4279. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4280. tempconnectorIdInt = atoi(sstr);
  4281. #endif
  4282. //***********validFrom**************/
  4283. c = 0;
  4284. loc = strstr(sLineWord, "validFrom");
  4285. //DEBUG_INFO("loc=%s\n",loc);
  4286. memset(sstr ,0, sizeof(sstr) );
  4287. if(loc != NULL)
  4288. {
  4289. while (loc[3+strlen("validFrom")+c] != '\"')
  4290. {
  4291. sstr[c] = loc[3+strlen("validFrom")+c];
  4292. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4293. c++;
  4294. }
  4295. sstr[c] = '\0';
  4296. DEBUG_INFO("validFrom=%s\n",sstr);
  4297. strcpy(tempvalidFromStr,sstr);
  4298. }
  4299. else
  4300. {
  4301. strcpy(tempvalidFromStr,"");
  4302. }
  4303. //**********startSchedule**********/
  4304. c = 0;
  4305. loc = strstr(sLineWord, "startSchedule");
  4306. //DEBUG_INFO("loc=%s\n",loc);
  4307. memset(sstr ,0, sizeof(sstr) );
  4308. while (loc[3+strlen("startSchedule")+c] != '\"')
  4309. {
  4310. sstr[c] = loc[3+strlen("startSchedule")+c];
  4311. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4312. c++;
  4313. }
  4314. sstr[c] = '\0';
  4315. strcpy(tempstartScheduleStr, sstr);
  4316. strcpy(TxDefaultProfileScheduleStr, sstr);
  4317. DEBUG_INFO(" debug 3-1\n");
  4318. //**********chargingRateUnit**********/
  4319. c = 0;
  4320. loc = strstr(sLineWord, "chargingRateUnit");
  4321. memset(sstr ,0, sizeof(sstr) );
  4322. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4323. {
  4324. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4325. c++;
  4326. }
  4327. sstr[c] = '\0';
  4328. strcpy(tempchargingRateUnitStr, sstr);
  4329. //**********minChargingRate*******/
  4330. c = 0;
  4331. loc = strstr(sLineWord, "minChargingRate");
  4332. //printf("loc=%s\n",loc);
  4333. if(loc != NULL)
  4334. {
  4335. memset(sstr ,0, sizeof(sstr) );
  4336. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4337. {
  4338. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4339. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4340. c++;
  4341. }
  4342. sstr[c] = '\0';
  4343. tempminChargingRateFloat = atof(sstr);
  4344. }
  4345. else
  4346. {
  4347. tempminChargingRateFloat = 0.0;
  4348. }
  4349. #if 0
  4350. //
  4351. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4352. tp.tm_isdst = -1;
  4353. time_t utc = mktime(&tp);
  4354. // current time
  4355. time_t t = time(NULL);
  4356. //diff_t = difftime(t, utc);
  4357. #endif
  4358. //parsing strings to words
  4359. i = 0;
  4360. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4361. loc = loc+3+strlen("chargingSchedulePeriod");
  4362. pch = strtok(loc ,"{");
  4363. while (pch != NULL)
  4364. {
  4365. strcpy(SchedulePeriodList[i], pch);
  4366. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4367. //printf ("%s\n",pch);
  4368. pch = strtok (NULL, "{");
  4369. i = i + 1;
  4370. }
  4371. n_SchedulePeriods = i;
  4372. for(int i=0;i<n_SchedulePeriods;i++)
  4373. {
  4374. //*************startPeriod****************/
  4375. c = 0;
  4376. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4377. memset(sstr ,0, sizeof(sstr) );
  4378. while (loc[strlen("startPeriod")+2+c] != ',')
  4379. {
  4380. sstr[c] = loc[strlen("startPeriod")+2+c];
  4381. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4382. c++;
  4383. }
  4384. sstr[c] = '\0';
  4385. tempStartPeriodInt = atoi(sstr);
  4386. //*************limit****************/
  4387. c = 0;
  4388. loc = strstr(SchedulePeriodList[i], "limit");
  4389. memset(sstr ,0, sizeof(sstr) );
  4390. while (loc[strlen("limit")+2+c] != ',')
  4391. {
  4392. sstr[c] = loc[strlen("limit")+2+c];
  4393. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4394. c++;
  4395. }
  4396. sstr[c] = '\0';
  4397. tempLimitInt = atof(sstr);
  4398. //*************numberPhases****************/
  4399. c = 0;
  4400. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4401. memset(sstr ,0, sizeof(sstr) );
  4402. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4403. {
  4404. sstr[c] = loc[strlen("numberPhases")+2+c];
  4405. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4406. c++;
  4407. }
  4408. sstr[c] = '\0';
  4409. tempNumberPhasesInt = atoi(sstr);
  4410. TxDefaultProfile.Duration = durationInt;
  4411. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4412. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4413. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4414. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4415. }
  4416. if(MinChargingRate < tempminChargingRateFloat)
  4417. MinChargingRate = tempminChargingRateFloat;
  4418. }
  4419. }
  4420. }// the end of ACCESS TxDefaultProfile
  4421. // Composite Schedule
  4422. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4423. {
  4424. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4425. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4426. {
  4427. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4428. {
  4429. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4430. }
  4431. else
  4432. {
  4433. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4434. }
  4435. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4436. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4437. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4438. }
  4439. }
  4440. //* Define temporary variables */
  4441. struct tm *gtime;
  4442. time_t now;
  4443. char buf[28];
  4444. /* Read the current system time */
  4445. time(&now);
  4446. /* Convert the system time to GMT (now UTC) */
  4447. gtime = gmtime(&now);
  4448. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4449. // make .conf
  4450. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4451. //MaxChargingProfilesInstalled is 10
  4452. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4453. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4454. //nPeriod = 1;
  4455. if(chargingRateUnitStr[0] != 0)
  4456. {
  4457. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4458. }
  4459. else
  4460. {
  4461. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4462. }
  4463. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4464. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4465. confirmPeriods = 1;
  4466. }
  4467. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4468. {
  4469. //*****************************ChargePointMaxProfile******************************************/
  4470. strcpy(fname, ChargePointMaxProfile_JSON);
  4471. ChargePointMaxProfileIsNull=TRUE;
  4472. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4473. {
  4474. fptr1 = fopen(fname, "r");
  4475. int c;
  4476. c = fgetc(fptr1);
  4477. //DEBUG_INFO("c:%d\n",c);
  4478. rewind(fptr1);
  4479. if(c == EOF)
  4480. {
  4481. DEBUG_INFO("\n End of file reached.");
  4482. ChargePointMaxProfileIsNull=TRUE;
  4483. fclose(fptr1);
  4484. }
  4485. else
  4486. {
  4487. ChargePointMaxProfileIsNull=FALSE;
  4488. while(fscanf(fptr1, "%s", word) != EOF)
  4489. {
  4490. if(strcmp(word, "chargingProfileId") == 0)
  4491. {
  4492. n_chargingProfile = n_chargingProfile + 1;
  4493. }
  4494. }
  4495. rewind(fptr1);
  4496. //search Charging Profile Element
  4497. int i = 0;
  4498. int j = 0;
  4499. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4500. #if 0
  4501. /***********connectorId****************/
  4502. c = 0;
  4503. loc = strstr(sLineWord, "connectorId");
  4504. memset(sstr ,0, sizeof(sstr) );
  4505. while (loc[strlen("connectorId")+2+c] != ',')
  4506. {
  4507. sstr[c] = loc[strlen("connectorId")+2+c];
  4508. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4509. c++;
  4510. }
  4511. sstr[c] = '\0';
  4512. tempconnectorIdInt = atoi(sstr);
  4513. #endif
  4514. //***********validFrom**************/
  4515. c = 0;
  4516. loc = strstr(sLineWord, "validFrom");
  4517. if(loc != NULL)
  4518. {
  4519. memset(sstr ,0, sizeof(sstr) );
  4520. while (loc[3+strlen("validFrom")+c] != '\"')
  4521. {
  4522. sstr[c] = loc[3+strlen("validFrom")+c];
  4523. c++;
  4524. }
  4525. sstr[c] = '\0';
  4526. strcpy(tempvalidFromStr,sstr);
  4527. }
  4528. else
  4529. {
  4530. strcpy(tempvalidFromStr,"");
  4531. }
  4532. //***********validFrom**************/
  4533. c = 0;
  4534. loc = strstr(sLineWord, "duration");
  4535. if(loc != NULL)
  4536. {
  4537. memset(sstr ,0, sizeof(sstr) );
  4538. while (loc[2+strlen("duration")+c] != ',')
  4539. {
  4540. sstr[c] = loc[2+strlen("duration")+c];
  4541. c++;
  4542. }
  4543. sstr[c] = '\0';
  4544. tempdurationInt = atoi(sstr);
  4545. }
  4546. else
  4547. {
  4548. tempdurationInt = 0;
  4549. }
  4550. //**********startSchedule**********/
  4551. c = 0;
  4552. loc = strstr(sLineWord, "startSchedule");
  4553. memset(sstr ,0, sizeof(sstr) );
  4554. while (loc[3+strlen("startSchedule")+c] != '\"')
  4555. {
  4556. sstr[c] = loc[3+strlen("startSchedule")+c];
  4557. c++;
  4558. }
  4559. sstr[c] = '\0';
  4560. strcpy(tempstartScheduleStr, sstr);
  4561. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4562. //**********chargingRateUnit**********/
  4563. c = 0;
  4564. loc = strstr(sLineWord, "chargingRateUnit");
  4565. memset(sstr ,0, sizeof(sstr) );
  4566. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4567. {
  4568. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4569. c++;
  4570. }
  4571. sstr[c] = '\0';
  4572. strcpy(tempchargingRateUnitStr, sstr);
  4573. //**********minChargingRate*******/
  4574. c = 0;
  4575. loc = strstr(sLineWord, "minChargingRate");
  4576. if(loc != NULL)
  4577. {
  4578. memset(sstr ,0, sizeof(sstr) );
  4579. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4580. {
  4581. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4582. c++;
  4583. }
  4584. sstr[c] = '\0';
  4585. tempminChargingRateFloat = atof(sstr);
  4586. }
  4587. else
  4588. {
  4589. tempminChargingRateFloat = 0.0;
  4590. }
  4591. #if 0
  4592. //
  4593. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4594. tp.tm_isdst = -1;
  4595. time_t utc = mktime(&tp);
  4596. time_t t = time(NULL);
  4597. //diff_t = difftime(t, utc);
  4598. #endif
  4599. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4600. //DEBUG_INFO(" debug 5 -1\n");
  4601. //parsing strings to words
  4602. i = 0;
  4603. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4604. loc = loc+3+strlen("chargingSchedulePeriod");
  4605. pch = strtok(loc ,"{");
  4606. while (pch != NULL)
  4607. {
  4608. strcpy(SchedulePeriodList[i], pch);
  4609. pch = strtok (NULL, "{");
  4610. i = i + 1;
  4611. }
  4612. n_SchedulePeriods = i;
  4613. for(int i=0;i<n_SchedulePeriods;i++)
  4614. {
  4615. //*************startPeriod****************/
  4616. c = 0;
  4617. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4618. memset(sstr ,0, sizeof(sstr) );
  4619. while (loc[strlen("startPeriod")+2+c] != ',')
  4620. {
  4621. sstr[c] = loc[strlen("startPeriod")+2+c];
  4622. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4623. c++;
  4624. }
  4625. sstr[c] = '\0';
  4626. tempStartPeriodInt = atoi(sstr);
  4627. //*************limit****************/
  4628. c = 0;
  4629. loc = strstr(SchedulePeriodList[i], "limit");
  4630. memset(sstr ,0, sizeof(sstr) );
  4631. while (loc[strlen("limit")+2+c] != ',')
  4632. {
  4633. sstr[c] = loc[strlen("limit")+2+c];
  4634. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4635. c++;
  4636. }
  4637. sstr[c] = '\0';
  4638. tempLimitInt = atof(sstr);
  4639. //*************numberPhases****************/
  4640. c = 0;
  4641. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4642. memset(sstr ,0, sizeof(sstr) );
  4643. while (loc[strlen("numberPhases")+2+c] != '}')
  4644. {
  4645. sstr[c] = loc[strlen("numberPhases")+2+c];
  4646. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4647. c++;
  4648. }
  4649. sstr[c] = '\0';
  4650. tempNumberPhasesInt = atoi(sstr);
  4651. if(j == 0)
  4652. {
  4653. ChargePointMaxProfile.Duration = tempdurationInt;
  4654. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4655. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4656. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4657. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4658. }
  4659. }
  4660. if(MinChargingRate < tempminChargingRateFloat)
  4661. {
  4662. MinChargingRate = tempminChargingRateFloat;
  4663. }
  4664. if(confirmPeriods < n_SchedulePeriods)
  4665. {
  4666. confirmPeriods = n_SchedulePeriods;
  4667. }
  4668. j = j + 1;
  4669. }
  4670. fclose(fptr1);
  4671. }
  4672. }// the end of access file ChargePointMaxProfile
  4673. //****************************TxDefaultProfile************************************************/
  4674. switch(connectorIdInt)
  4675. {
  4676. case 0:
  4677. break;
  4678. case 1:
  4679. strcpy(fname, TxDefaultProfile_1_JSON );
  4680. break;
  4681. case 2:
  4682. strcpy(fname, TxDefaultProfile_2_JSON );
  4683. break;
  4684. default:
  4685. strcpy(fname, TxDefaultProfile_1_JSON );
  4686. break;
  4687. }
  4688. TxDefaultProfileFileIsNull=TRUE;
  4689. if((access(fname,F_OK))!=-1)
  4690. {
  4691. fptr1 = fopen(fname, "r");
  4692. c = 0;
  4693. c = fgetc(fptr1);
  4694. //DEBUG_INFO("c:%d\n",c);
  4695. rewind(fptr1);
  4696. if(c == EOF)
  4697. {
  4698. DEBUG_INFO("\n End of file reached.");
  4699. TxDefaultProfileFileIsNull=TRUE;
  4700. fclose(fptr1);
  4701. }
  4702. else
  4703. {
  4704. TxDefaultProfileFileIsNull=FALSE;
  4705. while(fscanf(fptr1, "%s", word) != EOF)
  4706. {
  4707. if(strcmp(word, "chargingProfileId") == 0)
  4708. {
  4709. n_chargingProfile = n_chargingProfile + 1;
  4710. }
  4711. }
  4712. rewind(fptr1);
  4713. //search Charging Profile Element
  4714. int i = 0;
  4715. int j = 0;
  4716. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4717. //DEBUG_INFO(" 1-1\n");
  4718. #if 0
  4719. /***********connectorId****************/
  4720. c = 0;
  4721. loc = strstr(sLineWord, "connectorId");
  4722. memset(sstr ,0, sizeof(sstr) );
  4723. while (loc[strlen("connectorId")+2+c] != ',')
  4724. {
  4725. sstr[c] = loc[strlen("connectorId")+2+c];
  4726. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4727. c++;
  4728. }
  4729. sstr[c] = '\0';
  4730. tempconnectorIdInt = atoi(sstr);
  4731. #endif
  4732. //***********validFrom**************/
  4733. c = 0;
  4734. loc = strstr(sLineWord, "validFrom");
  4735. if(loc != NULL)
  4736. {
  4737. memset(sstr ,0, sizeof(sstr) );
  4738. while (loc[3+strlen("validFrom")+c] != '\"')
  4739. {
  4740. sstr[c] = loc[3+strlen("validFrom")+c];
  4741. c++;
  4742. }
  4743. sstr[c] = '\0';
  4744. strcpy(tempvalidFromStr,sstr);
  4745. }
  4746. else
  4747. {
  4748. strcpy(tempvalidFromStr,"");
  4749. }
  4750. //***********validFrom**************/
  4751. c = 0;
  4752. loc = strstr(sLineWord, "duration");
  4753. if(loc != NULL)
  4754. {
  4755. memset(sstr ,0, sizeof(sstr) );
  4756. while (loc[2+strlen("duration")+c] != ',')
  4757. {
  4758. sstr[c] = loc[2+strlen("duration")+c];
  4759. c++;
  4760. }
  4761. sstr[c] = '\0';
  4762. tempdurationInt = atoi(sstr);
  4763. }
  4764. else
  4765. {
  4766. tempdurationInt = 0;
  4767. }
  4768. //**********startSchedule**********/
  4769. c = 0;
  4770. loc = strstr(sLineWord, "startSchedule");
  4771. memset(sstr ,0, sizeof(sstr) );
  4772. while (loc[3+strlen("startSchedule")+c] != '\"')
  4773. {
  4774. sstr[c] = loc[3+strlen("startSchedule")+c];
  4775. c++;
  4776. }
  4777. sstr[c] = '\0';
  4778. strcpy(tempstartScheduleStr, sstr);
  4779. strcpy(TxDefaultProfileScheduleStr, sstr);
  4780. //**********chargingRateUnit**********/
  4781. c = 0;
  4782. loc = strstr(sLineWord, "chargingRateUnit");
  4783. memset(sstr ,0, sizeof(sstr) );
  4784. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4785. {
  4786. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4787. c++;
  4788. }
  4789. sstr[c] = '\0';
  4790. strcpy(tempchargingRateUnitStr, sstr);
  4791. //**********minChargingRate*******/
  4792. c = 0;
  4793. loc = strstr(sLineWord, "minChargingRate");
  4794. if(loc != NULL)
  4795. {
  4796. memset(sstr ,0, sizeof(sstr) );
  4797. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4798. {
  4799. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4800. c++;
  4801. }
  4802. sstr[c] = '\0';
  4803. tempminChargingRateFloat = atof(sstr);
  4804. }
  4805. else
  4806. {
  4807. tempminChargingRateFloat = 0.0;
  4808. }
  4809. #if 0
  4810. //
  4811. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4812. tp.tm_isdst = -1;
  4813. time_t utc = mktime(&tp);
  4814. time_t t = time(NULL);
  4815. //diff_t = difftime(t, utc);
  4816. #endif
  4817. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4818. //parsing strings to words
  4819. i = 0;
  4820. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4821. loc = loc+3+strlen("chargingSchedulePeriod");
  4822. pch = strtok(loc ,"{");
  4823. while (pch != NULL)
  4824. {
  4825. strcpy(SchedulePeriodList[i], pch);
  4826. pch = strtok (NULL, "{");
  4827. i = i + 1;
  4828. }
  4829. n_SchedulePeriods = i;
  4830. for(int i=0;i<n_SchedulePeriods;i++)
  4831. {
  4832. //*************startPeriod****************/
  4833. c = 0;
  4834. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4835. memset(sstr ,0, sizeof(sstr) );
  4836. while (loc[strlen("startPeriod")+2+c] != ',')
  4837. {
  4838. sstr[c] = loc[strlen("startPeriod")+2+c];
  4839. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4840. c++;
  4841. }
  4842. sstr[c] = '\0';
  4843. tempStartPeriodInt = atoi(sstr);
  4844. //*************limit****************/
  4845. c = 0;
  4846. loc = strstr(SchedulePeriodList[i], "limit");
  4847. memset(sstr ,0, sizeof(sstr) );
  4848. while (loc[strlen("limit")+2+c] != ',')
  4849. {
  4850. sstr[c] = loc[strlen("limit")+2+c];
  4851. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4852. c++;
  4853. }
  4854. sstr[c] = '\0';
  4855. tempLimitInt = atof(sstr);
  4856. //*************numberPhases****************/
  4857. c = 0;
  4858. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4859. memset(sstr ,0, sizeof(sstr) );
  4860. while (loc[strlen("numberPhases")+2+c] != '}')
  4861. {
  4862. sstr[c] = loc[strlen("numberPhases")+2+c];
  4863. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4864. c++;
  4865. }
  4866. sstr[c] = '\0';
  4867. tempNumberPhasesInt = atoi(sstr);
  4868. if(j == 0)
  4869. {
  4870. TxDefaultProfile.Duration = tempdurationInt;
  4871. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4872. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4873. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4874. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4875. }
  4876. else
  4877. {
  4878. //other stack level charging Profile
  4879. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  4880. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  4881. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  4882. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  4883. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  4884. }
  4885. }
  4886. if(MinChargingRate < tempminChargingRateFloat)
  4887. MinChargingRate = tempminChargingRateFloat;
  4888. if(confirmPeriods < n_SchedulePeriods)
  4889. confirmPeriods = n_SchedulePeriods;
  4890. j = j + 1;
  4891. //DEBUG_INFO(" 1-2\n");
  4892. }
  4893. fclose(fptr1);
  4894. //Stacking Charging Profiles
  4895. for(int l=0; l <(j-1) ;l++)
  4896. {
  4897. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  4898. {
  4899. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  4900. {
  4901. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  4902. {
  4903. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  4904. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  4905. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  4906. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4907. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4908. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4909. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4910. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4911. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4912. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4913. }
  4914. else
  4915. {
  4916. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4917. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4918. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4919. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4920. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4921. }
  4922. }
  4923. }
  4924. }
  4925. //end of Stacking Charging Profiles
  4926. }
  4927. }// the end of ACCESS TxDefaultProfile
  4928. //****************************TxProfile************************************************/
  4929. switch(connectorIdInt)
  4930. {
  4931. case 0:
  4932. break;
  4933. case 1:
  4934. strcpy(fname, TxProfile_1_JSON );
  4935. break;
  4936. case 2:
  4937. strcpy(fname, TxProfile_2_JSON );
  4938. break;
  4939. default:
  4940. strcpy(fname, TxProfile_1_JSON );
  4941. break;
  4942. }
  4943. TxProfileIsNull=TRUE;
  4944. if((access(fname,F_OK))!=-1)
  4945. {
  4946. fptr1 = fopen(fname, "r");
  4947. c = 0;
  4948. c = fgetc(fptr1);
  4949. //DEBUG_INFO("c:%d\n",c);
  4950. rewind(fptr1);
  4951. if(c == EOF)
  4952. {
  4953. DEBUG_INFO("\n End of file reached.");
  4954. TxProfileIsNull=TRUE;
  4955. fclose(fptr1);
  4956. }
  4957. else
  4958. {
  4959. TxProfileIsNull=FALSE;
  4960. while(fscanf(fptr1, "%s", word) != EOF)
  4961. {
  4962. if(strcmp(word, "chargingProfileId") == 0)
  4963. {
  4964. n_chargingProfile = n_chargingProfile + 1;
  4965. }
  4966. }
  4967. rewind(fptr1);
  4968. //search Charging Profile Element
  4969. int i= 0;
  4970. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4971. #if 0
  4972. /***********connectorId****************/
  4973. c = 0;
  4974. loc = strstr(sLineWord, "connectorId");
  4975. memset(sstr ,0, sizeof(sstr) );
  4976. while (loc[strlen("connectorId")+2+c] != ',')
  4977. {
  4978. sstr[c] = loc[strlen("connectorId")+2+c];
  4979. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4980. c++;
  4981. }
  4982. sstr[c] = '\0';
  4983. tempconnectorIdInt = atoi(sstr);
  4984. #endif
  4985. //***********validFrom**************/
  4986. c = 0;
  4987. loc = strstr(sLineWord, "validFrom");
  4988. if(loc != NULL)
  4989. {
  4990. memset(sstr ,0, sizeof(sstr) );
  4991. while (loc[3+strlen("validFrom")+c] != '\"')
  4992. {
  4993. sstr[c] = loc[3+strlen("validFrom")+c];
  4994. c++;
  4995. }
  4996. sstr[c] = '\0';
  4997. strcpy(tempvalidFromStr,sstr);
  4998. }
  4999. else
  5000. {
  5001. strcpy(tempvalidFromStr,"");
  5002. }
  5003. //**********startSchedule**********/
  5004. c = 0;
  5005. loc = strstr(sLineWord, "startSchedule");
  5006. memset(sstr ,0, sizeof(sstr) );
  5007. while (loc[3+strlen("startSchedule")+c] != '\"')
  5008. {
  5009. sstr[c] = loc[3+strlen("startSchedule")+c];
  5010. c++;
  5011. }
  5012. sstr[c] = '\0';
  5013. strcpy(tempstartScheduleStr, sstr);
  5014. strcpy(TxProfileScheduleStr, sstr);
  5015. //**********chargingRateUnit**********/
  5016. c = 0;
  5017. loc = strstr(sLineWord, "chargingRateUnit");
  5018. memset(sstr ,0, sizeof(sstr) );
  5019. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5020. {
  5021. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5022. c++;
  5023. }
  5024. sstr[c] = '\0';
  5025. strcpy(tempchargingRateUnitStr, sstr);
  5026. //**********minChargingRate*******/
  5027. c = 0;
  5028. loc = strstr(sLineWord, "minChargingRate");
  5029. if(loc != NULL)
  5030. {
  5031. memset(sstr ,0, sizeof(sstr) );
  5032. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5033. {
  5034. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5035. c++;
  5036. }
  5037. sstr[c] = '\0';
  5038. tempminChargingRateFloat = atof(sstr);
  5039. }
  5040. else
  5041. {
  5042. tempminChargingRateFloat = 0.0;
  5043. }
  5044. #if 0
  5045. //
  5046. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5047. tp.tm_isdst = -1;
  5048. time_t utc = mktime(&tp);
  5049. time_t t = time(NULL);
  5050. //diff_t = difftime(t, utc);
  5051. #endif
  5052. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5053. //parsing strings to words
  5054. i = 0;
  5055. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5056. loc = loc+3+strlen("chargingSchedulePeriod");
  5057. pch = strtok(loc ,"{");
  5058. while (pch != NULL)
  5059. {
  5060. strcpy(SchedulePeriodList[i], pch);
  5061. pch = strtok (NULL, "{");
  5062. i = i + 1;
  5063. }
  5064. n_SchedulePeriods = i;
  5065. for(int i=0;i<n_SchedulePeriods;i++)
  5066. {
  5067. //*************startPeriod****************/
  5068. c = 0;
  5069. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5070. memset(sstr ,0, sizeof(sstr) );
  5071. while (loc[strlen("startPeriod")+2+c] != ',')
  5072. {
  5073. sstr[c] = loc[strlen("startPeriod")+2+c];
  5074. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5075. c++;
  5076. }
  5077. sstr[c] = '\0';
  5078. tempStartPeriodInt = atoi(sstr);
  5079. //*************limit****************/
  5080. c = 0;
  5081. loc = strstr(SchedulePeriodList[i], "limit");
  5082. memset(sstr ,0, sizeof(sstr) );
  5083. while (loc[strlen("limit")+2+c] != ',')
  5084. {
  5085. sstr[c] = loc[strlen("limit")+2+c];
  5086. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5087. c++;
  5088. }
  5089. sstr[c] = '\0';
  5090. tempLimitInt = atof(sstr);
  5091. //*************numberPhases****************/
  5092. c = 0;
  5093. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5094. memset(sstr ,0, sizeof(sstr) );
  5095. while (loc[strlen("numberPhases")+2+c] != '}')
  5096. {
  5097. sstr[c] = loc[strlen("numberPhases")+2+c];
  5098. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5099. c++;
  5100. }
  5101. sstr[c] = '\0';
  5102. tempNumberPhasesInt = atoi(sstr);
  5103. TxProfile.Duration = durationInt;
  5104. TxProfile.TotalPeriod = n_SchedulePeriods;
  5105. TxProfile.Period[i].Limit = tempLimitInt;
  5106. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5107. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5108. }
  5109. if(MinChargingRate < tempminChargingRateFloat)
  5110. MinChargingRate = tempminChargingRateFloat;
  5111. if(confirmPeriods < n_SchedulePeriods)
  5112. confirmPeriods = n_SchedulePeriods;
  5113. }
  5114. fclose(fptr1);
  5115. }
  5116. }// the end of ACCESS TxProfile
  5117. //CompositeSchedule
  5118. int period=0;
  5119. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5120. {
  5121. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5122. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5123. {
  5124. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5125. {
  5126. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5127. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5128. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5129. period = period + 1;
  5130. }
  5131. else
  5132. {
  5133. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5134. {
  5135. }
  5136. else
  5137. {
  5138. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5139. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5140. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5141. period = period + 1;
  5142. }
  5143. }
  5144. }
  5145. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5146. {
  5147. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5148. {
  5149. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5150. {
  5151. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5152. }
  5153. else
  5154. {
  5155. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5156. }
  5157. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5158. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5159. period = period + 1;
  5160. }
  5161. }
  5162. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5163. {
  5164. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5165. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5166. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5167. period = period + 1;
  5168. }
  5169. }
  5170. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5171. {
  5172. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5173. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5174. {
  5175. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5176. {
  5177. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5178. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5179. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5180. period = period + 1;
  5181. }
  5182. else
  5183. {
  5184. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5185. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5186. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5187. period = period + 1;
  5188. }
  5189. }
  5190. }
  5191. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5192. {
  5193. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5194. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5195. {
  5196. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5197. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5198. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5199. period = period + 1;
  5200. }
  5201. }
  5202. confirmPeriods = period;
  5203. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5204. //* Define temporary variables */
  5205. struct tm *gtime;
  5206. time_t now;
  5207. char buf[28];
  5208. //* Read the current system time */
  5209. time(&now);
  5210. //* Convert the system time to GMT (now UTC) */
  5211. gtime = gmtime(&now);
  5212. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5213. // make .conf
  5214. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5215. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5216. //DEBUG_INFO(" debug 11\n");
  5217. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5218. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5219. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5220. }
  5221. else
  5222. {
  5223. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5224. }
  5225. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5226. return result;
  5227. }
  5228. int handleGetConfigurationRequest(char *uuid, char *payload)
  5229. {
  5230. mtrace();
  5231. int result = FAIL;
  5232. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5233. //struct json_object *jsonitem;
  5234. int MaxKeySupported = 0;
  5235. int n_keys = 0;
  5236. char requestKey[43][50]={0};
  5237. char search[]="[";
  5238. char sstr[500]={ 0 };
  5239. //int pos;
  5240. int l, c = 0;
  5241. int i = 0;
  5242. char *delim = "\",\"";
  5243. char * pch;
  5244. char *loc = strstr(payload, search);
  5245. //********************* Parsing String ***********************************/
  5246. if(loc == NULL) {
  5247. DEBUG_INFO("no key match in Configuration \n");
  5248. }
  5249. else {
  5250. //pos = loc - payload;
  5251. l = strlen(loc)-4;
  5252. while (c < l)
  5253. {
  5254. sstr[c] = loc[c+2];
  5255. c++;
  5256. }
  5257. sstr[c] = '\0';
  5258. //parsing strings to words
  5259. pch = strtok(sstr,delim);
  5260. if(pch == NULL)
  5261. {
  5262. strcpy(requestKey[0], sstr);
  5263. }
  5264. else
  5265. {
  5266. while (pch != NULL)
  5267. {
  5268. strcpy(requestKey[i], pch);
  5269. pch = strtok (NULL, delim);
  5270. i = i + 1;
  5271. }
  5272. n_keys = i;
  5273. }
  5274. }
  5275. UnknownKeynum = 0;
  5276. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5277. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5278. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5279. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5280. if(n_keys != 0)
  5281. {
  5282. for(int i=0;i<n_keys;i++)
  5283. {
  5284. getKeyValue(requestKey[i]);
  5285. //json_object_put(jsonitem);
  5286. }
  5287. }
  5288. else
  5289. {
  5290. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5291. getKeyValue("");
  5292. }
  5293. processUnkownKey();
  5294. sendGetConfigurationConfirmation(uuid);
  5295. return result;
  5296. }
  5297. static char fnamePlusPath[100]={0};
  5298. static char fnamePWithNoPath[60]={0};
  5299. void checkUploadLog(void)
  5300. {
  5301. FILE *fp;
  5302. /* Open the command for reading. */
  5303. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5304. if (fp == NULL) {
  5305. printf("Failed to run command\n" );
  5306. exit(1);
  5307. }
  5308. int ftppathlen = 0;
  5309. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5310. int i = 0;
  5311. /* Read the output a line at a time - output it. */
  5312. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5313. if(i==0)
  5314. {
  5315. ftppathlen = strlen(fnamePlusPath);
  5316. printf("%s\n", fnamePlusPath);
  5317. fnamePlusPath[ftppathlen]='\0';
  5318. break;
  5319. }
  5320. i= i+1;
  5321. }
  5322. /* close */
  5323. pclose(fp);
  5324. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5325. {
  5326. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5327. {
  5328. fnamePlusPath[k]='\0';
  5329. }
  5330. }
  5331. i=1;
  5332. //char fname[60]={0};
  5333. while(i < ftppathlen)
  5334. {
  5335. int len=ftppathlen-i;
  5336. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5337. {
  5338. printf("compare '/' all right\n");
  5339. break;
  5340. }
  5341. i=i+1;
  5342. }
  5343. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5344. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5345. fnamePWithNoPath[i+1] = '\0';
  5346. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5347. {
  5348. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5349. {
  5350. fnamePWithNoPath[j]='\0';
  5351. }
  5352. }
  5353. FILE* fp1 = fopen(fnamePlusPath, "r");
  5354. if (fp1)
  5355. {
  5356. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5357. // file exists
  5358. fclose(fp1);
  5359. }
  5360. else
  5361. {
  5362. // file doesn't exist
  5363. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5364. }
  5365. }
  5366. static char GetDiagnosticspayloadData[300]={0};
  5367. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5368. {
  5369. mtrace();
  5370. int result = FAIL;
  5371. 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. }