MessageHandler.c 577 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865
  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. static char * StopTransactionReasonStr[] = {
  514. MACROSTR(EmergencyStop),
  515. MACROSTR(EVDisconnected),
  516. MACROSTR(HardReset),
  517. MACROSTR(Local),
  518. MACROSTR(Other),
  519. MACROSTR(PowerLoss),
  520. MACROSTR(Reboot),
  521. MACROSTR(Remote),
  522. MACROSTR(SoftReset),
  523. MACROSTR(UnlockCommand),
  524. MACROSTR(DeAuthorized)
  525. };
  526. /*CancelReservationStatus*/
  527. typedef enum {
  528. CancelReservationStatus_Accepted,
  529. CancelReservationStatus_Rejected
  530. } CancelReservationStatus;
  531. static char * CancelReservationStatusStr[] = {
  532. MACROSTR(Accepted),
  533. MACROSTR(Rejected)
  534. };
  535. /*ReadingContext*/
  536. typedef enum {
  537. ReadingContext_Interruption_Begin,
  538. ReadingContext_Interruption_End,
  539. ReadingContext_Other,
  540. ReadingContext_Sample_Clock,
  541. ReadingContext_Sample_Periodic ,
  542. ReadingContext_Transaction_Begin ,
  543. ReadingContext_Transaction_End,
  544. ReadingContext_Trigger
  545. } ReadingContext;
  546. static char * ReadingContextStr[] = {
  547. MACROSTR(Interruption.Begin),
  548. MACROSTR(Interruption.End),
  549. MACROSTR(Other),
  550. MACROSTR(Sample.Clock),
  551. MACROSTR(Sample.Periodic),
  552. MACROSTR(Transaction.Begin),
  553. MACROSTR(Transaction.End),
  554. MACROSTR(Trigger)
  555. };
  556. /*ValueFormat*/
  557. typedef enum {
  558. Raw,
  559. SignedData
  560. } ValueFormat;
  561. static char * ValueFormatStr[] = {
  562. MACROSTR(Raw),
  563. MACROSTR(SignedData)
  564. };
  565. /*Measurand*/
  566. typedef enum {
  567. Current_Export ,
  568. Current_Import,
  569. Current_Offered,
  570. Energy_Active_Export_Register,
  571. Energy_Active_Import_Register,
  572. Energy_Reactive_Export_Register,
  573. Energy_Reactive_Import_Register,
  574. Energy_Active_Export_Interval,
  575. Energy_Active_Import_Interval,
  576. Energy_Reactive_Export_Interval,
  577. Energy_Reactive_Import_Interval,
  578. Frequency,
  579. Power_Active_Export ,
  580. Power_Active_Import,
  581. Power_Factor,
  582. Power_Offered,
  583. Power_Reactive_Export,
  584. Power_Reactive_Import,
  585. RPM,
  586. SoC,
  587. Temperature ,
  588. Voltage
  589. } Measurand;
  590. static char * MeasurandStr[] = {
  591. MACROSTR(Current.Export),
  592. MACROSTR(Current.Import),
  593. MACROSTR(Current.Offered),
  594. MACROSTR(Energy.Active.Export.Register),
  595. MACROSTR(Energy.Active.Import.Register),
  596. MACROSTR(Energy.Reactive.Export.Register),
  597. MACROSTR(Energy.Reactive.Import.Register),
  598. MACROSTR(Energy.Active.Export.Interval),
  599. MACROSTR(Energy.Active.Import.Interval),
  600. MACROSTR(Energy.Reactive.Export.Interval),
  601. MACROSTR(Energy.Reactive.Import.Interval),
  602. MACROSTR(Frequency),
  603. MACROSTR(Power.Active.Export),
  604. MACROSTR(Power.Active.Import),
  605. MACROSTR(Power.Factor),
  606. MACROSTR(Power.Offered),
  607. MACROSTR(Power.Reactive.ExportMACROSTR),
  608. MACROSTR(Power.Reactive.Import),
  609. MACROSTR(RPM),
  610. MACROSTR(SoC),
  611. MACROSTR(Temperature),
  612. MACROSTR(Voltage)
  613. };
  614. /*Location*/
  615. typedef enum {
  616. Location_Body,
  617. Location_Cable,
  618. Location_EV,
  619. Location_Inlet ,
  620. Location_Outlet
  621. } Location;
  622. static char * LocationStr[] = {
  623. MACROSTR(Body),
  624. MACROSTR(Cable),
  625. MACROSTR(EV),
  626. MACROSTR(Inlet),
  627. MACROSTR(Outlet)
  628. };
  629. /*Phase*/
  630. typedef enum {
  631. L1,
  632. L2,
  633. L3,
  634. N,
  635. L1_N,
  636. L2_N,
  637. L3_N,
  638. L1_L2,
  639. L2_L3,
  640. L3_L1
  641. } Phase;
  642. static char * PhaseStr[] = {
  643. MACROSTR(L1),
  644. MACROSTR(L2),
  645. MACROSTR(L3),
  646. MACROSTR(N),
  647. MACROSTR(L1-N),
  648. MACROSTR(L2-N),
  649. MACROSTR(L3-N),
  650. MACROSTR(L1-L2),
  651. MACROSTR(L2-L3),
  652. MACROSTR(L3-L1)
  653. };
  654. /*UnitOfMeasure*/
  655. typedef enum {
  656. UnitOfMeasure_Wh,
  657. UnitOfMeasure_kWh ,
  658. UnitOfMeasure_varh ,
  659. UnitOfMeasure_kvarh ,
  660. UnitOfMeasure_W ,
  661. UnitOfMeasure_kW ,
  662. UnitOfMeasure_VA ,
  663. UnitOfMeasure_kVA ,
  664. UnitOfMeasure_var ,
  665. UnitOfMeasure_kvar ,
  666. UnitOfMeasure_A ,
  667. UnitOfMeasure_V ,
  668. UnitOfMeasure_Celsius ,
  669. UnitOfMeasure_Fahrenheit ,
  670. UnitOfMeasure_K ,
  671. UnitOfMeasure_Percent
  672. } UnitOfMeasure;
  673. static char * UnitOfMeasureStr[] = {
  674. MACROSTR(Wh),
  675. MACROSTR(kWh),
  676. MACROSTR(varh),
  677. MACROSTR(kvarh),
  678. MACROSTR(W),
  679. MACROSTR(kW),
  680. MACROSTR(VA),
  681. MACROSTR(kVA),
  682. MACROSTR(var),
  683. MACROSTR(kvar),
  684. MACROSTR(A),
  685. MACROSTR(V),
  686. MACROSTR(Celsius),
  687. MACROSTR(Fahrenheit),
  688. MACROSTR(K),
  689. MACROSTR(Percent)
  690. };
  691. #if 0
  692. /*Configuration enum*/
  693. enum CoreProfile {
  694. AllowOfflineTxForUnknownId=0,
  695. AuthorizationCacheEnabled,
  696. AuthorizeRemoteTxRequests,
  697. BlinkRepeat,
  698. ClockAlignedDataInterval,
  699. ConnectionTimeOut,
  700. GetConfigurationMaxKeys,
  701. HeartbeatInterval,
  702. LightIntensity,
  703. LocalAuthorizeOffline,
  704. LocalPreAuthorize,
  705. MaxEnergyOnInvalidId,
  706. MeterValuesAlignedData,
  707. MeterValuesAlignedDataMaxLength,
  708. MeterValuesSampledData,
  709. MeterValuesSampledDataMaxLength,
  710. MeterValueSampleInterval,
  711. MinimumStatusDuration,
  712. NumberOfConnectors,
  713. ResetRetries,
  714. ConnectorPhaseRotation,
  715. ConnectorPhaseRotationMaxLength,
  716. StopTransactionOnEVSideDisconnect,
  717. StopTransactionOnInvalidId,
  718. StopTxnAlignedData,
  719. StopTxnAlignedDataMaxLength,
  720. StopTxnSampledData,
  721. StopTxnSampledDataMaxLength,
  722. SupportedFeatureProfiles,
  723. SupportedFeatureProfilesMaxLength,
  724. TransactionMessageAttempts,
  725. TransactionMessageRetryInterval,
  726. UnlockConnectorOnEVSideDisconnect,
  727. WebSocketPingInterval,
  728. _CoreProfile_CNT
  729. };
  730. #endif
  731. enum LocalAuthListManagementProfile{
  732. LocalAuthListEnabled=0,
  733. LocalAuthListMaxLength,
  734. SendLocalListMaxLength,
  735. _LocalAuthListManagementProfile_CNT
  736. };
  737. enum ReservationProfile{
  738. ReserveConnectorZeroSupported
  739. };
  740. enum SmartChargingProfile{
  741. ChargeProfileMaxStackLevel,
  742. ChargingScheduleAllowedChargingRateUnit,
  743. ChargingScheduleMaxPeriods,
  744. ConnectorSwitch3to1PhaseSupported,
  745. MaxChargingProfilesInstalled
  746. };
  747. enum ChargerSystemStatus{
  748. ChargerSystemStatus_Booting,
  749. ChargerSystemStatus_Idle,
  750. ChargerSystemStatus_Authorizing,
  751. ChargerSystemStatus_Preparing,
  752. ChargerSystemStatus_Charging,
  753. ChargerSystemStatus_Terminating,
  754. ChargerSystemStatus_Alarm,
  755. ChargerSystemStatus_Fault
  756. };
  757. enum GetConfigurationKey {
  758. GetConfiguration_AllowOfflineTxForUnknownId=0,
  759. GetConfiguration_AuthorizationCacheEnabled,
  760. GetConfiguration_AuthorizeRemoteTxRequests,
  761. GetConfiguration_BlinkRepeat,
  762. GetConfiguration_ClockAlignedDataInterval,
  763. GetConfiguration_ConnectionTimeOut,
  764. GetConfiguration_GetConfigurationMaxKeys,
  765. GetConfiguration_HeartbeatInterval,
  766. GetConfiguration_LightIntensity,
  767. GetConfiguration_LocalAuthorizeOffline,
  768. GetConfiguration_LocalPreAuthorize,
  769. GetConfiguration_MaxEnergyOnInvalidId,
  770. GetConfiguration_MeterValuesAlignedData,
  771. GetConfiguration_MeterValuesAlignedDataMaxLength,
  772. GetConfiguration_MeterValuesSampledData,
  773. GetConfiguration_MeterValuesSampledDataMaxLength,
  774. GetConfiguration_MeterValueSampleInterval,
  775. GetConfiguration_MinimumStatusDuration,
  776. GetConfiguration_NumberOfConnectors,
  777. GetConfiguration_ResetRetries,
  778. GetConfiguration_ConnectorPhaseRotation,
  779. GetConfiguration_ConnectorPhaseRotationMaxLength,
  780. GetConfiguration_StopTransactionOnEVSideDisconnect,
  781. GetConfiguration_StopTransactionOnInvalidId,
  782. GetConfiguration_StopTxnAlignedData,
  783. GetConfiguration_StopTxnAlignedDataMaxLength,
  784. GetConfiguration_StopTxnSampledData,
  785. GetConfiguration_StopTxnSampledDataMaxLength,
  786. GetConfiguration_SupportedFeatureProfiles,
  787. GetConfiguration_SupportedFeatureProfilesMaxLength,
  788. GetConfiguration_TransactionMessageAttempts,
  789. GetConfiguration_TransactionMessageRetryInterval,
  790. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  791. GetConfiguration_WebSocketPingInterval,
  792. GetConfiguration_LocalAuthListEnabled,
  793. GetConfiguration_LocalAuthListMaxLength,
  794. GetConfiguration_SendLocalListMaxLength,
  795. GetConfiguration_ReserveConnectorZeroSupported,
  796. GetConfiguration_ChargeProfileMaxStackLevel,
  797. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  798. GetConfiguration_ChargingScheduleMaxPeriods,
  799. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  800. GetConfiguration_MaxChargingProfilesInstalled,
  801. };
  802. //GetConfiguration Array
  803. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  804. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  805. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  806. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  807. //==========================================
  808. // Init all share memory
  809. //==========================================
  810. int InitShareMemory()
  811. {
  812. int result = PASS;
  813. int MeterSMId;
  814. //creat ShmSysConfigAndInfo
  815. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  816. {
  817. #ifdef SystemLogMessage
  818. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  819. #endif
  820. result = FAIL;
  821. }
  822. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  823. {
  824. #ifdef SystemLogMessage
  825. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  826. #endif
  827. result = FAIL;
  828. }
  829. else
  830. {}
  831. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  832. {
  833. #ifdef SystemLogMessage
  834. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  835. #endif
  836. result = FAIL;
  837. }
  838. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  839. {
  840. #ifdef SystemLogMessage
  841. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  842. #endif
  843. result = FAIL;
  844. }
  845. else
  846. {}
  847. //creat ShmPsuData
  848. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  849. {
  850. #ifdef SystemLogMessage
  851. DEBUG_ERROR("shmget ShmPsuData NG\n");
  852. #endif
  853. result = FAIL;
  854. }
  855. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  856. {
  857. #ifdef SystemLogMessage
  858. DEBUG_ERROR("shmat ShmPsuData NG\n");
  859. #endif
  860. result = FAIL;
  861. }
  862. else
  863. {}
  864. //creat ShmOCPP16Data
  865. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  866. {
  867. #ifdef SystemLogMessage
  868. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  869. #endif
  870. result = FAIL;
  871. }
  872. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  873. {
  874. #ifdef SystemLogMessage
  875. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  876. #endif
  877. result = FAIL;
  878. }
  879. else
  880. {}
  881. /****************************** For Initial Settings************************************************/
  882. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  883. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  884. {
  885. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  886. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  887. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  888. }
  889. // Charger PRE_SYS_MODE
  890. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  891. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  892. clientTime.Heartbeat=time((time_t*)NULL);
  893. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  894. {
  895. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  896. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  897. }
  898. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  899. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  900. // allocate Configuration memory address
  901. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  902. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  903. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  904. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  905. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  906. {
  907. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  908. DEBUG_INFO("DC ...\n");
  909. }
  910. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  911. {
  912. SystemInitial = AC_QUANTITY;
  913. DEBUG_INFO("AC ...\n");
  914. }
  915. //Status Setting
  916. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  917. {
  918. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  919. }
  920. for (int index = 0; index < CCS_QUANTITY; index++)
  921. {
  922. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  923. }
  924. for (int index = 0; index < GB_QUANTITY; index++)
  925. {
  926. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  927. }
  928. for (int index = 0; index < AC_QUANTITY; index++)
  929. {
  930. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  931. }
  932. return result;
  933. }
  934. int ProcessShareMemory()
  935. {
  936. if(InitShareMemory() == FAIL)
  937. {
  938. #ifdef SystemLogMessage
  939. DEBUG_ERROR("InitShareMemory NG\n");
  940. #endif
  941. if(ShmStatusCodeData!=NULL)
  942. {
  943. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  944. }
  945. sleep(5);
  946. return FAIL;
  947. }
  948. return PASS;
  949. }
  950. //---------------------------------------------
  951. // new:
  952. // enum SYSTEM_STATUS
  953. // {
  954. // SYS_MODE_BOOTING = 0,
  955. // SYS_MODE_IDLE = 1,
  956. // SYS_MODE_AUTHORIZING = 2,
  957. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  958. // SYS_MODE_REASSIGN = 4,
  959. // SYS_MODE_PREPARING = 5,
  960. // SYS_MODE_PREPARE_FOR_EV = 6,
  961. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  962. // SYS_MODE_CHARGING = 8,
  963. // SYS_MODE_TERMINATING = 9,
  964. // SYS_MODE_COMPLETE = 10,
  965. // SYS_MODE_ALARM = 11,
  966. // SYS_MODE_FAULT = 12,
  967. // SYS_MODE_RESERVATION = 13,
  968. // SYS_MODE_BOOKING = 14,
  969. // SYS_MODE_MAINTAIN = 15,
  970. // SYS_MODE_DEBUG = 16,
  971. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  972. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  973. // SYS_MODE_UPDATE = 19
  974. // };
  975. //
  976. //
  977. //-----------------------------------------
  978. void CheckSystemValue(void)
  979. {
  980. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  981. int IdleModeCnt = 0;
  982. char filenmae[100]={0};
  983. char str[100]={0};
  984. //===============================
  985. // send Heartbeat
  986. //===============================
  987. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  988. {
  989. printf("Heartbeat !!!\n");
  990. //parameter for test
  991. sendHeartbeatRequest(0);
  992. //==============================================
  993. // Reset Waiting Time
  994. //==============================================
  995. clientTime.Heartbeat=time((time_t*)NULL);
  996. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  997. }
  998. //==============================================
  999. // Update firmware request
  1000. //==============================================
  1001. if(isUpdateRequest == TRUE )
  1002. {
  1003. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1004. {
  1005. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1006. {
  1007. //check SystemStatus
  1008. /*************************DC*******************************/
  1009. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1010. {
  1011. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1012. {
  1013. IdleModeCnt = IdleModeCnt + 1;
  1014. }
  1015. }
  1016. for (int index = 0; index < CCS_QUANTITY; index++)
  1017. {
  1018. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1019. {
  1020. IdleModeCnt = IdleModeCnt + 1;
  1021. }
  1022. }
  1023. for (int index = 0; index < GB_QUANTITY; index++)
  1024. {
  1025. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1026. {
  1027. IdleModeCnt = IdleModeCnt + 1;
  1028. }
  1029. }
  1030. }
  1031. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1032. {
  1033. isUpdateRequest = FALSE;
  1034. }
  1035. }
  1036. else
  1037. {
  1038. /*************************AC*******************************/
  1039. for (int index = 0; index < AC_QUANTITY; index++)
  1040. {
  1041. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1042. {
  1043. IdleModeCnt = IdleModeCnt + 1;
  1044. }
  1045. }
  1046. if(IdleModeCnt == AC_QUANTITY)
  1047. {
  1048. isUpdateRequest = FALSE;
  1049. }
  1050. }
  1051. }
  1052. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1053. {
  1054. //===============================
  1055. // CSU Trigger Reset Conf
  1056. //===============================
  1057. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1058. {
  1059. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1060. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1061. {
  1062. server_sign = FALSE;
  1063. }
  1064. }
  1065. //===============================
  1066. // CSU Trigger Authorize Request
  1067. //===============================
  1068. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1069. {
  1070. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1071. {
  1072. sendAuthorizeRequest(0);
  1073. authorizeRetryTimes = authorizeRetryTimes + 1;
  1074. // authenrequest = TRUE
  1075. if(authorizeRetryTimes < 3)
  1076. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1077. }
  1078. }
  1079. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1080. {
  1081. authorizeRetryTimes = 0;
  1082. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1083. server_sign = FALSE;
  1084. }
  1085. //===============================
  1086. // CSU Trigger Smart Charging Profilw
  1087. //===============================
  1088. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1089. {
  1090. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1091. GetChargingProfileRequest(gun_index);
  1092. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1093. }
  1094. //==============================================
  1095. // Charger start transaction
  1096. //==============================================
  1097. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1098. {
  1099. sendStartTransactionRequest(gun_index);
  1100. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1101. clientTime.StartTransaction = time((time_t*)NULL);
  1102. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1103. }
  1104. //==============================================
  1105. // Charger stop transaction
  1106. //==============================================
  1107. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1108. {
  1109. sendStopTransactionRequest(gun_index);
  1110. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1111. clientTime.StopTransaction = time((time_t*)NULL);
  1112. }
  1113. //==============================================
  1114. // Charger status report
  1115. //==============================================
  1116. /* Check Mode Change */
  1117. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1118. {
  1119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1120. {
  1121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1122. {
  1123. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1124. {
  1125. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1126. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1127. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1128. statusModeChage[gun_index] = TRUE;
  1129. }
  1130. }
  1131. }
  1132. for (int index = 0; index < CCS_QUANTITY; index++)
  1133. {
  1134. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1135. {
  1136. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1137. {
  1138. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1139. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1140. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1141. statusModeChage[gun_index] = TRUE;
  1142. }
  1143. }
  1144. }
  1145. for (int index = 0; index < GB_QUANTITY; index++)
  1146. {
  1147. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1148. {
  1149. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1150. {
  1151. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1152. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1153. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1154. statusModeChage[gun_index] = TRUE;
  1155. }
  1156. }
  1157. }
  1158. }
  1159. else //AC
  1160. {
  1161. for (int index = 0; index < AC_QUANTITY; index++)
  1162. {
  1163. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1164. {
  1165. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1166. {
  1167. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1168. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1169. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1170. statusModeChage[gun_index] = TRUE;
  1171. }
  1172. }
  1173. }// END OF FOR
  1174. }// END OF ELSE
  1175. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1176. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1177. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1178. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1179. {
  1180. if(SystemInitial != 0)
  1181. SystemInitial = SystemInitial -1;
  1182. sendStatusNotificationRequest(gun_index);
  1183. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1184. statusModeChage[gun_index] = FALSE;
  1185. }
  1186. //==============================================
  1187. // Meter report
  1188. //==============================================
  1189. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1190. {
  1191. //check Transaction active
  1192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1193. {
  1194. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1195. {
  1196. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1197. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1198. {
  1199. meterValueSend[gun_index] =1;
  1200. }
  1201. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1202. {
  1203. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1204. if((access(filenmae,F_OK))!=-1)
  1205. {
  1206. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1207. sprintf(str,"rm -f %s",filenmae);
  1208. system(str);
  1209. }
  1210. }
  1211. }// End for CHAdeMO
  1212. for (int index = 0; index < CCS_QUANTITY; index++)
  1213. {
  1214. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1215. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1216. {
  1217. meterValueSend[gun_index] =1;
  1218. }
  1219. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1220. {
  1221. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1222. if((access(filenmae,F_OK))!=-1)
  1223. {
  1224. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1225. sprintf(str,"rm -f %s",filenmae);
  1226. system(str);
  1227. }
  1228. }
  1229. } // End for CCS
  1230. for (int index = 0; index < GB_QUANTITY; index++)
  1231. {
  1232. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1233. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1234. {
  1235. meterValueSend[gun_index] =1;
  1236. }
  1237. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1238. {
  1239. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1240. if((access(filenmae,F_OK))!=-1)
  1241. {
  1242. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1243. sprintf(str,"rm -f %s",filenmae);
  1244. system(str);
  1245. }
  1246. }
  1247. }// End for GB
  1248. }
  1249. else
  1250. {
  1251. for (int index = 0; index < AC_QUANTITY; index++)
  1252. {
  1253. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1254. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1255. {
  1256. meterValueSend[gun_index] =1;
  1257. }
  1258. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1259. {
  1260. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1261. if((access(filenmae,F_OK))!=-1)
  1262. {
  1263. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1264. sprintf(str,"rm -f %s",filenmae);
  1265. system(str);
  1266. }
  1267. }
  1268. }//End for AC
  1269. }//END OF ELSE
  1270. // sleep(1);
  1271. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1272. if(meterValueSend[gun_index] == 1)
  1273. sendMeterValuesRequest(gun_index);
  1274. }
  1275. //==============================================
  1276. // Check Connector reserved
  1277. //==============================================
  1278. //===============================
  1279. // Check if Reserve is expired
  1280. //===============================
  1281. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1282. {
  1283. double diff_t;
  1284. struct tm tp;
  1285. // current time
  1286. time_t t = time(NULL);
  1287. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1288. tp.tm_isdst = -1;
  1289. time_t utc = mktime(&tp);
  1290. diff_t = difftime(utc, t);
  1291. if(diff_t <= 0)
  1292. {
  1293. DEBUG_INFO("reserve expired !!! \n");
  1294. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1295. }
  1296. }//END OF Check if Reserve is expired
  1297. //==========================================
  1298. // csu trigger FirmwareStatusNotificationReq
  1299. //==========================================
  1300. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1301. {
  1302. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1303. }
  1304. //==========================================
  1305. // csu trigger CancelReservationConf
  1306. //==========================================
  1307. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1308. {
  1309. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1310. }
  1311. //==========================================
  1312. // csu trigger ChangeAvailabilityConf
  1313. //==========================================
  1314. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1315. {
  1316. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1317. }
  1318. //==========================================
  1319. // csu trigger UnlockConnectorConf
  1320. //==========================================
  1321. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1322. {
  1323. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1324. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1325. }
  1326. //==========================================
  1327. // csu trigger ReserveNowConf
  1328. //==========================================
  1329. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1330. {
  1331. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1332. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1333. }
  1334. //==========================================
  1335. // csu trigger DataTransferReq
  1336. //==========================================
  1337. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1338. {
  1339. sendDataTransferRequest(gun_index);
  1340. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1341. }
  1342. }
  1343. }
  1344. //==========================================
  1345. // send request routine
  1346. //==========================================
  1347. int sendAuthorizeRequest(int gun_index)
  1348. {
  1349. mtrace();
  1350. int result = FAIL;
  1351. char message[100]={0};
  1352. char guid[37];
  1353. char tempdata[65]={0};
  1354. DEBUG_INFO("sendAuthorizeRequest \n");
  1355. //Local Authorize
  1356. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))
  1357. {
  1358. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1359. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1360. {
  1361. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1362. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1363. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1364. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1365. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1366. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1367. authorizeRetryTimes = 0;
  1368. return result;
  1369. }
  1370. else
  1371. {
  1372. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1373. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1374. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1375. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1376. result = PASS;
  1377. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1378. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1379. authorizeRetryTimes = 0;
  1380. return result;
  1381. }
  1382. }
  1383. //initailize struct Authorize
  1384. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1385. //get data from shared memory
  1386. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1387. random_uuid(guid);
  1388. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1389. LWS_Send(message);
  1390. sprintf(tempdata, "Authorize,%d", gun_index);
  1391. if(hashmap_operation(0, guid, tempdata) == 1)
  1392. {
  1393. result = PASS;
  1394. DEBUG_ERROR("Authorize mapItem pass\n");
  1395. }
  1396. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1397. return result;
  1398. }
  1399. int sendBootNotificationRequest(void)
  1400. {
  1401. mtrace();
  1402. int result = FAIL;
  1403. char message[500]={0}, payload[700]={0};
  1404. char guid[37]={0};
  1405. char tempdata[65]={0};
  1406. int IsGunCharging = FALSE;
  1407. //check Transaction active
  1408. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1409. {
  1410. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1411. {
  1412. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1413. {
  1414. IsGunCharging = TRUE;
  1415. }
  1416. }
  1417. for (int index = 0; index < CCS_QUANTITY; index++)
  1418. {
  1419. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1420. {
  1421. IsGunCharging = TRUE;
  1422. }
  1423. }
  1424. for (int index = 0; index < GB_QUANTITY; index++)
  1425. {
  1426. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1427. {
  1428. IsGunCharging = TRUE;
  1429. }
  1430. }
  1431. }
  1432. else
  1433. {
  1434. for (int index = 0; index < AC_QUANTITY; index++)
  1435. {
  1436. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1437. {
  1438. IsGunCharging = TRUE;
  1439. }
  1440. }
  1441. }
  1442. if(IsGunCharging == TRUE)
  1443. {
  1444. server_sign = TRUE;
  1445. return result;
  1446. }
  1447. // Fill BootNotification fields
  1448. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1449. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1450. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1451. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1452. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1453. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1454. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1455. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1456. ShmOCPP16Data->ChargeBoxId
  1457. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1458. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1459. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1460. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1461. ,ShmOCPP16Data->BootNotification.CpIccid
  1462. ,ShmOCPP16Data->BootNotification.CpImsi
  1463. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1464. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1465. random_uuid(guid);
  1466. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1467. LWS_Send(message);
  1468. sprintf(tempdata, "BootNotification,0");
  1469. 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*/)
  1470. {
  1471. result = PASS;
  1472. }
  1473. memset(queuedata, 0, sizeof(queuedata));
  1474. strcpy(queuedata,message);
  1475. HeartBeatCount = 0;
  1476. //#ifdef SystemLogMessage
  1477. //DEBUG_INFO(">>>>>BootNotification request\n");
  1478. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1479. //#endif
  1480. return result;
  1481. }
  1482. int sendDataTransferRequest(int gun_index)
  1483. {
  1484. mtrace();
  1485. char message[1000]={0};
  1486. char guid[37]={0};
  1487. char tempdata[65]={0};
  1488. int result = FAIL;
  1489. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1490. random_uuid(guid);
  1491. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1492. MESSAGE_TYPE_CALL,
  1493. guid,
  1494. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1495. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1496. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1497. LWS_Send(message);
  1498. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1499. 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*/)
  1500. {
  1501. result = PASS;
  1502. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1503. }
  1504. return result;
  1505. }
  1506. int sendDiagnosticsStatusNotificationRequest(char *status)
  1507. {
  1508. mtrace();
  1509. int result = FAIL;
  1510. char message[110]={0};
  1511. char guid[37]={0};
  1512. char tempdata[65]={0};
  1513. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1514. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1515. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1516. random_uuid(guid);
  1517. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1518. LWS_Send(message);
  1519. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1520. if(hashmap_operation(0, guid, tempdata) == 1)
  1521. {
  1522. result = PASS;
  1523. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1524. }
  1525. //#ifdef SystemLogMessage
  1526. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1527. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1528. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1529. //#endif
  1530. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1531. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1532. //record status
  1533. if(strcmp(status,"Idle")==0)
  1534. {
  1535. DiagnosticsStatusNotificationStatus = 0;
  1536. }
  1537. else if(strcmp(status,"Uploaded")==0)
  1538. {
  1539. DiagnosticsStatusNotificationStatus = 1;
  1540. }
  1541. else if(strcmp(status,"UploadFailed")==0)
  1542. {
  1543. DiagnosticsStatusNotificationStatus = 2;
  1544. }
  1545. else if(strcmp(status,"Uploading")==0)
  1546. {
  1547. DiagnosticsStatusNotificationStatus = 3;
  1548. }
  1549. return result;
  1550. }
  1551. int sendFirmwareStatusNotificationRequest(char *status)
  1552. {
  1553. mtrace();
  1554. int result = FAIL;
  1555. char message[110]={0};
  1556. char guid[37]={0};
  1557. char tempdata[65]={0};
  1558. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1559. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1560. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1561. random_uuid(guid);
  1562. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1563. LWS_Send(message);
  1564. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1565. 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*/)
  1566. {
  1567. result = PASS;
  1568. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1569. }
  1570. //#ifdef SystemLogMessage
  1571. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1572. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1573. //#endif
  1574. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1575. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1576. //record status
  1577. if(strcmp(status,"Downloaded")==0)
  1578. {
  1579. FirmwareStatusNotificationStatus = 0;
  1580. }
  1581. else if(strcmp(status,"DownloadFailed")==0)
  1582. {
  1583. FirmwareStatusNotificationStatus = 1;
  1584. }
  1585. else if(strcmp(status,"Downloading")==0)
  1586. {
  1587. FirmwareStatusNotificationStatus = 2;
  1588. }
  1589. else if(strcmp(status,"Idle")==0)
  1590. {
  1591. FirmwareStatusNotificationStatus = 3;
  1592. }
  1593. else if(strcmp(status,"InstallationFailed")==0)
  1594. {
  1595. FirmwareStatusNotificationStatus = 4;
  1596. }
  1597. else if(strcmp(status,"Installing")==0)
  1598. {
  1599. FirmwareStatusNotificationStatus = 5;
  1600. }
  1601. else if(strcmp(status,"Installed")==0)
  1602. {
  1603. FirmwareStatusNotificationStatus = 6;
  1604. }
  1605. return result;
  1606. }
  1607. int sendHeartbeatRequest(int gun_index)
  1608. {
  1609. mtrace();
  1610. int result = FAIL;
  1611. char message[80]={0};
  1612. char guid[37]={0};
  1613. char tempdata[65]={0};
  1614. random_uuid(guid);
  1615. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1616. , MESSAGE_TYPE_CALL
  1617. , guid );
  1618. LWS_Send(message);
  1619. sprintf(tempdata, "Heartbeat,%d", 0);
  1620. 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*/)
  1621. {
  1622. result = PASS;
  1623. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1624. }
  1625. return result;
  1626. }
  1627. int sendStartTransactionRequest(int gun_index)
  1628. {
  1629. mtrace();
  1630. int result = FAIL;
  1631. char message[250]={0};
  1632. char guid[37]={0};
  1633. struct timeval tmnow;
  1634. struct tm *tm;
  1635. char buf[28];//, usec_buf[6];
  1636. char tempdata[65]={0};
  1637. DEBUG_INFO("sendStartTransactionRequest...");
  1638. gettimeofday(&tmnow, NULL);
  1639. time_t t;
  1640. t = time(NULL);
  1641. /*UTC time and date*/
  1642. tm = gmtime(&t);
  1643. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1644. #if 0 // remove temporally
  1645. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1646. strcat(buf,".");
  1647. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1648. strcat(buf,usec_buf);
  1649. #endif
  1650. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1651. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1652. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1653. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1654. {
  1655. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1656. {
  1657. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1658. {
  1659. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1660. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1661. }
  1662. }
  1663. for (int index = 0; index < CCS_QUANTITY; index++)
  1664. {
  1665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1666. {
  1667. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1668. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1669. }
  1670. }
  1671. for (int index = 0; index < GB_QUANTITY; index++)
  1672. {
  1673. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1674. {
  1675. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1676. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1677. }
  1678. }
  1679. }
  1680. else
  1681. {
  1682. for (int index = 0; index < AC_QUANTITY; index++)
  1683. {
  1684. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1685. {
  1686. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1687. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1688. }
  1689. }
  1690. }//END OF ELSE
  1691. random_uuid(guid);
  1692. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1693. , MESSAGE_TYPE_CALL
  1694. , guid
  1695. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1696. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1697. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1698. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1699. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1700. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1701. 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*/)
  1702. {
  1703. result = PASS;
  1704. }
  1705. strcpy(queuedata, message);
  1706. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1707. LWS_Send(message);
  1708. #if 0
  1709. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1710. 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*/)
  1711. {
  1712. result = PASS;
  1713. }
  1714. strcpy(queuedata, message);
  1715. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1716. #endif
  1717. //#ifdef SystemLogMessage
  1718. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1719. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1720. //#endif
  1721. return result;
  1722. }
  1723. int sendStatusNotificationRequest(int gun_index)
  1724. {
  1725. mtrace();
  1726. int result = FAIL;
  1727. char message[600]={0};
  1728. char guid[37];
  1729. int currentStatus = 0;
  1730. struct timeval tmnow;
  1731. struct tm *tm;
  1732. char buf[28];//, usec_buf[6];
  1733. char tempdata[65]={0};
  1734. gettimeofday(&tmnow, NULL);
  1735. time_t t;
  1736. t = time(NULL);
  1737. /*UTC time and date*/
  1738. tm = gmtime(&t);
  1739. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1740. #if 0 // remove temporally
  1741. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1742. strcat(buf,".");
  1743. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1744. strcat(buf,usec_buf);
  1745. #endif
  1746. printf("%s",buf);
  1747. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1748. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1749. // it's option
  1750. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1751. /*
  1752. enum _SYSTEM_STATUS
  1753. {
  1754. S_BOOTING = 0,
  1755. S_IDLE, = 1
  1756. S_AUTHORIZING, =2
  1757. S_REASSIGN_CHECK, =3
  1758. S_REASSIGN, =4
  1759. S_PRECHARGE, =5
  1760. S_PREPARING_FOR_EV, =6
  1761. S_PREPARING_FOR_EVSE, =7
  1762. S_CHARGING, =8
  1763. S_TERMINATING, =9
  1764. S_COMPLETE, =10
  1765. S_ALARM, =11
  1766. S_FAULT =12
  1767. }
  1768. */
  1769. //check Transaction active
  1770. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1771. {
  1772. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1773. {
  1774. //printf("gun_index=%d\n",gun_index);
  1775. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1776. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1777. {
  1778. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1779. currentStatus = 0; //OCPP Status
  1780. }
  1781. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1782. {
  1783. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1784. currentStatus = 1; //OCPP Status
  1785. }
  1786. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1787. {
  1788. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1789. currentStatus = 2; //OCPP Status
  1790. }
  1791. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1792. {
  1793. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1794. currentStatus = 5; //OCPP Status
  1795. }
  1796. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1797. {
  1798. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1799. currentStatus = 4; //OCPP Status
  1800. }
  1801. 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) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) )) //S_TERMINATING ---> Unavailable
  1802. {
  1803. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1804. currentStatus = 7; //OCPP Status: Unavailable
  1805. }
  1806. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1807. {
  1808. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1809. currentStatus = 8; //OCPP Status: Faulted
  1810. }
  1811. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1812. {
  1813. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1814. currentStatus = 6; //OCPP Status: Reserved
  1815. }
  1816. }//end of for CHAdeMO_QUANTITY
  1817. for (int index = 0; index < CCS_QUANTITY; index++)
  1818. {
  1819. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1820. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1821. {
  1822. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1823. currentStatus = 0; //OCPP Status
  1824. }
  1825. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1826. {
  1827. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1828. currentStatus = 1; //OCPP Status
  1829. }
  1830. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1831. {
  1832. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1833. currentStatus = 2; //OCPP Status
  1834. }
  1835. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1836. {
  1837. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1838. currentStatus = 5; //OCPP Status
  1839. }
  1840. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1841. {
  1842. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1843. currentStatus = 4; //OCPP Status
  1844. }
  1845. 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) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) )) //S_TERMINATING ---> Unavailable
  1846. {
  1847. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[Unavailable]);
  1848. currentStatus = 7; //OCPP Status : Unavailable
  1849. }
  1850. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1851. {
  1852. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1853. currentStatus = 8; //OCPP Status
  1854. }
  1855. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1856. {
  1857. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1858. currentStatus = 6; //OCPP Status
  1859. }
  1860. }
  1861. for (int index = 0; index < GB_QUANTITY; index++)
  1862. {
  1863. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1864. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1865. {
  1866. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1867. currentStatus = 0; //OCPP Status
  1868. }
  1869. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1870. {
  1871. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1872. currentStatus = 1; //OCPP Status
  1873. }
  1874. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1875. {
  1876. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1877. currentStatus = 2; //OCPP Status
  1878. }
  1879. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1880. {
  1881. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1882. currentStatus = 5; //OCPP Status
  1883. }
  1884. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1885. {
  1886. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1887. currentStatus = 4; //OCPP Status
  1888. }
  1889. 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) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_TERMINATING ---> Unavailable
  1890. {
  1891. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1892. currentStatus = 7; //OCPP Status: Unavailable
  1893. }
  1894. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1895. {
  1896. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1897. currentStatus = 8; //OCPP Status: Faulted
  1898. }
  1899. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1900. {
  1901. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1902. currentStatus = 6; //OCPP Status: Faulted
  1903. }
  1904. }
  1905. }
  1906. else
  1907. {
  1908. for (int index = 0; index < AC_QUANTITY; index++)
  1909. {
  1910. //printf("gun_index=%d\n",gun_index);
  1911. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1912. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1913. {
  1914. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1915. currentStatus = 0; //OCPP Status
  1916. }
  1917. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1918. {
  1919. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1920. currentStatus = 1; //OCPP Status
  1921. }
  1922. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1923. {
  1924. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1925. currentStatus = 2; //OCPP Status
  1926. }
  1927. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1928. {
  1929. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1930. currentStatus = 5; //OCPP Status
  1931. }
  1932. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1933. {
  1934. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1935. currentStatus = 4; //OCPP Status
  1936. }
  1937. 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) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) )) //S_TERMINATING ---> Unavailable
  1938. {
  1939. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1940. currentStatus = 7; //OCPP Status: Unavailable
  1941. }
  1942. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1943. {
  1944. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1945. currentStatus = 8; //OCPP Status: Faulted
  1946. }
  1947. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1948. {
  1949. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1950. currentStatus = 6; //OCPP Status: Reserved
  1951. }
  1952. }//end of for AC_QUANTITY
  1953. }//END OF ELSE
  1954. //it's option
  1955. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1956. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1957. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  1958. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1959. random_uuid(guid);
  1960. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1961. , MESSAGE_TYPE_CALL
  1962. , guid
  1963. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1964. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1965. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1966. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1967. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1968. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1969. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1970. LWS_Send(message);
  1971. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1972. 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*/)
  1973. {
  1974. //DEBUG_ERROR("statusNotification mapitem pass");
  1975. result = PASS;
  1976. }
  1977. //#ifdef SystemLogMessage
  1978. //DEBUG_INFO(">>>>>StatusNotification request\n");
  1979. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1980. //#endif
  1981. return result;
  1982. }
  1983. int sendStopTransactionRequest(int gun_index)
  1984. {
  1985. mtrace();
  1986. int result = FAIL;
  1987. //char message[1500]={0};
  1988. char guid[37]={0};
  1989. char tempdata[65]={0};
  1990. //int idx_sample=0;
  1991. DEBUG_ERROR("sendStopTransactionRequest \n");
  1992. memset(queuedata, 0, sizeof(queuedata));
  1993. //ENERGY_ACTIVE_IMPORT_REGISTER
  1994. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1995. {
  1996. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1997. {
  1998. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1999. {
  2000. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2001. //Check Status
  2002. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2003. {
  2004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2005. }
  2006. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2007. }
  2008. }// END OF CHAdeMO_QUANTITY
  2009. for (int index = 0; index < CCS_QUANTITY; index++)
  2010. {
  2011. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2012. {
  2013. //for test
  2014. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2015. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2016. //Check Status
  2017. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2018. {
  2019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2020. }
  2021. else
  2022. {
  2023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2024. }
  2025. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2026. }
  2027. }// END OF CCS_QUANTITY
  2028. for (int index = 0; index < GB_QUANTITY; index++)
  2029. {
  2030. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2031. {
  2032. // for test
  2033. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2034. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2035. //Check Status
  2036. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2037. {
  2038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2039. }
  2040. else
  2041. {
  2042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2043. }
  2044. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2045. }
  2046. }// END OF GB_QUANTITY
  2047. }
  2048. else
  2049. {
  2050. for (int index = 0; index < AC_QUANTITY; index++)
  2051. {
  2052. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2053. {
  2054. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2055. //Check Status
  2056. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2057. {
  2058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2059. }
  2060. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2061. }
  2062. }// END OF AC_QUANTITY
  2063. }//END OF ELSE
  2064. //Stop Transaction Time
  2065. struct timeval tmnow;
  2066. struct tm *tm;
  2067. char buf[28];//, usec_buf[6];
  2068. gettimeofday(&tmnow, NULL);
  2069. time_t t;
  2070. t = time(NULL);
  2071. /*UTC time and date*/
  2072. tm = gmtime(&t);
  2073. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2074. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2076. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2077. random_uuid(guid);
  2078. /***********************************transactionData******************************************************/
  2079. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2080. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2081. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2083. //=================================
  2084. // Transaction_Begin
  2085. //=================================
  2086. // Energy.Active.Export.Interval
  2087. //idx_sample=0;
  2088. 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
  2089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2091. 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*/]);
  2092. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2093. {
  2094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2095. }
  2096. else
  2097. {
  2098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2099. }
  2100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2102. //=================================
  2103. // Transaction_End
  2104. //=================================
  2105. //Current.Export
  2106. //idx_sample=1;
  2107. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2108. {
  2109. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2110. {
  2111. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2112. {
  2113. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2114. }
  2115. }
  2116. for (int index = 0; index < CCS_QUANTITY; index++)
  2117. {
  2118. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2119. {
  2120. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2121. }
  2122. }
  2123. for (int index = 0; index < GB_QUANTITY; index++)
  2124. {
  2125. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2126. {
  2127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2128. }
  2129. }
  2130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2131. }
  2132. else
  2133. {
  2134. for (int index = 0; index < AC_QUANTITY; index++)
  2135. {
  2136. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2137. {
  2138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2139. }
  2140. }
  2141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2142. }// END FOR AC ELSE
  2143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2146. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2149. //Energy.Active.Export.Interval
  2150. //idx_sample=2;
  2151. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2152. {
  2153. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2154. {
  2155. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2156. {
  2157. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2158. }
  2159. }
  2160. for (int index = 0; index < CCS_QUANTITY; index++)
  2161. {
  2162. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2163. {
  2164. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2165. }
  2166. }
  2167. for (int index = 0; index < GB_QUANTITY; index++)
  2168. {
  2169. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2170. {
  2171. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2172. }
  2173. }
  2174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2175. }
  2176. else
  2177. {
  2178. for (int index = 0; index < AC_QUANTITY; index++)
  2179. {
  2180. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2181. {
  2182. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2183. }
  2184. }
  2185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2186. }// END FOR AC ELSE
  2187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2190. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2193. //Power.Active.Export
  2194. //idx_sample=3;
  2195. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2196. {
  2197. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2198. {
  2199. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2200. {
  2201. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2202. }
  2203. }
  2204. for (int index = 0; index < CCS_QUANTITY; index++)
  2205. {
  2206. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2207. {
  2208. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2209. }
  2210. }
  2211. for (int index = 0; index < GB_QUANTITY; index++)
  2212. {
  2213. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2214. {
  2215. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2216. }
  2217. }
  2218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2219. }
  2220. else
  2221. {
  2222. for (int index = 0; index < AC_QUANTITY; index++)
  2223. {
  2224. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2225. {
  2226. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2227. }
  2228. }
  2229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2230. }// END FOR AC ELSE
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2234. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2237. //Voltage
  2238. //idx_sample=4;
  2239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2240. {
  2241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2242. {
  2243. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2244. {
  2245. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2246. }
  2247. }
  2248. for (int index = 0; index < CCS_QUANTITY; index++)
  2249. {
  2250. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2251. {
  2252. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2253. }
  2254. }
  2255. for (int index = 0; index < GB_QUANTITY; index++)
  2256. {
  2257. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2258. {
  2259. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2260. }
  2261. }
  2262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2263. }
  2264. else
  2265. {
  2266. for (int index = 0; index < AC_QUANTITY; index++)
  2267. {
  2268. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2269. {
  2270. 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
  2271. }
  2272. }
  2273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2274. }// END FOR AC ELSE
  2275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2278. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2281. //SoC
  2282. //idx_sample=5;
  2283. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2284. {
  2285. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2286. {
  2287. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2288. {
  2289. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2290. }
  2291. }
  2292. for (int index = 0; index < CCS_QUANTITY; index++)
  2293. {
  2294. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2295. {
  2296. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2297. }
  2298. }
  2299. for (int index = 0; index < GB_QUANTITY; index++)
  2300. {
  2301. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2302. {
  2303. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2304. }
  2305. }
  2306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2312. } // END FOR DC CASE
  2313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2314. {
  2315. 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\" } ] } ] } ]"
  2316. ,MESSAGE_TYPE_CALL
  2317. ,guid
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2323. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2336. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2340. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2341. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2342. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2343. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2344. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2345. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2346. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2347. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2348. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2349. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2364. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2366. );
  2367. }
  2368. else
  2369. {
  2370. 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\" } ] } ] } ]"
  2371. ,MESSAGE_TYPE_CALL
  2372. ,guid
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2378. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2385. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2386. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2387. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2388. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2390. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2391. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2392. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2393. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2394. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2395. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2396. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2397. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2398. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2399. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2400. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2401. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2402. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2403. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2404. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2405. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2406. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2407. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2408. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2409. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2410. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2411. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2412. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2413. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2414. );
  2415. }
  2416. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2417. if(hashmap_operation(0, guid, tempdata) == 1)
  2418. {
  2419. result = PASS;
  2420. DEBUG_INFO("StopTransaction mapitem pass\n");
  2421. }
  2422. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2423. LWS_Send(queuedata);
  2424. #if 0
  2425. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2426. if(hashmap_operation(0, guid, tempdata) == 1)
  2427. {
  2428. result = PASS;
  2429. DEBUG_INFO("StopTransaction mapitem pass\n");
  2430. }
  2431. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2432. #endif
  2433. //for test
  2434. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2435. return result;
  2436. }
  2437. int sendMeterValuesRequest(int gun_index)
  2438. {
  2439. mtrace();
  2440. int result = FAIL;
  2441. // char message[1500]={0};
  2442. char guid[37]={0};
  2443. //int idx_sample=0;
  2444. //int length = 0;
  2445. char tempdata[65]={0};
  2446. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2447. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2448. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2449. {
  2450. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2451. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2452. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2453. return result;
  2454. }
  2455. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2456. {
  2457. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2458. }
  2459. memset(queuedata, 0, sizeof(queuedata));
  2460. //set value
  2461. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2462. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2463. random_uuid(guid);
  2464. //UTC Date time
  2465. struct timeval tmnow;
  2466. struct tm *tm;
  2467. char buf[28];//, usec_buf[6];
  2468. gettimeofday(&tmnow, NULL);
  2469. time_t t;
  2470. t = time(NULL);
  2471. /*UTC time and date*/
  2472. tm = gmtime(&t);
  2473. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2474. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2475. //idx_sample=0;
  2476. //********************************(1)Current.Export************************************************/
  2477. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2478. {
  2479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2480. {
  2481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2482. {
  2483. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2484. }
  2485. }
  2486. for (int index = 0; index < CCS_QUANTITY; index++)
  2487. {
  2488. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2489. {
  2490. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2491. }
  2492. }
  2493. for (int index = 0; index < GB_QUANTITY; index++)
  2494. {
  2495. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2496. {
  2497. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2498. }
  2499. }
  2500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2501. }
  2502. else
  2503. {
  2504. for (int index = 0; index < AC_QUANTITY; index++)
  2505. {
  2506. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2507. {
  2508. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2509. }
  2510. }
  2511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2512. }// END FOR AC ELSE
  2513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2515. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2516. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2519. //idx_sample=1;
  2520. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2522. {
  2523. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2524. {
  2525. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2526. {
  2527. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2528. }
  2529. }
  2530. for (int index = 0; index < CCS_QUANTITY; index++)
  2531. {
  2532. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2533. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2534. {
  2535. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2536. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2537. }
  2538. }
  2539. for (int index = 0; index < GB_QUANTITY; index++)
  2540. {
  2541. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2542. {
  2543. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2544. }
  2545. }
  2546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2547. }
  2548. else
  2549. {
  2550. for (int index = 0; index < AC_QUANTITY; index++)
  2551. {
  2552. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2553. {
  2554. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2555. }
  2556. }
  2557. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2558. }//END FOR AC ELSE
  2559. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2560. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2562. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2565. //idx_sample=2;
  2566. //********************************(4)Power.Active.Export************************************************/
  2567. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2568. {
  2569. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2570. {
  2571. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2572. {
  2573. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2574. }
  2575. }
  2576. for (int index = 0; index < CCS_QUANTITY; index++)
  2577. {
  2578. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2579. {
  2580. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2581. }
  2582. }
  2583. for (int index = 0; index < GB_QUANTITY; index++)
  2584. {
  2585. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2586. {
  2587. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2588. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2589. }
  2590. }
  2591. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2592. }
  2593. else
  2594. {
  2595. for (int index = 0; index < AC_QUANTITY; index++)
  2596. {
  2597. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2598. {
  2599. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2600. }
  2601. }
  2602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2603. }// END FOR AC ELSE
  2604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2607. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2609. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2610. //idx_sample=3;
  2611. //***********************************************(5)VOLTAGE******************************************************/
  2612. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2613. {
  2614. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2615. {
  2616. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2617. {
  2618. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2619. }
  2620. }
  2621. for (int index = 0; index < CCS_QUANTITY; index++)
  2622. {
  2623. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2624. {
  2625. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2626. }
  2627. }
  2628. for (int index = 0; index < GB_QUANTITY; index++)
  2629. {
  2630. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2631. {
  2632. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2633. }
  2634. }
  2635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2636. }
  2637. else
  2638. {
  2639. for (int index = 0; index < AC_QUANTITY; index++)
  2640. {
  2641. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2642. {
  2643. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2644. }
  2645. }
  2646. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2647. }//END FOR AC ELSE
  2648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2651. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2655. {
  2656. //idx_sample=4;
  2657. //sampledValue = NULL;
  2658. //***********************************************(6)SOC******************************************************/
  2659. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2660. {
  2661. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2662. {
  2663. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2664. }
  2665. }
  2666. for (int index = 0; index < CCS_QUANTITY; index++)
  2667. {
  2668. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2669. {
  2670. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2671. }
  2672. }
  2673. for (int index = 0; index < GB_QUANTITY; index++)
  2674. {
  2675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2676. {
  2677. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2678. }
  2679. }
  2680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2684. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2685. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2686. }
  2687. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2688. {
  2689. 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\"}]}]}]"
  2690. ,MESSAGE_TYPE_CALL
  2691. ,guid
  2692. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2693. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2694. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2730. );
  2731. }
  2732. else
  2733. {
  2734. 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\"}]}]}]"
  2735. ,MESSAGE_TYPE_CALL
  2736. ,guid
  2737. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2738. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2739. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2758. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2768. );
  2769. }
  2770. // Put request guid to hash map
  2771. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2772. 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*/)
  2773. {
  2774. result = PASS;
  2775. DEBUG_INFO("MeterValues mapitem pass\n");
  2776. }
  2777. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2778. LWS_Send(queuedata);
  2779. #if 0
  2780. // Put request guid to hash map
  2781. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2782. 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*/)
  2783. {
  2784. result = PASS;
  2785. DEBUG_INFO("MeterValues mapitem pass\n");
  2786. }
  2787. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2788. #endif
  2789. return result;
  2790. }
  2791. //==========================================
  2792. // send confirm routine
  2793. //==========================================
  2794. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2795. {
  2796. mtrace();
  2797. int result = FAIL;
  2798. char message[100]={0};
  2799. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2800. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2801. LWS_Send(message);
  2802. result = TRUE;
  2803. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2804. return result;
  2805. }
  2806. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2807. {
  2808. mtrace();
  2809. int result = FAIL;
  2810. char message[100]={0};
  2811. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2812. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2813. LWS_Send(message);
  2814. result = TRUE;
  2815. return result;
  2816. }
  2817. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2818. {
  2819. mtrace();
  2820. int result = FAIL;
  2821. char message[100]={0};
  2822. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2823. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2824. LWS_Send(message);
  2825. result = TRUE;
  2826. return result;
  2827. }
  2828. int sendClearCacheConfirmation(char *uuid,char *payload)
  2829. {
  2830. mtrace();
  2831. int result = FAIL;
  2832. char message[500]={0};
  2833. // int count = 0;
  2834. // int gun_index = 0;
  2835. // char guid[37];
  2836. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2837. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2838. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2839. LWS_Send(message);
  2840. return result;
  2841. }
  2842. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2843. {
  2844. mtrace();
  2845. int result = FAIL;
  2846. char message[500]={0};
  2847. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2848. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2849. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2850. LWS_Send(message);
  2851. return result;
  2852. }
  2853. int sendDataTransferConfirmation(char *uuid,char *payload)
  2854. {
  2855. mtrace();
  2856. char statusStr[20]={0};
  2857. char dataStr[10]={0};
  2858. char sstr[20]={0};
  2859. int c = 0;
  2860. char *loc;
  2861. int result = FAIL;
  2862. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2863. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2864. /**********************status**************************/
  2865. loc = strstr(payload, "status");
  2866. memset(sstr ,0, sizeof(sstr) );
  2867. c = 0;
  2868. while (loc[3+strlen("status")+c] != '\"')
  2869. {
  2870. sstr[c] = loc[3+strlen("status")+c];
  2871. c++;
  2872. }
  2873. sstr[c] = '\0';
  2874. strcpy(statusStr, sstr);
  2875. /**********************data**************************/
  2876. loc = strstr(payload, "data");
  2877. memset(sstr ,0, sizeof(sstr) );
  2878. c = 0;
  2879. while (loc[3+strlen("data")+c] != '\"')
  2880. {
  2881. sstr[c] = loc[3+strlen("data")+c];
  2882. c++;
  2883. }
  2884. sstr[c] = '\0';
  2885. strcpy(dataStr, sstr);
  2886. return result;
  2887. }
  2888. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2889. {
  2890. mtrace();
  2891. int result = FAIL;
  2892. char message[1000]={0};
  2893. double diff_f = 0.0;
  2894. int diff_i = 0;
  2895. int diffSeconds = 0;
  2896. struct tm tp;
  2897. int TimeZero = FALSE;
  2898. int CompositeScheduleIndex = 0;
  2899. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2900. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2901. {
  2902. TimeZero = TRUE;
  2903. }
  2904. else
  2905. {
  2906. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2907. }
  2908. if(TimeZero == FALSE)
  2909. {
  2910. tp.tm_isdst = -1;
  2911. time_t utc = mktime(&tp);
  2912. time_t t = time(NULL);
  2913. diff_f = difftime(t, utc);
  2914. diff_i = (int)diff_f;
  2915. diffSeconds = diff_i % 86400;//86400 seconds/day
  2916. }
  2917. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2918. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2919. #if 0 //remove temporally
  2920. 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}"
  2921. ,MESSAGE_TYPE_CALLRESULT
  2922. ,uuid
  2923. ,payload
  2924. ,connectorIdInt
  2925. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2926. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2927. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2928. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2929. #endif
  2930. if(nPeriod == 0)
  2931. {
  2932. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2933. ,MESSAGE_TYPE_CALLRESULT
  2934. ,uuid
  2935. ,payload
  2936. ,connectorIdInt
  2937. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2938. }
  2939. else
  2940. {
  2941. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2942. ,MESSAGE_TYPE_CALLRESULT
  2943. ,uuid
  2944. ,payload
  2945. ,connectorIdInt
  2946. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2947. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2948. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2949. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2950. int len = nPeriod;
  2951. //Last Period StartPriod is less than diffSeconds
  2952. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2953. {
  2954. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2955. , 0
  2956. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2957. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2958. }
  2959. else
  2960. {
  2961. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2962. {
  2963. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2964. {
  2965. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2966. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2967. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2968. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2969. }
  2970. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2971. {
  2972. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2973. , (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*/))
  2974. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2975. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2976. }
  2977. }
  2978. }
  2979. sprintf(message + strlen(message), "]}}]");
  2980. }
  2981. LWS_Send(message);
  2982. result = TRUE;
  2983. return result;
  2984. }
  2985. int sendGetConfigurationConfirmation(char *uuid)
  2986. {
  2987. mtrace();
  2988. int result = FAIL;
  2989. int MaxKeySupported = 0;
  2990. int sentConfigurationNumber= 0;
  2991. int sentunConfigurationNumber= 0;
  2992. char message[4000]={0};
  2993. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2994. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2995. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2996. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  2997. ,MESSAGE_TYPE_CALLRESULT
  2998. ,uuid );
  2999. //configuration key
  3000. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3001. {
  3002. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3003. {
  3004. if (sentConfigurationNumber == 0)
  3005. {
  3006. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3007. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3008. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3009. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3010. }
  3011. else
  3012. {
  3013. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3014. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3015. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3016. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3017. }
  3018. sentConfigurationNumber = sentConfigurationNumber + 1;
  3019. }
  3020. }
  3021. sprintf(message + strlen(message), "]");
  3022. if(UnknownKeynum != 0)
  3023. {
  3024. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3025. //unkown key
  3026. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3027. {
  3028. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3029. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3030. if(sentunConfigurationNumber == 0)
  3031. {
  3032. sprintf(message + strlen(message), "\"%s\""
  3033. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3034. }
  3035. else
  3036. {
  3037. sprintf(message + strlen(message), ",\"%s\""
  3038. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3039. }
  3040. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3041. }
  3042. sprintf(message + strlen(message), "]");
  3043. }
  3044. sprintf(message + strlen(message), "} ]");
  3045. LWS_Send(message);
  3046. return result;
  3047. }
  3048. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3049. {
  3050. mtrace();
  3051. int result = FAIL;
  3052. char message[400]={0};
  3053. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3054. if(strcmp(payload,"")==0)
  3055. {
  3056. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3057. }
  3058. else
  3059. {
  3060. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3061. }
  3062. LWS_Send(message);
  3063. result = TRUE;
  3064. return result;
  3065. }
  3066. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3067. {
  3068. mtrace();
  3069. int result = FAIL;
  3070. char message[80]={0};
  3071. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3072. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3073. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3074. LWS_Send(message);
  3075. result = TRUE;
  3076. return result;
  3077. }
  3078. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3079. {
  3080. mtrace();
  3081. int result = FAIL;
  3082. char message[80]={0};
  3083. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3084. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3085. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3086. LWS_Send(message);
  3087. result = TRUE;
  3088. return result;
  3089. }
  3090. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3091. {
  3092. mtrace();
  3093. int result = FAIL;
  3094. char message[80]={0};
  3095. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3096. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3097. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3098. LWS_Send(message);
  3099. result = TRUE;
  3100. return result;
  3101. }
  3102. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3103. {
  3104. mtrace();
  3105. int result = FAIL;
  3106. char message[80]={0};
  3107. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3108. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3109. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3110. LWS_Send(message);
  3111. result = TRUE;
  3112. return result;
  3113. }
  3114. int sendResetConfirmation(char *uuid,char *payload)
  3115. {
  3116. mtrace();
  3117. int result = FAIL;
  3118. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3119. char message[80]={0};
  3120. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3121. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3122. LWS_Send(message);
  3123. result = TRUE;
  3124. return result;
  3125. }
  3126. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3127. {
  3128. mtrace();
  3129. int result = FAIL;
  3130. char message[500]={0};
  3131. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3132. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3133. LWS_Send(message);
  3134. result = TRUE;
  3135. return result;
  3136. }
  3137. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3138. {
  3139. mtrace();
  3140. int result = FAIL;
  3141. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3142. char message[80]={0};
  3143. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3144. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3145. LWS_Send(message);
  3146. result = TRUE;
  3147. return result;
  3148. }
  3149. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3150. {
  3151. mtrace();
  3152. int result = FAIL;
  3153. char message[80]={0};
  3154. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3155. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3156. LWS_Send(message);
  3157. result = TRUE;
  3158. return result;
  3159. }
  3160. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3161. {
  3162. mtrace();
  3163. int result = FAIL;
  3164. char message[80]={0};
  3165. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3166. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3167. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3168. LWS_Send(message);
  3169. result = TRUE;
  3170. return result;
  3171. }
  3172. int sendUpdateFirmwareConfirmation(char *uuid)
  3173. {
  3174. mtrace();
  3175. int result = FAIL;
  3176. char message[60]={0};
  3177. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3178. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3179. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3180. LWS_Send(message);
  3181. result = TRUE;
  3182. return result;
  3183. }
  3184. //==========================================
  3185. // send CallError routine
  3186. //==========================================
  3187. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3188. {
  3189. mtrace();
  3190. //int result = FAIL;
  3191. char message[220]={0};
  3192. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3193. #ifdef SystemLogMessage
  3194. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3195. uniqueId, action, errorCode, errorDescription);
  3196. #endif
  3197. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3198. LWS_Send(message);
  3199. //result = TRUE;
  3200. }
  3201. //==========================================
  3202. // Handle server request routine Start
  3203. //==========================================
  3204. #define GUN_NUM 1
  3205. int handleCancelReservationRequest(char *uuid, char *payload)
  3206. {
  3207. mtrace();
  3208. int result = FAIL;
  3209. int gunNO = 0;
  3210. int reservationIdInt =0;
  3211. char comfirmstr[20];
  3212. int c = 0;
  3213. char *loc;
  3214. char sstr[100]={0};
  3215. DEBUG_INFO("handle CancelReservationRequest\n");
  3216. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3217. c = 0;
  3218. loc = strstr(payload, "reservationId");
  3219. memset(sstr ,0, sizeof(sstr) );
  3220. while (loc[strlen("reservationId")+2+c] != '}')
  3221. {
  3222. sstr[c] = loc[strlen("reservationId")+2+c];
  3223. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3224. c++;
  3225. }
  3226. sstr[c] = '\0';
  3227. reservationIdInt = atoi(sstr);
  3228. memset(comfirmstr, 0, sizeof comfirmstr);
  3229. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3230. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3231. //check Transaction active
  3232. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3233. {
  3234. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3235. {
  3236. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3237. {
  3238. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3239. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3240. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3241. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3242. goto end;
  3243. }
  3244. }
  3245. for (int index = 0; index < CCS_QUANTITY; index++)
  3246. {
  3247. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3248. {
  3249. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3250. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3251. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3252. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3253. goto end;
  3254. }
  3255. }
  3256. for (int index = 0; index < GB_QUANTITY; index++)
  3257. {
  3258. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3259. {
  3260. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3261. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3262. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3263. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3264. goto end;
  3265. }
  3266. }
  3267. }
  3268. else
  3269. {
  3270. for (int index = 0; index < AC_QUANTITY; index++)
  3271. {
  3272. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3273. {
  3274. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3275. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3276. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3277. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3278. goto end;
  3279. }
  3280. }
  3281. }// END FOR AC ELSE
  3282. //The reservationId does NOT match the reservationId
  3283. sendCancelReservationConfirmation(uuid, comfirmstr);
  3284. end:
  3285. // Fill in ocpp packet uuid
  3286. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3287. return result;
  3288. }
  3289. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3290. {
  3291. mtrace();
  3292. int result = FAIL;
  3293. int gunIndex = 0;
  3294. char sstr[90]={0};
  3295. char typeStr[16]={0};
  3296. char comfirmstr[20];
  3297. int specificId = FALSE;
  3298. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3299. char *loc;
  3300. //int intervalInt = 0;
  3301. int c = 0;
  3302. /*** connectorId ****/
  3303. c = 0;
  3304. loc = strstr(payload, "connectorId");
  3305. memset(sstr ,0, sizeof(sstr) );
  3306. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3307. {
  3308. sstr[c] = loc[strlen("connectorId")+2+c];
  3309. c++;
  3310. }
  3311. sstr[c] = '\0';
  3312. gunIndex = atoi(sstr);
  3313. /***type ****/
  3314. loc = strstr(payload, "type");
  3315. memset(sstr ,0, sizeof(sstr) );
  3316. c = 0;
  3317. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3318. {
  3319. sstr[c] = loc[3+strlen("type")+c];
  3320. c++;
  3321. }
  3322. sstr[c] = '\0';
  3323. strcpy(typeStr, sstr);
  3324. if(gunIndex != 0)
  3325. {
  3326. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3327. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3328. }
  3329. else
  3330. {
  3331. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3332. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3333. }
  3334. memset(comfirmstr, 0, sizeof comfirmstr);
  3335. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3336. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3337. {
  3338. specificId = TRUE;
  3339. }
  3340. if(specificId == FALSE)
  3341. goto end;
  3342. if(gunIndex != 0)
  3343. {
  3344. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3345. }
  3346. else
  3347. {
  3348. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3349. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3350. }
  3351. /*
  3352. enum SYSTEM_STATUS
  3353. {
  3354. SYS_MODE_BOOTING = 0,
  3355. SYS_MODE_IDLE = 1,
  3356. SYS_MODE_AUTHORIZING = 2,
  3357. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3358. SYS_MODE_REASSIGN = 4,
  3359. SYS_MODE_PREPARING = 5,
  3360. SYS_MODE_PREPARE_FOR_EV = 6,
  3361. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3362. SYS_MODE_CHARGING = 8,
  3363. SYS_MODE_TERMINATING = 9,
  3364. SYS_MODE_COMPLETE = 10,
  3365. SYS_MODE_ALARM = 11,
  3366. SYS_MODE_FAULT = 12,
  3367. SYS_MODE_RESERVATION = 13,
  3368. SYS_MODE_BOOKING = 14,
  3369. SYS_MODE_MAINTAIN = 15,
  3370. SYS_MODE_DEBUG = 16,
  3371. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3372. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3373. SYS_MODE_UPDATE = 19
  3374. };
  3375. */
  3376. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3377. {
  3378. //check Transaction active
  3379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3380. {
  3381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3382. {
  3383. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3384. {
  3385. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3386. {
  3387. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3388. }
  3389. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3390. {
  3391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3392. }
  3393. else
  3394. {
  3395. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3396. }
  3397. goto end;
  3398. }
  3399. }//END FOR CHAdeMO_QUANTITY
  3400. for (int index = 0; index < CCS_QUANTITY; index++)
  3401. {
  3402. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3403. {
  3404. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3405. {
  3406. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3407. }
  3408. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3409. {
  3410. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3411. }
  3412. else
  3413. {
  3414. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3415. }
  3416. goto end;
  3417. }
  3418. }//END FOR CCS_QUANTITY
  3419. for (int index = 0; index < GB_QUANTITY; index++)
  3420. {
  3421. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3422. {
  3423. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3424. {
  3425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3426. }
  3427. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3428. {
  3429. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3430. }
  3431. else
  3432. {
  3433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3434. }
  3435. goto end;
  3436. }
  3437. }// END FOR GB_QUANTITY
  3438. }
  3439. else
  3440. {
  3441. for (int index = 0; index < AC_QUANTITY; index++)
  3442. {
  3443. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3444. {
  3445. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3446. {
  3447. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3448. }
  3449. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3450. {
  3451. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3452. }
  3453. else
  3454. {
  3455. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3456. }
  3457. goto end;
  3458. }
  3459. }//END FOR AC_QUANTITY
  3460. }// END FOR AC ELSE
  3461. }//END FOR AvailabilityTypeStr[Inoperative]
  3462. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3463. {
  3464. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3465. //check Transaction active
  3466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3467. {
  3468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3469. {
  3470. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3471. {
  3472. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3473. goto end;
  3474. }
  3475. }//END FOR CHAdeMO_QUANTITY
  3476. for (int index = 0; index < CCS_QUANTITY; index++)
  3477. {
  3478. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3479. {
  3480. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3481. goto end;
  3482. }
  3483. }//END FOR CCS_QUANTITY
  3484. for (int index = 0; index < GB_QUANTITY; index++)
  3485. {
  3486. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3487. {
  3488. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3489. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3490. goto end;
  3491. }
  3492. }// END FOR GB_QUANTITY
  3493. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3494. }
  3495. else
  3496. {
  3497. for (int index = 0; index < AC_QUANTITY; index++)
  3498. {
  3499. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3500. {
  3501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3502. goto end;
  3503. }
  3504. }//END FOR CHAdeMO_QUANTITY
  3505. }//END FOR AC ELSE
  3506. }//END FOR AvailabilityTypeStr[Operative]
  3507. end:
  3508. if(gunIndex != 0)
  3509. {
  3510. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3511. }
  3512. else
  3513. {
  3514. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3515. }
  3516. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3517. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3518. return result;
  3519. }
  3520. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3521. {
  3522. mtrace();
  3523. int result = FAIL;
  3524. char sstr[100]={0};
  3525. char keystr[40]={0};
  3526. char valuestr[100]={0};
  3527. char *loc;
  3528. int c = 0;
  3529. char comfirmstr[20]={0};
  3530. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3531. /***key ****/
  3532. loc = strstr(payload, "key");
  3533. memset(sstr ,0, sizeof(sstr) );
  3534. c = 0;
  3535. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3536. {
  3537. sstr[c] = loc[3+strlen("key")+c];
  3538. c++;
  3539. }
  3540. sstr[c] = '\0';
  3541. strcpy(keystr, sstr);
  3542. //DEBUG_INFO( "keystr=%s\n",keystr);
  3543. /***value ****/
  3544. loc = strstr(payload, "value");
  3545. memset(sstr ,0, sizeof(sstr) );
  3546. c = 0;
  3547. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3548. {
  3549. sstr[c] = loc[3+strlen("value")+c];
  3550. c++;
  3551. }
  3552. sstr[c] = '\0';
  3553. strcpy(valuestr, sstr);
  3554. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3555. if((uuid==NULL) || (payload ==NULL) )
  3556. {
  3557. #ifdef Debug
  3558. DEBUG_INFO("payload is null\n");
  3559. #endif
  3560. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3561. }
  3562. else
  3563. {
  3564. int status = setKeyValue(keystr, valuestr);
  3565. switch(status)
  3566. {
  3567. case ConfigurationStatus_Accepted:
  3568. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3569. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3570. StoreConfigurationTable();
  3571. break;
  3572. case ConfigurationStatus_Rejected:
  3573. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3574. break;
  3575. case RebootRequired:
  3576. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3577. StoreConfigurationTable();
  3578. break;
  3579. case NotSupported:
  3580. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3581. break;
  3582. default:
  3583. break;
  3584. }
  3585. }
  3586. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3587. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3588. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3589. return result;
  3590. }
  3591. int handleClearCacheRequest(char *uuid, char *payload)
  3592. {
  3593. mtrace();
  3594. int result = FAIL;
  3595. char comfirmstr[20];
  3596. int fd;
  3597. char rmFileCmd[100]={0};
  3598. struct stat stats;
  3599. DEBUG_INFO("handle ClearCacheRequest\n");
  3600. stat("../Storage/OCPP", &stats);
  3601. // Check for directory existence
  3602. if (S_ISDIR(stats.st_mode) == 1)
  3603. {
  3604. //DEBUG_ERROR("\n OCPP directory exist \n");
  3605. }
  3606. else
  3607. {
  3608. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3609. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3610. system(rmFileCmd);
  3611. }
  3612. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3613. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3614. {
  3615. DEBUG_INFO("AuthorizationCache file exist.\n");
  3616. }
  3617. else
  3618. {
  3619. DEBUG_INFO("AuthorizationCache file not exist\n");
  3620. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3621. if(log == NULL)
  3622. {
  3623. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3624. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3625. goto end;
  3626. }
  3627. else
  3628. {
  3629. fclose(log);
  3630. }
  3631. }
  3632. fd = open(AuthorizationCache_JSON,O_RDWR);
  3633. if(fd < 0)
  3634. {
  3635. DEBUG_INFO("open AuthorizationCache file failed\n");
  3636. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3637. }
  3638. else
  3639. {
  3640. DEBUG_INFO("open AuthorizationCache file successful\n");
  3641. //* 清空? 件 */
  3642. ftruncate(fd,0);
  3643. //* ? 新设置? 件? 移??*/
  3644. lseek(fd,0,SEEK_SET);
  3645. close(fd);
  3646. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3647. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3648. }
  3649. end:
  3650. sendClearCacheConfirmation(uuid, comfirmstr);
  3651. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3652. return result;
  3653. }
  3654. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3655. {
  3656. mtrace();
  3657. int result = FAIL;
  3658. int resultRename;
  3659. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3660. char chargingProfilePurposeStr[26]={0};
  3661. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3662. char tempchargingProfilePurposeStr[26]={0};
  3663. char sstr[160]={0};//sstr[200]={ 0 };
  3664. char str[100]={0};
  3665. int c = 0;
  3666. //int i = 0;
  3667. //char * pch;
  3668. char *loc;
  3669. char fname[200];
  3670. char comfirmstr[20]={0};
  3671. char word[1000]={0};
  3672. int clearflag = FALSE;
  3673. int chargingProfileIdIsNULL = FALSE;
  3674. int connectorIsNULL = FALSE;
  3675. int chargingProfilePurposeIsNULL = FALSE;
  3676. int stackLevelIsNULL = FALSE;
  3677. FILE *fptr1, *fptr2;
  3678. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3679. int n_chargingProfile=0;
  3680. char sLineWord[1060]={0};
  3681. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3682. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3683. //***id ****/
  3684. c = 0;
  3685. loc = strstr(payload, "id");
  3686. memset(sstr ,0, sizeof(sstr) );
  3687. if(loc == NULL)
  3688. {
  3689. chargingProfileIdIsNULL = TRUE;
  3690. }
  3691. else
  3692. {
  3693. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3694. {
  3695. sstr[c] = loc[strlen("id")+2+c];
  3696. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3697. c++;
  3698. }
  3699. sstr[c] = '\0';
  3700. chargingProfileIdInt = atoi(sstr);
  3701. }
  3702. //***connectorId ****/
  3703. c=0;
  3704. loc = strstr(payload, "connectorId");
  3705. memset(sstr ,0, sizeof(sstr) );
  3706. if(loc == NULL)
  3707. {
  3708. connectorIsNULL = TRUE;
  3709. }
  3710. else
  3711. {
  3712. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3713. {
  3714. sstr[c] = loc[strlen("connectorId")+2+c];
  3715. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3716. c++;
  3717. }
  3718. sstr[c] = '\0';
  3719. connectorIdInt = atoi(sstr);
  3720. }
  3721. //***chargingProfilePurpose ****/
  3722. loc = strstr(payload, "chargingProfilePurpose");
  3723. memset(sstr ,0, sizeof(sstr) );
  3724. c = 0;
  3725. if(loc == NULL)
  3726. {
  3727. chargingProfilePurposeIsNULL = TRUE;
  3728. }
  3729. else
  3730. {
  3731. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3732. {
  3733. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3734. c++;
  3735. }
  3736. sstr[c] = '\0';
  3737. strcpy(chargingProfilePurposeStr, sstr);
  3738. }
  3739. //***stackLevel ****/
  3740. c=0;
  3741. loc = strstr(payload, "stackLevel");
  3742. memset(sstr ,0, sizeof(sstr) );
  3743. if(loc == NULL)
  3744. {
  3745. stackLevelIsNULL = TRUE;
  3746. }
  3747. else
  3748. {
  3749. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3750. {
  3751. sstr[c] = loc[strlen("stackLevel")+2+c];
  3752. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3753. c++;
  3754. }
  3755. sstr[c] = '\0';
  3756. stackLevelInt = atoi(sstr);
  3757. }
  3758. if(connectorIsNULL == FALSE)
  3759. {
  3760. switch(connectorIdInt)
  3761. {
  3762. case 0:
  3763. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3764. {
  3765. strcpy(fname, ChargePointMaxProfile_JSON);
  3766. }
  3767. // else
  3768. // {
  3769. // strcpy(fname, TxDefaultProfile_0_JSON);
  3770. // }
  3771. break;
  3772. case 1:
  3773. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3774. {
  3775. strcpy(fname, TxDefaultProfile_1_JSON);
  3776. }
  3777. // else
  3778. // {
  3779. // strcpy(fname, TxProfile_1_JSON);
  3780. // }
  3781. break;
  3782. case 2:
  3783. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3784. {
  3785. strcpy(fname, TxDefaultProfile_2_JSON);
  3786. }
  3787. // else
  3788. // {
  3789. // strcpy(fname, TxProfile_2_JSON);
  3790. // }
  3791. break;
  3792. default:
  3793. strcpy(fname, ChargePointMaxProfile_JSON );
  3794. break;
  3795. }
  3796. }
  3797. else
  3798. {
  3799. strcpy(fname, ChargePointMaxProfile_JSON );
  3800. }
  3801. fptr1 = fopen(fname, "r");
  3802. if (!fptr1)
  3803. {
  3804. //file not exist
  3805. DEBUG_INFO("Unable to open the input file!!\n");
  3806. fptr1 = fopen(fname, "w+");
  3807. }
  3808. fclose(fptr1);
  3809. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3810. {
  3811. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3812. goto end;
  3813. }
  3814. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3815. {
  3816. //clear the whole contents of a file in C
  3817. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3818. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3819. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3820. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3821. fclose(fopen(TxProfile_1_JSON, "w"));
  3822. fclose(fopen(TxProfile_2_JSON, "w"));
  3823. #if 0
  3824. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3825. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3826. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3827. #endif
  3828. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3829. }
  3830. else
  3831. {
  3832. fptr1 = fopen(fname, "r");
  3833. fptr2 = fopen(temp, "w+");
  3834. while(fscanf(fptr1, "%s", word) != EOF)
  3835. {
  3836. //DEBUG_INFO("word=%s\n",word);
  3837. if(strcmp(word, "chargingProfileId") == 0)
  3838. {
  3839. n_chargingProfile = n_chargingProfile + 1;
  3840. DEBUG_INFO("chargingProfileId Found\n");
  3841. }
  3842. }
  3843. rewind(fptr1);
  3844. //search Charging Profile Element
  3845. //int i= 0;
  3846. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3847. {
  3848. //*************************tempconnectorIdInt*********************************/
  3849. loc = strstr(sLineWord, "connectorId");
  3850. c = 0;
  3851. memset(sstr ,0, sizeof(sstr) );
  3852. while (loc[strlen("connectorId")+2+c] != ',')
  3853. {
  3854. sstr[c] = loc[strlen("connectorId")+2+c];
  3855. c++;
  3856. }
  3857. sstr[c] = '\0';
  3858. tempconnectorIdInt = atoi(sstr);
  3859. //chargingProfileId
  3860. c = 0;
  3861. loc = strstr(sLineWord, "chargingProfileId");
  3862. memset(sstr ,0, sizeof(sstr) );
  3863. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3864. {
  3865. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3866. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3867. c++;
  3868. }
  3869. sstr[c] = '\0';
  3870. tempchargingProfileIdInt = atoi(sstr);
  3871. //stackLevel
  3872. c = 0;
  3873. loc = strstr(sLineWord, "stackLevel");
  3874. memset(sstr ,0, sizeof(sstr) );
  3875. while (loc[strlen("stackLevel")+2+c] != ',')
  3876. {
  3877. sstr[c] = loc[strlen("stackLevel")+2+c];
  3878. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3879. c++;
  3880. }
  3881. sstr[c] = '\0';
  3882. tempstackLevelInt = atoi(sstr);
  3883. c = 0;
  3884. loc = strstr(sLineWord, "chargingProfilePurpose");
  3885. memset(sstr ,0, sizeof(sstr) );
  3886. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3887. {
  3888. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3889. c++;
  3890. }
  3891. sstr[c] = '\0';
  3892. strcpy(tempchargingProfilePurposeStr, sstr);
  3893. if(chargingProfileIdIsNULL == FALSE)
  3894. {
  3895. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3896. {
  3897. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3898. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3899. clearflag = TRUE;
  3900. continue;
  3901. }
  3902. else
  3903. {
  3904. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3905. //json_object_array_add(newHeatMap, jsonitem);
  3906. fprintf(fptr2, sLineWord);//writing data into file
  3907. }
  3908. }
  3909. else
  3910. {
  3911. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3912. {
  3913. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3914. {
  3915. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3916. clearflag = TRUE;
  3917. continue;
  3918. }
  3919. }
  3920. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3921. {
  3922. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3923. {
  3924. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3925. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3926. {
  3927. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3928. clearflag = TRUE;
  3929. continue;
  3930. }
  3931. }
  3932. }
  3933. else
  3934. {
  3935. //json_object_array_add(newHeatMap, jsonitem);
  3936. fprintf(fptr2, sLineWord);//writing data into file
  3937. }
  3938. }
  3939. memset(sLineWord, 0, sizeof sLineWord);
  3940. }
  3941. if(clearflag == FALSE)
  3942. {
  3943. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3944. goto end;
  3945. }
  3946. fclose(fptr1);
  3947. fclose(fptr2);
  3948. sprintf(str,"rm -f %s",fname);
  3949. system(str);
  3950. resultRename = rename(temp, fname);
  3951. if(resultRename == 0)
  3952. {
  3953. DEBUG_INFO("File ChargingProfile renamed successfully");
  3954. }
  3955. else
  3956. {
  3957. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  3958. }
  3959. }
  3960. end:
  3961. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3962. return result;
  3963. }
  3964. int handleDataTransferRequest(char *uuid, char *payload)
  3965. {
  3966. mtrace();
  3967. int result = FAIL;
  3968. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  3969. char tempvendorId[255]={0};
  3970. char tempmessageId[50]={0};
  3971. char tempdata[50]={0};
  3972. char sstr[160]={0};//sstr[200]={ 0 };
  3973. char message[80]={0};
  3974. int c = 0;
  3975. char *loc;
  3976. DEBUG_INFO("handle DataTransferRequest\n");
  3977. if((uuid != NULL) && (payload != NULL))
  3978. {
  3979. //===============================
  3980. // vendorId
  3981. //===============================
  3982. c = 0;
  3983. loc = strstr(payload, "vendorId");
  3984. while (loc[strlen("vendorId")+3+c] != '\"')
  3985. {
  3986. sstr[c] = loc[strlen("vendorId")+3+c];
  3987. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3988. c++;
  3989. }
  3990. sstr[c] = '\0';
  3991. strcpy(tempvendorId,sstr);
  3992. //===============================
  3993. // messageId
  3994. //===============================
  3995. memset(sstr ,0, sizeof(sstr) );
  3996. c = 0;
  3997. loc = strstr(payload, "messageId");
  3998. while (loc[strlen("messageId")+3+c] != '\"')
  3999. {
  4000. sstr[c] = loc[strlen("messageId")+3+c];
  4001. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4002. c++;
  4003. }
  4004. sstr[c] = '\0';
  4005. strcpy(tempmessageId,sstr);
  4006. //===============================
  4007. // data
  4008. //===============================
  4009. memset(sstr ,0, sizeof(sstr) );
  4010. c = 0;
  4011. loc = strstr(payload, "data");
  4012. printf("loc=%s\n",loc);
  4013. while (loc[strlen("data")+3+c] != '\"')
  4014. {
  4015. sstr[c] = loc[strlen("data")+3+c];
  4016. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4017. c++;
  4018. }
  4019. sstr[c] = '\0';
  4020. strcpy(tempdata,sstr);
  4021. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4022. }
  4023. else
  4024. {
  4025. char guid[37]={0};
  4026. random_uuid(guid);
  4027. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4028. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4029. }
  4030. LWS_Send(message);
  4031. return result;
  4032. }
  4033. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4034. {
  4035. mtrace();
  4036. int result = FAIL;
  4037. int connectorIdInt, durationInt;
  4038. char chargingRateUnitStr[4]={0};
  4039. //int tempconnectorIdInt,
  4040. int tempdurationInt;
  4041. float tempminChargingRateFloat = 0.0;
  4042. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4043. int tempStartPeriodInt=0;
  4044. float tempLimitInt=0.0;//0.1;
  4045. int tempNumberPhasesInt=0;
  4046. char fname[200];
  4047. char comfirmstr[20];
  4048. //float totallimit =0.0;
  4049. float MinChargingRate =0.0;
  4050. //double diff_t;
  4051. //struct tm tp;
  4052. FILE *fptr1;
  4053. int c = 0;
  4054. //int i = 0;
  4055. char * pch;
  4056. char *loc;
  4057. char sstr[200]={ 0 };
  4058. int n_chargingProfile = 0;
  4059. int n_SchedulePeriods = 0;
  4060. char SchedulePeriodList[10][200]={0};
  4061. char sLineWord[800]={0};
  4062. //int n_periods = 0;
  4063. char word[1000]={0};
  4064. int confirmPeriods = 0;
  4065. struct StructProfile ChargePointMaxProfile;
  4066. struct StructProfile TxDefaultProfile;
  4067. struct StructProfile TxProfile;
  4068. struct StructProfile TxDefaultProfiletemp[2]={0};
  4069. int TxDefaultProfileFileIsNull=FALSE;
  4070. int ChargePointMaxProfileIsNull=FALSE;
  4071. int TxProfileIsNull=FALSE;
  4072. int CompositeSceduleIndex = 0;
  4073. char ChargePointMaxProfileScheduleStr[30]={0};
  4074. char TxDefaultProfileScheduleStr[30]={0};
  4075. char TxProfileScheduleStr[30]={0};
  4076. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4077. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4078. memset(&TxProfile,0,sizeof(struct StructProfile));
  4079. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4080. c=0;
  4081. loc = strstr(payload, "connectorId");
  4082. memset(sstr ,0, sizeof(sstr) );
  4083. while ((loc[strlen("connectorId")+2+c] != '}') && (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. connectorIdInt = atoi(sstr);
  4091. c=0;
  4092. loc = strstr(payload, "duration");
  4093. memset(sstr ,0, sizeof(sstr) );
  4094. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4095. {
  4096. sstr[c] = loc[strlen("duration")+2+c];
  4097. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4098. c++;
  4099. }
  4100. sstr[c] = '\0';
  4101. durationInt = atoi(sstr);
  4102. c = 0;
  4103. loc = strstr(payload, "chargingRateUnit");
  4104. memset(sstr ,0, sizeof(sstr) );
  4105. if(loc == NULL)
  4106. {
  4107. }
  4108. else
  4109. {
  4110. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4111. {
  4112. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4113. c++;
  4114. }
  4115. sstr[c] = '\0';
  4116. strcpy(chargingRateUnitStr, sstr);
  4117. }
  4118. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4119. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4120. if(connectorIdInt==0) // connectorId is 0
  4121. {
  4122. //******************************ChargePointMaxProfile*****************************************************/
  4123. strcpy(fname, ChargePointMaxProfile_JSON );
  4124. char word[30]={0};
  4125. char sLineWord[1060]={0};
  4126. int n_chargingProfile=0;
  4127. ChargePointMaxProfileIsNull=TRUE;
  4128. if((access(fname,F_OK))!=-1)
  4129. {
  4130. fptr1 = fopen(fname, "r");
  4131. int c;
  4132. c = fgetc(fptr1);
  4133. //DEBUG_INFO("c:%d\n",c);
  4134. rewind(fptr1);
  4135. if(c == EOF)
  4136. {
  4137. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4138. ChargePointMaxProfileIsNull=TRUE;
  4139. fclose(fptr1);
  4140. }
  4141. else
  4142. {
  4143. ChargePointMaxProfileIsNull=FALSE;
  4144. while(fscanf(fptr1, "%s", word) != EOF)
  4145. {
  4146. if(strcmp(word, "chargingProfileId") == 0)
  4147. {
  4148. n_chargingProfile = n_chargingProfile + 1;
  4149. printf("Found\n");
  4150. }
  4151. }
  4152. rewind(fptr1);
  4153. //search Charging Profile Element
  4154. int i= 0;
  4155. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4156. #if 0
  4157. /***********connectorId****************/
  4158. c = 0;
  4159. loc = strstr(sLineWord, "connectorId");
  4160. // printf("loc=%s\n",loc);
  4161. memset(sstr ,0, sizeof(sstr) );
  4162. while (loc[strlen("connectorId")+2+c] != ',')
  4163. {
  4164. sstr[c] = loc[strlen("connectorId")+2+c];
  4165. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4166. c++;
  4167. }
  4168. sstr[c] = '\0';
  4169. tempconnectorIdInt = atoi(sstr);
  4170. #endif
  4171. //***********validFrom**************/
  4172. c = 0;
  4173. loc = strstr(sLineWord, "validFrom");
  4174. //DEBUG_INFO("loc=%s\n",loc);
  4175. memset(sstr ,0, sizeof(sstr) );
  4176. if(loc != NULL)
  4177. {
  4178. while (loc[3+strlen("validFrom")+c] != '\"')
  4179. {
  4180. sstr[c] = loc[3+strlen("validFrom")+c];
  4181. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4182. c++;
  4183. }
  4184. sstr[c] = '\0';
  4185. DEBUG_INFO("validFrom=%s\n",sstr);
  4186. strcpy(tempvalidFromStr,sstr);
  4187. }
  4188. else
  4189. {
  4190. strcpy(tempvalidFromStr,"");
  4191. }
  4192. //**********startSchedule**********/
  4193. c = 0;
  4194. loc = strstr(sLineWord, "startSchedule");
  4195. //DEBUG_INFO("loc=%s\n",loc);
  4196. memset(sstr ,0, sizeof(sstr) );
  4197. while (loc[3+strlen("startSchedule")+c] != '\"')
  4198. {
  4199. sstr[c] = loc[3+strlen("startSchedule")+c];
  4200. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4201. c++;
  4202. }
  4203. sstr[c] = '\0';
  4204. strcpy(tempstartScheduleStr, sstr);
  4205. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4206. //**********chargingRateUnit**********/
  4207. c = 0;
  4208. loc = strstr(sLineWord, "chargingRateUnit");
  4209. memset(sstr ,0, sizeof(sstr) );
  4210. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4211. {
  4212. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4213. c++;
  4214. }
  4215. sstr[c] = '\0';
  4216. strcpy(tempchargingRateUnitStr, sstr);
  4217. //**********minChargingRate*******/
  4218. c = 0;
  4219. loc = strstr(sLineWord, "minChargingRate");
  4220. //printf("loc=%s\n",loc);
  4221. if(loc != NULL)
  4222. {
  4223. memset(sstr ,0, sizeof(sstr) );
  4224. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4225. {
  4226. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4227. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4228. c++;
  4229. }
  4230. sstr[c] = '\0';
  4231. tempminChargingRateFloat = atof(sstr);
  4232. }
  4233. else
  4234. {
  4235. tempminChargingRateFloat = 0.0;
  4236. }
  4237. //
  4238. #if 0
  4239. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4240. tp.tm_isdst = -1;
  4241. time_t utc = mktime(&tp);
  4242. // current time
  4243. time_t t = time(NULL);
  4244. #endif
  4245. //diff_t = difftime(t, utc);
  4246. //parsing strings to words
  4247. i = 0;
  4248. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4249. loc = loc+3+strlen("chargingSchedulePeriod");
  4250. pch = strtok(loc ,"{");
  4251. while (pch != NULL)
  4252. {
  4253. strcpy(SchedulePeriodList[i], pch);
  4254. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4255. //printf ("%s\n",pch);
  4256. pch = strtok (NULL, "{");
  4257. i = i + 1;
  4258. }
  4259. n_SchedulePeriods = i;
  4260. for(int i=0;i<n_SchedulePeriods;i++)
  4261. {
  4262. //*************startPeriod****************/
  4263. c = 0;
  4264. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4265. memset(sstr ,0, sizeof(sstr) );
  4266. while (loc[strlen("startPeriod")+2+c] != ',')
  4267. {
  4268. sstr[c] = loc[strlen("startPeriod")+2+c];
  4269. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4270. c++;
  4271. }
  4272. sstr[c] = '\0';
  4273. tempStartPeriodInt = atoi(sstr);
  4274. //*************limit****************/
  4275. c = 0;
  4276. loc = strstr(SchedulePeriodList[i], "limit");
  4277. memset(sstr ,0, sizeof(sstr) );
  4278. while (loc[strlen("limit")+2+c] != ',')
  4279. {
  4280. sstr[c] = loc[strlen("limit")+2+c];
  4281. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4282. c++;
  4283. }
  4284. sstr[c] = '\0';
  4285. tempLimitInt = atof(sstr);
  4286. //*************numberPhases****************/
  4287. c = 0;
  4288. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4289. memset(sstr ,0, sizeof(sstr) );
  4290. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4291. {
  4292. sstr[c] = loc[strlen("numberPhases")+2+c];
  4293. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4294. c++;
  4295. }
  4296. sstr[c] = '\0';
  4297. tempNumberPhasesInt = atoi(sstr);
  4298. ChargePointMaxProfile.Duration = durationInt;
  4299. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4300. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4301. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4302. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4303. }
  4304. if(MinChargingRate < tempminChargingRateFloat)
  4305. MinChargingRate = tempminChargingRateFloat;
  4306. }
  4307. }// End of file ChargingProfile
  4308. } //THE END OF ACCESS ChargePointMaxProfile
  4309. //******************************TxDefaultProfile***********************************************/
  4310. strcpy(fname, TxDefaultProfile_0_JSON);
  4311. memset(word, 0, 30);
  4312. memset(sLineWord, 0, 1060);
  4313. //char word[30]={0};
  4314. //char sLineWord[1060]={0};
  4315. n_chargingProfile=0;
  4316. TxDefaultProfileFileIsNull=TRUE;
  4317. if((access(fname,F_OK))!=-1)
  4318. {
  4319. fptr1 = fopen(fname, "r");
  4320. c = 0;
  4321. c = fgetc(fptr1);
  4322. //DEBUG_INFO("c:%d\n",c);
  4323. rewind(fptr1);
  4324. if(c == EOF)
  4325. {
  4326. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4327. TxDefaultProfileFileIsNull=TRUE;
  4328. fclose(fptr1);
  4329. }
  4330. else
  4331. {
  4332. TxDefaultProfileFileIsNull=FALSE;
  4333. while(fscanf(fptr1, "%s", word) != EOF)
  4334. {
  4335. if(strcmp(word, "chargingProfileId") == 0)
  4336. {
  4337. n_chargingProfile = n_chargingProfile + 1;
  4338. printf("Found\n");
  4339. }
  4340. }
  4341. rewind(fptr1);
  4342. //search Charging Profile Element
  4343. int i= 0;
  4344. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4345. #if 0
  4346. /***********connectorId****************/
  4347. c = 0;
  4348. loc = strstr(sLineWord, "connectorId");
  4349. // printf("loc=%s\n",loc);
  4350. memset(sstr ,0, sizeof(sstr) );
  4351. while (loc[strlen("connectorId")+2+c] != ',')
  4352. {
  4353. sstr[c] = loc[strlen("connectorId")+2+c];
  4354. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4355. c++;
  4356. }
  4357. sstr[c] = '\0';
  4358. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4359. tempconnectorIdInt = atoi(sstr);
  4360. #endif
  4361. //***********validFrom**************/
  4362. c = 0;
  4363. loc = strstr(sLineWord, "validFrom");
  4364. //DEBUG_INFO("loc=%s\n",loc);
  4365. memset(sstr ,0, sizeof(sstr) );
  4366. if(loc != NULL)
  4367. {
  4368. while (loc[3+strlen("validFrom")+c] != '\"')
  4369. {
  4370. sstr[c] = loc[3+strlen("validFrom")+c];
  4371. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4372. c++;
  4373. }
  4374. sstr[c] = '\0';
  4375. DEBUG_INFO("validFrom=%s\n",sstr);
  4376. strcpy(tempvalidFromStr,sstr);
  4377. }
  4378. else
  4379. {
  4380. strcpy(tempvalidFromStr,"");
  4381. }
  4382. //**********startSchedule**********/
  4383. c = 0;
  4384. loc = strstr(sLineWord, "startSchedule");
  4385. //DEBUG_INFO("loc=%s\n",loc);
  4386. memset(sstr ,0, sizeof(sstr) );
  4387. while (loc[3+strlen("startSchedule")+c] != '\"')
  4388. {
  4389. sstr[c] = loc[3+strlen("startSchedule")+c];
  4390. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4391. c++;
  4392. }
  4393. sstr[c] = '\0';
  4394. strcpy(tempstartScheduleStr, sstr);
  4395. strcpy(TxDefaultProfileScheduleStr, sstr);
  4396. DEBUG_INFO(" debug 3-1\n");
  4397. //**********chargingRateUnit**********/
  4398. c = 0;
  4399. loc = strstr(sLineWord, "chargingRateUnit");
  4400. memset(sstr ,0, sizeof(sstr) );
  4401. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4402. {
  4403. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4404. c++;
  4405. }
  4406. sstr[c] = '\0';
  4407. strcpy(tempchargingRateUnitStr, sstr);
  4408. //**********minChargingRate*******/
  4409. c = 0;
  4410. loc = strstr(sLineWord, "minChargingRate");
  4411. //printf("loc=%s\n",loc);
  4412. if(loc != NULL)
  4413. {
  4414. memset(sstr ,0, sizeof(sstr) );
  4415. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4416. {
  4417. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4418. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4419. c++;
  4420. }
  4421. sstr[c] = '\0';
  4422. tempminChargingRateFloat = atof(sstr);
  4423. }
  4424. else
  4425. {
  4426. tempminChargingRateFloat = 0.0;
  4427. }
  4428. #if 0
  4429. //
  4430. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4431. tp.tm_isdst = -1;
  4432. time_t utc = mktime(&tp);
  4433. // current time
  4434. time_t t = time(NULL);
  4435. //diff_t = difftime(t, utc);
  4436. #endif
  4437. //parsing strings to words
  4438. i = 0;
  4439. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4440. loc = loc+3+strlen("chargingSchedulePeriod");
  4441. pch = strtok(loc ,"{");
  4442. while (pch != NULL)
  4443. {
  4444. strcpy(SchedulePeriodList[i], pch);
  4445. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4446. //printf ("%s\n",pch);
  4447. pch = strtok (NULL, "{");
  4448. i = i + 1;
  4449. }
  4450. n_SchedulePeriods = i;
  4451. for(int i=0;i<n_SchedulePeriods;i++)
  4452. {
  4453. //*************startPeriod****************/
  4454. c = 0;
  4455. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4456. memset(sstr ,0, sizeof(sstr) );
  4457. while (loc[strlen("startPeriod")+2+c] != ',')
  4458. {
  4459. sstr[c] = loc[strlen("startPeriod")+2+c];
  4460. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4461. c++;
  4462. }
  4463. sstr[c] = '\0';
  4464. tempStartPeriodInt = atoi(sstr);
  4465. //*************limit****************/
  4466. c = 0;
  4467. loc = strstr(SchedulePeriodList[i], "limit");
  4468. memset(sstr ,0, sizeof(sstr) );
  4469. while (loc[strlen("limit")+2+c] != ',')
  4470. {
  4471. sstr[c] = loc[strlen("limit")+2+c];
  4472. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4473. c++;
  4474. }
  4475. sstr[c] = '\0';
  4476. tempLimitInt = atof(sstr);
  4477. //*************numberPhases****************/
  4478. c = 0;
  4479. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4480. memset(sstr ,0, sizeof(sstr) );
  4481. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4482. {
  4483. sstr[c] = loc[strlen("numberPhases")+2+c];
  4484. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4485. c++;
  4486. }
  4487. sstr[c] = '\0';
  4488. tempNumberPhasesInt = atoi(sstr);
  4489. TxDefaultProfile.Duration = durationInt;
  4490. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4491. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4492. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4493. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4494. }
  4495. if(MinChargingRate < tempminChargingRateFloat)
  4496. MinChargingRate = tempminChargingRateFloat;
  4497. }
  4498. }
  4499. }// the end of ACCESS TxDefaultProfile
  4500. // Composite Schedule
  4501. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4502. {
  4503. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4504. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4505. {
  4506. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4507. {
  4508. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4509. }
  4510. else
  4511. {
  4512. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4513. }
  4514. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4515. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4516. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4517. }
  4518. }
  4519. //* Define temporary variables */
  4520. struct tm *gtime;
  4521. time_t now;
  4522. char buf[28];
  4523. /* Read the current system time */
  4524. time(&now);
  4525. /* Convert the system time to GMT (now UTC) */
  4526. gtime = gmtime(&now);
  4527. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4528. // make .conf
  4529. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4530. //MaxChargingProfilesInstalled is 10
  4531. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4532. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4533. //nPeriod = 1;
  4534. if(chargingRateUnitStr[0] != 0)
  4535. {
  4536. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4537. }
  4538. else
  4539. {
  4540. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4541. }
  4542. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4543. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4544. confirmPeriods = 1;
  4545. }
  4546. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4547. {
  4548. //*****************************ChargePointMaxProfile******************************************/
  4549. strcpy(fname, ChargePointMaxProfile_JSON);
  4550. ChargePointMaxProfileIsNull=TRUE;
  4551. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4552. {
  4553. fptr1 = fopen(fname, "r");
  4554. int c;
  4555. c = fgetc(fptr1);
  4556. //DEBUG_INFO("c:%d\n",c);
  4557. rewind(fptr1);
  4558. if(c == EOF)
  4559. {
  4560. DEBUG_INFO("\n End of file reached.");
  4561. ChargePointMaxProfileIsNull=TRUE;
  4562. fclose(fptr1);
  4563. }
  4564. else
  4565. {
  4566. ChargePointMaxProfileIsNull=FALSE;
  4567. while(fscanf(fptr1, "%s", word) != EOF)
  4568. {
  4569. if(strcmp(word, "chargingProfileId") == 0)
  4570. {
  4571. n_chargingProfile = n_chargingProfile + 1;
  4572. }
  4573. }
  4574. rewind(fptr1);
  4575. //search Charging Profile Element
  4576. int i = 0;
  4577. int j = 0;
  4578. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4579. #if 0
  4580. /***********connectorId****************/
  4581. c = 0;
  4582. loc = strstr(sLineWord, "connectorId");
  4583. memset(sstr ,0, sizeof(sstr) );
  4584. while (loc[strlen("connectorId")+2+c] != ',')
  4585. {
  4586. sstr[c] = loc[strlen("connectorId")+2+c];
  4587. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4588. c++;
  4589. }
  4590. sstr[c] = '\0';
  4591. tempconnectorIdInt = atoi(sstr);
  4592. #endif
  4593. //***********validFrom**************/
  4594. c = 0;
  4595. loc = strstr(sLineWord, "validFrom");
  4596. if(loc != NULL)
  4597. {
  4598. memset(sstr ,0, sizeof(sstr) );
  4599. while (loc[3+strlen("validFrom")+c] != '\"')
  4600. {
  4601. sstr[c] = loc[3+strlen("validFrom")+c];
  4602. c++;
  4603. }
  4604. sstr[c] = '\0';
  4605. strcpy(tempvalidFromStr,sstr);
  4606. }
  4607. else
  4608. {
  4609. strcpy(tempvalidFromStr,"");
  4610. }
  4611. //***********validFrom**************/
  4612. c = 0;
  4613. loc = strstr(sLineWord, "duration");
  4614. if(loc != NULL)
  4615. {
  4616. memset(sstr ,0, sizeof(sstr) );
  4617. while (loc[2+strlen("duration")+c] != ',')
  4618. {
  4619. sstr[c] = loc[2+strlen("duration")+c];
  4620. c++;
  4621. }
  4622. sstr[c] = '\0';
  4623. tempdurationInt = atoi(sstr);
  4624. }
  4625. else
  4626. {
  4627. tempdurationInt = 0;
  4628. }
  4629. //**********startSchedule**********/
  4630. c = 0;
  4631. loc = strstr(sLineWord, "startSchedule");
  4632. memset(sstr ,0, sizeof(sstr) );
  4633. while (loc[3+strlen("startSchedule")+c] != '\"')
  4634. {
  4635. sstr[c] = loc[3+strlen("startSchedule")+c];
  4636. c++;
  4637. }
  4638. sstr[c] = '\0';
  4639. strcpy(tempstartScheduleStr, sstr);
  4640. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4641. //**********chargingRateUnit**********/
  4642. c = 0;
  4643. loc = strstr(sLineWord, "chargingRateUnit");
  4644. memset(sstr ,0, sizeof(sstr) );
  4645. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4646. {
  4647. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4648. c++;
  4649. }
  4650. sstr[c] = '\0';
  4651. strcpy(tempchargingRateUnitStr, sstr);
  4652. //**********minChargingRate*******/
  4653. c = 0;
  4654. loc = strstr(sLineWord, "minChargingRate");
  4655. if(loc != NULL)
  4656. {
  4657. memset(sstr ,0, sizeof(sstr) );
  4658. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4659. {
  4660. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4661. c++;
  4662. }
  4663. sstr[c] = '\0';
  4664. tempminChargingRateFloat = atof(sstr);
  4665. }
  4666. else
  4667. {
  4668. tempminChargingRateFloat = 0.0;
  4669. }
  4670. #if 0
  4671. //
  4672. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4673. tp.tm_isdst = -1;
  4674. time_t utc = mktime(&tp);
  4675. time_t t = time(NULL);
  4676. //diff_t = difftime(t, utc);
  4677. #endif
  4678. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4679. //DEBUG_INFO(" debug 5 -1\n");
  4680. //parsing strings to words
  4681. i = 0;
  4682. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4683. loc = loc+3+strlen("chargingSchedulePeriod");
  4684. pch = strtok(loc ,"{");
  4685. while (pch != NULL)
  4686. {
  4687. strcpy(SchedulePeriodList[i], pch);
  4688. pch = strtok (NULL, "{");
  4689. i = i + 1;
  4690. }
  4691. n_SchedulePeriods = i;
  4692. for(int i=0;i<n_SchedulePeriods;i++)
  4693. {
  4694. //*************startPeriod****************/
  4695. c = 0;
  4696. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4697. memset(sstr ,0, sizeof(sstr) );
  4698. while (loc[strlen("startPeriod")+2+c] != ',')
  4699. {
  4700. sstr[c] = loc[strlen("startPeriod")+2+c];
  4701. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4702. c++;
  4703. }
  4704. sstr[c] = '\0';
  4705. tempStartPeriodInt = atoi(sstr);
  4706. //*************limit****************/
  4707. c = 0;
  4708. loc = strstr(SchedulePeriodList[i], "limit");
  4709. memset(sstr ,0, sizeof(sstr) );
  4710. while (loc[strlen("limit")+2+c] != ',')
  4711. {
  4712. sstr[c] = loc[strlen("limit")+2+c];
  4713. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4714. c++;
  4715. }
  4716. sstr[c] = '\0';
  4717. tempLimitInt = atof(sstr);
  4718. //*************numberPhases****************/
  4719. c = 0;
  4720. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4721. memset(sstr ,0, sizeof(sstr) );
  4722. while (loc[strlen("numberPhases")+2+c] != '}')
  4723. {
  4724. sstr[c] = loc[strlen("numberPhases")+2+c];
  4725. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4726. c++;
  4727. }
  4728. sstr[c] = '\0';
  4729. tempNumberPhasesInt = atoi(sstr);
  4730. if(j == 0)
  4731. {
  4732. ChargePointMaxProfile.Duration = tempdurationInt;
  4733. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4734. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4735. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4736. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4737. }
  4738. }
  4739. if(MinChargingRate < tempminChargingRateFloat)
  4740. {
  4741. MinChargingRate = tempminChargingRateFloat;
  4742. }
  4743. if(confirmPeriods < n_SchedulePeriods)
  4744. {
  4745. confirmPeriods = n_SchedulePeriods;
  4746. }
  4747. j = j + 1;
  4748. }
  4749. fclose(fptr1);
  4750. }
  4751. }// the end of access file ChargePointMaxProfile
  4752. //****************************TxDefaultProfile************************************************/
  4753. switch(connectorIdInt)
  4754. {
  4755. case 0:
  4756. break;
  4757. case 1:
  4758. strcpy(fname, TxDefaultProfile_1_JSON );
  4759. break;
  4760. case 2:
  4761. strcpy(fname, TxDefaultProfile_2_JSON );
  4762. break;
  4763. default:
  4764. strcpy(fname, TxDefaultProfile_1_JSON );
  4765. break;
  4766. }
  4767. TxDefaultProfileFileIsNull=TRUE;
  4768. if((access(fname,F_OK))!=-1)
  4769. {
  4770. fptr1 = fopen(fname, "r");
  4771. c = 0;
  4772. c = fgetc(fptr1);
  4773. //DEBUG_INFO("c:%d\n",c);
  4774. rewind(fptr1);
  4775. if(c == EOF)
  4776. {
  4777. DEBUG_INFO("\n End of file reached.");
  4778. TxDefaultProfileFileIsNull=TRUE;
  4779. fclose(fptr1);
  4780. }
  4781. else
  4782. {
  4783. TxDefaultProfileFileIsNull=FALSE;
  4784. while(fscanf(fptr1, "%s", word) != EOF)
  4785. {
  4786. if(strcmp(word, "chargingProfileId") == 0)
  4787. {
  4788. n_chargingProfile = n_chargingProfile + 1;
  4789. }
  4790. }
  4791. rewind(fptr1);
  4792. //search Charging Profile Element
  4793. int i = 0;
  4794. int j = 0;
  4795. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4796. //DEBUG_INFO(" 1-1\n");
  4797. #if 0
  4798. /***********connectorId****************/
  4799. c = 0;
  4800. loc = strstr(sLineWord, "connectorId");
  4801. memset(sstr ,0, sizeof(sstr) );
  4802. while (loc[strlen("connectorId")+2+c] != ',')
  4803. {
  4804. sstr[c] = loc[strlen("connectorId")+2+c];
  4805. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4806. c++;
  4807. }
  4808. sstr[c] = '\0';
  4809. tempconnectorIdInt = atoi(sstr);
  4810. #endif
  4811. //***********validFrom**************/
  4812. c = 0;
  4813. loc = strstr(sLineWord, "validFrom");
  4814. if(loc != NULL)
  4815. {
  4816. memset(sstr ,0, sizeof(sstr) );
  4817. while (loc[3+strlen("validFrom")+c] != '\"')
  4818. {
  4819. sstr[c] = loc[3+strlen("validFrom")+c];
  4820. c++;
  4821. }
  4822. sstr[c] = '\0';
  4823. strcpy(tempvalidFromStr,sstr);
  4824. }
  4825. else
  4826. {
  4827. strcpy(tempvalidFromStr,"");
  4828. }
  4829. //***********validFrom**************/
  4830. c = 0;
  4831. loc = strstr(sLineWord, "duration");
  4832. if(loc != NULL)
  4833. {
  4834. memset(sstr ,0, sizeof(sstr) );
  4835. while (loc[2+strlen("duration")+c] != ',')
  4836. {
  4837. sstr[c] = loc[2+strlen("duration")+c];
  4838. c++;
  4839. }
  4840. sstr[c] = '\0';
  4841. tempdurationInt = atoi(sstr);
  4842. }
  4843. else
  4844. {
  4845. tempdurationInt = 0;
  4846. }
  4847. //**********startSchedule**********/
  4848. c = 0;
  4849. loc = strstr(sLineWord, "startSchedule");
  4850. memset(sstr ,0, sizeof(sstr) );
  4851. while (loc[3+strlen("startSchedule")+c] != '\"')
  4852. {
  4853. sstr[c] = loc[3+strlen("startSchedule")+c];
  4854. c++;
  4855. }
  4856. sstr[c] = '\0';
  4857. strcpy(tempstartScheduleStr, sstr);
  4858. strcpy(TxDefaultProfileScheduleStr, sstr);
  4859. //**********chargingRateUnit**********/
  4860. c = 0;
  4861. loc = strstr(sLineWord, "chargingRateUnit");
  4862. memset(sstr ,0, sizeof(sstr) );
  4863. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4864. {
  4865. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4866. c++;
  4867. }
  4868. sstr[c] = '\0';
  4869. strcpy(tempchargingRateUnitStr, sstr);
  4870. //**********minChargingRate*******/
  4871. c = 0;
  4872. loc = strstr(sLineWord, "minChargingRate");
  4873. if(loc != NULL)
  4874. {
  4875. memset(sstr ,0, sizeof(sstr) );
  4876. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4877. {
  4878. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4879. c++;
  4880. }
  4881. sstr[c] = '\0';
  4882. tempminChargingRateFloat = atof(sstr);
  4883. }
  4884. else
  4885. {
  4886. tempminChargingRateFloat = 0.0;
  4887. }
  4888. #if 0
  4889. //
  4890. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4891. tp.tm_isdst = -1;
  4892. time_t utc = mktime(&tp);
  4893. time_t t = time(NULL);
  4894. //diff_t = difftime(t, utc);
  4895. #endif
  4896. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4897. //parsing strings to words
  4898. i = 0;
  4899. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4900. loc = loc+3+strlen("chargingSchedulePeriod");
  4901. pch = strtok(loc ,"{");
  4902. while (pch != NULL)
  4903. {
  4904. strcpy(SchedulePeriodList[i], pch);
  4905. pch = strtok (NULL, "{");
  4906. i = i + 1;
  4907. }
  4908. n_SchedulePeriods = i;
  4909. for(int i=0;i<n_SchedulePeriods;i++)
  4910. {
  4911. //*************startPeriod****************/
  4912. c = 0;
  4913. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4914. memset(sstr ,0, sizeof(sstr) );
  4915. while (loc[strlen("startPeriod")+2+c] != ',')
  4916. {
  4917. sstr[c] = loc[strlen("startPeriod")+2+c];
  4918. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4919. c++;
  4920. }
  4921. sstr[c] = '\0';
  4922. tempStartPeriodInt = atoi(sstr);
  4923. //*************limit****************/
  4924. c = 0;
  4925. loc = strstr(SchedulePeriodList[i], "limit");
  4926. memset(sstr ,0, sizeof(sstr) );
  4927. while (loc[strlen("limit")+2+c] != ',')
  4928. {
  4929. sstr[c] = loc[strlen("limit")+2+c];
  4930. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4931. c++;
  4932. }
  4933. sstr[c] = '\0';
  4934. tempLimitInt = atof(sstr);
  4935. //*************numberPhases****************/
  4936. c = 0;
  4937. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4938. memset(sstr ,0, sizeof(sstr) );
  4939. while (loc[strlen("numberPhases")+2+c] != '}')
  4940. {
  4941. sstr[c] = loc[strlen("numberPhases")+2+c];
  4942. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4943. c++;
  4944. }
  4945. sstr[c] = '\0';
  4946. tempNumberPhasesInt = atoi(sstr);
  4947. if(j == 0)
  4948. {
  4949. TxDefaultProfile.Duration = tempdurationInt;
  4950. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4951. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4952. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4953. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4954. }
  4955. else
  4956. {
  4957. //other stack level charging Profile
  4958. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  4959. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  4960. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  4961. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  4962. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  4963. }
  4964. }
  4965. if(MinChargingRate < tempminChargingRateFloat)
  4966. MinChargingRate = tempminChargingRateFloat;
  4967. if(confirmPeriods < n_SchedulePeriods)
  4968. confirmPeriods = n_SchedulePeriods;
  4969. j = j + 1;
  4970. //DEBUG_INFO(" 1-2\n");
  4971. }
  4972. fclose(fptr1);
  4973. //Stacking Charging Profiles
  4974. for(int l=0; l <(j-1) ;l++)
  4975. {
  4976. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  4977. {
  4978. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  4979. {
  4980. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  4981. {
  4982. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  4983. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  4984. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  4985. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4986. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4987. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4988. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4989. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4990. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4991. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4992. }
  4993. else
  4994. {
  4995. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4996. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4997. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4998. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4999. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5000. }
  5001. }
  5002. }
  5003. }
  5004. //end of Stacking Charging Profiles
  5005. }
  5006. }// the end of ACCESS TxDefaultProfile
  5007. //****************************TxProfile************************************************/
  5008. switch(connectorIdInt)
  5009. {
  5010. case 0:
  5011. break;
  5012. case 1:
  5013. strcpy(fname, TxProfile_1_JSON );
  5014. break;
  5015. case 2:
  5016. strcpy(fname, TxProfile_2_JSON );
  5017. break;
  5018. default:
  5019. strcpy(fname, TxProfile_1_JSON );
  5020. break;
  5021. }
  5022. TxProfileIsNull=TRUE;
  5023. if((access(fname,F_OK))!=-1)
  5024. {
  5025. fptr1 = fopen(fname, "r");
  5026. c = 0;
  5027. c = fgetc(fptr1);
  5028. //DEBUG_INFO("c:%d\n",c);
  5029. rewind(fptr1);
  5030. if(c == EOF)
  5031. {
  5032. DEBUG_INFO("\n End of file reached.");
  5033. TxProfileIsNull=TRUE;
  5034. fclose(fptr1);
  5035. }
  5036. else
  5037. {
  5038. TxProfileIsNull=FALSE;
  5039. while(fscanf(fptr1, "%s", word) != EOF)
  5040. {
  5041. if(strcmp(word, "chargingProfileId") == 0)
  5042. {
  5043. n_chargingProfile = n_chargingProfile + 1;
  5044. }
  5045. }
  5046. rewind(fptr1);
  5047. //search Charging Profile Element
  5048. int i= 0;
  5049. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5050. #if 0
  5051. /***********connectorId****************/
  5052. c = 0;
  5053. loc = strstr(sLineWord, "connectorId");
  5054. memset(sstr ,0, sizeof(sstr) );
  5055. while (loc[strlen("connectorId")+2+c] != ',')
  5056. {
  5057. sstr[c] = loc[strlen("connectorId")+2+c];
  5058. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5059. c++;
  5060. }
  5061. sstr[c] = '\0';
  5062. tempconnectorIdInt = atoi(sstr);
  5063. #endif
  5064. //***********validFrom**************/
  5065. c = 0;
  5066. loc = strstr(sLineWord, "validFrom");
  5067. if(loc != NULL)
  5068. {
  5069. memset(sstr ,0, sizeof(sstr) );
  5070. while (loc[3+strlen("validFrom")+c] != '\"')
  5071. {
  5072. sstr[c] = loc[3+strlen("validFrom")+c];
  5073. c++;
  5074. }
  5075. sstr[c] = '\0';
  5076. strcpy(tempvalidFromStr,sstr);
  5077. }
  5078. else
  5079. {
  5080. strcpy(tempvalidFromStr,"");
  5081. }
  5082. //**********startSchedule**********/
  5083. c = 0;
  5084. loc = strstr(sLineWord, "startSchedule");
  5085. memset(sstr ,0, sizeof(sstr) );
  5086. while (loc[3+strlen("startSchedule")+c] != '\"')
  5087. {
  5088. sstr[c] = loc[3+strlen("startSchedule")+c];
  5089. c++;
  5090. }
  5091. sstr[c] = '\0';
  5092. strcpy(tempstartScheduleStr, sstr);
  5093. strcpy(TxProfileScheduleStr, sstr);
  5094. //**********chargingRateUnit**********/
  5095. c = 0;
  5096. loc = strstr(sLineWord, "chargingRateUnit");
  5097. memset(sstr ,0, sizeof(sstr) );
  5098. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5099. {
  5100. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5101. c++;
  5102. }
  5103. sstr[c] = '\0';
  5104. strcpy(tempchargingRateUnitStr, sstr);
  5105. //**********minChargingRate*******/
  5106. c = 0;
  5107. loc = strstr(sLineWord, "minChargingRate");
  5108. if(loc != NULL)
  5109. {
  5110. memset(sstr ,0, sizeof(sstr) );
  5111. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5112. {
  5113. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5114. c++;
  5115. }
  5116. sstr[c] = '\0';
  5117. tempminChargingRateFloat = atof(sstr);
  5118. }
  5119. else
  5120. {
  5121. tempminChargingRateFloat = 0.0;
  5122. }
  5123. #if 0
  5124. //
  5125. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5126. tp.tm_isdst = -1;
  5127. time_t utc = mktime(&tp);
  5128. time_t t = time(NULL);
  5129. //diff_t = difftime(t, utc);
  5130. #endif
  5131. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5132. //parsing strings to words
  5133. i = 0;
  5134. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5135. loc = loc+3+strlen("chargingSchedulePeriod");
  5136. pch = strtok(loc ,"{");
  5137. while (pch != NULL)
  5138. {
  5139. strcpy(SchedulePeriodList[i], pch);
  5140. pch = strtok (NULL, "{");
  5141. i = i + 1;
  5142. }
  5143. n_SchedulePeriods = i;
  5144. for(int i=0;i<n_SchedulePeriods;i++)
  5145. {
  5146. //*************startPeriod****************/
  5147. c = 0;
  5148. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5149. memset(sstr ,0, sizeof(sstr) );
  5150. while (loc[strlen("startPeriod")+2+c] != ',')
  5151. {
  5152. sstr[c] = loc[strlen("startPeriod")+2+c];
  5153. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5154. c++;
  5155. }
  5156. sstr[c] = '\0';
  5157. tempStartPeriodInt = atoi(sstr);
  5158. //*************limit****************/
  5159. c = 0;
  5160. loc = strstr(SchedulePeriodList[i], "limit");
  5161. memset(sstr ,0, sizeof(sstr) );
  5162. while (loc[strlen("limit")+2+c] != ',')
  5163. {
  5164. sstr[c] = loc[strlen("limit")+2+c];
  5165. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5166. c++;
  5167. }
  5168. sstr[c] = '\0';
  5169. tempLimitInt = atof(sstr);
  5170. //*************numberPhases****************/
  5171. c = 0;
  5172. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5173. memset(sstr ,0, sizeof(sstr) );
  5174. while (loc[strlen("numberPhases")+2+c] != '}')
  5175. {
  5176. sstr[c] = loc[strlen("numberPhases")+2+c];
  5177. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5178. c++;
  5179. }
  5180. sstr[c] = '\0';
  5181. tempNumberPhasesInt = atoi(sstr);
  5182. TxProfile.Duration = durationInt;
  5183. TxProfile.TotalPeriod = n_SchedulePeriods;
  5184. TxProfile.Period[i].Limit = tempLimitInt;
  5185. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5186. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5187. }
  5188. if(MinChargingRate < tempminChargingRateFloat)
  5189. MinChargingRate = tempminChargingRateFloat;
  5190. if(confirmPeriods < n_SchedulePeriods)
  5191. confirmPeriods = n_SchedulePeriods;
  5192. }
  5193. fclose(fptr1);
  5194. }
  5195. }// the end of ACCESS TxProfile
  5196. //CompositeSchedule
  5197. int period=0;
  5198. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5199. {
  5200. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5201. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5202. {
  5203. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5204. {
  5205. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5206. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5207. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5208. period = period + 1;
  5209. }
  5210. else
  5211. {
  5212. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5213. {
  5214. }
  5215. else
  5216. {
  5217. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5218. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5219. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5220. period = period + 1;
  5221. }
  5222. }
  5223. }
  5224. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5225. {
  5226. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5227. {
  5228. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5229. {
  5230. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5231. }
  5232. else
  5233. {
  5234. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5235. }
  5236. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5237. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5238. period = period + 1;
  5239. }
  5240. }
  5241. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5242. {
  5243. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5244. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5245. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5246. period = period + 1;
  5247. }
  5248. }
  5249. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5250. {
  5251. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5252. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5253. {
  5254. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5255. {
  5256. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5257. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5258. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5259. period = period + 1;
  5260. }
  5261. else
  5262. {
  5263. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5264. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5265. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5266. period = period + 1;
  5267. }
  5268. }
  5269. }
  5270. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5271. {
  5272. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5273. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5274. {
  5275. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5276. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5277. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5278. period = period + 1;
  5279. }
  5280. }
  5281. confirmPeriods = period;
  5282. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5283. //* Define temporary variables */
  5284. struct tm *gtime;
  5285. time_t now;
  5286. char buf[28];
  5287. //* Read the current system time */
  5288. time(&now);
  5289. //* Convert the system time to GMT (now UTC) */
  5290. gtime = gmtime(&now);
  5291. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5292. // make .conf
  5293. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5294. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5295. //DEBUG_INFO(" debug 11\n");
  5296. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5297. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5298. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5299. }
  5300. else
  5301. {
  5302. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5303. }
  5304. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5305. return result;
  5306. }
  5307. int handleGetConfigurationRequest(char *uuid, char *payload)
  5308. {
  5309. mtrace();
  5310. int result = FAIL;
  5311. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5312. //struct json_object *jsonitem;
  5313. int MaxKeySupported = 0;
  5314. int n_keys = 0;
  5315. char requestKey[43][50]={0};
  5316. char search[]="[";
  5317. char sstr[500]={ 0 };
  5318. //int pos;
  5319. int l, c = 0;
  5320. int i = 0;
  5321. char *delim = "\",\"";
  5322. char * pch;
  5323. char *loc = strstr(payload, search);
  5324. //********************* Parsing String ***********************************/
  5325. if(loc == NULL) {
  5326. DEBUG_INFO("no key match in Configuration \n");
  5327. }
  5328. else {
  5329. //pos = loc - payload;
  5330. l = strlen(loc)-4;
  5331. while (c < l)
  5332. {
  5333. sstr[c] = loc[c+2];
  5334. c++;
  5335. }
  5336. sstr[c] = '\0';
  5337. //parsing strings to words
  5338. pch = strtok(sstr,delim);
  5339. if(pch == NULL)
  5340. {
  5341. strcpy(requestKey[0], sstr);
  5342. }
  5343. else
  5344. {
  5345. while (pch != NULL)
  5346. {
  5347. strcpy(requestKey[i], pch);
  5348. pch = strtok (NULL, delim);
  5349. i = i + 1;
  5350. }
  5351. n_keys = i;
  5352. }
  5353. }
  5354. UnknownKeynum = 0;
  5355. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5356. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5357. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5358. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5359. if(n_keys != 0)
  5360. {
  5361. for(int i=0;i<n_keys;i++)
  5362. {
  5363. getKeyValue(requestKey[i]);
  5364. //json_object_put(jsonitem);
  5365. }
  5366. }
  5367. else
  5368. {
  5369. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5370. getKeyValue("");
  5371. }
  5372. processUnkownKey();
  5373. sendGetConfigurationConfirmation(uuid);
  5374. return result;
  5375. }
  5376. static char GetDiagnosticspayloadData[300]={0};
  5377. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5378. {
  5379. mtrace();
  5380. int result = FAIL;
  5381. //void *ret; //
  5382. char fnamePlusPath[100]="";
  5383. char fname[40]="";
  5384. pthread_t t; // pthread 變數
  5385. time_t rawtime;
  5386. struct tm * timeinfo;
  5387. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5388. system("exec /root/logPackTools 'log' 6");
  5389. //char buffer [128];
  5390. time (&rawtime);
  5391. //printf("%ld\n", rawtime);
  5392. timeinfo = localtime (&rawtime);
  5393. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5394. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5395. if((access(fnamePlusPath,F_OK))!=-1)
  5396. {
  5397. DEBUG_INFO("fnamePlusPath exist.\n");
  5398. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5399. }
  5400. else
  5401. {
  5402. DEBUG_INFO("fnamePlusPath not exist!\n");
  5403. }
  5404. memset(GetDiagnosticspayloadData, 0, 300);
  5405. strcpy(GetDiagnosticspayloadData, payload);
  5406. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5407. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5408. // pthread_join(t, NULL/*&ret*/);
  5409. return result;
  5410. }
  5411. void* GetDiagnosticsProcess(void* data)
  5412. {
  5413. pthread_detach(pthread_self());
  5414. mtrace();
  5415. int retriesInt=0, retryIntervalInt=0;
  5416. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5417. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5418. 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};
  5419. int port=0;
  5420. char fnamePlusPath[100]="";//="00000_2019-06-09_160902_CSULog.zip";
  5421. char fname[40]="";
  5422. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5423. int c = 0;
  5424. char *loc;
  5425. int isSuccess = FALSE;
  5426. char ftpbuf[200]={0};
  5427. //char temp[100]={0};
  5428. char * pch;
  5429. // [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"}]
  5430. //char *str = (char*) data; // ? ?輸入資 ?
  5431. char str[300]={ 0 };
  5432. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5433. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5434. DEBUG_INFO("GetDiagnosticsProcess\n");
  5435. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5436. //****************location*******************/
  5437. c = 0;
  5438. memset(sstr ,0, sizeof(sstr) );
  5439. loc = strstr(str, "location");
  5440. while (loc[3+strlen("location")+c] != '\"')
  5441. {
  5442. sstr[c] = loc[3+strlen("location")+c];
  5443. c++;
  5444. }
  5445. sstr[c] = '\0';
  5446. strcpy(locationstr,sstr);
  5447. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5448. if(strcmp(locationstr,"")==0)
  5449. {
  5450. DEBUG_INFO("location is <Empty>!\n");
  5451. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5452. goto end;
  5453. }
  5454. //****************retries*******************/
  5455. c = 0;
  5456. loc = strstr(str, "retries");
  5457. if(loc == NULL)
  5458. {
  5459. retriesIsNULL = TRUE;
  5460. }
  5461. else
  5462. {
  5463. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5464. {
  5465. sstr[c] = loc[strlen("retries")+2+c];
  5466. c++;
  5467. }
  5468. sstr[c] = '\0';
  5469. retriesInt = atoi(sstr);
  5470. }
  5471. if(retriesIsNULL == TRUE)
  5472. {
  5473. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5474. }
  5475. //****************retryInterval*******************/
  5476. c = 0;
  5477. loc = strstr(str, "retryInterval");
  5478. if(loc == NULL)
  5479. {
  5480. retryIntervalIsNULL = TRUE;
  5481. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5482. }
  5483. else
  5484. {
  5485. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5486. {
  5487. sstr[c] = loc[strlen("retryInterval")+2+c];
  5488. c++;
  5489. }
  5490. sstr[c] = '\0';
  5491. retryIntervalInt = atoi(sstr);
  5492. }
  5493. //****************startTime*******************/
  5494. c = 0;
  5495. memset(sstr ,0, sizeof(sstr) );
  5496. loc = strstr(str, "startTime");
  5497. if(loc == NULL)
  5498. {
  5499. startTimeIsNULL = TRUE;
  5500. }
  5501. else
  5502. {
  5503. while (loc[3+strlen("startTime")+c] != '\"')
  5504. {
  5505. sstr[c] = loc[3+strlen("startTime")+c];
  5506. c++;
  5507. }
  5508. sstr[c] = '\0';
  5509. strcpy(startTimestr,sstr);
  5510. }
  5511. //****************stopTime*******************/
  5512. c = 0;
  5513. memset(sstr ,0, sizeof(sstr) );
  5514. loc = strstr(str, "stopTime");
  5515. if(loc == NULL)
  5516. {
  5517. stopTimeIsNULL = TRUE;
  5518. }
  5519. else
  5520. {
  5521. while (loc[3+strlen("stopTime")+c] != '\"')
  5522. {
  5523. sstr[c] = loc[3+strlen("stopTime")+c];
  5524. c++;
  5525. }
  5526. sstr[c] = '\0';
  5527. strcpy(stopTimestr,sstr);
  5528. }
  5529. memset(protocol, 0, sizeof(protocol));
  5530. memset(user, 0, sizeof(user) );
  5531. memset(password, 0, sizeof(password));
  5532. memset(host, 0, sizeof(host));
  5533. memset(path, 0, sizeof(path));
  5534. memset(ftppath, 0, sizeof(ftppath));
  5535. memset(host1, 0, sizeof(host1));
  5536. memset(path1, 0, sizeof(path1));
  5537. /*location: ftp://user:password@host:port/path*/
  5538. time_t rawtime;
  5539. struct tm * timeinfo;
  5540. //char buffer [128];
  5541. time (&rawtime);
  5542. //printf("%ld\n", rawtime);
  5543. timeinfo = localtime (&rawtime);
  5544. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5545. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5546. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5547. if((access(fnamePlusPath,F_OK))!=-1)
  5548. {
  5549. DEBUG_INFO("fnamePlusPath exist.\n");
  5550. }
  5551. else
  5552. {
  5553. DEBUG_INFO("fnamePlusPath not exist!\n");
  5554. goto end;
  5555. }
  5556. pch=strchr(locationstr,'@');
  5557. if(pch==NULL)
  5558. {
  5559. sscanf(locationstr,
  5560. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5561. protocol, host, &port, path);
  5562. strcpy(user,"anonymous");
  5563. strcpy(password,"");
  5564. }
  5565. else
  5566. {
  5567. //DEBUG_INFO("pch=%s\n", pch);
  5568. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5569. protocol, user, password, host, &port, path);
  5570. }
  5571. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5572. {
  5573. DEBUG_INFO("protocol is not ftp/http ! \n");
  5574. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5575. goto end;
  5576. }
  5577. if(strncmp(locationstr,"http", 4) == 0)
  5578. {
  5579. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  5580. protocol, host, path);
  5581. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  5582. // protocol, user, password, host, path);
  5583. sprintf(ftppath,"/%s", path);
  5584. //DEBUG_INFO("protocol =%s\n",protocol);
  5585. //DEBUG_INFO("host =%s\n",host);
  5586. //DEBUG_INFO("path =%s\n",path);
  5587. //DEBUG_INFO("ftppath=%s\n",ftppath);
  5588. //int ftppathlen=strlen(ftppath);
  5589. //int i=1;
  5590. //char filenametemp[50];
  5591. //while(i < ftppathlen)
  5592. //{
  5593. // int len=ftppathlen-i;
  5594. // if(ftppath[len]== 47) // '/' ascll code: 47
  5595. // {
  5596. // DEBUG_INFO("compare '/' all right\n");
  5597. // break;
  5598. // }
  5599. // i=i+1;
  5600. //}
  5601. //memset(filenametemp, 0, sizeof(filenametemp));
  5602. //strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5603. //filenametemp[i+1] = 0;
  5604. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  5605. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5606. strftime (fnamePlusPath,sizeof(fnamePlusPath),"/mnt/%4Y-%2m.zip",timeinfo);
  5607. do{
  5608. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);//httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5609. sleep(retryIntervalInt);
  5610. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5611. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  5612. if(!isSuccess)
  5613. {
  5614. //BulldogUtil.sleepMs(interval*1000);
  5615. DEBUG_INFO("Diagnostics fail.\n");
  5616. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5617. }
  5618. else
  5619. {
  5620. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5621. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5622. //isUpdateRequest = TRUE;
  5623. }
  5624. }
  5625. else
  5626. {
  5627. sscanf(host,"%[^/]%s",host1, path1);
  5628. sprintf(ftppath,"%s", path1);
  5629. DEBUG_INFO("protocol =%s\n",protocol);
  5630. DEBUG_INFO("user =%s\n",user);
  5631. DEBUG_INFO("password =%s\n",password);
  5632. DEBUG_INFO("host1 =%s\n",host1);
  5633. DEBUG_INFO("port =%d\n",port);
  5634. DEBUG_INFO("path1 =%s\n",path1);
  5635. DEBUG_INFO("ftppath=%s\n",ftppath);
  5636. int ftppathlen=strlen(ftppath);
  5637. int i=1;
  5638. char filenametemp[50];
  5639. while(i < ftppathlen)
  5640. {
  5641. int len=ftppathlen-i;
  5642. if(ftppath[len]== 47) // '/' ascll code: 47
  5643. {
  5644. DEBUG_INFO("find '/' all right\n");
  5645. break;
  5646. }
  5647. i=i+1;
  5648. }
  5649. memset(filenametemp, 0, sizeof(filenametemp));
  5650. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5651. filenametemp[i+1] = 0;
  5652. memset(ftpbuf, 0, sizeof(ftpbuf));
  5653. if(port == 0)
  5654. port = 21;
  5655. do{
  5656. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5657. sleep(retryIntervalInt);
  5658. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5659. if(!isSuccess)
  5660. {
  5661. //BulldogUtil.sleepMs(interval*1000);
  5662. DEBUG_INFO("Diagnostics fail.\n");
  5663. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5664. }
  5665. else
  5666. {
  5667. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5668. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5669. //isUpdateRequest = TRUE;
  5670. }
  5671. }
  5672. end:
  5673. // json_object_put(obj);
  5674. DiagnosticsStatusNotificationStatus = 0; //Idle
  5675. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5676. }
  5677. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5678. {
  5679. mtrace();
  5680. int result = FAIL;
  5681. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5682. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5683. {
  5684. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5685. localversion = -1;
  5686. }
  5687. else
  5688. {
  5689. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5690. OCPP_getListVerion();
  5691. }
  5692. //from db.OCPP_getListVerion
  5693. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5694. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5695. sendGetLocalListVersionConfirmation(uuid,"");
  5696. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5697. return result;
  5698. }
  5699. int handleRemoteStartRequest(char *uuid, char *payload)
  5700. {
  5701. mtrace();
  5702. int result = FAIL;
  5703. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5704. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5705. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5706. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5707. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5708. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5709. int chargingSchedulePeriodCount = 0;
  5710. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5711. int c = 0;
  5712. char *loc;
  5713. char comfirmstr[20]={0};
  5714. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5715. if(server_pending == TRUE)
  5716. {
  5717. return 0;
  5718. }
  5719. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5720. //**********connectorId****************/
  5721. c = 0;
  5722. memset(sstr ,0, sizeof(sstr) );
  5723. loc = strstr(payload, "connectorId");
  5724. if(loc == NULL)
  5725. {
  5726. connectorIdIsNULL = TRUE;
  5727. }
  5728. else
  5729. {
  5730. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5731. {
  5732. sstr[c] = loc[strlen("connectorId")+2+c];
  5733. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5734. c++;
  5735. }
  5736. sstr[c] = '\0';
  5737. connectorIdInt = atoi(sstr);
  5738. }
  5739. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  5740. {
  5741. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5742. goto end;
  5743. }
  5744. //****************idTag*******************/
  5745. c = 0;
  5746. memset(sstr ,0, sizeof(sstr) );
  5747. loc = strstr(payload, "idTag");
  5748. while (loc[3+strlen("idTag")+c] != '\"')
  5749. {
  5750. sstr[c] = loc[3+strlen("idTag")+c];
  5751. c++;
  5752. }
  5753. sstr[c] = '\0';
  5754. strcpy(idTagstr,sstr);
  5755. //****************chargingProfile*******************/
  5756. c = 0;
  5757. memset(sstr ,0, sizeof(sstr) );
  5758. loc = strstr(payload, "chargingProfile");
  5759. if(loc == NULL)
  5760. {
  5761. chargingProfileIsNULL = TRUE;
  5762. }
  5763. else
  5764. {
  5765. //****************chargingProfileId*******************/
  5766. c=0;
  5767. loc = strstr(payload, "chargingProfileId");
  5768. memset(sstr ,0, sizeof(sstr) );
  5769. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5770. {
  5771. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5772. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5773. c++;
  5774. }
  5775. sstr[c] = '\0';
  5776. chargingProfileIdInt = atoi(sstr);
  5777. //****************transactionId*******************/
  5778. loc = strstr(payload, "transactionId");
  5779. if(loc == NULL)
  5780. {
  5781. transactionIdIsNULL = TRUE;
  5782. }
  5783. else
  5784. {
  5785. c=0;
  5786. memset(sstr ,0, sizeof(sstr) );
  5787. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5788. {
  5789. sstr[c] = loc[strlen("transactionId")+2+c];
  5790. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5791. c++;
  5792. }
  5793. sstr[c] = '\0';
  5794. transactionIdInt = atoi(sstr);
  5795. }
  5796. //****************stackLevel*******************/
  5797. c=0;
  5798. loc = strstr(payload, "stackLevel");
  5799. memset(sstr ,0, sizeof(sstr) );
  5800. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5801. {
  5802. sstr[c] = loc[strlen("stackLevel")+2+c];
  5803. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5804. c++;
  5805. }
  5806. sstr[c] = '\0';
  5807. stackLevelInt = atoi(sstr);
  5808. //****************chargingProfilePurpose*******************/
  5809. c = 0;
  5810. memset(sstr ,0, sizeof(sstr) );
  5811. loc = strstr(payload, "chargingProfilePurpose");
  5812. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5813. {
  5814. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5815. c++;
  5816. }
  5817. sstr[c] = '\0';
  5818. strcpy(chargingProfilePurposestr,sstr);
  5819. //****************chargingProfileKind*******************/
  5820. c = 0;
  5821. memset(sstr ,0, sizeof(sstr) );
  5822. loc = strstr(payload, "chargingProfileKind");
  5823. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5824. {
  5825. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5826. c++;
  5827. }
  5828. sstr[c] = '\0';
  5829. strcpy(chargingProfileKindstr,sstr);
  5830. //****************recurrencyKind*******************/
  5831. loc = strstr(payload, "recurrencyKind");
  5832. if(loc == NULL)
  5833. {
  5834. recurrencyKindIsNULL = TRUE;
  5835. }
  5836. else
  5837. {
  5838. c = 0;
  5839. memset(sstr ,0, sizeof(sstr) );
  5840. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5841. {
  5842. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5843. c++;
  5844. }
  5845. sstr[c] = '\0';
  5846. strcpy(recurrencyKindstr,sstr);
  5847. }
  5848. //****************validFrom*******************/
  5849. loc = strstr(payload, "validFrom");
  5850. if(loc == NULL)
  5851. {
  5852. validFromIsNULL = TRUE;
  5853. }
  5854. else
  5855. {
  5856. c = 0;
  5857. memset(sstr ,0, sizeof(sstr) );
  5858. while (loc[3+strlen("validFrom")+c] != '\"')
  5859. {
  5860. sstr[c] = loc[3+strlen("validFrom")+c];
  5861. c++;
  5862. }
  5863. sstr[c] = '\0';
  5864. strcpy(validFromstr,sstr);
  5865. }
  5866. //****************validTo*******************/
  5867. loc = strstr(payload, "validTo");
  5868. if(loc == NULL)
  5869. {
  5870. validToIsNULL = TRUE;
  5871. }
  5872. else
  5873. {
  5874. c = 0;
  5875. memset(sstr ,0, sizeof(sstr) );
  5876. while (loc[3+strlen("validTo")+c] != '\"')
  5877. {
  5878. sstr[c] = loc[3+strlen("validTo")+c];
  5879. c++;
  5880. }
  5881. sstr[c] = '\0';
  5882. strcpy(validTostr,sstr);
  5883. }
  5884. //****************chargingSchedule*******************/
  5885. loc = strstr(payload, "chargingSchedule");
  5886. if(loc != NULL)
  5887. {
  5888. //****************duration*******************/
  5889. loc = strstr(payload, "duration");
  5890. if(loc == NULL)
  5891. {
  5892. durationIsNULL = TRUE;
  5893. }
  5894. else
  5895. {
  5896. c=0;
  5897. memset(sstr ,0, sizeof(sstr) );
  5898. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5899. {
  5900. sstr[c] = loc[strlen("duration")+2+c];
  5901. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5902. c++;
  5903. }
  5904. sstr[c] = '\0';
  5905. durationInt = atoi(sstr);
  5906. }
  5907. //****************startSchedule******************/
  5908. loc = strstr(payload, "startSchedule");
  5909. if(loc == NULL)
  5910. {
  5911. startScheduleIsNULL = TRUE;
  5912. }
  5913. else
  5914. {
  5915. c = 0;
  5916. memset(sstr ,0, sizeof(sstr) );
  5917. while (loc[3+strlen("startSchedule")+c] != '\"')
  5918. {
  5919. sstr[c] = loc[3+strlen("startSchedule")+c];
  5920. c++;
  5921. }
  5922. sstr[c] = '\0';
  5923. strcpy(startSchedulestr,sstr);
  5924. }
  5925. //****************chargingRateUnit*******************/
  5926. c = 0;
  5927. memset(sstr ,0, sizeof(sstr) );
  5928. loc = strstr(payload, "chargingRateUnit");
  5929. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5930. {
  5931. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5932. c++;
  5933. }
  5934. sstr[c] = '\0';
  5935. strcpy(chargingRateUnitstr,sstr);
  5936. //****************minChargingRate*******************/
  5937. loc = strstr(payload, "minChargingRate");
  5938. if(loc == NULL)
  5939. {
  5940. minChargingRateIsNULL = TRUE;
  5941. }
  5942. else
  5943. {
  5944. c=0;
  5945. memset(sstr ,0, sizeof(sstr) );
  5946. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5947. {
  5948. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5949. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5950. c++;
  5951. }
  5952. sstr[c] = '\0';
  5953. minChargingRateflaot = atof(sstr);
  5954. }
  5955. //****************chargingSchedulePeriod count*******************/
  5956. int what_len = strlen("startPeriod");
  5957. char *where = payload;
  5958. while ((where = strstr(where, "startPeriod"))) {
  5959. where += what_len;
  5960. chargingSchedulePeriodCount++;
  5961. }
  5962. where = payload;
  5963. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5964. {
  5965. //****************startPeriod*******************/
  5966. c=0;
  5967. loc = strstr(where, "startPeriod");
  5968. memset(sstr ,0, sizeof(sstr) );
  5969. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5970. {
  5971. sstr[c] = loc[strlen("startPeriod")+2+c];
  5972. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5973. c++;
  5974. }
  5975. sstr[c] = '\0';
  5976. startPeriodInt[periodNums] = atoi(sstr);
  5977. //****************limit*******************/
  5978. c=0;
  5979. loc = strstr(where, "limit");
  5980. memset(sstr ,0, sizeof(sstr) );
  5981. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5982. {
  5983. sstr[c] = loc[strlen("limit")+2+c];
  5984. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5985. c++;
  5986. }
  5987. sstr[c] = '\0';
  5988. limitflaot[periodNums] = atof(sstr);
  5989. //****************numberPhases*******************/
  5990. loc = strstr(where, "numberPhases");
  5991. if(loc == NULL)
  5992. {
  5993. numberPhasesIsNULL = TRUE;
  5994. }
  5995. else
  5996. {
  5997. c=0;
  5998. memset(sstr ,0, sizeof(sstr) );
  5999. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6000. {
  6001. sstr[c] = loc[strlen("numberPhases")+2+c];
  6002. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6003. c++;
  6004. }
  6005. sstr[c] = '\0';
  6006. numberPhasesInt[periodNums] = atoi(sstr);
  6007. }
  6008. where = loc;
  6009. }
  6010. }
  6011. }
  6012. /*
  6013. enum _SYSTEM_STATUS
  6014. {
  6015. S_BOOTING = 0,
  6016. S_IDLE, = 1
  6017. S_AUTHORIZING, =2
  6018. S_REASSIGN_CHECK, =3
  6019. S_REASSIGN, =4
  6020. S_PRECHARGE, =5
  6021. S_PREPARING_FOR_EV, =6
  6022. S_PREPARING_FOR_EVSE, =7
  6023. S_CHARGING, =8
  6024. S_TERMINATING, =9
  6025. S_COMPLETE, =10
  6026. S_ALARM, =11
  6027. S_FAULT =12
  6028. }
  6029. */
  6030. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6031. {
  6032. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6033. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6034. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6035. //check Transaction active
  6036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6037. {
  6038. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6039. {
  6040. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6041. {
  6042. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6043. {
  6044. //Reserved
  6045. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6046. }
  6047. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6048. {
  6049. //Reserved
  6050. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6051. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6052. goto end;
  6053. }
  6054. else
  6055. {
  6056. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6057. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6058. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6059. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6060. {
  6061. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6062. goto end;
  6063. }
  6064. }//END FOR ELSE
  6065. }
  6066. }// END FOR CHAdeMO_QUANTITY
  6067. for (int index = 0; index < CCS_QUANTITY; index++)
  6068. {
  6069. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6070. {
  6071. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6072. {
  6073. //Reserved
  6074. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6075. }
  6076. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6077. {
  6078. //Reserved
  6079. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6080. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6081. goto end;
  6082. }
  6083. else
  6084. {
  6085. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6086. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6087. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6088. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6089. {
  6090. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6091. goto end;
  6092. }
  6093. }// END FOR ELSE
  6094. }
  6095. }// END FOR CCS_QUANTITY
  6096. for (int index = 0; index < GB_QUANTITY; index++)
  6097. {
  6098. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6099. {
  6100. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6101. {
  6102. //Reserved
  6103. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6104. }
  6105. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6106. {
  6107. //Reserved
  6108. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6109. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6110. goto end;
  6111. }
  6112. else
  6113. {
  6114. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6115. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6116. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6117. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6118. {
  6119. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6120. goto end;
  6121. }
  6122. }// END FOR ELSE
  6123. }
  6124. } // END FOR GB_QUANTITY
  6125. }
  6126. else
  6127. {
  6128. for (int index = 0; index < AC_QUANTITY; index++)
  6129. {
  6130. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6131. {
  6132. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6133. {
  6134. //Reserved
  6135. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6136. }
  6137. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6138. {
  6139. //Reserved
  6140. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6141. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6142. goto end;
  6143. }
  6144. else
  6145. {
  6146. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6147. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6148. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6149. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6150. {
  6151. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6152. goto end;
  6153. }
  6154. }//END FOR ELSE
  6155. }
  6156. }// END FOR AC_QUANTITY
  6157. }
  6158. if(chargingProfileIsNULL == FALSE)
  6159. {
  6160. //ChargingProfile
  6161. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6162. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6163. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6164. if(recurrencyKindIsNULL == FALSE) //OPTION
  6165. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6166. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6167. if(transactionIdIsNULL == FALSE) // OPTION
  6168. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6169. if(validFromIsNULL == FALSE) // OPTION
  6170. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6171. if(validToIsNULL == FALSE) //OPTION
  6172. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6173. //ChargingSchedule
  6174. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6175. if(durationIsNULL == FALSE) //OPTION
  6176. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6177. if(minChargingRateIsNULL == FALSE) //OPTION
  6178. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6179. if(startScheduleIsNULL == FALSE) //OPTION
  6180. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6181. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6182. {
  6183. //ChargingSchedulePeriod
  6184. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6185. if(numberPhasesIsNULL == FALSE)
  6186. {
  6187. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6188. }
  6189. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6190. }
  6191. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6192. {
  6193. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6194. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6195. //memset idTag
  6196. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6197. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6198. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6199. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6200. }
  6201. else
  6202. {
  6203. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6204. }
  6205. }
  6206. else
  6207. {
  6208. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6209. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6210. //memset idTag
  6211. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6212. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6213. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6214. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6215. }
  6216. }
  6217. else
  6218. {
  6219. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6220. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6221. }
  6222. end:
  6223. if(connectorIdIsNULL == FALSE)
  6224. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6225. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6226. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6227. //OCPP send RemoteStartConfirmation by first.
  6228. sendRemoteStartConfirmation(uuid, comfirmstr);
  6229. return result;
  6230. }
  6231. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6232. {
  6233. mtrace();
  6234. int result = FAIL;
  6235. int match = FALSE;
  6236. int GunNO = 0;
  6237. int transactionIdInt=0;
  6238. int transactionIdIsNULL= FALSE;
  6239. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6240. int c = 0;
  6241. char *loc;
  6242. char comfirmstr[20];
  6243. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6244. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6245. if(server_pending == TRUE)
  6246. {
  6247. return 0;
  6248. }
  6249. c=0;
  6250. loc = strstr(payload, "transactionId");
  6251. if(loc == NULL)
  6252. {
  6253. transactionIdIsNULL= TRUE;
  6254. }
  6255. else
  6256. {
  6257. memset(sstr ,0, sizeof(sstr) );
  6258. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6259. {
  6260. sstr[c] = loc[strlen("transactionId")+2+c];
  6261. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6262. c++;
  6263. }
  6264. sstr[c] = '\0';
  6265. transactionIdInt = atoi(sstr);
  6266. }
  6267. if(transactionIdIsNULL == FALSE)
  6268. {
  6269. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6270. {
  6271. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6272. {
  6273. //check Transaction active
  6274. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6275. {
  6276. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6277. {
  6278. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6279. {
  6280. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6281. {
  6282. match = TRUE;
  6283. GunNO = gun_index;
  6284. }
  6285. }
  6286. }// END FOR CHAdeMO_QUANTITY
  6287. for (int index = 0; index < CCS_QUANTITY; index++)
  6288. {
  6289. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6290. {
  6291. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6292. {
  6293. match = TRUE;
  6294. GunNO = gun_index;
  6295. }
  6296. }
  6297. }// END FOR CCS_QUANTITY
  6298. for (int index = 0; index < GB_QUANTITY; index++)
  6299. {
  6300. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6301. {
  6302. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6303. {
  6304. match = TRUE;
  6305. GunNO = gun_index;
  6306. }
  6307. }
  6308. }// END FOR GB_QUANTITY
  6309. }
  6310. else
  6311. {
  6312. for (int index = 0; index < AC_QUANTITY; index++)
  6313. {
  6314. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6315. {
  6316. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6317. {
  6318. match = TRUE;
  6319. GunNO = gun_index;
  6320. }
  6321. }
  6322. }// END FOR CHAdeMO_QUANTITY
  6323. }// END FOR AC ELSE
  6324. }// CHECK IF ResponseTransactionId == transactionIdInt
  6325. }//END FOR
  6326. if( match == TRUE)
  6327. {
  6328. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6329. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6330. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6331. }
  6332. else
  6333. {
  6334. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6335. }
  6336. }
  6337. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6338. return result;
  6339. }
  6340. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6341. {
  6342. mtrace();
  6343. int result = FAIL;
  6344. int connectorIdInt=0, reservationIdInt=0;
  6345. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6346. char comfirmstr[20]={0};
  6347. char sstr[180]={ 0 };
  6348. int c = 0;
  6349. char *loc;
  6350. //char *ptr;
  6351. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6352. //***(1)connectorId ****/
  6353. c=0;
  6354. loc = strstr(payload, "connectorId");
  6355. memset(sstr ,0, sizeof(sstr) );
  6356. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6357. {
  6358. sstr[c] = loc[strlen("connectorId")+2+c];
  6359. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6360. c++;
  6361. }
  6362. sstr[c] = '\0';
  6363. connectorIdInt = atoi(sstr);
  6364. //***(2)expiryDate ****/
  6365. loc = strstr(payload, "expiryDate");
  6366. memset(sstr ,0, sizeof(sstr) );
  6367. c = 0;
  6368. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6369. {
  6370. sstr[c] = loc[3+strlen("expiryDate")+c];
  6371. c++;
  6372. }
  6373. sstr[c] = '\0';
  6374. strcpy(expiryDatestr, sstr);
  6375. //***(3)idTag ****/
  6376. loc = strstr(payload, "idTag");
  6377. memset(sstr ,0, sizeof(sstr) );
  6378. c = 0;
  6379. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6380. {
  6381. sstr[c] = loc[3+strlen("idTag")+c];
  6382. c++;
  6383. }
  6384. sstr[c] = '\0';
  6385. strcpy(idTagstr, sstr);
  6386. //***(4)parentIdTag ****/
  6387. loc = strstr(payload, "parentIdTag");
  6388. memset(sstr ,0, sizeof(sstr) );
  6389. c = 0;
  6390. if(loc == NULL)
  6391. {
  6392. strcpy(parentIdTagstr, "");
  6393. }
  6394. else
  6395. {
  6396. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6397. {
  6398. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6399. c++;
  6400. }
  6401. sstr[c] = '\0';
  6402. strcpy(parentIdTagstr, sstr);
  6403. }
  6404. //***(5)reservationId ****/
  6405. c=0;
  6406. loc = strstr(payload, "reservationId");
  6407. memset(sstr ,0, sizeof(sstr) );
  6408. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6409. {
  6410. sstr[c] = loc[strlen("reservationId")+2+c];
  6411. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6412. c++;
  6413. }
  6414. sstr[c] = '\0';
  6415. reservationIdInt = atoi(sstr);
  6416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6417. /*
  6418. enum SYSTEM_STATUS
  6419. {
  6420. SYS_MODE_BOOTING = 0,
  6421. SYS_MODE_IDLE = 1,
  6422. SYS_MODE_AUTHORIZING = 2,
  6423. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6424. SYS_MODE_REASSIGN = 4,
  6425. SYS_MODE_PREPARING = 5,
  6426. SYS_MODE_PREPARE_FOR_EV = 6,
  6427. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6428. SYS_MODE_CHARGING = 8,
  6429. SYS_MODE_TERMINATING = 9,
  6430. SYS_MODE_COMPLETE = 10,
  6431. SYS_MODE_ALARM = 11,
  6432. SYS_MODE_FAULT = 12,
  6433. SYS_MODE_RESERVATION = 13,
  6434. SYS_MODE_BOOKING = 14,
  6435. SYS_MODE_MAINTAIN = 15,
  6436. SYS_MODE_DEBUG = 16,
  6437. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6438. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6439. SYS_MODE_UPDATE = 19
  6440. };
  6441. */
  6442. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6443. {
  6444. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6445. goto end;
  6446. }
  6447. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6448. {
  6449. //check Transaction active
  6450. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6451. {
  6452. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6453. {
  6454. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6455. {
  6456. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6457. {
  6458. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6459. {
  6460. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6461. {
  6462. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6463. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6464. }
  6465. 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'))
  6466. {
  6467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6468. }
  6469. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6470. {
  6471. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6472. }
  6473. else
  6474. {
  6475. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6476. }
  6477. }
  6478. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6479. {
  6480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6481. }
  6482. }
  6483. else
  6484. {
  6485. //replace reservation
  6486. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6488. }
  6489. }
  6490. } // END FOR CHAdeMO_QUANTITY
  6491. for (int index = 0; index < CCS_QUANTITY; index++)
  6492. {
  6493. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6494. {
  6495. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6496. {
  6497. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6498. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6499. {
  6500. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6501. {
  6502. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6503. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6504. }
  6505. 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'))
  6506. {
  6507. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6508. }
  6509. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6510. {
  6511. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6512. }
  6513. else
  6514. {
  6515. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6516. }
  6517. }
  6518. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6519. {
  6520. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6521. }
  6522. }
  6523. else
  6524. {
  6525. //replace reservation
  6526. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6527. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6528. }
  6529. }
  6530. } // END FOR CCS_QUANTITY
  6531. for (int index = 0; index < GB_QUANTITY; index++)
  6532. {
  6533. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6534. {
  6535. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6536. {
  6537. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6538. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6539. {
  6540. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6541. {
  6542. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6544. }
  6545. 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'))
  6546. {
  6547. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6548. }
  6549. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6550. {
  6551. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6552. }
  6553. else
  6554. {
  6555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6556. }
  6557. }
  6558. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6559. {
  6560. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6561. }
  6562. }
  6563. else
  6564. {
  6565. //replace reservation
  6566. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6567. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6568. }
  6569. }
  6570. }// END FOR GB_QUANTITY
  6571. }
  6572. else
  6573. {
  6574. for (int index = 0; index < AC_QUANTITY; index++)
  6575. {
  6576. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6577. {
  6578. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6579. {
  6580. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6581. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6582. {
  6583. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6584. {
  6585. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6587. }
  6588. 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'))
  6589. {
  6590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6591. }
  6592. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6593. {
  6594. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6595. }
  6596. else
  6597. {
  6598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6599. }
  6600. }
  6601. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6602. {
  6603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6604. }
  6605. }
  6606. else
  6607. {
  6608. //replace reservation
  6609. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6610. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6611. }
  6612. }
  6613. } // END FOR AC_QUANTITY
  6614. }//END FOR AC ELSE
  6615. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6616. }
  6617. else if(connectorIdInt == 0)
  6618. {
  6619. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6620. {
  6621. //check Transaction active
  6622. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6623. {
  6624. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6625. {
  6626. 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'))
  6627. {
  6628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6629. goto end;
  6630. }
  6631. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6632. {
  6633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6634. goto end;
  6635. }
  6636. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6637. {
  6638. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6639. goto end;
  6640. }
  6641. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6642. {
  6643. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6644. goto end;
  6645. }
  6646. }
  6647. }// END FOR CHAdeMO_QUANTITY
  6648. for (int index = 0; index < CCS_QUANTITY; index++)
  6649. {
  6650. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6651. {
  6652. 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'))
  6653. {
  6654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6655. }
  6656. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6657. {
  6658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6659. }
  6660. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6661. {
  6662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6663. }
  6664. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6665. {
  6666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6667. }
  6668. }
  6669. } // END FOR CCS_QUANTITY
  6670. for (int index = 0; index < GB_QUANTITY; index++)
  6671. {
  6672. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6673. {
  6674. 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'))
  6675. {
  6676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6677. }
  6678. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6679. {
  6680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6681. }
  6682. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6683. {
  6684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6685. }
  6686. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6687. {
  6688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6689. }
  6690. }
  6691. } // END FOR GB_QUANTITY
  6692. }
  6693. else
  6694. {
  6695. for (int index = 0; index < AC_QUANTITY; index++)
  6696. {
  6697. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6698. {
  6699. 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'))
  6700. {
  6701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6702. goto end;
  6703. }
  6704. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6705. {
  6706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6707. goto end;
  6708. }
  6709. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6710. {
  6711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6712. goto end;
  6713. }
  6714. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6715. {
  6716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6717. goto end;
  6718. }
  6719. }
  6720. }// END FOR AC_QUANTITY
  6721. }
  6722. //The connectorId is 0
  6723. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6725. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6726. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6727. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6728. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6729. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6730. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6731. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6732. result = TRUE;
  6733. return result;
  6734. }
  6735. else
  6736. {
  6737. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6738. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6739. }
  6740. if(strcmp(comfirmstr,"Accepted") == 0)
  6741. {
  6742. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6743. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6744. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6745. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6746. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6747. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6748. result = TRUE;
  6749. return result;
  6750. }
  6751. end:
  6752. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6753. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6754. return result;
  6755. }
  6756. int handleResetRequest(char *uuid, char *payload)
  6757. {
  6758. mtrace();
  6759. int result = FAIL;
  6760. char sstr[10]={0};
  6761. char typestr[10]={0};
  6762. char comfirmstr[20]={0};
  6763. int c = 0;
  6764. char *loc;
  6765. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6766. DEBUG_INFO("handleResetRequest ...\n");
  6767. loc = strstr(payload, "type");
  6768. memset(sstr ,0, sizeof(sstr) );
  6769. c = 0;
  6770. while (loc[3+strlen("type")+c] != '\"')
  6771. {
  6772. sstr[c] = loc[3+strlen("type")+c];
  6773. c++;
  6774. }
  6775. sstr[c] = '\0';
  6776. strcpy(typestr,sstr);
  6777. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6778. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6779. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6780. {
  6781. //check Transaction active
  6782. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6783. {
  6784. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6785. {
  6786. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6787. {
  6788. //0: unplug, 1: Plug-in
  6789. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6790. }
  6791. }
  6792. for (int index = 0; index < CCS_QUANTITY; index++)
  6793. {
  6794. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6795. {
  6796. //0: unplug, 1: Plug-in
  6797. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6798. }
  6799. }
  6800. for (int index = 0; index < GB_QUANTITY; index++)
  6801. {
  6802. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6803. {
  6804. //0: unplug, 1: Plug-in
  6805. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6806. }
  6807. }
  6808. }
  6809. else
  6810. {
  6811. for (int index = 0; index < AC_QUANTITY; index++)
  6812. {
  6813. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6814. {
  6815. //0: unplug, 1: Plug-in
  6816. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6817. }
  6818. }
  6819. }// END FOR AC ELSE
  6820. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6821. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6822. result = TRUE;
  6823. return result;
  6824. }
  6825. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6826. {
  6827. //check Transaction active
  6828. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6829. {
  6830. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6831. {
  6832. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6833. {
  6834. //0: unplug, 1: Plug-in
  6835. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6836. }
  6837. }
  6838. for (int index = 0; index < CCS_QUANTITY; index++)
  6839. {
  6840. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6841. {
  6842. //0: unplug, 1: Plug-in
  6843. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6844. }
  6845. }
  6846. for (int index = 0; index < GB_QUANTITY; index++)
  6847. {
  6848. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6849. {
  6850. //0: unplug, 1: Plug-in
  6851. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6852. }
  6853. }
  6854. }
  6855. else
  6856. {
  6857. for (int index = 0; index < AC_QUANTITY; index++)
  6858. {
  6859. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6860. {
  6861. //0: unplug, 1: Plug-in
  6862. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6863. }
  6864. }
  6865. }// END FOR AC ELSE
  6866. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6867. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6868. result = TRUE;
  6869. return result;
  6870. }
  6871. else
  6872. {
  6873. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6874. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6875. goto errorend;
  6876. }
  6877. errorend:
  6878. sendResetConfirmation(uuid, comfirmstr);
  6879. return result;
  6880. }
  6881. int handleSendLocalListRequest(char *uuid, char *payload)
  6882. {
  6883. mtrace();
  6884. int result = FAIL;
  6885. int listVersionInt;
  6886. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6887. char listsearch[]="listVersion";
  6888. char updateTypesearch[]="updateType";
  6889. char localAuthorizationListsearch[]="localAuthorizationList";
  6890. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6891. char CardList[500][160]={0};
  6892. char updateTypestr[15]={0};
  6893. char idTagstr[20]={0};
  6894. char parentIdTag[20]={0};
  6895. char expiryDate[30]={0};
  6896. char idTagstatus[16]={0};
  6897. int c = 0;
  6898. int i = 0;
  6899. char *delim1 = "}";
  6900. char * pch;
  6901. char *loc;
  6902. //char *ptr;
  6903. char comfirmstr[20];
  6904. //int n_localAuthorizations = 0;
  6905. int checkState_Faulted = FALSE;
  6906. DEBUG_INFO("handleSendLocalListRequest\n");
  6907. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6908. {
  6909. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6910. goto end;
  6911. }
  6912. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6913. {
  6914. //check Charge Point state
  6915. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6916. {
  6917. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6918. {
  6919. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6920. }
  6921. }
  6922. for (int index = 0; index < CCS_QUANTITY; index++)
  6923. {
  6924. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6925. {
  6926. checkState_Faulted = TRUE; //OCPP Status
  6927. }
  6928. }
  6929. for (int index = 0; index < GB_QUANTITY; index++)
  6930. {
  6931. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6932. {
  6933. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6934. }
  6935. }
  6936. }
  6937. else
  6938. {
  6939. //check Charge Point state
  6940. for (int index = 0; index < AC_QUANTITY; index++)
  6941. {
  6942. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6943. {
  6944. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6945. }
  6946. }
  6947. }// END FOR AC ELSE
  6948. if(checkState_Faulted == TRUE)
  6949. {
  6950. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6951. goto end;
  6952. }
  6953. //listVersion
  6954. c = 0;
  6955. loc = strstr(payload, listsearch);
  6956. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  6957. {
  6958. sstr[c] = loc[strlen("listVersion")+2+c];
  6959. c++;
  6960. }
  6961. sstr[c] = '\0';
  6962. listVersionInt = atoi(sstr);
  6963. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6964. //updateType
  6965. loc = strstr(payload, updateTypesearch);
  6966. c = 0;
  6967. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6968. {
  6969. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6970. c++;
  6971. }
  6972. sstr[c] = '\0';
  6973. strcpy(updateTypestr, sstr);
  6974. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6975. //localAuthorizationList
  6976. memset(sstr ,0, sizeof(sstr) );
  6977. loc = strstr(payload, localAuthorizationListsearch);
  6978. if(loc != NULL) // localAuthorizationList is not NULL
  6979. {
  6980. //Check UpdateType
  6981. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6982. {
  6983. //Local list full update
  6984. printf("Local list full update.\n");
  6985. OCPP_cleanLocalList();
  6986. }
  6987. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6988. {
  6989. //Local list different update
  6990. printf("Local list different update.\n");
  6991. OCPP_getListVerion();
  6992. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6993. {
  6994. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6995. goto end;
  6996. }
  6997. }
  6998. else
  6999. {
  7000. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7001. goto end;
  7002. }
  7003. c = 0;
  7004. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7005. {
  7006. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7007. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7008. c++;
  7009. }
  7010. sstr[c] = '\0';
  7011. //DEBUG_INFO("sstr=%s\n", sstr);
  7012. //parsing strings to words
  7013. i = 0;
  7014. pch = strtok(sstr,delim1);
  7015. while (pch != NULL)
  7016. {
  7017. strcpy(CardList[i], pch);
  7018. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7019. pch = strtok (NULL, delim1);
  7020. i = i + 1;
  7021. }
  7022. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7023. //local Authorizations List Numbers
  7024. //n_localAuthorizations = i;
  7025. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7026. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7027. c= 0;
  7028. while(c < i)
  7029. {
  7030. //Search "IdToken"
  7031. memset(sstr ,0, sizeof(sstr) );
  7032. loc = strstr(CardList[c], "idTag");
  7033. int j = 0;
  7034. while (loc[3+strlen("idTag")+j] != '\"')
  7035. {
  7036. sstr[j] = loc[3+strlen("idTag")+j];
  7037. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7038. j++;
  7039. }
  7040. sstr[j] = '\0';
  7041. strcpy(idTagstr, sstr);
  7042. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7043. //Search "expiryDate"
  7044. memset(sstr ,0, sizeof(sstr) );
  7045. loc = strstr(CardList[c], "expiryDate");
  7046. j = 0;
  7047. if(loc != NULL)
  7048. {
  7049. while (loc[3+strlen("expiryDate")+j] != '\"')
  7050. {
  7051. sstr[j] = loc[3+strlen("expiryDate")+j];
  7052. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7053. j++;
  7054. }
  7055. sstr[j] = '\0';
  7056. strcpy(expiryDate, sstr);
  7057. }
  7058. else
  7059. {
  7060. strcpy(expiryDate, "");
  7061. }
  7062. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7063. //Search "parentIdTag"
  7064. memset(sstr ,0, sizeof(sstr) );
  7065. loc = strstr(CardList[c], "parentIdTag");
  7066. j = 0;
  7067. if(loc != NULL)
  7068. {
  7069. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7070. {
  7071. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7072. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7073. j++;
  7074. }
  7075. sstr[j] = '\0';
  7076. strcpy(parentIdTag, sstr);
  7077. }
  7078. else
  7079. {
  7080. strcpy(parentIdTag, "");
  7081. }
  7082. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7083. //Search "status"
  7084. memset(sstr ,0, sizeof(sstr) );
  7085. loc = strstr(CardList[c], "status");
  7086. j = 0;
  7087. while (loc[3+strlen("status")+j] != '\"')
  7088. {
  7089. sstr[j] = loc[3+strlen("status")+j];
  7090. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7091. j++;
  7092. }
  7093. sstr[j] = '\0';
  7094. strcpy(idTagstatus, sstr);
  7095. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7096. OCPP_getIdTag(idTagstr);
  7097. //OCPP_getIdTag("test"); For Test
  7098. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7099. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7100. {
  7101. //Local list full update
  7102. DEBUG_INFO("Local list full update.\n");
  7103. // update list
  7104. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7105. OCPP_get_TableAuthlocalAllData();
  7106. }
  7107. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7108. {
  7109. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7110. {
  7111. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7112. }
  7113. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7114. {
  7115. OCPP_deleteIdTag(idTagstr);
  7116. }
  7117. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7118. {
  7119. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7120. }
  7121. }
  7122. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7123. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7124. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7125. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7126. c++;
  7127. }
  7128. }
  7129. else
  7130. {
  7131. //Check UpdateType
  7132. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7133. {
  7134. //Local list full update
  7135. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7136. OCPP_cleanLocalList();
  7137. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7138. goto end;
  7139. }
  7140. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7141. {
  7142. //Local list different update
  7143. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7144. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7145. goto end;
  7146. }
  7147. }
  7148. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7149. end:
  7150. sendSendLocalListConfirmation(uuid, comfirmstr);
  7151. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7152. return result;
  7153. }
  7154. #define MAX 200
  7155. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7156. {
  7157. mtrace();
  7158. int result = FAIL;
  7159. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7160. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7161. char chargingProfilePurposeStr[30]={0};
  7162. char chargingProfileKindStr[16]={0};
  7163. char recurrencyKindStr[10]={0};
  7164. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7165. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7166. int chargingSchedulePeriodCount = 0;
  7167. //int updateflag = FALSE;
  7168. char comfirmstr[20]={0};
  7169. int meet= FALSE;
  7170. char sstr[10]={0};
  7171. int c = 0;
  7172. char *loc;
  7173. FILE *fptr1;//, *fptr2;
  7174. //int lno=0;//, linectr = 0;
  7175. //int modifyflag = FALSE;
  7176. char filename[MAX]={0};
  7177. char tempfile[] = "../Storage/OCPP/temp.json";
  7178. //int resultRename=0;
  7179. char rmFileCmd[50]={0};
  7180. char tempchargingProfilePurposeStr[30]={0};
  7181. //[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}}}]
  7182. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7183. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7184. //*********************connectorId***************************/
  7185. loc = strstr(payload, "connectorId");
  7186. c = 0;
  7187. memset(sstr ,0, sizeof(sstr) );
  7188. while (loc[strlen("connectorId")+2+c] != ',')
  7189. {
  7190. sstr[c] = loc[strlen("connectorId")+2+c];
  7191. c++;
  7192. }
  7193. sstr[c] = '\0';
  7194. connectorIdInt = atoi(sstr);
  7195. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7196. {
  7197. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7198. }
  7199. else
  7200. {
  7201. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7202. }
  7203. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7204. //*********************chargingProfileId***************************/
  7205. loc = strstr(payload, "chargingProfileId");
  7206. c = 0;
  7207. memset(sstr ,0, sizeof(sstr) );
  7208. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7209. {
  7210. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7211. c++;
  7212. }
  7213. sstr[c] = '\0';
  7214. chargingProfileIdInt = atoi(sstr);
  7215. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7216. {
  7217. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7218. }
  7219. else
  7220. {
  7221. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7222. }
  7223. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7224. //*********************transactionId***************************/
  7225. loc = strstr(payload, "transactionId");
  7226. if(loc != NULL)
  7227. {
  7228. c = 0;
  7229. memset(sstr ,0, sizeof(sstr) );
  7230. while (loc[strlen("transactionId")+2+c] != ',')
  7231. {
  7232. sstr[c] = loc[strlen("transactionId")+2+c];
  7233. c++;
  7234. }
  7235. sstr[c] = '\0';
  7236. transactionIdInt = atoi(sstr);
  7237. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7238. {
  7239. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7240. }
  7241. else
  7242. {
  7243. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7244. }
  7245. }
  7246. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7247. //*********************stackLevel***************************/
  7248. loc = strstr(payload, "stackLevel");
  7249. c = 0;
  7250. memset(sstr ,0, sizeof(sstr) );
  7251. while (loc[strlen("stackLevel")+2+c] != ',')
  7252. {
  7253. sstr[c] = loc[strlen("stackLevel")+2+c];
  7254. c++;
  7255. }
  7256. sstr[c] = '\0';
  7257. stackLevelInt = atoi(sstr);
  7258. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7259. {
  7260. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7261. }
  7262. else
  7263. {
  7264. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7265. }
  7266. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7267. //*********************chargingProfilePurpose***************************/
  7268. loc = strstr(payload, "chargingProfilePurpose");
  7269. c = 0;
  7270. memset(sstr ,0, sizeof(sstr) );
  7271. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7272. {
  7273. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7274. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7275. c++;
  7276. }
  7277. sstr[c] = '\0';
  7278. strcpy(chargingProfilePurposeStr,sstr);
  7279. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7280. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7281. {
  7282. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7283. }
  7284. else
  7285. {
  7286. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7287. }
  7288. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7289. //*********************chargingProfileKind***************************/
  7290. loc = strstr(payload, "chargingProfileKind");
  7291. c = 0;
  7292. memset(sstr ,0, sizeof(sstr) );
  7293. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7294. {
  7295. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7296. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7297. c++;
  7298. }
  7299. sstr[c] = '\0';
  7300. strcpy(chargingProfileKindStr,sstr);
  7301. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7302. {
  7303. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7304. }
  7305. else
  7306. {
  7307. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7308. }
  7309. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7310. //*********************recurrencyKind***************************/
  7311. loc = strstr(payload, "recurrencyKind");
  7312. if(loc != NULL)
  7313. {
  7314. c = 0;
  7315. memset(sstr ,0, sizeof(sstr) );
  7316. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7317. {
  7318. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7319. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7320. c++;
  7321. }
  7322. sstr[c] = '\0';
  7323. strcpy(recurrencyKindStr,sstr);
  7324. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7325. {
  7326. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7327. }
  7328. else
  7329. {
  7330. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7331. }
  7332. }
  7333. else
  7334. {
  7335. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7336. {
  7337. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7338. }
  7339. else
  7340. {
  7341. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7342. }
  7343. }
  7344. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7345. //*********************validFrom***************************/
  7346. loc = strstr(payload, "validFrom");
  7347. if(loc != NULL)
  7348. {
  7349. c = 0;
  7350. memset(sstr ,0, sizeof(sstr) );
  7351. while (loc[3+strlen("validFrom")+c] != '\"')
  7352. {
  7353. sstr[c] = loc[3+strlen("validFrom")+c];
  7354. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7355. c++;
  7356. }
  7357. sstr[c] = '\0';
  7358. strcpy(validFromStr,sstr);
  7359. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7360. {
  7361. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7362. }
  7363. else
  7364. {
  7365. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7366. }
  7367. }
  7368. else
  7369. {
  7370. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7371. {
  7372. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7373. }
  7374. else
  7375. {
  7376. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7377. }
  7378. }
  7379. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7380. //*********************validTo***************************/
  7381. loc = strstr(payload, "validTo");
  7382. if(loc != NULL)
  7383. {
  7384. c = 0;
  7385. memset(sstr ,0, sizeof(sstr) );
  7386. while (loc[3+strlen("validTo")+c] != '\"')
  7387. {
  7388. sstr[c] = loc[3+strlen("validTo")+c];
  7389. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7390. c++;
  7391. }
  7392. sstr[c] = '\0';
  7393. strcpy(validToStr,sstr);
  7394. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7395. {
  7396. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7397. }
  7398. else
  7399. {
  7400. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7401. }
  7402. }
  7403. else
  7404. {
  7405. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7406. {
  7407. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7408. }
  7409. else
  7410. {
  7411. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7412. }
  7413. }
  7414. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7415. //*********************duration***************************/
  7416. loc = strstr(payload, "duration");
  7417. if(loc != NULL)
  7418. {
  7419. c = 0;
  7420. memset(sstr ,0, sizeof(sstr) );
  7421. while (loc[strlen("duration")+2+c] != ',')
  7422. {
  7423. sstr[c] = loc[strlen("duration")+2+c];
  7424. c++;
  7425. }
  7426. sstr[c] = '\0';
  7427. durationInt = atoi(sstr);
  7428. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7429. {
  7430. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7431. }
  7432. else
  7433. {
  7434. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7435. }
  7436. }
  7437. else
  7438. {
  7439. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7440. {
  7441. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7442. }
  7443. else
  7444. {
  7445. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7446. }
  7447. }
  7448. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7449. //*********************startSchedule***************************/
  7450. loc = strstr(payload, "startSchedule");
  7451. if(loc != NULL)
  7452. {
  7453. c = 0;
  7454. memset(sstr ,0, sizeof(sstr) );
  7455. while (loc[3+strlen("startSchedule")+c] != '\"')
  7456. {
  7457. sstr[c] = loc[3+strlen("startSchedule")+c];
  7458. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7459. c++;
  7460. }
  7461. sstr[c] = '\0';
  7462. strcpy(startScheduleStr,sstr);
  7463. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7464. {
  7465. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7466. }
  7467. else
  7468. {
  7469. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7470. }
  7471. }
  7472. else
  7473. {
  7474. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7475. {
  7476. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7477. }
  7478. else
  7479. {
  7480. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7481. }
  7482. }
  7483. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7484. //*********************chargingRateUnit***************************/
  7485. loc = strstr(payload, "chargingRateUnit");
  7486. if(loc != NULL)
  7487. {
  7488. c = 0;
  7489. memset(sstr ,0, sizeof(sstr) );
  7490. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7491. {
  7492. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7494. c++;
  7495. }
  7496. sstr[c] = '\0';
  7497. strcpy(chargingRateUnitStr,sstr);
  7498. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7499. {
  7500. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7501. }
  7502. else
  7503. {
  7504. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7505. }
  7506. }
  7507. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7508. //****************chargingSchedulePeriod count start*******************/
  7509. int what_len = strlen("startPeriod");
  7510. char tempChargingProfile[1000]={0};
  7511. strcpy(tempChargingProfile,(const char*)payload);
  7512. char *where = tempChargingProfile;
  7513. if (what_len)
  7514. {
  7515. while ((where = strstr(where, "startPeriod"))) {
  7516. where += what_len;
  7517. chargingSchedulePeriodCount++;
  7518. }
  7519. }
  7520. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7521. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7522. //where = payload;
  7523. int templength = 0;
  7524. //int searchstart = 0;
  7525. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7526. {
  7527. //****************startPeriod*******************/
  7528. c=0;
  7529. loc = strstr(tempChargingProfile + templength, "startPeriod");
  7530. memset(sstr ,0, sizeof(sstr) );
  7531. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7532. {
  7533. sstr[c] = loc[strlen("startPeriod")+2+c];
  7534. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7535. c++;
  7536. }
  7537. sstr[c] = '\0';
  7538. startPeriodInt[periodNums] = atoi(sstr);
  7539. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7540. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7541. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7542. {
  7543. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7544. }
  7545. else
  7546. {
  7547. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7548. }
  7549. templength = strlen("startPeriod")+2+c;
  7550. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7551. //****************limit*******************/
  7552. c=0;
  7553. loc = strstr(tempChargingProfile + templength, "limit");
  7554. memset(sstr ,0, sizeof(sstr) );
  7555. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7556. {
  7557. sstr[c] = loc[strlen("limit")+2+c];
  7558. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7559. c++;
  7560. }
  7561. sstr[c] = '\0';
  7562. limitflaot[periodNums] = atof(sstr);
  7563. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7564. {
  7565. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7566. }
  7567. else
  7568. {
  7569. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7570. }
  7571. templength = templength + strlen("limit")+2+c;
  7572. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7573. //****************numberPhases*******************/
  7574. loc = strstr(tempChargingProfile + templength, "numberPhases");
  7575. if(loc != NULL)
  7576. {
  7577. c=0;
  7578. memset(sstr ,0, sizeof(sstr) );
  7579. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7580. {
  7581. sstr[c] = loc[strlen("numberPhases")+2+c];
  7582. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7583. c++;
  7584. }
  7585. sstr[c] = '\0';
  7586. numberPhasesInt[periodNums] = atoi(sstr);
  7587. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7588. {
  7589. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7590. }
  7591. else
  7592. {
  7593. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7594. }
  7595. templength = templength + strlen("numberPhases")+2+c;
  7596. }
  7597. //where = loc;
  7598. }
  7599. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7600. //****************chargingSchedulePeriod count end*******************/
  7601. //*********************minChargingRate***************************/
  7602. loc = strstr(payload, "minChargingRate");
  7603. if(loc != NULL)
  7604. {
  7605. c = 0;
  7606. memset(sstr ,0, sizeof(sstr) );
  7607. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7608. {
  7609. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7610. c++;
  7611. }
  7612. sstr[c] = '\0';
  7613. minChargingRateFloat = atof(sstr);
  7614. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7615. {
  7616. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7617. }
  7618. else
  7619. {
  7620. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7621. }
  7622. }
  7623. else
  7624. {
  7625. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7626. {
  7627. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7628. }
  7629. else
  7630. {
  7631. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7632. }
  7633. }
  7634. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7635. {
  7636. //printf("set chargingProfile 1-2\n");
  7637. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7638. if(connectorIdInt != 0)
  7639. {
  7640. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7641. goto end;
  7642. }
  7643. strcpy(filename, ChargePointMaxProfile_JSON );
  7644. fptr1 = fopen(filename, "r");
  7645. if (!fptr1)
  7646. {
  7647. //file not exist
  7648. DEBUG_INFO("Unable to open the input file!!\n");
  7649. fptr1 = fopen(filename, "w+");
  7650. }
  7651. fclose(fptr1);
  7652. }
  7653. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7654. {
  7655. //printf("set chargingProfile 1-3\n");
  7656. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7657. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7658. {
  7659. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7660. goto end;
  7661. }
  7662. switch(connectorIdInt)
  7663. {
  7664. case 0:
  7665. strcpy(filename, TxDefaultProfile_0_JSON );
  7666. break;
  7667. case 1:
  7668. strcpy(filename, TxDefaultProfile_1_JSON );
  7669. break;
  7670. case 2:
  7671. strcpy(filename, TxDefaultProfile_2_JSON );
  7672. break;
  7673. default:
  7674. strcpy(filename, TxDefaultProfile_0_JSON );
  7675. break;
  7676. }
  7677. fptr1 = fopen(filename, "r");
  7678. if (!fptr1)
  7679. {
  7680. //file not exist
  7681. //DEBUG_INFO("Unable to open the input file!!\n");
  7682. fptr1 = fopen(filename, "w+");
  7683. }
  7684. fclose(fptr1);
  7685. }
  7686. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7687. {
  7688. //printf("set chargingProfile 1-4\n");
  7689. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7690. //check Transaction active
  7691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7692. {
  7693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7694. {
  7695. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7696. {
  7697. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7698. {
  7699. meet = TRUE;
  7700. break;
  7701. }
  7702. }
  7703. }
  7704. }
  7705. for (int index = 0; index < CCS_QUANTITY; index++)
  7706. {
  7707. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7708. {
  7709. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7710. {
  7711. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7712. {
  7713. meet = TRUE;
  7714. break;
  7715. }
  7716. }
  7717. }
  7718. }
  7719. for (int index = 0; index < GB_QUANTITY; index++)
  7720. {
  7721. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7722. {
  7723. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7724. {
  7725. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7726. {
  7727. meet = TRUE;
  7728. break;
  7729. }
  7730. }
  7731. }
  7732. }
  7733. if(meet == FALSE)
  7734. {
  7735. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7736. goto end;
  7737. }
  7738. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7739. {
  7740. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7741. goto end;
  7742. }
  7743. switch(connectorIdInt)
  7744. {
  7745. case 0:
  7746. break;
  7747. case 1:
  7748. strcpy(filename, TxProfile_1_JSON);
  7749. break;
  7750. case 2:
  7751. strcpy(filename, TxProfile_2_JSON);
  7752. break;
  7753. default:
  7754. strcpy(filename, TxProfile_1_JSON);
  7755. break;
  7756. }
  7757. fptr1 = fopen(filename, "r");
  7758. if (!fptr1)
  7759. {
  7760. //file not exist
  7761. DEBUG_INFO("Unable to open the input file!!\n");
  7762. fptr1 = fopen(filename, "w+");
  7763. }
  7764. fclose(fptr1);
  7765. }
  7766. //**********************************Write to File********************************************************/
  7767. FILE *infile;
  7768. FILE *outfile;
  7769. // open file for writing
  7770. infile = fopen (filename, "r");
  7771. outfile = fopen (tempfile, "w");
  7772. int d =0;
  7773. d = fgetc(infile);
  7774. //DEBUG_INFO("d:%d\n",d);
  7775. rewind(infile);
  7776. //*检测到文件结束标识返回1,否则返回0。*/
  7777. if(d == EOF)
  7778. {
  7779. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7780. fprintf(outfile,"%s\n",payload);
  7781. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7782. fclose(infile);
  7783. fclose(outfile);
  7784. sprintf(rmFileCmd,"rm -f %s",filename);
  7785. system(rmFileCmd);
  7786. rename(tempfile, filename);
  7787. #if 0
  7788. resultRename = rename(tempfile, filename);
  7789. if(resultRename == 0)
  7790. {
  7791. DEBUG_INFO("File chargingProfile renamed successfully");
  7792. }
  7793. else
  7794. {
  7795. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7796. }
  7797. #endif
  7798. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7799. //system(rmFileCmd);
  7800. }
  7801. else
  7802. {
  7803. char buf[1000]={0};
  7804. int ChargingProfileAdded = FALSE;
  7805. while (fgets(buf, sizeof(buf), infile) != NULL)
  7806. {
  7807. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7808. //*************************tempconnectorIdInt*********************************/
  7809. loc = strstr(buf, "connectorId");
  7810. c = 0;
  7811. memset(sstr ,0, sizeof(sstr) );
  7812. while (loc[strlen("connectorId")+2+c] != ',')
  7813. {
  7814. sstr[c] = loc[strlen("connectorId")+2+c];
  7815. c++;
  7816. }
  7817. sstr[c] = '\0';
  7818. tempconnectorIdInt = atoi(sstr);
  7819. //*************************tempchargingProfileIdInt*********************************/
  7820. loc = strstr(buf, "chargingProfileId");
  7821. c = 0;
  7822. memset(sstr ,0, sizeof(sstr) );
  7823. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7824. {
  7825. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7826. c++;
  7827. }
  7828. sstr[c] = '\0';
  7829. tempchargingProfileIdInt = atoi(sstr);
  7830. //*************************tempstackLevelInt*********************************/
  7831. loc = strstr(buf, "stackLevel");
  7832. c = 0;
  7833. memset(sstr ,0, sizeof(sstr) );
  7834. while (loc[strlen("stackLevel")+2+c] != ',')
  7835. {
  7836. sstr[c] = loc[strlen("stackLevel")+2+c];
  7837. c++;
  7838. }
  7839. sstr[c] = '\0';
  7840. tempstackLevelInt = atoi(sstr);
  7841. //*************************tempchargingProfilePurposeStr*********************************/
  7842. loc = strstr(payload, "chargingProfilePurpose");
  7843. c = 0;
  7844. memset(sstr ,0, sizeof(sstr) );
  7845. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7846. {
  7847. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7848. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7849. c++;
  7850. }
  7851. sstr[c] = '\0';
  7852. strcpy(tempchargingProfilePurposeStr,sstr);
  7853. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7854. {
  7855. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7856. {
  7857. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7858. if(ChargingProfileAdded == FALSE)
  7859. {
  7860. fprintf(outfile,"%s\n",payload);
  7861. ChargingProfileAdded = TRUE;
  7862. }
  7863. }
  7864. else
  7865. {
  7866. if(tempstackLevelInt < stackLevelInt)
  7867. {
  7868. if(ChargingProfileAdded == FALSE)
  7869. {
  7870. fprintf(outfile,"%s\n",payload);
  7871. ChargingProfileAdded = TRUE;
  7872. fprintf(outfile,"%s\n",buf);
  7873. }
  7874. else
  7875. {
  7876. fprintf(outfile,"%s\n",buf);
  7877. }
  7878. }
  7879. else
  7880. {
  7881. if(ChargingProfileAdded == FALSE)
  7882. {
  7883. fprintf(outfile,"%s\n",buf);
  7884. fprintf(outfile,"%s\n",payload);
  7885. ChargingProfileAdded = TRUE;
  7886. }
  7887. else
  7888. {
  7889. fprintf(outfile,"%s\n",buf);
  7890. }
  7891. }
  7892. }
  7893. }
  7894. else
  7895. {
  7896. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7897. {
  7898. if(ChargingProfileAdded == FALSE)
  7899. {
  7900. fprintf(outfile,"%s\n",payload);
  7901. ChargingProfileAdded = TRUE;
  7902. fprintf(outfile,"%s\n",buf);
  7903. }
  7904. else
  7905. {
  7906. fprintf(outfile,"%s\n",buf);
  7907. }
  7908. }
  7909. else if(tempstackLevelInt < stackLevelInt)
  7910. {
  7911. if(ChargingProfileAdded == FALSE)
  7912. {
  7913. fprintf(outfile,"%s\n",payload);
  7914. ChargingProfileAdded = TRUE;
  7915. fprintf(outfile,"%s\n",buf);
  7916. }
  7917. else
  7918. {
  7919. fprintf(outfile,"%s\n",buf);
  7920. }
  7921. }
  7922. else
  7923. {
  7924. if(ChargingProfileAdded == FALSE)
  7925. {
  7926. fprintf(outfile,"%s\n",buf);
  7927. fprintf(outfile,"%s\n",payload);
  7928. ChargingProfileAdded = TRUE;
  7929. }
  7930. else
  7931. {
  7932. fprintf(outfile,"%s\n",buf);
  7933. }
  7934. }
  7935. }
  7936. } // end of while loop
  7937. fclose(infile);
  7938. fclose(outfile);
  7939. sprintf(rmFileCmd,"rm -f %s",filename);
  7940. system(rmFileCmd);
  7941. rename(tempfile, filename);
  7942. #if 0
  7943. resultRename = rename(tempfile, filename);
  7944. if(resultRename == 0)
  7945. {
  7946. DEBUG_INFO("File chargingProfile renamed successfully");
  7947. }
  7948. else
  7949. {
  7950. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7951. }
  7952. #endif
  7953. result = TRUE;
  7954. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7955. }
  7956. end:
  7957. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7958. return result;
  7959. return result;
  7960. }
  7961. int handleTriggerMessageRequest(char *uuid, char *payload)
  7962. {
  7963. mtrace();
  7964. int result = FAIL;
  7965. int connectorIdIsNULL = FALSE;
  7966. int connectorIdInt =0;
  7967. char sstr[40]={0};
  7968. char requestedMessagestr[40]={0};
  7969. char comfirmstr[20]={0};
  7970. int c = 0;
  7971. char *loc;
  7972. DEBUG_INFO("handleTriggerMessageRequest\n");
  7973. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7974. c = 0;
  7975. loc = strstr(payload, "requestedMessage");
  7976. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7977. {
  7978. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7979. c++;
  7980. }
  7981. sstr[c] = '\0';
  7982. strcpy(requestedMessagestr, sstr);
  7983. c = 0;
  7984. loc = strstr(payload, "connectorId");
  7985. if(loc == NULL)
  7986. {
  7987. connectorIdIsNULL = TRUE;
  7988. }
  7989. else
  7990. {
  7991. memset(sstr ,0, sizeof(sstr) );
  7992. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7993. {
  7994. sstr[c] = loc[strlen("connectorId")+2+c];
  7995. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7996. c++;
  7997. }
  7998. sstr[c] = '\0';
  7999. connectorIdInt = atoi(sstr);
  8000. }
  8001. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8002. {
  8003. //connectorIdInt = json_object_get_int(connectorId);
  8004. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8005. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8006. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8007. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8008. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8009. }
  8010. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8011. {
  8012. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8013. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8014. return TRUE;
  8015. }
  8016. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8017. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8018. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8019. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8020. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8021. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8022. {
  8023. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8024. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8025. return TRUE;
  8026. }
  8027. else
  8028. {
  8029. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8030. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8031. }
  8032. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8033. {
  8034. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8035. {
  8036. FirmwareStatusNotificationStatus = 3;
  8037. }
  8038. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8039. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8040. }
  8041. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8042. {
  8043. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8044. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8045. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8046. }
  8047. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8048. {
  8049. sendBootNotificationRequest();
  8050. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8051. }
  8052. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8053. {
  8054. sendHeartbeatRequest(connectorIdInt);
  8055. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8056. }
  8057. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8058. {
  8059. if(connectorIdIsNULL == FALSE)
  8060. {
  8061. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8062. {
  8063. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8064. sendMeterValuesRequest(connectorIdInt -1);
  8065. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8066. }
  8067. }
  8068. else
  8069. {
  8070. for(int idx=0;idx< gunTotalNumber;idx++)
  8071. {
  8072. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8073. sendMeterValuesRequest(idx);
  8074. }
  8075. }
  8076. }
  8077. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8078. {
  8079. if(connectorIdIsNULL == FALSE)
  8080. {
  8081. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8082. {
  8083. sendStatusNotificationRequest(connectorIdInt -1);
  8084. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8085. }
  8086. }
  8087. else
  8088. {
  8089. for(int idx=0;idx< gunTotalNumber;idx++)
  8090. sendStatusNotificationRequest(idx);
  8091. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8092. }
  8093. }
  8094. return result;
  8095. }
  8096. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8097. {
  8098. mtrace();
  8099. int result = FAIL;
  8100. char sstr[6]={0};
  8101. int connectorIdInt =0;
  8102. char comfirmstr[20]={0};
  8103. int c = 0;
  8104. char *loc;
  8105. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8106. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8107. c = 0;
  8108. loc = strstr(payload, "connectorId");
  8109. memset(sstr ,0, sizeof(sstr) );
  8110. while (loc[strlen("connectorId")+2+c] != '}')
  8111. {
  8112. sstr[c] = loc[strlen("connectorId")+2+c];
  8113. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8114. c++;
  8115. }
  8116. sstr[c] = '\0';
  8117. connectorIdInt = atoi(sstr);
  8118. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8119. if(gunTotalNumber == 0)
  8120. {
  8121. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8122. goto end;
  8123. }
  8124. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8125. {
  8126. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8127. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8128. goto end;
  8129. }
  8130. else
  8131. {
  8132. //check Transaction active
  8133. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8134. {
  8135. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8136. {
  8137. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8138. {
  8139. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8140. }
  8141. }
  8142. for (int index = 0; index < CCS_QUANTITY; index++)
  8143. {
  8144. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8145. {
  8146. //stop Transaction
  8147. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8148. }
  8149. }
  8150. for (int index = 0; index < GB_QUANTITY; index++)
  8151. {
  8152. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8153. {
  8154. //stop Transaction
  8155. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8156. }
  8157. }
  8158. }
  8159. else
  8160. {
  8161. for (int index = 0; index < AC_QUANTITY; index++)
  8162. {
  8163. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8164. {
  8165. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8166. }
  8167. }
  8168. }// END FOR AC ELSE
  8169. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8170. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8171. result = TRUE;
  8172. return result;
  8173. }
  8174. end:
  8175. //json_object_put(obj); --- remove temporally
  8176. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8177. return result;
  8178. }
  8179. static char UpdateFirmwarepayloadData[300]={0};
  8180. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8181. {
  8182. mtrace();
  8183. int result = FAIL;
  8184. pthread_t t;
  8185. sendUpdateFirmwareConfirmation(uuid);
  8186. memset(UpdateFirmwarepayloadData, 0, 300);
  8187. strcpy(UpdateFirmwarepayloadData, payload);
  8188. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8189. ////pthread_join(t, NULL); //
  8190. //pthread_detach(t);
  8191. //sendUpdateFirmwareConfirmation(uuid);
  8192. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8193. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8194. return result;
  8195. }
  8196. void *UpdateFirmwareProcess(void *data)
  8197. {
  8198. pthread_detach(pthread_self());
  8199. mtrace();
  8200. int retriesInt =0, retryIntervalInt=0;
  8201. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8202. int port=0;
  8203. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8204. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8205. //char comfirmstr[20];
  8206. int isSuccess = 0;
  8207. char ftpbuf[200];
  8208. char temp[100];
  8209. char * pch;
  8210. int retriesISNULL=FALSE;
  8211. int retryInterval=FALSE;
  8212. int c = 0;
  8213. //int i = 0;
  8214. char *loc;
  8215. char sstr[300]={ 0 };
  8216. char str[300]={ 0 };
  8217. //char *str = (char*) data; // ? ?輸入資 ?
  8218. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8219. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8220. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8221. //***************location **************/
  8222. loc = strstr(str, "location");
  8223. memset(sstr ,0, sizeof(sstr) );
  8224. c = 0;
  8225. while (loc[3+strlen("location")+c] != '\"')
  8226. {
  8227. sstr[c] = loc[3+strlen("location")+c];
  8228. c++;
  8229. }
  8230. sstr[c] = '\0';
  8231. strcpy(locationstr, sstr);
  8232. //***************retries**************/
  8233. c = 0;
  8234. loc = strstr(str, "retries");
  8235. if(loc == NULL)
  8236. {
  8237. retriesISNULL=TRUE;
  8238. }
  8239. else
  8240. {
  8241. memset(sstr ,0, sizeof(sstr) );
  8242. while (loc[strlen("retries")+2+c] != ',')
  8243. {
  8244. sstr[c] = loc[strlen("retries")+2+c];
  8245. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8246. c++;
  8247. }
  8248. sstr[c] = '\0';
  8249. }
  8250. if(retriesISNULL == FALSE)
  8251. {
  8252. retriesInt = atoi(sstr);
  8253. }
  8254. //***************retrieveDate **************/
  8255. loc = strstr(str, "retrieveDate");
  8256. memset(sstr ,0, sizeof(sstr) );
  8257. c = 0;
  8258. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8259. {
  8260. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8261. c++;
  8262. }
  8263. sstr[c] = '\0';
  8264. strcpy(retrieveDatestr, sstr);
  8265. //***************retryInterval **************/
  8266. c = 0;
  8267. loc = strstr(str, "retryInterval");
  8268. memset(sstr ,0, sizeof(sstr) );
  8269. if(loc == NULL)
  8270. {
  8271. retryInterval=TRUE;
  8272. }
  8273. else
  8274. {
  8275. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8276. {
  8277. sstr[c] = loc[strlen("retryInterval")+2+c];
  8278. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8279. c++;
  8280. }
  8281. sstr[c] = '\0';
  8282. }
  8283. if(retryInterval==FALSE)
  8284. {
  8285. retryIntervalInt = atoi(sstr);
  8286. }
  8287. memset(ftppath, 0, sizeof(ftppath));
  8288. memset(path, 0, sizeof(path));
  8289. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8290. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8291. if(strncmp(locationstr,"http", 4) == 0)
  8292. {
  8293. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8294. protocol, host, path);
  8295. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8296. // protocol, user, password, host, path);
  8297. sprintf(ftppath,"/%s", path);
  8298. //DEBUG_INFO("protocol =%s\n",protocol);
  8299. //DEBUG_INFO("host =%s\n",host);
  8300. //DEBUG_INFO("path =%s\n",path);
  8301. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8302. int ftppathlen=strlen(ftppath);
  8303. int i=1;
  8304. char filenametemp[50];
  8305. while(i < ftppathlen)
  8306. {
  8307. int len=ftppathlen-i;
  8308. if(ftppath[len]== 47) // '/' ascll code: 47
  8309. {
  8310. DEBUG_INFO("compare '/' all right\n");
  8311. break;
  8312. }
  8313. i=i+1;
  8314. }
  8315. memset(filenametemp, 0, sizeof(filenametemp));
  8316. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8317. filenametemp[i+1] = 0;
  8318. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8319. do{
  8320. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8321. sleep(retryIntervalInt);
  8322. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8323. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8324. if(!isSuccess)
  8325. {
  8326. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8327. }
  8328. else
  8329. {
  8330. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8331. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8332. isUpdateRequest = TRUE;
  8333. }
  8334. }
  8335. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8336. {
  8337. memset(ftpbuf, 0, sizeof(ftpbuf));
  8338. memset(temp, 0, sizeof(temp));
  8339. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8340. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8341. int ftppathlen=strlen(ftpbuf);
  8342. int i=1;
  8343. char filenametemp[50];
  8344. while(i < ftppathlen)
  8345. {
  8346. int len=ftppathlen-i;
  8347. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8348. {
  8349. DEBUG_INFO(" compare '/' all right\n");
  8350. break;
  8351. }
  8352. i=i+1;
  8353. }
  8354. memset(filenametemp, 0, sizeof(filenametemp));
  8355. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8356. filenametemp[i+1] = 0;
  8357. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8358. pch=strchr(temp,'@');
  8359. if(pch==NULL)
  8360. {
  8361. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8362. protocol, host, &port, path);
  8363. strcpy(user,"anonymous");
  8364. strcpy(password,"");
  8365. }
  8366. else
  8367. {
  8368. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8369. protocol, user, password, host, &port, path);
  8370. }
  8371. sscanf(host,"%[^/]%s",host1, path1);
  8372. sprintf(ftppath,"%s", path1);
  8373. //DEBUG_INFO("protocol =%s\n",protocol);
  8374. //DEBUG_INFO("user =%s\n",user);
  8375. //DEBUG_INFO("password =%s\n",password);
  8376. //DEBUG_INFO("host1 =%s\n",host1);
  8377. //DEBUG_INFO("port =%d\n",port);
  8378. //DEBUG_INFO("path1 =%s\n",path1);
  8379. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8380. //ftpFile(host, user, password, port, ftppath, fname);
  8381. //download firmware pthred
  8382. if(port == 0)
  8383. {
  8384. port = 21;
  8385. }
  8386. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8387. do{
  8388. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8389. sleep(retryIntervalInt);
  8390. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8391. if(!isSuccess)
  8392. {
  8393. //BulldogUtil.sleepMs(interval*1000);
  8394. DEBUG_INFO("Update firmware request and download file fail.\n");
  8395. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8396. }
  8397. else
  8398. {
  8399. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8400. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8401. isUpdateRequest = TRUE;
  8402. }
  8403. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8404. }
  8405. else
  8406. {
  8407. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8408. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8409. }
  8410. pthread_exit(NULL);
  8411. }
  8412. //==========================================
  8413. // Handle server response routine
  8414. //==========================================
  8415. void handleAuthorizeResponse(char *payload, int gun_index)
  8416. {
  8417. mtrace();
  8418. char expiryDatestr[30]={0};
  8419. char parentIdTagstr[20]={0};
  8420. char statusstr[20]={0};
  8421. char expiryDatestrtemp[30]={0};
  8422. char parentIdTagstrtemp[20]={0};
  8423. char IdTagstrtemp[20]={0};
  8424. char statusstrtemp[20]={0};
  8425. int expiryDateISNULL=FALSE;
  8426. int parentIdTagISNULL=FALSE;
  8427. char sstr[160]={ 0 };
  8428. char* filename = AuthorizationCache_JSON;
  8429. char tempfile[] = "../Storage/OCPP/temp.json";
  8430. int c = 0;
  8431. char *loc;
  8432. int resultRename=0;
  8433. int responseIdTagInfoAsZero= 0;
  8434. char rmFileCmd[50]={0};
  8435. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8436. //***********expiryDate*************/
  8437. loc = strstr(payload, "expiryDate");
  8438. memset(sstr ,0, sizeof(sstr) );
  8439. c = 0;
  8440. if(loc == NULL)
  8441. {
  8442. expiryDateISNULL = TRUE;
  8443. }
  8444. else
  8445. {
  8446. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8447. {
  8448. sstr[c] = loc[3+strlen("expiryDate")+c];
  8449. c++;
  8450. }
  8451. sstr[c] = '\0';
  8452. strcpy(expiryDatestr, sstr);
  8453. }
  8454. //***********parentIdTag*************/
  8455. loc = strstr(payload, "parentIdTag");
  8456. memset(sstr ,0, sizeof(sstr) );
  8457. c = 0;
  8458. if(loc == NULL)
  8459. {
  8460. parentIdTagISNULL = TRUE;
  8461. }
  8462. else
  8463. {
  8464. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8465. {
  8466. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8467. c++;
  8468. }
  8469. sstr[c] = '\0';
  8470. strcpy(parentIdTagstr, sstr);
  8471. }
  8472. //***********status*************/
  8473. loc = strstr(payload, "status");
  8474. memset(sstr ,0, sizeof(sstr) );
  8475. c = 0;
  8476. while (loc[3+strlen("status")+c] != '\"')
  8477. {
  8478. sstr[c] = loc[3+strlen("status")+c];
  8479. c++;
  8480. }
  8481. sstr[c] = '\0';
  8482. strcpy(statusstr, sstr);
  8483. if(expiryDateISNULL == FALSE)
  8484. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8485. if(parentIdTagISNULL == FALSE)
  8486. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8487. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8488. //Update idTag information to authorization cache if supproted
  8489. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8490. {
  8491. if((access(filename,F_OK))!=-1)
  8492. {
  8493. DEBUG_INFO("AuthorizationCache exist.\n");
  8494. }
  8495. else
  8496. {
  8497. DEBUG_INFO("AuthorizationCache not exist\n");
  8498. FILE *log = fopen(filename, "w+");
  8499. if(log == NULL)
  8500. {
  8501. DEBUG_INFO("log is NULL\n");
  8502. goto out;
  8503. }
  8504. else
  8505. {
  8506. fclose(log);
  8507. }
  8508. }
  8509. FILE *infile;
  8510. FILE *outfile;
  8511. // open file for writing
  8512. infile = fopen (filename, "r");
  8513. outfile = fopen (tempfile, "w");
  8514. //*检测到文件结束标识返回1,否则返回0。*/
  8515. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8516. int c;
  8517. c = fgetc(infile);
  8518. //DEBUG_INFO("c:%d\n",c);
  8519. rewind(infile);
  8520. if(c == EOF)
  8521. {
  8522. DEBUG_INFO("Orignal File is NULL\n");
  8523. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8524. {
  8525. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8526. }
  8527. else
  8528. {
  8529. strcpy(expiryDatestrtemp, "");
  8530. }
  8531. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8532. {
  8533. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8534. }
  8535. else
  8536. {
  8537. //write Authorize IdTag
  8538. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8539. }
  8540. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8541. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8542. fclose(infile);
  8543. fclose(outfile);
  8544. sprintf(rmFileCmd,"rm -f %s",filename);
  8545. system(rmFileCmd);
  8546. resultRename = rename(tempfile, filename);
  8547. if(resultRename == 0)
  8548. {
  8549. DEBUG_INFO("File renamed successfully");
  8550. }
  8551. else
  8552. {
  8553. DEBUG_INFO("Error: unable to rename the file");
  8554. }
  8555. }
  8556. else
  8557. {
  8558. char buf[160]={0};
  8559. while (fgets(buf, sizeof(buf), infile) != NULL)
  8560. {
  8561. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8562. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8563. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8564. memset(statusstr, 0, sizeof(statusstrtemp));
  8565. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8566. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8567. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8568. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8569. //------------------IdTag-----------------------
  8570. loc = strstr(buf, "idTag");
  8571. memset(sstr ,0, sizeof(sstr) );
  8572. c = 0;
  8573. while (loc[3+strlen("idTag")+c] != '\"')
  8574. {
  8575. sstr[c] = loc[3+strlen("idTag")+c];
  8576. c++;
  8577. }
  8578. sstr[c] = '\0';
  8579. strcpy(IdTagstrtemp,sstr);
  8580. //*********************expiryDate***************/
  8581. loc = strstr(buf, "expiryDate");
  8582. memset(sstr ,0, sizeof(sstr) );
  8583. c = 0;
  8584. while (loc[3+strlen("expiryDate")+c] != '\"')
  8585. {
  8586. sstr[c] = loc[3+strlen("expiryDate")+c];
  8587. c++;
  8588. }
  8589. sstr[c] = '\0';
  8590. strcpy(expiryDatestr,sstr);
  8591. //*********************parentIdTag***************/
  8592. loc = strstr(buf, "parentIdTag");
  8593. memset(sstr ,0, sizeof(sstr) );
  8594. c = 0;
  8595. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8596. {
  8597. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8598. c++;
  8599. }
  8600. sstr[c] = '\0';
  8601. strcpy(parentIdTagstr,sstr);
  8602. //*********************status***************/
  8603. loc = strstr(buf, "status");
  8604. memset(sstr ,0, sizeof(sstr) );
  8605. c = 0;
  8606. while (loc[3+strlen("status")+c] != '\"')
  8607. {
  8608. sstr[c] = loc[3+strlen("status")+c];
  8609. c++;
  8610. }
  8611. sstr[c] = '\0';
  8612. strcpy(statusstr,sstr);
  8613. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8614. {
  8615. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8616. responseIdTagInfoAsZero = 1;
  8617. }
  8618. else
  8619. {
  8620. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8621. }
  8622. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8623. {
  8624. //modify item
  8625. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8626. {
  8627. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8628. }
  8629. else
  8630. {
  8631. strcpy(expiryDatestrtemp, "");
  8632. }
  8633. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8634. {
  8635. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8636. }
  8637. else
  8638. {
  8639. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8640. }
  8641. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8642. }
  8643. else
  8644. {
  8645. //wrie original item
  8646. strcpy(expiryDatestrtemp, expiryDatestr);
  8647. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8648. strcpy(statusstrtemp, statusstr);
  8649. }
  8650. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8651. }
  8652. fclose(infile);
  8653. fclose(outfile);
  8654. sprintf(rmFileCmd,"rm -f %s",filename);
  8655. system(rmFileCmd);
  8656. resultRename = rename(tempfile, filename);
  8657. if(resultRename == 0)
  8658. {
  8659. DEBUG_INFO("File renamed successfully");
  8660. }
  8661. else
  8662. {
  8663. DEBUG_INFO("Error: unable to rename the file");
  8664. }
  8665. }
  8666. }
  8667. out:
  8668. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8669. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8670. authorizeRetryTimes = 0;
  8671. }
  8672. void handleBootNotificationResponse(char *payload, int gun_index)
  8673. {
  8674. mtrace();
  8675. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8676. char statusStr[12]={0};
  8677. char currentTimeStr[30]={0};
  8678. char *loc;
  8679. int intervalInt = 0;
  8680. int c = 0;
  8681. //double diff_t;
  8682. struct tm tp;
  8683. char buf[28]={0};
  8684. char timebuf[50]={0};
  8685. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8686. //*** interval ****/
  8687. c = 0;
  8688. loc = strstr(payload, "interval");
  8689. //printf("loc=%s\n",loc);
  8690. memset(sstr ,0, sizeof(sstr) );
  8691. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8692. {
  8693. sstr[c] = loc[strlen("interval")+2+c];
  8694. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8695. c++;
  8696. }
  8697. sstr[c] = '\0';
  8698. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8699. intervalInt = atoi(sstr);
  8700. //***status ****/
  8701. loc = strstr(payload, "status");
  8702. memset(sstr ,0, sizeof(sstr) );
  8703. c = 0;
  8704. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8705. {
  8706. sstr[c] = loc[3+strlen("status")+c];
  8707. c++;
  8708. }
  8709. sstr[c] = '\0';
  8710. strcpy(statusStr, sstr);
  8711. //***currentTime ****/
  8712. loc = strstr(payload, "currentTime");
  8713. //printf("loc=%s\n",loc);
  8714. memset(sstr ,0, sizeof(sstr) );
  8715. c = 0;
  8716. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8717. {
  8718. sstr[c] = loc[3+strlen("currentTime")+c];
  8719. c++;
  8720. }
  8721. sstr[c] = '\0';
  8722. strcpy(currentTimeStr, sstr);
  8723. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8724. HeartBeatWaitTime = BootNotificationInterval;
  8725. clientTime.Heartbeat=time((time_t*)NULL);
  8726. //write back to ShmOCPP16Data->BootNotification
  8727. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8728. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8729. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8730. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8731. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8732. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8733. {
  8734. server_sign = TRUE;
  8735. server_pending =FALSE;
  8736. }
  8737. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8738. {
  8739. server_pending = TRUE;
  8740. }
  8741. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8742. tp.tm_isdst = -1;
  8743. //time_t utc = mktime(&tp);
  8744. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8745. memset(timebuf, 0, sizeof timebuf);
  8746. sprintf(timebuf,"date -s '%s'",buf);
  8747. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8748. system(timebuf);
  8749. //==============================================
  8750. // RTC sync
  8751. //==============================================
  8752. system("/sbin/hwclock -w --systohc");
  8753. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8754. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8755. }
  8756. void handleDataTransferResponse(char *payload, int gun_index)
  8757. {
  8758. char sstr[160]={0};//sstr[200]={ 0 };
  8759. int c = 0;
  8760. char *loc;
  8761. DEBUG_INFO("handleDataTransferResponse ...\n");
  8762. loc = strstr(payload, "status");
  8763. printf("loc=%s\n",loc);
  8764. c = 0;
  8765. while (loc[3+strlen("status")+c] != '\"')
  8766. {
  8767. sstr[c] = loc[3+strlen("status")+c];
  8768. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8769. c++;
  8770. }
  8771. sstr[c] = '\0';
  8772. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8773. }
  8774. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8775. {
  8776. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8777. //struct json_object *obj;
  8778. // obj = json_tokener_parse(payload);
  8779. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8780. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8781. //No fields are defined.
  8782. }
  8783. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8784. {
  8785. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8786. //struct json_object *obj;
  8787. // obj = json_tokener_parse(payload);
  8788. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8789. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8790. //No fields are defined.
  8791. }
  8792. void handleHeartbeatResponse(char *payload, int gun_index)
  8793. {
  8794. mtrace();
  8795. //double diff_t;
  8796. struct tm tp;
  8797. char buf[28]={0};
  8798. char timebuf[50]={0};
  8799. char sstr[30]={ 0 };
  8800. int c = 0;
  8801. char *loc;
  8802. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8803. if((HeartBeatCount%360) == 0)
  8804. {
  8805. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8806. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8807. }
  8808. HeartBeatCount = HeartBeatCount + 1;
  8809. c = 0;
  8810. loc = strstr(payload, "currentTime");
  8811. memset(sstr ,0, sizeof(sstr) );
  8812. while (loc[3+strlen("currentTime")+c] != '\"')
  8813. {
  8814. sstr[c] = loc[3+strlen("currentTime")+c];
  8815. c++;
  8816. }
  8817. sstr[c] = '\0';
  8818. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8819. // #ifdef SystemLogMessage
  8820. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8821. // #endif
  8822. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8823. tp.tm_isdst = -1;
  8824. //time_t utc = mktime(&tp);
  8825. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8826. memset(timebuf, 0, sizeof timebuf);
  8827. sprintf(timebuf,"date -s '%s'",buf);
  8828. system(timebuf);
  8829. //==============================================
  8830. // RTC sync
  8831. //==============================================
  8832. system("/sbin/hwclock -w --systohc");
  8833. if(FirstHeartBeat == 0)
  8834. {
  8835. FirstHeartBeat = 1;
  8836. }
  8837. HeartBeatWithNOResponse = 0;
  8838. }
  8839. void handleMeterValuesResponse(char *payload, int gun_index)
  8840. {
  8841. mtrace();
  8842. //struct json_object *obj;
  8843. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8844. //No fields are defined.
  8845. }
  8846. void handleStartTransactionResponse(char *payload, int gun_index)
  8847. {
  8848. mtrace();
  8849. char sstr[28]={ 0 };
  8850. int c = 0;
  8851. char *loc;
  8852. int transactionIdInt = 0;
  8853. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8854. DEBUG_INFO("handleStartTransactionResponse\n");
  8855. //****************expiryDate********************/
  8856. loc = strstr(payload, "expiryDate");
  8857. if(loc == NULL)
  8858. {
  8859. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8860. }
  8861. else
  8862. {
  8863. c = 0;
  8864. memset(sstr ,0, sizeof(sstr) );
  8865. while (loc[3+strlen("expiryDate")+c] != '\"')
  8866. {
  8867. sstr[c] = loc[3+strlen("expiryDate")+c];
  8868. c++;
  8869. }
  8870. sstr[c] = '\0';
  8871. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8872. }
  8873. //****************parentIdTag********************/
  8874. loc = strstr(payload, "parentIdTag");
  8875. if(loc == NULL)
  8876. {
  8877. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8878. }
  8879. else
  8880. {
  8881. c = 0;
  8882. memset(sstr ,0, sizeof(sstr) );
  8883. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8884. {
  8885. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8886. c++;
  8887. }
  8888. sstr[c] = '\0';
  8889. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8890. }
  8891. //****************status********************/
  8892. loc = strstr(payload, "status");
  8893. if(loc == NULL)
  8894. {
  8895. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8896. }
  8897. else
  8898. {
  8899. c = 0;
  8900. memset(sstr ,0, sizeof(sstr) );
  8901. while (loc[3+strlen("status")+c] != '\"')
  8902. {
  8903. sstr[c] = loc[3+strlen("status")+c];
  8904. c++;
  8905. }
  8906. sstr[c] = '\0';
  8907. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8908. }
  8909. //****************transactionId********************/
  8910. c=0;
  8911. loc = strstr(payload, "transactionId");
  8912. memset(sstr ,0, sizeof(sstr) );
  8913. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8914. {
  8915. sstr[c] = loc[strlen("transactionId")+2+c];
  8916. c++;
  8917. }
  8918. sstr[c] = '\0';
  8919. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8920. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8921. TransactionId[gun_index] = transactionIdInt;
  8922. DEBUG_INFO("gun_index: %d\n", gun_index);
  8923. DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  8924. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8925. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8926. #ifdef SystemLogMessage
  8927. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8928. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8929. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8930. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8931. #endif
  8932. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8933. {
  8934. //add Charging Record
  8935. SettingChargingRecord(gun_index, transactionIdInt);
  8936. }
  8937. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8938. }
  8939. void handleStatusNotificationResponse(char *payload, int gun_index)
  8940. {
  8941. mtrace();
  8942. printf("handleStatusNotificationResponse\n");
  8943. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8944. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8945. }
  8946. void handleStopTransactionnResponse(char *payload, int gun_index)
  8947. {
  8948. mtrace();
  8949. char sstr[30]={ 0 };
  8950. int c = 0;
  8951. char *loc;
  8952. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8953. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8954. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8955. loc = strstr(payload, "idTagInfo");
  8956. //***********************idTagInfo************************/
  8957. if(loc != NULL)
  8958. {
  8959. //***********************expiryDate************************/
  8960. loc = strstr(payload, "expiryDate");
  8961. if(loc != NULL)
  8962. {
  8963. memset(sstr ,0, sizeof(sstr) );
  8964. c = 0;
  8965. while (loc[3+strlen("expiryDate")+c] != '\"')
  8966. {
  8967. sstr[c] = loc[3+strlen("expiryDate")+c];
  8968. c++;
  8969. }
  8970. sstr[c] = '\0';
  8971. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8972. }
  8973. //***********************parentIdTag************************/
  8974. loc = strstr(payload, "parentIdTag");
  8975. if(loc != NULL)
  8976. {
  8977. memset(sstr ,0, sizeof(sstr) );
  8978. c = 0;
  8979. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8980. {
  8981. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8982. c++;
  8983. }
  8984. sstr[c] = '\0';
  8985. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8986. }
  8987. //***********************status************************/
  8988. loc = strstr(payload, "status");
  8989. memset(sstr ,0, sizeof(sstr) );
  8990. c = 0;
  8991. while (loc[3+strlen("status")+c] != '\"')
  8992. {
  8993. sstr[c] = loc[3+strlen("status")+c];
  8994. c++;
  8995. }
  8996. sstr[c] = '\0';
  8997. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8998. }
  8999. #ifdef SystemLogMessage
  9000. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9001. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9002. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9003. #endif
  9004. }
  9005. //==========================================
  9006. // Handle Error routine
  9007. //==========================================
  9008. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9009. {
  9010. mtrace();
  9011. #ifdef SystemLogMessage
  9012. DEBUG_INFO("errorCode: %s\n", errorCode);
  9013. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9014. DEBUG_INFO("errorDetails: %s\n", payload);
  9015. #endif
  9016. }
  9017. //===============================================
  9018. // Common routine
  9019. //===============================================
  9020. int initialConfigurationTable(void)
  9021. {
  9022. FILE *fp;
  9023. FILE *outfile;
  9024. char str[200]={0};
  9025. char sstr[100]={0};
  9026. int c = 0;
  9027. char *loc;
  9028. printf("initialConfigurationTable \n");
  9029. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9030. if((access("../Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9031. {
  9032. outfile = fopen("../Storage/OCPP/OCPPConfiguration" , "w+");
  9033. if(outfile == NULL) {
  9034. DEBUG_INFO("Error opening file");
  9035. return FALSE;
  9036. }
  9037. //outfile = fopen ("../Storage/OCPP/OCPPConfiguration", "a");
  9038. /*Core Profile*/
  9039. //AllowOfflineTxForUnknownId
  9040. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9041. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9044. //DEBUG_INFO("data=%s\n",data);
  9045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  9046. //AuthorizationCacheEnabled
  9047. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9051. //AuthorizeRemoteTxRequests
  9052. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "TRUE");
  9056. //BlinkRepeat
  9057. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9061. //ClockAlignedDataInterval
  9062. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9066. //ConnectionTimeOut
  9067. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9071. //GetConfigurationMaxKeys
  9072. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9076. // HeartbeatInterval
  9077. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9081. // LightIntensity
  9082. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9086. // LocalAuthorizeOffline
  9087. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9091. // LocalPreAuthorize
  9092. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9096. // MaxEnergyOnInvalidId
  9097. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9100. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9102. // MeterValuesAlignedData
  9103. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9107. // MeterValuesAlignedDataMaxLength
  9108. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9112. // MeterValuesSampledData
  9113. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9117. // MeterValuesSampledDataMaxLength
  9118. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9122. // MeterValueSampleInterval
  9123. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9127. // MinimumStatusDuration
  9128. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9132. // NumberOfConnectors
  9133. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9135. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9136. {
  9137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9138. }
  9139. else
  9140. {
  9141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9142. }
  9143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9144. // ResetRetries
  9145. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9149. // ConnectorPhaseRotation
  9150. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9154. // ConnectorPhaseRotationMaxLength
  9155. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9159. // StopTransactionOnEVSideDisconnect
  9160. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9164. // StopTransactionOnInvalidId
  9165. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9169. // StopTxnAlignedData
  9170. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9174. // StopTxnAlignedDataMaxLength
  9175. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9179. // StopTxnSampledData
  9180. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Energy.Active.Import.Register");
  9184. // StopTxnSampledDataMaxLength
  9185. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", "0");
  9189. // SupportedFeatureProfiles
  9190. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "0");
  9194. // SupportedFeatureProfilesMaxLength
  9195. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9199. // TransactionMessageAttempts
  9200. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9203. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9205. // TransactionMessageRetryInterval
  9206. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9209. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9211. // UnlockConnectorOnEVSideDisconnect
  9212. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9216. // WebSocketPingInterval
  9217. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9221. //* Local Auth List Management Profile*/
  9222. #if 0
  9223. //For OCTT Test Case
  9224. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9227. #endif
  9228. #if 1
  9229. //LocalAuthListEnabled
  9230. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9234. #endif
  9235. //LocalAuthListMaxLength
  9236. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9240. //SendLocalListMaxLength
  9241. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9245. //ReserveConnectorZeroSupported
  9246. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9250. //* Smart Charging Profile */
  9251. //ChargeProfileMaxStackLevel
  9252. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9256. // ChargingScheduleAllowedChargingRateUnit
  9257. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9261. // ChargingScheduleMaxPeriods
  9262. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9266. // ConnectorSwitch3to1PhaseSupported
  9267. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9271. // MaxChargingProfilesInstalled
  9272. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9276. fclose(outfile);
  9277. }
  9278. else
  9279. {
  9280. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9281. char keystr[60]={0};
  9282. char readonlystr[10]={0};
  9283. char valuestr[100]={0};
  9284. fp = fopen("../Storage/OCPP/OCPPConfiguration" , "r");
  9285. if(fp == NULL) {
  9286. DEBUG_INFO("Error opening file");
  9287. return FALSE;
  9288. }
  9289. while( fgets (str, sizeof(str), fp)!=NULL )
  9290. {
  9291. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9292. //*************************key*********************************/
  9293. loc = strstr(str, "key");
  9294. c = 0;
  9295. memset(sstr ,0, sizeof(sstr) );
  9296. while (loc[strlen("key")+3+c] != '\"')
  9297. {
  9298. sstr[c] = loc[strlen("key")+3+c];
  9299. c++;
  9300. }
  9301. sstr[c] = '\0';
  9302. strcpy(keystr,sstr);
  9303. //*************************readonly*********************************/
  9304. loc = strstr(str, "readonly");
  9305. c = 0;
  9306. memset(sstr ,0, sizeof(sstr) );
  9307. while (loc[strlen("readonly")+2+c] != ',')
  9308. {
  9309. sstr[c] = loc[strlen("readonly")+2+c];
  9310. c++;
  9311. }
  9312. sstr[c] = '\0';
  9313. strcpy(readonlystr,sstr);
  9314. //*************************value*********************************/
  9315. loc = strstr(str, "value");
  9316. c = 0;
  9317. memset(sstr ,0, sizeof(sstr) );
  9318. while (loc[strlen("value")+3+c] != '\"')
  9319. {
  9320. sstr[c] = loc[strlen("value")+3+c];
  9321. c++;
  9322. }
  9323. sstr[c] = '\0';
  9324. strcpy(valuestr,sstr);
  9325. // DEBUG_INFO("keystr=%s\n",keystr);
  9326. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9327. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9328. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9329. {
  9330. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9331. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9333. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9334. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9335. }
  9336. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9337. {
  9338. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9339. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9341. }
  9342. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9343. {
  9344. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9346. }
  9347. if(strcmp(keystr, "BlinkRepeat") == 0)
  9348. {
  9349. //Charger.BlinkRepeat = Integer.parseInt(value);
  9350. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9352. }
  9353. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9354. {
  9355. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9357. }
  9358. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9359. {
  9360. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9362. }
  9363. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9364. {
  9365. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9367. }
  9368. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9369. {
  9370. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9372. HeartBeatWaitTime = atoi(valuestr);
  9373. }
  9374. if(strcmp(keystr, "LightIntensity") == 0)
  9375. {
  9376. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9378. }
  9379. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9380. {
  9381. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9383. }
  9384. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9385. {
  9386. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9388. }
  9389. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9390. {
  9391. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9393. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9394. }
  9395. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9396. {
  9397. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9399. }
  9400. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9401. {
  9402. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9404. }
  9405. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9406. {
  9407. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9409. }
  9410. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9411. {
  9412. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9414. }
  9415. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9416. {
  9417. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9419. }
  9420. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9421. {
  9422. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9424. }
  9425. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9426. {
  9427. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9429. }
  9430. if(strcmp(keystr, "ResetRetries") == 0)
  9431. {
  9432. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9434. }
  9435. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9436. {
  9437. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9439. }
  9440. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9441. {
  9442. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9444. }
  9445. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  9446. {
  9447. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  9449. }
  9450. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  9451. {
  9452. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  9454. }
  9455. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  9456. {
  9457. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  9459. }
  9460. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  9461. {
  9462. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9464. }
  9465. if(strcmp(keystr, "StopTxnSampledData") == 0)
  9466. {
  9467. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  9469. }
  9470. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  9471. {
  9472. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9474. }
  9475. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  9476. {
  9477. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  9479. }
  9480. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  9481. {
  9482. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  9484. }
  9485. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  9486. {
  9487. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  9489. TransactionMessageAttemptsValue = atoi(valuestr);
  9490. }
  9491. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  9492. {
  9493. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  9495. TransactionMessageRetryIntervalValue = atoi(valuestr);
  9496. }
  9497. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  9498. {
  9499. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  9501. }
  9502. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  9503. {
  9504. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  9506. }
  9507. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  9508. {
  9509. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  9511. }
  9512. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  9513. {
  9514. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  9516. }
  9517. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  9518. {
  9519. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  9521. }
  9522. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  9523. {
  9524. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  9526. }
  9527. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  9528. {
  9529. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  9531. }
  9532. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  9533. {
  9534. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  9536. }
  9537. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  9538. {
  9539. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  9541. }
  9542. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  9543. {
  9544. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  9546. }
  9547. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  9548. {
  9549. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  9551. }
  9552. }
  9553. fclose(fp);
  9554. }
  9555. return 0;
  9556. }
  9557. void StoreConfigurationTable(void)
  9558. {
  9559. FILE *outfile;
  9560. outfile = fopen("../Storage/OCPP/OCPPConfiguration" , "w+");
  9561. if(outfile == NULL)
  9562. {
  9563. DEBUG_INFO("Error opening file");
  9564. return ;
  9565. }
  9566. /*Core Profile*/
  9567. //AllowOfflineTxForUnknownId
  9568. /*
  9569. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9570. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9573. */
  9574. //DEBUG_INFO("data=%s\n",data);
  9575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9576. //AuthorizationCacheEnabled
  9577. /*
  9578. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9581. */
  9582. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9583. //AuthorizeRemoteTxRequests
  9584. /*
  9585. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9588. */
  9589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9590. //BlinkRepeat
  9591. /*
  9592. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9595. */
  9596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9597. //ClockAlignedDataInterval
  9598. /*
  9599. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9602. */
  9603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9604. //ConnectionTimeOut
  9605. /*
  9606. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9609. */
  9610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9611. //GetConfigurationMaxKeys
  9612. /*
  9613. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9616. */
  9617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9618. // HeartbeatInterval
  9619. /*
  9620. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9623. */
  9624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9625. // LightIntensity
  9626. /*
  9627. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9630. */
  9631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9632. // LocalAuthorizeOffline
  9633. /*
  9634. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9637. */
  9638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9639. // LocalPreAuthorize
  9640. /*
  9641. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9644. */
  9645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9646. // MaxEnergyOnInvalidId
  9647. /*
  9648. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9651. */
  9652. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9654. // MeterValuesAlignedData
  9655. /*
  9656. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9659. */
  9660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9661. // MeterValuesAlignedDataMaxLength
  9662. /*
  9663. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9666. */
  9667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9668. // MeterValuesSampledData
  9669. /*
  9670. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9673. */
  9674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9675. // MeterValuesSampledDataMaxLength
  9676. /*
  9677. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9680. */
  9681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9682. // MeterValueSampleInterval
  9683. /*
  9684. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9687. */
  9688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9689. // MinimumStatusDuration
  9690. /*
  9691. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9694. */
  9695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9696. // NumberOfConnectors
  9697. /*
  9698. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9700. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9701. {
  9702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9703. }
  9704. else
  9705. {
  9706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9707. }
  9708. */
  9709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9710. // ResetRetries
  9711. /*
  9712. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9715. */
  9716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9717. // ConnectorPhaseRotation
  9718. /*
  9719. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9722. */
  9723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9724. // ConnectorPhaseRotationMaxLength
  9725. /*
  9726. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9729. */
  9730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9731. // StopTransactionOnEVSideDisconnect
  9732. /*
  9733. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9736. */
  9737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9738. // StopTransactionOnInvalidId
  9739. /*
  9740. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9743. */
  9744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9745. // StopTxnAlignedData
  9746. /*
  9747. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9750. */
  9751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9752. // StopTxnAlignedDataMaxLength
  9753. /*
  9754. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9757. */
  9758. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9759. // StopTxnSampledData
  9760. /*
  9761. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9764. */
  9765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9766. // StopTxnSampledDataMaxLength
  9767. /*
  9768. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9771. */
  9772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9773. // SupportedFeatureProfiles
  9774. /*
  9775. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9778. */
  9779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  9780. // SupportedFeatureProfilesMaxLength
  9781. /*
  9782. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9785. */
  9786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  9787. // TransactionMessageAttempts
  9788. /*
  9789. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9792. */
  9793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9794. // TransactionMessageRetryInterval
  9795. /*
  9796. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9799. */
  9800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9801. // UnlockConnectorOnEVSideDisconnect
  9802. /*
  9803. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9806. */
  9807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  9808. // WebSocketPingInterval
  9809. /*
  9810. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9813. */
  9814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  9815. //* Local Auth List Management Profile*/
  9816. //LocalAuthListEnabled
  9817. /*
  9818. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9821. */
  9822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9823. //LocalAuthListMaxLength
  9824. /*
  9825. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9828. */
  9829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  9830. //SendLocalListMaxLength
  9831. /*
  9832. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9835. */
  9836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  9837. //ReserveConnectorZeroSupported
  9838. /*
  9839. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9842. */
  9843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9844. //* Smart Charging Profile */
  9845. //ChargeProfileMaxStackLevel
  9846. /*
  9847. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9850. */
  9851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9852. // ChargingScheduleAllowedChargingRateUnit
  9853. /*
  9854. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9857. */
  9858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9859. // ChargingScheduleMaxPeriods
  9860. /*
  9861. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9864. */
  9865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9866. // ConnectorSwitch3to1PhaseSupported
  9867. /*
  9868. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9871. */
  9872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9873. // MaxChargingProfilesInstalled
  9874. /*
  9875. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9878. */
  9879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9880. fclose(outfile);
  9881. }
  9882. void getKeyValue(char *keyReq)
  9883. {
  9884. int isEmpty = FALSE;
  9885. int isKnowKey = FALSE;
  9886. //int unKnowIndex = 0;
  9887. DEBUG_INFO("getKeyValue \n");
  9888. DEBUG_INFO("keyReq=%s \n",keyReq);
  9889. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9890. isEmpty = TRUE;
  9891. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9892. {
  9893. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  9894. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9896. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9897. {
  9898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9899. }
  9900. else
  9901. {
  9902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9903. }
  9904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9905. isKnowKey = TRUE;
  9906. }
  9907. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9908. {
  9909. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9912. {
  9913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9914. }
  9915. else
  9916. {
  9917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9918. }
  9919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9920. isKnowKey = TRUE;
  9921. }
  9922. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9923. {
  9924. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9927. {
  9928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9929. }
  9930. else
  9931. {
  9932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9933. }
  9934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9935. isKnowKey = TRUE;
  9936. }
  9937. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9938. {
  9939. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9941. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9942. {
  9943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9944. }
  9945. else
  9946. {
  9947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9948. }
  9949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9950. isKnowKey = TRUE;
  9951. }
  9952. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9953. {
  9954. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9957. {
  9958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9959. }
  9960. else
  9961. {
  9962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9963. }
  9964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9965. isKnowKey = TRUE;
  9966. }
  9967. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9968. {
  9969. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9972. {
  9973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9974. }
  9975. else
  9976. {
  9977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9978. }
  9979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9980. isKnowKey = TRUE;
  9981. }
  9982. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9983. {
  9984. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9986. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9987. {
  9988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9989. }
  9990. else
  9991. {
  9992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9993. }
  9994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9995. isKnowKey = TRUE;
  9996. }
  9997. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9998. {
  9999. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10001. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10002. {
  10003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10004. }
  10005. else
  10006. {
  10007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10008. }
  10009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10010. isKnowKey = TRUE;
  10011. }
  10012. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10013. {
  10014. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10017. {
  10018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10019. }
  10020. else
  10021. {
  10022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10023. }
  10024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10025. isKnowKey = TRUE;
  10026. }
  10027. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10028. {
  10029. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10032. {
  10033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10034. }
  10035. else
  10036. {
  10037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10038. }
  10039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10040. isKnowKey = TRUE;
  10041. }
  10042. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10043. {
  10044. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10046. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10047. {
  10048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10049. }
  10050. else
  10051. {
  10052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10053. }
  10054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10055. isKnowKey = TRUE;
  10056. }
  10057. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10058. {
  10059. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10062. {
  10063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10064. }
  10065. else
  10066. {
  10067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10068. }
  10069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10070. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10071. isKnowKey = TRUE;
  10072. }
  10073. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10074. {
  10075. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10078. {
  10079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10080. }
  10081. else
  10082. {
  10083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10084. }
  10085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10086. isKnowKey = TRUE;
  10087. }
  10088. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10089. {
  10090. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10093. {
  10094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10095. }
  10096. else
  10097. {
  10098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10099. }
  10100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10101. isKnowKey = TRUE;
  10102. }
  10103. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10104. {
  10105. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10108. {
  10109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10110. }
  10111. else
  10112. {
  10113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10114. }
  10115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10116. isKnowKey = TRUE;
  10117. }
  10118. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10119. {
  10120. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10122. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10123. {
  10124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10125. }
  10126. else
  10127. {
  10128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10129. }
  10130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10131. isKnowKey = TRUE;
  10132. }
  10133. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10134. {
  10135. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10137. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10138. {
  10139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10140. }
  10141. else
  10142. {
  10143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10144. }
  10145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10146. isKnowKey = TRUE;
  10147. }
  10148. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10149. {
  10150. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10153. {
  10154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10155. }
  10156. else
  10157. {
  10158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10159. }
  10160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10161. isKnowKey = TRUE;
  10162. }
  10163. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10164. {
  10165. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10168. {
  10169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10170. }
  10171. else
  10172. {
  10173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10174. }
  10175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10176. isKnowKey = TRUE;
  10177. }
  10178. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10179. {
  10180. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10182. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10183. {
  10184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10185. }
  10186. else
  10187. {
  10188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10189. }
  10190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10191. isKnowKey = TRUE;
  10192. }
  10193. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10194. {
  10195. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10197. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10198. {
  10199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10200. }
  10201. else
  10202. {
  10203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10204. }
  10205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10206. isKnowKey = TRUE;
  10207. }
  10208. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10209. {
  10210. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10213. {
  10214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10215. }
  10216. else
  10217. {
  10218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10219. }
  10220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10221. isKnowKey = TRUE;
  10222. }
  10223. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10224. {
  10225. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10227. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10228. {
  10229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10230. }
  10231. else
  10232. {
  10233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10234. }
  10235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10236. isKnowKey = TRUE;
  10237. }
  10238. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10239. {
  10240. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10243. {
  10244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10245. }
  10246. else
  10247. {
  10248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10249. }
  10250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10251. isKnowKey = TRUE;
  10252. }
  10253. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10254. {
  10255. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10257. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10258. {
  10259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10260. }
  10261. else
  10262. {
  10263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10264. }
  10265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10266. isKnowKey = TRUE;
  10267. }
  10268. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10269. {
  10270. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10273. {
  10274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10275. }
  10276. else
  10277. {
  10278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10279. }
  10280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10281. isKnowKey = TRUE;
  10282. }
  10283. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10284. {
  10285. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10287. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10288. {
  10289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10290. }
  10291. else
  10292. {
  10293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10294. }
  10295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10296. isKnowKey = TRUE;
  10297. }
  10298. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10299. {
  10300. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10302. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10303. {
  10304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10305. }
  10306. else
  10307. {
  10308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10309. }
  10310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10311. isKnowKey = TRUE;
  10312. }
  10313. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10314. {
  10315. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10317. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10318. {
  10319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10320. }
  10321. else
  10322. {
  10323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10324. }
  10325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10326. isKnowKey = TRUE;
  10327. }
  10328. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10329. {
  10330. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10332. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10333. {
  10334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10335. }
  10336. else
  10337. {
  10338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10339. }
  10340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10341. isKnowKey = TRUE;
  10342. }
  10343. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10344. {
  10345. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10347. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10348. {
  10349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10350. }
  10351. else
  10352. {
  10353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10354. }
  10355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10356. isKnowKey = TRUE;
  10357. }
  10358. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10359. {
  10360. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10362. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10363. {
  10364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10365. }
  10366. else
  10367. {
  10368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10369. }
  10370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10371. isKnowKey = TRUE;
  10372. }
  10373. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10374. {
  10375. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10378. {
  10379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10380. }
  10381. else
  10382. {
  10383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10384. }
  10385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10386. isKnowKey = TRUE;
  10387. }
  10388. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10389. {
  10390. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10393. {
  10394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10395. }
  10396. else
  10397. {
  10398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10399. }
  10400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10401. isKnowKey = TRUE;
  10402. }
  10403. #if 0
  10404. //For OCTT Test Case
  10405. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10406. {
  10407. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10409. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10410. {
  10411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10412. }
  10413. else
  10414. {
  10415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10416. }
  10417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10418. isKnowKey = TRUE;
  10419. }
  10420. #endif
  10421. #if 1
  10422. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10423. {
  10424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10426. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10427. {
  10428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10429. }
  10430. else
  10431. {
  10432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10433. }
  10434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10435. isKnowKey = TRUE;
  10436. }
  10437. #endif
  10438. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10439. {
  10440. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10442. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10443. {
  10444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10445. }
  10446. else
  10447. {
  10448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10449. }
  10450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  10451. isKnowKey = TRUE;
  10452. }
  10453. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  10454. {
  10455. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  10456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  10457. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  10458. {
  10459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10460. }
  10461. else
  10462. {
  10463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10464. }
  10465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  10466. isKnowKey = TRUE;
  10467. }
  10468. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  10469. {
  10470. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  10471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  10472. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  10473. {
  10474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  10475. }
  10476. else
  10477. {
  10478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  10479. }
  10480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10481. isKnowKey = TRUE;
  10482. }
  10483. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  10484. {
  10485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  10486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  10487. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  10488. {
  10489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  10490. }
  10491. else
  10492. {
  10493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  10494. }
  10495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10496. isKnowKey = TRUE;
  10497. }
  10498. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  10499. {
  10500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  10501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  10502. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  10503. {
  10504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  10505. }
  10506. else
  10507. {
  10508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  10509. }
  10510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10511. isKnowKey = TRUE;
  10512. }
  10513. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  10514. {
  10515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  10516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  10517. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  10518. {
  10519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  10520. }
  10521. else
  10522. {
  10523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  10524. }
  10525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10526. isKnowKey = TRUE;
  10527. }
  10528. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  10529. {
  10530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  10531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  10532. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  10533. {
  10534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  10535. }
  10536. else
  10537. {
  10538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  10539. }
  10540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10541. isKnowKey = TRUE;
  10542. }
  10543. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  10544. {
  10545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  10546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  10547. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  10548. {
  10549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  10550. }
  10551. else
  10552. {
  10553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  10554. }
  10555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10556. isKnowKey = TRUE;
  10557. }
  10558. //=========================================================
  10559. if(!isEmpty && !isKnowKey)
  10560. {
  10561. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  10562. strcpy(unknownkey[UnknownKeynum], keyReq);
  10563. UnknownKeynum = UnknownKeynum + 1;
  10564. }
  10565. }
  10566. void processUnkownKey(void)
  10567. {
  10568. DEBUG_INFO("processUnkownKey\n");
  10569. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  10570. for(int index=0; index < UnknownKeynum; index++)
  10571. {
  10572. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  10573. {
  10574. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  10575. }
  10576. }
  10577. }
  10578. int setKeyValue(char *key, char *value)
  10579. {
  10580. int isSuccess = NotSupported;
  10581. int check_ascii=0;
  10582. char str[10]={0};
  10583. #ifdef Debug
  10584. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  10585. #endif
  10586. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  10587. {
  10588. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10590. {
  10591. strcpy(str, (const char*)value);
  10592. for(int i = 0; str[i]; i++){
  10593. str[i] = tolower(str[i]);
  10594. }
  10595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10596. isSuccess = ConfigurationStatus_Accepted;
  10597. }
  10598. else
  10599. {
  10600. isSuccess = ConfigurationStatus_Rejected;
  10601. }
  10602. }
  10603. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  10604. {
  10605. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10607. {
  10608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  10609. isSuccess = ConfigurationStatus_Accepted;
  10610. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  10611. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  10612. }
  10613. else
  10614. {
  10615. isSuccess = ConfigurationStatus_Rejected;
  10616. }
  10617. }
  10618. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  10619. {
  10620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10621. {
  10622. strcpy(str, (const char*)value);
  10623. for(int i = 0; str[i]; i++)
  10624. {
  10625. str[i] = tolower(str[i]);
  10626. }
  10627. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  10628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10629. isSuccess = ConfigurationStatus_Accepted;
  10630. }
  10631. else
  10632. {
  10633. isSuccess = ConfigurationStatus_Rejected;
  10634. }
  10635. }
  10636. if(strcmp(key, "BlinkRepeat") == 0)
  10637. {
  10638. //Charger.BlinkRepeat = Integer.parseInt(value);
  10639. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10640. {
  10641. check_ascii = value[0];
  10642. if( (check_ascii < 48) || (check_ascii > 57) )
  10643. {
  10644. isSuccess = ConfigurationStatus_Rejected;
  10645. }
  10646. else
  10647. {
  10648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  10649. isSuccess = ConfigurationStatus_Accepted;
  10650. }
  10651. }
  10652. else
  10653. {
  10654. isSuccess = ConfigurationStatus_Rejected;
  10655. }
  10656. }
  10657. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  10658. {
  10659. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10660. {
  10661. check_ascii = value[0];
  10662. if( (check_ascii < 48) || (check_ascii > 57) )
  10663. {
  10664. isSuccess = ConfigurationStatus_Rejected;
  10665. }
  10666. else
  10667. {
  10668. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  10669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  10670. isSuccess = ConfigurationStatus_Accepted;
  10671. }
  10672. }
  10673. else
  10674. {
  10675. isSuccess = ConfigurationStatus_Rejected;
  10676. }
  10677. }
  10678. if(strcmp(key, "ConnectionTimeOut") == 0 )
  10679. {
  10680. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10681. {
  10682. check_ascii = value[0];
  10683. if( (check_ascii < 48) || (check_ascii > 57) )
  10684. {
  10685. isSuccess = ConfigurationStatus_Rejected;
  10686. }
  10687. else
  10688. {
  10689. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  10690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  10691. isSuccess = ConfigurationStatus_Accepted;
  10692. }
  10693. }
  10694. else
  10695. {
  10696. isSuccess = ConfigurationStatus_Rejected;
  10697. }
  10698. }
  10699. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  10700. {
  10701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10702. {
  10703. check_ascii = value[0];
  10704. if( (check_ascii < 48) || (check_ascii > 57) )
  10705. {
  10706. isSuccess = ConfigurationStatus_Rejected;
  10707. }
  10708. else
  10709. {
  10710. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  10712. isSuccess = ConfigurationStatus_Accepted;
  10713. }
  10714. }
  10715. else
  10716. {
  10717. isSuccess = ConfigurationStatus_Rejected;
  10718. }
  10719. }
  10720. if(strcmp(key, "HeartbeatInterval") == 0)
  10721. {
  10722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10723. {
  10724. check_ascii = value[0];
  10725. if( (check_ascii < 48) || (check_ascii > 57) )
  10726. {
  10727. isSuccess = ConfigurationStatus_Rejected;
  10728. }
  10729. else
  10730. {
  10731. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  10733. HeartBeatWaitTime = atoi(value);
  10734. isSuccess = ConfigurationStatus_Accepted;
  10735. }
  10736. }
  10737. else
  10738. {
  10739. isSuccess = ConfigurationStatus_Rejected;
  10740. }
  10741. }
  10742. if(strcmp(key, "LightIntensity") == 0)
  10743. {
  10744. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10745. {
  10746. check_ascii = value[0];
  10747. if( (check_ascii < 48) || (check_ascii > 57) )
  10748. {
  10749. isSuccess = ConfigurationStatus_Rejected;
  10750. }
  10751. else
  10752. {
  10753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10754. isSuccess = ConfigurationStatus_Accepted;
  10755. }
  10756. }
  10757. else
  10758. {
  10759. isSuccess = ConfigurationStatus_Rejected;
  10760. }
  10761. }
  10762. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10763. {
  10764. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10765. {
  10766. strcpy(str, (const char*)value);
  10767. for(int i = 0; str[i]; i++)
  10768. {
  10769. str[i] = tolower(str[i]);
  10770. }
  10771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10772. isSuccess = ConfigurationStatus_Accepted;
  10773. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10774. }
  10775. else
  10776. {
  10777. isSuccess = ConfigurationStatus_Rejected;
  10778. }
  10779. }
  10780. if(strcmp(key, "LocalPreAuthorize") == 0)
  10781. {
  10782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10783. {
  10784. strcpy(str, (const char*)value);
  10785. for(int i = 0; str[i]; i++)
  10786. {
  10787. str[i] = tolower(str[i]);
  10788. }
  10789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10790. isSuccess = ConfigurationStatus_Accepted;
  10791. }
  10792. else
  10793. {
  10794. isSuccess = ConfigurationStatus_Rejected;
  10795. }
  10796. }
  10797. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10798. {
  10799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10800. {
  10801. check_ascii = value[0];
  10802. if( (check_ascii < 48) || (check_ascii > 57) )
  10803. {
  10804. isSuccess = ConfigurationStatus_Rejected;
  10805. }
  10806. else
  10807. {
  10808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10809. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  10810. isSuccess = ConfigurationStatus_Accepted;
  10811. }
  10812. }
  10813. else
  10814. {
  10815. isSuccess = ConfigurationStatus_Rejected;
  10816. }
  10817. }
  10818. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10819. {
  10820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10821. {
  10822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10823. isSuccess = ConfigurationStatus_Accepted;
  10824. }
  10825. else
  10826. {
  10827. isSuccess = ConfigurationStatus_Rejected;
  10828. }
  10829. }
  10830. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  10831. {
  10832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10833. {
  10834. check_ascii = value[0];
  10835. if( (check_ascii < 48) || (check_ascii > 57) )
  10836. {
  10837. isSuccess = ConfigurationStatus_Rejected;
  10838. }
  10839. else
  10840. {
  10841. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  10843. isSuccess = ConfigurationStatus_Accepted;
  10844. }
  10845. }
  10846. else
  10847. {
  10848. isSuccess = ConfigurationStatus_Rejected;
  10849. }
  10850. }
  10851. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10852. {
  10853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10854. {
  10855. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10856. isSuccess = ConfigurationStatus_Accepted;
  10857. }
  10858. else
  10859. {
  10860. isSuccess = ConfigurationStatus_Rejected;
  10861. }
  10862. }
  10863. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  10864. {
  10865. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10866. {
  10867. check_ascii = value[0];
  10868. if( (check_ascii < 48) || (check_ascii > 57) )
  10869. {
  10870. isSuccess = ConfigurationStatus_Rejected;
  10871. }
  10872. else
  10873. {
  10874. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  10876. isSuccess = ConfigurationStatus_Accepted;
  10877. }
  10878. }
  10879. else
  10880. {
  10881. isSuccess = ConfigurationStatus_Rejected;
  10882. }
  10883. }
  10884. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10885. {
  10886. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10887. {
  10888. check_ascii = value[0];
  10889. if( (check_ascii < 48) || (check_ascii > 57) )
  10890. {
  10891. isSuccess = ConfigurationStatus_Rejected;
  10892. }
  10893. else
  10894. {
  10895. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10897. isSuccess = ConfigurationStatus_Accepted;
  10898. }
  10899. }
  10900. else
  10901. {
  10902. isSuccess = ConfigurationStatus_Rejected;
  10903. }
  10904. }
  10905. if(strcmp(key, "MinimumStatusDuration") == 0)
  10906. {
  10907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10908. {
  10909. check_ascii = value[0];
  10910. if( (check_ascii < 48) || (check_ascii > 57) )
  10911. {
  10912. isSuccess = ConfigurationStatus_Rejected;
  10913. }
  10914. else
  10915. {
  10916. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10918. isSuccess = ConfigurationStatus_Accepted;
  10919. }
  10920. }
  10921. else
  10922. {
  10923. isSuccess = ConfigurationStatus_Rejected;
  10924. }
  10925. }
  10926. if(strcmp(key, "NumberOfConnectors") == 0)
  10927. {
  10928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10929. {
  10930. check_ascii = value[0];
  10931. if( (check_ascii < 48) || (check_ascii > 57) )
  10932. {
  10933. isSuccess = ConfigurationStatus_Rejected;
  10934. }
  10935. else
  10936. {
  10937. //Charger.ResetRetries = Integer.parseInt(value);
  10938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  10939. isSuccess = ConfigurationStatus_Accepted;
  10940. }
  10941. }
  10942. else
  10943. {
  10944. isSuccess = ConfigurationStatus_Rejected;
  10945. }
  10946. }
  10947. if(strcmp(key, "ResetRetries") == 0)
  10948. {
  10949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10950. {
  10951. check_ascii = value[0];
  10952. if( (check_ascii < 48) || (check_ascii > 57) )
  10953. {
  10954. isSuccess = ConfigurationStatus_Rejected;
  10955. }
  10956. else
  10957. {
  10958. //Charger.ResetRetries = Integer.parseInt(value);
  10959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10960. isSuccess = ConfigurationStatus_Accepted;
  10961. }
  10962. }
  10963. else
  10964. {
  10965. isSuccess = ConfigurationStatus_Rejected;
  10966. }
  10967. }
  10968. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10969. {
  10970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10971. {
  10972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10973. isSuccess = ConfigurationStatus_Accepted;
  10974. }
  10975. else
  10976. {
  10977. isSuccess = ConfigurationStatus_Rejected;
  10978. }
  10979. }
  10980. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  10981. {
  10982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10983. {
  10984. check_ascii = value[0];
  10985. if( (check_ascii < 48) || (check_ascii > 57) )
  10986. {
  10987. isSuccess = ConfigurationStatus_Rejected;
  10988. }
  10989. else
  10990. {
  10991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  10992. isSuccess = ConfigurationStatus_Accepted;
  10993. }
  10994. }
  10995. else
  10996. {
  10997. isSuccess = ConfigurationStatus_Rejected;
  10998. }
  10999. }
  11000. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11001. {
  11002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11003. {
  11004. strcpy(str, (const char*)value);
  11005. for(int i = 0; str[i]; i++)
  11006. {
  11007. str[i] = tolower(str[i]);
  11008. }
  11009. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11011. isSuccess = ConfigurationStatus_Accepted;
  11012. }
  11013. else
  11014. {
  11015. isSuccess = ConfigurationStatus_Rejected;
  11016. }
  11017. }
  11018. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11019. {
  11020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11021. {
  11022. strcpy(str, (const char*)value);
  11023. for(int i = 0; str[i]; i++)
  11024. {
  11025. str[i] = tolower(str[i]);
  11026. }
  11027. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11029. isSuccess = ConfigurationStatus_Accepted;
  11030. }
  11031. else
  11032. {
  11033. isSuccess = ConfigurationStatus_Rejected;
  11034. }
  11035. }
  11036. if(strcmp(key, "StopTxnAlignedData") == 0)
  11037. {
  11038. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11039. {
  11040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11041. isSuccess = ConfigurationStatus_Accepted;
  11042. }
  11043. else
  11044. {
  11045. isSuccess = ConfigurationStatus_Rejected;
  11046. }
  11047. }
  11048. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11049. {
  11050. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11051. {
  11052. check_ascii = value[0];
  11053. if( (check_ascii < 48) || (check_ascii > 57) )
  11054. {
  11055. isSuccess = ConfigurationStatus_Rejected;
  11056. }
  11057. else
  11058. {
  11059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11060. isSuccess = ConfigurationStatus_Accepted;
  11061. }
  11062. }
  11063. else
  11064. {
  11065. isSuccess = ConfigurationStatus_Rejected;
  11066. }
  11067. }
  11068. if(strcmp(key, "StopTxnSampledData") == 0)
  11069. {
  11070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11071. {
  11072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11073. isSuccess = ConfigurationStatus_Accepted;
  11074. }
  11075. else
  11076. {
  11077. isSuccess = ConfigurationStatus_Rejected;
  11078. }
  11079. }
  11080. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11081. {
  11082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11083. {
  11084. check_ascii = value[0];
  11085. if( (check_ascii < 48) || (check_ascii > 57) )
  11086. {
  11087. isSuccess = ConfigurationStatus_Rejected;
  11088. }
  11089. else
  11090. {
  11091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11092. isSuccess = ConfigurationStatus_Accepted;
  11093. }
  11094. }
  11095. else
  11096. {
  11097. isSuccess = ConfigurationStatus_Rejected;
  11098. }
  11099. }
  11100. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11101. {
  11102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11103. {
  11104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11105. isSuccess = ConfigurationStatus_Accepted;
  11106. }
  11107. else
  11108. {
  11109. isSuccess = ConfigurationStatus_Rejected;
  11110. }
  11111. }
  11112. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11113. {
  11114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11115. {
  11116. check_ascii = value[0];
  11117. if( (check_ascii < 48) || (check_ascii > 57) )
  11118. {
  11119. isSuccess = ConfigurationStatus_Rejected;
  11120. }
  11121. else
  11122. {
  11123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11124. isSuccess = ConfigurationStatus_Accepted;
  11125. }
  11126. }
  11127. else
  11128. {
  11129. isSuccess = ConfigurationStatus_Rejected;
  11130. }
  11131. }
  11132. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11133. {
  11134. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11135. {
  11136. check_ascii = value[0];
  11137. if( (check_ascii < 48) || (check_ascii > 57) )
  11138. {
  11139. isSuccess = ConfigurationStatus_Rejected;
  11140. }
  11141. else
  11142. {
  11143. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11145. TransactionMessageAttemptsValue = atoi(value);
  11146. isSuccess = ConfigurationStatus_Accepted;
  11147. }
  11148. }
  11149. else
  11150. {
  11151. isSuccess = ConfigurationStatus_Rejected;
  11152. }
  11153. }
  11154. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11155. {
  11156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11157. {
  11158. check_ascii = value[0];
  11159. if( (check_ascii < 48) || (check_ascii > 57) )
  11160. {
  11161. isSuccess = ConfigurationStatus_Rejected;
  11162. }
  11163. else
  11164. {
  11165. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11167. TransactionMessageRetryIntervalValue = atoi(value);
  11168. isSuccess = ConfigurationStatus_Accepted;
  11169. }
  11170. }
  11171. else
  11172. {
  11173. isSuccess = ConfigurationStatus_Rejected;
  11174. }
  11175. }
  11176. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11177. {
  11178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11179. {
  11180. strcpy(str, (const char*)value);
  11181. for(int i = 0; str[i]; i++)
  11182. {
  11183. str[i] = tolower(str[i]);
  11184. }
  11185. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11187. isSuccess = ConfigurationStatus_Accepted;
  11188. }
  11189. else
  11190. {
  11191. isSuccess = ConfigurationStatus_Rejected;
  11192. }
  11193. }
  11194. if(strcmp(key, "WebSocketPingInterval") == 0)
  11195. {
  11196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11197. {
  11198. check_ascii = value[0];
  11199. if( (check_ascii < 48) || (check_ascii > 57) )
  11200. {
  11201. isSuccess = ConfigurationStatus_Rejected;
  11202. }
  11203. else
  11204. {
  11205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11206. isSuccess = ConfigurationStatus_Accepted;
  11207. }
  11208. }
  11209. else
  11210. {
  11211. isSuccess = ConfigurationStatus_Rejected;
  11212. }
  11213. }
  11214. #if 0
  11215. //For OCPP Test Case
  11216. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11217. {
  11218. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11219. {
  11220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11221. isSuccess = ConfigurationStatus_Accepted;
  11222. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11223. }
  11224. else
  11225. {
  11226. isSuccess = ConfigurationStatus_Rejected;
  11227. }
  11228. }
  11229. #endif
  11230. #if 1
  11231. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11232. {
  11233. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11234. {
  11235. strcpy(str, (const char*)value);
  11236. for(int i = 0; str[i]; i++)
  11237. {
  11238. str[i] = tolower(str[i]);
  11239. }
  11240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11241. isSuccess = ConfigurationStatus_Accepted;
  11242. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11243. }
  11244. else
  11245. {
  11246. isSuccess = ConfigurationStatus_Rejected;
  11247. }
  11248. }
  11249. #endif
  11250. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11251. {
  11252. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11253. {
  11254. check_ascii = value[0];
  11255. if( (check_ascii < 48) || (check_ascii > 57) )
  11256. {
  11257. isSuccess = ConfigurationStatus_Rejected;
  11258. }
  11259. else
  11260. {
  11261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11262. isSuccess = ConfigurationStatus_Accepted;
  11263. }
  11264. }
  11265. else
  11266. {
  11267. isSuccess = ConfigurationStatus_Rejected;
  11268. }
  11269. }
  11270. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11271. {
  11272. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11273. {
  11274. check_ascii = value[0];
  11275. if( (check_ascii < 48) || (check_ascii > 57) )
  11276. {
  11277. isSuccess = ConfigurationStatus_Rejected;
  11278. }
  11279. else
  11280. {
  11281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11282. isSuccess = ConfigurationStatus_Accepted;
  11283. }
  11284. }
  11285. else
  11286. {
  11287. isSuccess = ConfigurationStatus_Rejected;
  11288. }
  11289. }
  11290. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11291. {
  11292. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11293. {
  11294. strcpy(str, (const char*)value);
  11295. for(int i = 0; str[i]; i++)
  11296. {
  11297. str[i] = tolower(str[i]);
  11298. }
  11299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11300. isSuccess = ConfigurationStatus_Accepted;
  11301. }
  11302. else
  11303. {
  11304. isSuccess = ConfigurationStatus_Rejected;
  11305. }
  11306. }
  11307. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11308. {
  11309. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11310. {
  11311. check_ascii = value[0];
  11312. if( (check_ascii < 48) || (check_ascii > 57) )
  11313. {
  11314. isSuccess = ConfigurationStatus_Rejected;
  11315. }
  11316. else
  11317. {
  11318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11319. isSuccess = ConfigurationStatus_Accepted;
  11320. }
  11321. }
  11322. else
  11323. {
  11324. isSuccess = ConfigurationStatus_Rejected;
  11325. }
  11326. }
  11327. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11328. {
  11329. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11330. {
  11331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11332. isSuccess = ConfigurationStatus_Accepted;
  11333. }
  11334. else
  11335. {
  11336. isSuccess = ConfigurationStatus_Rejected;
  11337. }
  11338. }
  11339. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11340. {
  11341. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11342. {
  11343. check_ascii = value[0];
  11344. if( (check_ascii < 48) || (check_ascii > 57) )
  11345. {
  11346. isSuccess = ConfigurationStatus_Rejected;
  11347. }
  11348. else
  11349. {
  11350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11351. isSuccess = ConfigurationStatus_Accepted;
  11352. }
  11353. }
  11354. else
  11355. {
  11356. isSuccess = ConfigurationStatus_Rejected;
  11357. }
  11358. }
  11359. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11360. {
  11361. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11362. {
  11363. strcpy(str, (const char*)value);
  11364. for(int i = 0; str[i]; i++)
  11365. {
  11366. str[i] = tolower(str[i]);
  11367. }
  11368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11369. isSuccess = ConfigurationStatus_Accepted;
  11370. }
  11371. else
  11372. {
  11373. isSuccess = ConfigurationStatus_Rejected;
  11374. }
  11375. }
  11376. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11377. {
  11378. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11379. {
  11380. check_ascii = value[0];
  11381. if( (check_ascii < 48) || (check_ascii > 57) )
  11382. {
  11383. isSuccess = ConfigurationStatus_Rejected;
  11384. }
  11385. else
  11386. {
  11387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11388. isSuccess = ConfigurationStatus_Accepted;
  11389. }
  11390. }
  11391. else
  11392. {
  11393. isSuccess = ConfigurationStatus_Rejected;
  11394. }
  11395. }
  11396. return isSuccess;
  11397. }
  11398. int updateSetting(char *key, char *value)
  11399. {
  11400. mtrace();
  11401. int isSuccess = FALSE;
  11402. char string[1000]={0}, buffer[1000]={0};
  11403. char strtemp[50]={0};
  11404. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11405. int pos, c = 0;
  11406. char *loc;
  11407. int pos1=0;
  11408. FILE *f = fopen("/var/www/settings1", "r");
  11409. if(f == NULL)
  11410. {
  11411. #ifdef Debug
  11412. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11413. #endif
  11414. return isSuccess;
  11415. }
  11416. fseek(f, 0, SEEK_END);
  11417. long fsize = ftell(f);
  11418. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11419. fread(string, 1, fsize, f);
  11420. fclose(f);
  11421. string[fsize] = 0;
  11422. loc = strstr(string, key);
  11423. if(loc != NULL)
  11424. {
  11425. DEBUG_INFO("key exist!\n");
  11426. pos = loc - string-1;
  11427. f = fopen("/var/www/settings1", "w");
  11428. strncpy(buffer, string, pos);
  11429. fprintf(f, "%s", buffer);
  11430. memset(sstr ,0, sizeof(sstr) );
  11431. c = 0;
  11432. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11433. {
  11434. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11435. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11436. c++;
  11437. }
  11438. sstr[c] = '\0';
  11439. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11440. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11441. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11442. memset(buffer ,0, sizeof(buffer) );
  11443. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11444. //printf("buffer=%s",buffer);
  11445. fprintf(f, "%s", buffer);
  11446. fclose(f);
  11447. }
  11448. else
  11449. {
  11450. printf("key not exist!\n");
  11451. f = fopen("/var/www/settings1", "w+");
  11452. fputs(string, f);
  11453. fseek(f, -1, SEEK_CUR);
  11454. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  11455. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  11456. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  11457. fclose(f);
  11458. }
  11459. isSuccess = TRUE;
  11460. return isSuccess;
  11461. }
  11462. int TransactionMessageAttemptsGet(void)
  11463. {
  11464. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11465. }
  11466. int FirstHeartBeatResponse(void)
  11467. {
  11468. return FirstHeartBeat;
  11469. }
  11470. int TransactionMessageRetryIntervalGet(void)
  11471. {
  11472. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11473. }
  11474. #define SA struct sockaddr
  11475. #define MAXBUF 1024
  11476. //static int m_socket_data;
  11477. //static int sockfd;
  11478. int ReadHttpStatus(int sock){
  11479. //char c;
  11480. char buff[1024]="",*ptr=buff+1;
  11481. int bytes_received, status;
  11482. DEBUG_INFO("Begin Response ..\n");
  11483. while((bytes_received = recv(sock, ptr, 1, 0))){
  11484. if(bytes_received==-1){
  11485. perror("ReadHttpStatus");
  11486. exit(1);
  11487. }
  11488. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  11489. ptr++;
  11490. }
  11491. *ptr=0;
  11492. ptr=buff+1;
  11493. sscanf(ptr,"%*s %d ", &status);
  11494. DEBUG_INFO("%s\n",ptr);
  11495. DEBUG_INFO("status=%d\n",status);
  11496. DEBUG_INFO("End Response ..\n");
  11497. return (bytes_received>0)?status:0;
  11498. }
  11499. //the only filed that it parsed is 'Content-Length'
  11500. int ParseHeader(int sock){
  11501. //char c;
  11502. char buff[1024]="",*ptr=buff+4;
  11503. int bytes_received;
  11504. DEBUG_INFO("Begin HEADER ..\n");
  11505. while((bytes_received = recv(sock, ptr, 1, 0))){
  11506. if(bytes_received==-1){
  11507. perror("Parse Header");
  11508. exit(1);
  11509. }
  11510. if(
  11511. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  11512. (ptr[-1]=='\r') && (*ptr=='\n' )
  11513. ) break;
  11514. ptr++;
  11515. }
  11516. *ptr=0;
  11517. ptr=buff+4;
  11518. //printf("%s",ptr);
  11519. if(bytes_received){
  11520. ptr=strstr(ptr,"Content-Length:");
  11521. if(ptr){
  11522. sscanf(ptr,"%*s %d",&bytes_received);
  11523. }else
  11524. bytes_received=-1; //unknown size
  11525. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  11526. }
  11527. DEBUG_INFO("End HEADER ..\n");
  11528. return bytes_received ;
  11529. }
  11530. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  11531. {
  11532. char rmFileCmd[100]={0};
  11533. char FilePath[100]={0};
  11534. char ftpbuf[200];
  11535. int systemresult;
  11536. //DEBUG_INFO("filename=%s\n",filename);
  11537. //DEBUG_INFO("url=%s\n",url);
  11538. sprintf(FilePath,"../mnt/%s",filename);
  11539. if((access(FilePath,F_OK))!=-1)
  11540. {
  11541. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11542. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11543. system(rmFileCmd);
  11544. }
  11545. memset(ftpbuf, 0, sizeof(ftpbuf));
  11546. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11547. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11548. systemresult = system(ftpbuf);
  11549. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11550. if(systemresult != 0)
  11551. {
  11552. DEBUG_INFO("http DownLoad error!\n");
  11553. return FALSE;
  11554. }
  11555. return TRUE;
  11556. }
  11557. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  11558. {
  11559. char rmFileCmd[100]={0};
  11560. char FilePath[100]={0};
  11561. char ftpbuf[200];
  11562. int systemresult;
  11563. //char temp[100];
  11564. #if 0
  11565. struct hostent* server;
  11566. char *IPbuffer;
  11567. server = gethostbyname(location);
  11568. // To convert an Internet network
  11569. // address into ASCII string
  11570. IPbuffer = inet_ntoa(*((struct in_addr*)
  11571. server->h_addr_list[0]));
  11572. #endif
  11573. sprintf(FilePath,"../mnt/%s",filename);
  11574. if((access(FilePath,F_OK))!=-1)
  11575. {
  11576. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11577. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11578. system(rmFileCmd);
  11579. }
  11580. memset(ftpbuf, 0, sizeof(ftpbuf));
  11581. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11582. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  11583. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11584. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11585. systemresult = system(ftpbuf);
  11586. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11587. if(systemresult != 0)
  11588. {
  11589. printf("wget error!\n");
  11590. return FALSE;
  11591. }
  11592. return TRUE;
  11593. }
  11594. int httpUploadFile(char *location, char *path, char *filename,char *url)
  11595. {
  11596. char rmFileCmd[100]={0};
  11597. char FilePath[100]={0};
  11598. char ftpbuf[200];
  11599. int systemresult;
  11600. DEBUG_INFO("filename=%s\n",filename);
  11601. DEBUG_INFO("url=%s\n",url);
  11602. sprintf(FilePath,"%s","../mnt/upload_file.txt");
  11603. if((access(FilePath,F_OK))!=-1)
  11604. {
  11605. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11606. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11607. system(rmFileCmd);
  11608. }
  11609. FILE *fp = fopen("../mnt/upload_file.txt", "w+");
  11610. if(fp == NULL)
  11611. {
  11612. DEBUG_INFO("log is NULL\n");
  11613. return 0;
  11614. }
  11615. else
  11616. {
  11617. fprintf(fp, "%s\n", url);
  11618. fprintf(fp, "%s\n", filename);
  11619. fclose(fp);
  11620. }
  11621. memset(ftpbuf, 0, sizeof(ftpbuf));
  11622. sprintf(ftpbuf, "%s","../bin/php-cgi /var/www/ocpp_upload.php");
  11623. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11624. systemresult = system(ftpbuf);
  11625. DEBUG_INFO("systemresult=%d\n",systemresult);
  11626. if(systemresult != 0)
  11627. {
  11628. DEBUG_INFO("http DownLoad error!\n");
  11629. return FALSE;
  11630. }
  11631. return TRUE;
  11632. }
  11633. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  11634. {
  11635. struct hostent* server;
  11636. char *IPbuffer;
  11637. char ftpbuf[200];
  11638. int systemresult;
  11639. // To retrieve host information
  11640. server = gethostbyname(location);
  11641. // To convert an Internet network
  11642. // address into ASCII string
  11643. IPbuffer = inet_ntoa(*((struct in_addr*)
  11644. server->h_addr_list[0]));
  11645. memset(ftpbuf, 0, sizeof(ftpbuf));
  11646. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  11647. /* format : ftpput -u username -p passwd IP target source*/
  11648. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  11649. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11650. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11651. systemresult = system(ftpbuf);
  11652. DEBUG_INFO("systemresult=%d\n",systemresult);
  11653. if(systemresult != 0)
  11654. {
  11655. DEBUG_INFO("ftpput error!\n");
  11656. return FALSE;
  11657. }
  11658. return TRUE;
  11659. }
  11660. int SettingChargingRecord(int target, int transactionId)
  11661. {
  11662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11663. {
  11664. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11665. {
  11666. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11667. {
  11668. addBuff(target, transactionId, 0);
  11669. return TRUE;
  11670. }
  11671. }
  11672. for (int index = 0; index < CCS_QUANTITY; index++)
  11673. {
  11674. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11675. {
  11676. addBuff(target, transactionId, 0);
  11677. return TRUE;
  11678. }
  11679. }
  11680. for (int index = 0; index < GB_QUANTITY; index++)
  11681. {
  11682. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11683. {
  11684. addBuff(target, transactionId, 0);
  11685. return TRUE;
  11686. }
  11687. }
  11688. }
  11689. else
  11690. {
  11691. for (int index = 0; index < AC_QUANTITY; index++)
  11692. {
  11693. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11694. {
  11695. addBuff(target, transactionId, 0);
  11696. return TRUE;
  11697. }
  11698. }
  11699. }
  11700. return FALSE;
  11701. }
  11702. int addBuff(int gun_idx, int user_id, int cmd_sn)
  11703. {
  11704. int isSuccess = FALSE;
  11705. //char *query = NULL;
  11706. sqlite3_stmt *stmt;
  11707. int rc; // return code
  11708. char str[20];
  11709. sprintf(str,"%d",user_id);
  11710. 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 */
  11711. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  11712. rc = sqlite3_step(stmt); /* 3 */
  11713. if (rc != SQLITE_DONE) {
  11714. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  11715. goto out;
  11716. }
  11717. sqlite3_finalize(stmt);
  11718. // free(query);
  11719. out:
  11720. //----------------------
  11721. // close SQLite database
  11722. //----------------------
  11723. sqlite3_close(db);
  11724. printf("database closed.\n");
  11725. return isSuccess;
  11726. }
  11727. /**
  11728. * Place the contents of the specified file into a memory buffer
  11729. *
  11730. * @param[in] filename The path and name of the file to read
  11731. * @param[out] filebuffer A pointer to the contents in memory
  11732. * @return status 0 success, 1 on failure
  11733. */
  11734. int get_file_contents(const char* filename, char** outbuffer) {
  11735. FILE* file = NULL;
  11736. long filesize;
  11737. const int blocksize = 1;
  11738. size_t readsize;
  11739. char* filebuffer;
  11740. // Open the file
  11741. file = fopen(filename, "r");
  11742. if (NULL == file)
  11743. {
  11744. printf("'%s' not opened\n", filename);
  11745. exit(EXIT_FAILURE);
  11746. }
  11747. // Determine the file size
  11748. fseek(file, 0, SEEK_END);
  11749. filesize = ftell(file);
  11750. rewind (file);
  11751. // Allocate memory for the file contents
  11752. filebuffer = (char*) malloc(sizeof(char) * filesize);
  11753. *outbuffer = filebuffer;
  11754. if (filebuffer == NULL)
  11755. {
  11756. fputs ("malloc out-of-memory", stderr);
  11757. exit(EXIT_FAILURE);
  11758. }
  11759. // Read in the file
  11760. readsize = fread(filebuffer, blocksize, filesize, file);
  11761. if (readsize != filesize)
  11762. {
  11763. fputs ("didn't read file completely",stderr);
  11764. exit(EXIT_FAILURE);
  11765. }
  11766. // Clean exit
  11767. fclose(file);
  11768. return EXIT_SUCCESS;
  11769. }
  11770. static int selectSqlCount = 0;
  11771. static int callback(void *data, int argc, char **argv, char **azColName){
  11772. int i;
  11773. printf("%s: ", (const char*)data);
  11774. selectSqlCount = argc;
  11775. for(i = 0; i<argc; i++){
  11776. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  11777. }
  11778. printf("\n");
  11779. return 0;
  11780. }
  11781. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  11782. //int i;
  11783. //printf("%s:\n", (const char*)data);
  11784. localversion = argv[5] ? atoi(argv[5]) : 0;
  11785. printf("localversion=%d\n", localversion);
  11786. return 0;
  11787. }
  11788. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  11789. //int i;
  11790. //printf("%s:\n", (const char*)data);
  11791. //idTag
  11792. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  11793. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  11794. //parentIdTag
  11795. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  11796. //expir_date
  11797. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  11798. //status
  11799. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  11800. //version
  11801. idTagQuery.listVersionInt = atoi(argv[5]);
  11802. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  11803. return 0;
  11804. }
  11805. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  11806. int i;
  11807. //printf("%s:\n", (const char*)data);
  11808. #if 1
  11809. for(i=0; i<argc; i++){
  11810. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  11811. }
  11812. //printf("");
  11813. #endif
  11814. // localversion = argv[5] ? atoi(argv[5]) : 0;
  11815. // printf("localversion=%d\n", localversion);
  11816. return 0;
  11817. }
  11818. /** sqlite3_exec的回调。
  11819. *
  11820. * 向控制台打印查询的结果。
  11821. *
  11822. * @param in data 传递给回调函数的数据。
  11823. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  11824. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  11825. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  11826. * @return 状态码。
  11827. */
  11828. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  11829. {
  11830. for (int i = 0; i < n_columns; i++)
  11831. {
  11832. DEBUG_INFO("%s/t", col_values[i]);
  11833. }
  11834. DEBUG_INFO("/n");
  11835. return 0;
  11836. }
  11837. void OCPP_getListVerion()
  11838. {
  11839. int rc = 0;
  11840. // const char* data = "Callback function called";
  11841. char sql[100];
  11842. char zErrMsg[100];
  11843. memset(sql, 0, 100);
  11844. memset(zErrMsg, 0, 100);
  11845. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  11846. /* Execute SQL statement */
  11847. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  11848. DEBUG_INFO("rc=%d\n",rc);
  11849. if( rc != SQLITE_OK ){
  11850. DEBUG_INFO("SQL error: %s", zErrMsg);
  11851. //sqlite3_free(zErrMsg);
  11852. }else{
  11853. DEBUG_INFO("Operation done successfully");
  11854. }
  11855. }
  11856. void OCPP_getIdTag(char *idTag)
  11857. {
  11858. int rc = 0;
  11859. // const char* data = "Callback function called";
  11860. char sql[100];
  11861. char zErrMsg[100];
  11862. memset(sql, 0, 100);
  11863. memset(zErrMsg, 0, 100);
  11864. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  11865. memset(&idTagQuery, 0, sizeof(idTagQuery));
  11866. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11867. /* Execute SQL statement */
  11868. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  11869. if( rc != SQLITE_OK ){
  11870. DEBUG_INFO("SQL error: %s", zErrMsg);
  11871. //sqlite3_free(zErrMsg);
  11872. }else{
  11873. printf("Operation done successfully");
  11874. }
  11875. //return ver;
  11876. }
  11877. void OCPP_get_TableAuthlocalAllData(void)
  11878. {
  11879. int rc = 0;
  11880. // const char* data = "Callback function called";
  11881. char sql[100];
  11882. char zErrMsg[100];
  11883. memset(sql, 0, 100);
  11884. memset(zErrMsg, 0, 100);
  11885. sprintf(sql,"select * from ocpp_auth_local ");
  11886. /* Execute SQL statement */
  11887. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  11888. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  11889. if( rc != SQLITE_OK ){
  11890. DEBUG_INFO("SQL error: %s", zErrMsg);
  11891. //sqlite3_free(zErrMsg);
  11892. }else{
  11893. DEBUG_INFO("Operation done successfully");
  11894. }
  11895. //return ver;
  11896. }
  11897. int OCPP_cleanLocalList()
  11898. {
  11899. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  11900. char *errMsg = 0;
  11901. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  11902. if (SQLITE_OK != rc)
  11903. {
  11904. DEBUG_INFO("%s\n",errMsg);
  11905. return FALSE;
  11906. }
  11907. else
  11908. {
  11909. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  11910. }
  11911. return TRUE;
  11912. }
  11913. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11914. {
  11915. int isSuccess = FALSE;
  11916. int ret = 0;
  11917. //const char* data = "Callback function called";
  11918. char sql[200];
  11919. char zErrMsg[100];
  11920. memset(sql, 0, 200);
  11921. memset(zErrMsg, 0, 100);
  11922. 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);
  11923. //* Execute SQL statement */
  11924. //zErrMsg = 0;
  11925. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  11926. if( ret != SQLITE_OK ){
  11927. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  11928. // free(zErrMsg);
  11929. // free(sql);
  11930. return isSuccess;
  11931. }
  11932. DEBUG_INFO("successfully Insert records created\n");
  11933. isSuccess = TRUE;
  11934. return isSuccess;
  11935. }
  11936. void OCPP_deleteIdTag(char *idTag)
  11937. {
  11938. //int ver = 0;
  11939. //int isSuccess = FALSE;
  11940. int rc = 0;
  11941. char sql[100];
  11942. char zErrMsg[100];
  11943. memset(sql, 0, 100);
  11944. memset(zErrMsg, 0, 100);
  11945. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  11946. //* Execute SQL statement */
  11947. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  11948. if( rc != SQLITE_OK ){
  11949. DEBUG_INFO("SQL error: %s", zErrMsg);
  11950. //sqlite3_free(zErrMsg);
  11951. }else{
  11952. DEBUG_INFO("Operation done successfully");
  11953. }
  11954. }
  11955. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11956. {
  11957. int isSuccess = FALSE;
  11958. int ret = 0;
  11959. const char* data = "Callback function called";
  11960. char sql[200];
  11961. char zErrMsg[100];
  11962. memset(sql, 0, 200);
  11963. memset(zErrMsg, 0, 100);
  11964. //* selectFromTable */
  11965. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  11966. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11967. //* Execute SQL statement */
  11968. selectSqlCount = 0;
  11969. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11970. if( ret != SQLITE_OK ){
  11971. printf("Error SQL: %s\n", zErrMsg);
  11972. }
  11973. printf("successfully select operation done\n");
  11974. memset(sql, 0, 200);
  11975. memset(zErrMsg, 0, 100);
  11976. if(selectSqlCount == 0)
  11977. {
  11978. //Insert
  11979. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  11980. 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);
  11981. DEBUG_INFO("sql:%s\n", sql);
  11982. //* Execute SQL statement */
  11983. //zErrMsg = 0;
  11984. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  11985. if( ret != SQLITE_OK ){
  11986. printf("SQL error: %s\n", zErrMsg);
  11987. return isSuccess;
  11988. }
  11989. DEBUG_INFO("successfully Insert records created\n");
  11990. isSuccess = TRUE;
  11991. }
  11992. else
  11993. {
  11994. //Update
  11995. //* Create merged SQL statement */
  11996. 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);
  11997. /* Execute SQL statement */
  11998. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11999. if( ret != SQLITE_OK ){
  12000. printf("SQL error: %s\n", zErrMsg);
  12001. //sqlite3_free(zErrMsg);
  12002. //sqlite3_free(sql);
  12003. return isSuccess;
  12004. }
  12005. DEBUG_INFO("Successfully operation done \n");
  12006. isSuccess = TRUE;
  12007. }
  12008. return isSuccess;
  12009. }
  12010. int GetOcppServerURL()
  12011. {
  12012. int result = FALSE;
  12013. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12014. memset(OcppHost, 0, sizeof(OcppHost));
  12015. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12016. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12017. {
  12018. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12019. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12020. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12021. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12022. result = TRUE;
  12023. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12024. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12025. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12026. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12027. goto End;
  12028. }
  12029. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12030. {
  12031. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12032. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12033. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12034. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12035. result = TRUE;
  12036. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12037. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12038. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12039. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12040. goto End;
  12041. }
  12042. else
  12043. {
  12044. strcpy(OcppHost,"");
  12045. }
  12046. End:
  12047. return result;
  12048. }
  12049. int GetOcppPath()
  12050. {
  12051. int result = FALSE;
  12052. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12053. {
  12054. if(OcppTempPath == NULL)
  12055. {
  12056. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12057. }
  12058. else
  12059. {
  12060. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12061. }
  12062. result = TRUE;
  12063. goto End;
  12064. }
  12065. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12066. {
  12067. if(OcppTempPath == NULL)
  12068. {
  12069. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12070. }
  12071. else
  12072. {
  12073. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12074. }
  12075. result = TRUE;
  12076. goto End;
  12077. }
  12078. else
  12079. {
  12080. strcpy(OcppPath,"");
  12081. }
  12082. End:
  12083. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12084. return result;
  12085. }
  12086. int GetOcppPort()
  12087. {
  12088. return OcppPort;
  12089. }
  12090. int GetOcppConnStatus(void)
  12091. {
  12092. return ShmOCPP16Data->OcppConnStatus;
  12093. }
  12094. void SetOcppConnStatus(uint8_t status)
  12095. {
  12096. ShmOCPP16Data->OcppConnStatus = status;
  12097. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12098. if(status == FALSE)
  12099. {
  12100. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12101. {
  12102. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12103. }
  12104. else
  12105. {
  12106. SystemInitial = AC_QUANTITY;
  12107. }
  12108. }
  12109. }
  12110. int GetHeartBeatWithNOResponse(void)
  12111. {
  12112. return HeartBeatWithNOResponse;
  12113. }
  12114. void SetHeartBeatWithNOResponse(void)
  12115. {
  12116. HeartBeatWithNOResponse = 0;
  12117. }
  12118. int GetTransactionId(int gunindex)
  12119. {
  12120. return TransactionId[gunindex];
  12121. }
  12122. void SetTransactionIdZero(int gunindex)
  12123. {
  12124. TransactionId[gunindex] = 0;
  12125. }
  12126. int InternetDisconnect(void)
  12127. {
  12128. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12129. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12130. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12131. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12132. }
  12133. void GetChargingProfileRequest(int gunindex)
  12134. {
  12135. mtrace();
  12136. //int connectorIdInt, durationInt;
  12137. //char chargingRateUnitStr[4]={0};
  12138. int tempdurationInt = 0;
  12139. int tempchargingProfileId = 0;
  12140. int tempstackLevel = 0;
  12141. int temptransactionId = 0;
  12142. float tempminChargingRateFloat = 0.0;
  12143. char tempchargingProfilePurposeStr[24]={0};
  12144. char tempchargingProfileKindStr[12]={0};
  12145. char temprecurrencyKindStr[8]={0};
  12146. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12147. char tempvalidToStr[28]={0};
  12148. int tempStartPeriodInt = 0;
  12149. float tempLimitInt = 0.0;//0.1;
  12150. int tempNumberPhasesInt=0;
  12151. char fname[200];
  12152. //char comfirmstr[20];
  12153. float MinChargingRate =0.0;
  12154. double diff_t;
  12155. struct tm tp;
  12156. FILE *fptr1;//, *fptr2;
  12157. int c = 0;
  12158. char * pch;
  12159. char *loc;
  12160. char sstr[200]={ 0 };
  12161. int n_chargingProfile = 0;
  12162. int n_SchedulePeriods = 0;
  12163. char SchedulePeriodList[10][200]={0};
  12164. char sLineWord[800]={0};
  12165. char word[1000]={0};
  12166. int confirmPeriods = 0;
  12167. struct StructProfile ChargePointMaxProfile;
  12168. struct StructProfile TxDefaultProfile;
  12169. struct StructProfile TxProfile;
  12170. struct StructProfile TxDefaultProfiletemp[2]={0};
  12171. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12172. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12173. struct StructChargingProfile TxProfile_TEMP={0};
  12174. int TxDefaultProfileFileIsNull=FALSE;
  12175. int ChargePointMaxProfileIsNull=FALSE;
  12176. int TxProfileIsNull=FALSE;
  12177. // int CompositeSceduleIndex = 0;
  12178. char ChargePointMaxProfileScheduleStr[30]={0};
  12179. char TxDefaultProfileScheduleStr[30]={0};
  12180. char TxProfileScheduleStr[30]={0};
  12181. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12182. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12183. memset(&TxProfile,0,sizeof(struct StructProfile));
  12184. DEBUG_INFO("GetChargingProfileRequest\n");
  12185. //*****************************ChargePointMaxProfile******************************************/
  12186. strcpy(fname, ChargePointMaxProfile_JSON);
  12187. ChargePointMaxProfileIsNull=TRUE;
  12188. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12189. {
  12190. fptr1 = fopen(fname, "r");
  12191. int c;
  12192. c = fgetc(fptr1);
  12193. //DEBUG_INFO("c:%d\n",c);
  12194. rewind(fptr1);
  12195. if(c == EOF)
  12196. {
  12197. DEBUG_INFO("\n End of file reached.");
  12198. ChargePointMaxProfileIsNull=TRUE;
  12199. fclose(fptr1);
  12200. }
  12201. else
  12202. {
  12203. ChargePointMaxProfileIsNull=FALSE;
  12204. while(fscanf(fptr1, "%s", word) != EOF)
  12205. {
  12206. if(strcmp(word, "chargingProfileId") == 0)
  12207. {
  12208. n_chargingProfile = n_chargingProfile + 1;
  12209. }
  12210. }
  12211. rewind(fptr1);
  12212. //search Charging Profile Element
  12213. int i = 0;
  12214. int j = 0;
  12215. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12216. //***********chargingProfileId**************/
  12217. c = 0;
  12218. loc = strstr(sLineWord, "chargingProfileId");
  12219. //DEBUG_INFO("loc=%s\n",loc);
  12220. memset(sstr ,0, sizeof(sstr) );
  12221. if(loc != NULL)
  12222. {
  12223. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12224. {
  12225. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12226. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12227. c++;
  12228. }
  12229. sstr[c] = '\0';
  12230. tempchargingProfileId = atoi(sstr);
  12231. }
  12232. else
  12233. {
  12234. tempchargingProfileId = 0;
  12235. }
  12236. //***********stackLevel**************/
  12237. c = 0;
  12238. loc = strstr(sLineWord, "stackLevel");
  12239. //DEBUG_INFO("loc=%s\n",loc);
  12240. memset(sstr ,0, sizeof(sstr) );
  12241. if(loc != NULL)
  12242. {
  12243. while (loc[2+strlen("stackLevel")+c] != '\"')
  12244. {
  12245. sstr[c] = loc[2+strlen("stackLevel")+c];
  12246. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12247. c++;
  12248. }
  12249. sstr[c] = '\0';
  12250. tempstackLevel = atoi(sstr);
  12251. }
  12252. else
  12253. {
  12254. tempstackLevel = 0;
  12255. }
  12256. //***********chargingProfilePurpose **************/
  12257. c = 0;
  12258. loc = strstr(sLineWord, "chargingProfilePurpose");
  12259. //DEBUG_INFO("loc=%s\n",loc);
  12260. memset(sstr ,0, sizeof(sstr) );
  12261. if(loc != NULL)
  12262. {
  12263. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12264. {
  12265. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12266. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12267. c++;
  12268. }
  12269. sstr[c] = '\0';
  12270. strcpy(tempchargingProfilePurposeStr,sstr);
  12271. }
  12272. else
  12273. {
  12274. strcpy(tempchargingProfilePurposeStr,"");
  12275. }
  12276. //***********chargingProfileKind **************/
  12277. c = 0;
  12278. loc = strstr(sLineWord, "chargingProfileKind");
  12279. //DEBUG_INFO("loc=%s\n",loc);
  12280. memset(sstr ,0, sizeof(sstr) );
  12281. if(loc != NULL)
  12282. {
  12283. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12284. {
  12285. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12286. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12287. c++;
  12288. }
  12289. sstr[c] = '\0';
  12290. strcpy(tempchargingProfileKindStr,sstr);
  12291. }
  12292. else
  12293. {
  12294. strcpy(tempchargingProfileKindStr,"");
  12295. }
  12296. //***********recurrencyKind **************/
  12297. c = 0;
  12298. loc = strstr(sLineWord, "recurrencyKind");
  12299. //DEBUG_INFO("loc=%s\n",loc);
  12300. memset(sstr ,0, sizeof(sstr) );
  12301. if(loc != NULL)
  12302. {
  12303. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12304. {
  12305. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12306. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12307. c++;
  12308. }
  12309. sstr[c] = '\0';
  12310. strcpy(temprecurrencyKindStr,sstr);
  12311. }
  12312. else
  12313. {
  12314. strcpy(temprecurrencyKindStr,"");
  12315. }
  12316. //***********validFrom**************/
  12317. c = 0;
  12318. loc = strstr(sLineWord, "validFrom");
  12319. //DEBUG_INFO("loc=%s\n",loc);
  12320. memset(sstr ,0, sizeof(sstr) );
  12321. if(loc != NULL)
  12322. {
  12323. while (loc[3+strlen("validFrom")+c] != '\"')
  12324. {
  12325. sstr[c] = loc[3+strlen("validFrom")+c];
  12326. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12327. c++;
  12328. }
  12329. sstr[c] = '\0';
  12330. strcpy(tempvalidFromStr,sstr);
  12331. }
  12332. else
  12333. {
  12334. strcpy(tempvalidFromStr,"");
  12335. }
  12336. //***********validTo **************/
  12337. c = 0;
  12338. loc = strstr(sLineWord, "validTo");
  12339. //DEBUG_INFO("loc=%s\n",loc);
  12340. memset(sstr ,0, sizeof(sstr) );
  12341. if(loc != NULL)
  12342. {
  12343. while (loc[3+strlen("validTo")+c] != '\"')
  12344. {
  12345. sstr[c] = loc[3+strlen("validTo")+c];
  12346. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12347. c++;
  12348. }
  12349. sstr[c] = '\0';
  12350. strcpy(tempvalidToStr,sstr);
  12351. }
  12352. else
  12353. {
  12354. strcpy(tempvalidToStr,"");
  12355. }
  12356. //***********validFrom**************/
  12357. c = 0;
  12358. loc = strstr(sLineWord, "validFrom");
  12359. if(loc != NULL)
  12360. {
  12361. memset(sstr ,0, sizeof(sstr) );
  12362. while (loc[3+strlen("validFrom")+c] != '\"')
  12363. {
  12364. sstr[c] = loc[3+strlen("validFrom")+c];
  12365. c++;
  12366. }
  12367. sstr[c] = '\0';
  12368. strcpy(tempvalidFromStr,sstr);
  12369. }
  12370. else
  12371. {
  12372. strcpy(tempvalidFromStr,"");
  12373. }
  12374. //***********duration**************/
  12375. c = 0;
  12376. loc = strstr(sLineWord, "duration");
  12377. if(loc != NULL)
  12378. {
  12379. memset(sstr ,0, sizeof(sstr) );
  12380. while (loc[2+strlen("duration")+c] != ',')
  12381. {
  12382. sstr[c] = loc[2+strlen("duration")+c];
  12383. c++;
  12384. }
  12385. sstr[c] = '\0';
  12386. tempdurationInt = atoi(sstr);
  12387. }
  12388. else
  12389. {
  12390. tempdurationInt = 0;
  12391. }
  12392. //**********startSchedule**********/
  12393. c = 0;
  12394. loc = strstr(sLineWord, "startSchedule");
  12395. memset(sstr ,0, sizeof(sstr) );
  12396. while (loc[3+strlen("startSchedule")+c] != '\"')
  12397. {
  12398. sstr[c] = loc[3+strlen("startSchedule")+c];
  12399. c++;
  12400. }
  12401. sstr[c] = '\0';
  12402. strcpy(tempstartScheduleStr, sstr);
  12403. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  12404. //**********chargingRateUnit**********/
  12405. c = 0;
  12406. loc = strstr(sLineWord, "chargingRateUnit");
  12407. memset(sstr ,0, sizeof(sstr) );
  12408. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12409. {
  12410. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12411. c++;
  12412. }
  12413. sstr[c] = '\0';
  12414. strcpy(tempchargingRateUnitStr, sstr);
  12415. //**********minChargingRate*******/
  12416. c = 0;
  12417. loc = strstr(sLineWord, "minChargingRate");
  12418. if(loc != NULL)
  12419. {
  12420. memset(sstr ,0, sizeof(sstr) );
  12421. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12422. {
  12423. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12424. c++;
  12425. }
  12426. sstr[c] = '\0';
  12427. tempminChargingRateFloat = atof(sstr);
  12428. }
  12429. else
  12430. {
  12431. tempminChargingRateFloat = 0.0;
  12432. }
  12433. //
  12434. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12435. tp.tm_isdst = -1;
  12436. time_t utc = mktime(&tp);
  12437. time_t t = time(NULL);
  12438. diff_t = difftime(t, utc);
  12439. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12440. //parsing strings to words
  12441. i = 0;
  12442. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12443. loc = loc+3+strlen("chargingSchedulePeriod");
  12444. pch = strtok(loc ,"{");
  12445. while (pch != NULL)
  12446. {
  12447. strcpy(SchedulePeriodList[i], pch);
  12448. pch = strtok (NULL, "{");
  12449. i = i + 1;
  12450. }
  12451. n_SchedulePeriods = i;
  12452. for(int i=0;i<n_SchedulePeriods;i++)
  12453. {
  12454. //*************startPeriod****************/
  12455. c = 0;
  12456. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12457. memset(sstr ,0, sizeof(sstr) );
  12458. while (loc[strlen("startPeriod")+2+c] != ',')
  12459. {
  12460. sstr[c] = loc[strlen("startPeriod")+2+c];
  12461. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12462. c++;
  12463. }
  12464. sstr[c] = '\0';
  12465. tempStartPeriodInt = atoi(sstr);
  12466. //*************limit****************/
  12467. c = 0;
  12468. loc = strstr(SchedulePeriodList[i], "limit");
  12469. memset(sstr ,0, sizeof(sstr) );
  12470. while (loc[strlen("limit")+2+c] != ',')
  12471. {
  12472. sstr[c] = loc[strlen("limit")+2+c];
  12473. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12474. c++;
  12475. }
  12476. sstr[c] = '\0';
  12477. tempLimitInt = atof(sstr);
  12478. //*************numberPhases****************/
  12479. c = 0;
  12480. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12481. memset(sstr ,0, sizeof(sstr) );
  12482. while (loc[strlen("numberPhases")+2+c] != '}')
  12483. {
  12484. sstr[c] = loc[strlen("numberPhases")+2+c];
  12485. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12486. c++;
  12487. }
  12488. sstr[c] = '\0';
  12489. tempNumberPhasesInt = atoi(sstr);
  12490. if(j == 0)
  12491. {
  12492. ChargePointMaxProfile.Duration = tempdurationInt;
  12493. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  12494. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  12495. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12496. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12497. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12498. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  12499. ChargePointMaxProfile_TEMP.TransactionId = 0;
  12500. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12501. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12502. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12503. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12504. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12505. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12506. }
  12507. }
  12508. if(MinChargingRate < tempminChargingRateFloat)
  12509. {
  12510. MinChargingRate = tempminChargingRateFloat;
  12511. }
  12512. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12513. if(confirmPeriods < n_SchedulePeriods)
  12514. {
  12515. confirmPeriods = n_SchedulePeriods;
  12516. }
  12517. j = j + 1;
  12518. }
  12519. fclose(fptr1);
  12520. }
  12521. }// the end of access file ChargePointMaxProfile
  12522. //****************************TxDefaultProfile************************************************/
  12523. switch(gunindex + 1)
  12524. {
  12525. case 0:
  12526. break;
  12527. case 1:
  12528. strcpy(fname, TxDefaultProfile_1_JSON );
  12529. break;
  12530. case 2:
  12531. strcpy(fname, TxDefaultProfile_2_JSON );
  12532. break;
  12533. default:
  12534. strcpy(fname, TxDefaultProfile_1_JSON );
  12535. break;
  12536. }
  12537. TxDefaultProfileFileIsNull=TRUE;
  12538. if((access(fname,F_OK))!=-1)
  12539. {
  12540. fptr1 = fopen(fname, "r");
  12541. c = 0;
  12542. c = fgetc(fptr1);
  12543. //DEBUG_INFO("c:%d\n",c);
  12544. rewind(fptr1);
  12545. if(c == EOF)
  12546. {
  12547. DEBUG_INFO("\n End of file reached.");
  12548. TxDefaultProfileFileIsNull=TRUE;
  12549. fclose(fptr1);
  12550. }
  12551. else
  12552. {
  12553. TxDefaultProfileFileIsNull=FALSE;
  12554. while(fscanf(fptr1, "%s", word) != EOF)
  12555. {
  12556. if(strcmp(word, "chargingProfileId") == 0)
  12557. {
  12558. n_chargingProfile = n_chargingProfile + 1;
  12559. }
  12560. }
  12561. rewind(fptr1);
  12562. //search Charging Profile Element
  12563. int i = 0;
  12564. int j = 0;
  12565. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12566. #if 0
  12567. /***********connectorId****************/
  12568. c = 0;
  12569. loc = strstr(sLineWord, "connectorId");
  12570. memset(sstr ,0, sizeof(sstr) );
  12571. while (loc[strlen("connectorId")+2+c] != ',')
  12572. {
  12573. sstr[c] = loc[strlen("connectorId")+2+c];
  12574. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12575. c++;
  12576. }
  12577. sstr[c] = '\0';
  12578. tempconnectorIdInt = atoi(sstr);
  12579. #endif
  12580. //***********chargingProfileId**************/
  12581. c = 0;
  12582. loc = strstr(sLineWord, "chargingProfileId");
  12583. //DEBUG_INFO("loc=%s\n",loc);
  12584. memset(sstr ,0, sizeof(sstr) );
  12585. if(loc != NULL)
  12586. {
  12587. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12588. {
  12589. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12590. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12591. c++;
  12592. }
  12593. sstr[c] = '\0';
  12594. tempchargingProfileId = atoi(sstr);
  12595. }
  12596. else
  12597. {
  12598. tempchargingProfileId = 0;
  12599. }
  12600. //***********stackLevel**************/
  12601. c = 0;
  12602. loc = strstr(sLineWord, "stackLevel");
  12603. //DEBUG_INFO("loc=%s\n",loc);
  12604. memset(sstr ,0, sizeof(sstr) );
  12605. if(loc != NULL)
  12606. {
  12607. while (loc[2+strlen("stackLevel")+c] != '\"')
  12608. {
  12609. sstr[c] = loc[2+strlen("stackLevel")+c];
  12610. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12611. c++;
  12612. }
  12613. sstr[c] = '\0';
  12614. tempstackLevel = atoi(sstr);
  12615. }
  12616. else
  12617. {
  12618. tempstackLevel = 0;
  12619. }
  12620. //***********chargingProfilePurpose **************/
  12621. c = 0;
  12622. loc = strstr(sLineWord, "chargingProfilePurpose");
  12623. //DEBUG_INFO("loc=%s\n",loc);
  12624. memset(sstr ,0, sizeof(sstr) );
  12625. if(loc != NULL)
  12626. {
  12627. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12628. {
  12629. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12630. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12631. c++;
  12632. }
  12633. sstr[c] = '\0';
  12634. strcpy(tempchargingProfilePurposeStr,sstr);
  12635. }
  12636. else
  12637. {
  12638. strcpy(tempchargingProfilePurposeStr,"");
  12639. }
  12640. //***********chargingProfileKind **************/
  12641. c = 0;
  12642. loc = strstr(sLineWord, "chargingProfileKind");
  12643. //DEBUG_INFO("loc=%s\n",loc);
  12644. memset(sstr ,0, sizeof(sstr) );
  12645. if(loc != NULL)
  12646. {
  12647. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12648. {
  12649. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12650. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12651. c++;
  12652. }
  12653. sstr[c] = '\0';
  12654. strcpy(tempchargingProfileKindStr,sstr);
  12655. }
  12656. else
  12657. {
  12658. strcpy(tempchargingProfileKindStr,"");
  12659. }
  12660. //***********recurrencyKind **************/
  12661. c = 0;
  12662. loc = strstr(sLineWord, "recurrencyKind");
  12663. //DEBUG_INFO("loc=%s\n",loc);
  12664. memset(sstr ,0, sizeof(sstr) );
  12665. if(loc != NULL)
  12666. {
  12667. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12668. {
  12669. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12670. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12671. c++;
  12672. }
  12673. sstr[c] = '\0';
  12674. strcpy(temprecurrencyKindStr,sstr);
  12675. }
  12676. else
  12677. {
  12678. strcpy(temprecurrencyKindStr,"");
  12679. }
  12680. //***********validFrom**************/
  12681. c = 0;
  12682. loc = strstr(sLineWord, "validFrom");
  12683. if(loc != NULL)
  12684. {
  12685. memset(sstr ,0, sizeof(sstr) );
  12686. while (loc[3+strlen("validFrom")+c] != '\"')
  12687. {
  12688. sstr[c] = loc[3+strlen("validFrom")+c];
  12689. c++;
  12690. }
  12691. sstr[c] = '\0';
  12692. strcpy(tempvalidFromStr,sstr);
  12693. }
  12694. else
  12695. {
  12696. strcpy(tempvalidFromStr,"");
  12697. }
  12698. //***********validFrom**************/
  12699. c = 0;
  12700. loc = strstr(sLineWord, "duration");
  12701. if(loc != NULL)
  12702. {
  12703. memset(sstr ,0, sizeof(sstr) );
  12704. while (loc[2+strlen("duration")+c] != ',')
  12705. {
  12706. sstr[c] = loc[2+strlen("duration")+c];
  12707. c++;
  12708. }
  12709. sstr[c] = '\0';
  12710. tempdurationInt = atoi(sstr);
  12711. }
  12712. else
  12713. {
  12714. tempdurationInt = 0;
  12715. }
  12716. //**********startSchedule**********/
  12717. c = 0;
  12718. loc = strstr(sLineWord, "startSchedule");
  12719. memset(sstr ,0, sizeof(sstr) );
  12720. while (loc[3+strlen("startSchedule")+c] != '\"')
  12721. {
  12722. sstr[c] = loc[3+strlen("startSchedule")+c];
  12723. c++;
  12724. }
  12725. sstr[c] = '\0';
  12726. strcpy(tempstartScheduleStr, sstr);
  12727. strcpy(TxDefaultProfileScheduleStr, sstr);
  12728. //**********chargingRateUnit**********/
  12729. c = 0;
  12730. loc = strstr(sLineWord, "chargingRateUnit");
  12731. memset(sstr ,0, sizeof(sstr) );
  12732. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12733. {
  12734. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12735. c++;
  12736. }
  12737. sstr[c] = '\0';
  12738. strcpy(tempchargingRateUnitStr, sstr);
  12739. //**********minChargingRate*******/
  12740. c = 0;
  12741. loc = strstr(sLineWord, "minChargingRate");
  12742. if(loc != NULL)
  12743. {
  12744. memset(sstr ,0, sizeof(sstr) );
  12745. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12746. {
  12747. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12748. c++;
  12749. }
  12750. sstr[c] = '\0';
  12751. tempminChargingRateFloat = atof(sstr);
  12752. }
  12753. else
  12754. {
  12755. tempminChargingRateFloat = 0.0;
  12756. }
  12757. //
  12758. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12759. tp.tm_isdst = -1;
  12760. time_t utc = mktime(&tp);
  12761. time_t t = time(NULL);
  12762. diff_t = difftime(t, utc);
  12763. printf("diff between startScheduleStr and now =%f\n",diff_t);
  12764. //parsing strings to words
  12765. i = 0;
  12766. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12767. loc = loc+3+strlen("chargingSchedulePeriod");
  12768. pch = strtok(loc ,"{");
  12769. while (pch != NULL)
  12770. {
  12771. strcpy(SchedulePeriodList[i], pch);
  12772. pch = strtok (NULL, "{");
  12773. i = i + 1;
  12774. }
  12775. n_SchedulePeriods = i;
  12776. for(int i=0;i<n_SchedulePeriods;i++)
  12777. {
  12778. //*************startPeriod****************/
  12779. c = 0;
  12780. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12781. memset(sstr ,0, sizeof(sstr) );
  12782. while (loc[strlen("startPeriod")+2+c] != ',')
  12783. {
  12784. sstr[c] = loc[strlen("startPeriod")+2+c];
  12785. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12786. c++;
  12787. }
  12788. sstr[c] = '\0';
  12789. tempStartPeriodInt = atoi(sstr);
  12790. //*************limit****************/
  12791. c = 0;
  12792. loc = strstr(SchedulePeriodList[i], "limit");
  12793. memset(sstr ,0, sizeof(sstr) );
  12794. while (loc[strlen("limit")+2+c] != ',')
  12795. {
  12796. sstr[c] = loc[strlen("limit")+2+c];
  12797. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12798. c++;
  12799. }
  12800. sstr[c] = '\0';
  12801. tempLimitInt = atof(sstr);
  12802. //*************numberPhases****************/
  12803. c = 0;
  12804. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12805. memset(sstr ,0, sizeof(sstr) );
  12806. while (loc[strlen("numberPhases")+2+c] != '}')
  12807. {
  12808. sstr[c] = loc[strlen("numberPhases")+2+c];
  12809. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12810. c++;
  12811. }
  12812. sstr[c] = '\0';
  12813. tempNumberPhasesInt = atoi(sstr);
  12814. if(j == 0)
  12815. {
  12816. TxDefaultProfile.Duration = tempdurationInt;
  12817. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  12818. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  12819. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12820. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12821. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12822. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  12823. TxDefaultProfile_TEMP.TransactionId = 0;
  12824. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  12825. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12826. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12827. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12828. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12829. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12830. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12831. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12832. }
  12833. else
  12834. {
  12835. //other stack level charging Profile
  12836. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  12837. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  12838. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  12839. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  12840. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  12841. }
  12842. }
  12843. if(MinChargingRate < tempminChargingRateFloat)
  12844. {
  12845. MinChargingRate = tempminChargingRateFloat;
  12846. }
  12847. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12848. if(confirmPeriods < n_SchedulePeriods)
  12849. confirmPeriods = n_SchedulePeriods;
  12850. j = j + 1;
  12851. }
  12852. fclose(fptr1);
  12853. //Stacking Charging Profiles
  12854. for(int l=0; l <(j-1) ;l++)
  12855. {
  12856. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  12857. {
  12858. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  12859. {
  12860. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  12861. {
  12862. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  12863. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  12864. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  12865. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12866. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12867. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12868. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12869. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12870. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12871. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12872. }
  12873. else
  12874. {
  12875. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12876. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12877. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12878. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12879. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12880. }
  12881. }
  12882. }
  12883. }
  12884. //end of Stacking Charging Profiles
  12885. }
  12886. }// the end of ACCESS TxDefaultProfile
  12887. //****************************TxProfile************************************************/
  12888. switch(gunindex + 1)
  12889. {
  12890. case 0:
  12891. break;
  12892. case 1:
  12893. strcpy(fname, TxProfile_1_JSON );
  12894. break;
  12895. case 2:
  12896. strcpy(fname, TxProfile_2_JSON );
  12897. break;
  12898. default:
  12899. strcpy(fname, TxProfile_1_JSON );
  12900. break;
  12901. }
  12902. TxProfileIsNull=TRUE;
  12903. if((access(fname,F_OK))!=-1)
  12904. {
  12905. fptr1 = fopen(fname, "r");
  12906. c = 0;
  12907. c = fgetc(fptr1);
  12908. //DEBUG_INFO("c:%d\n",c);
  12909. rewind(fptr1);
  12910. if(c == EOF)
  12911. {
  12912. DEBUG_INFO("\n End of file reached.");
  12913. TxProfileIsNull=TRUE;
  12914. fclose(fptr1);
  12915. }
  12916. else
  12917. {
  12918. TxProfileIsNull=FALSE;
  12919. while(fscanf(fptr1, "%s", word) != EOF)
  12920. {
  12921. if(strcmp(word, "chargingProfileId") == 0)
  12922. {
  12923. n_chargingProfile = n_chargingProfile + 1;
  12924. }
  12925. }
  12926. rewind(fptr1);
  12927. //search Charging Profile Element
  12928. int i= 0;
  12929. int j= 0;
  12930. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12931. #if 0
  12932. /***********connectorId****************/
  12933. c = 0;
  12934. loc = strstr(sLineWord, "connectorId");
  12935. memset(sstr ,0, sizeof(sstr) );
  12936. while (loc[strlen("connectorId")+2+c] != ',')
  12937. {
  12938. sstr[c] = loc[strlen("connectorId")+2+c];
  12939. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12940. c++;
  12941. }
  12942. sstr[c] = '\0';
  12943. tempconnectorIdInt = atoi(sstr);
  12944. #endif
  12945. //***********chargingProfileId**************/
  12946. c = 0;
  12947. loc = strstr(sLineWord, "chargingProfileId");
  12948. memset(sstr ,0, sizeof(sstr) );
  12949. if(loc != NULL)
  12950. {
  12951. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12952. {
  12953. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12954. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12955. c++;
  12956. }
  12957. sstr[c] = '\0';
  12958. tempchargingProfileId = atoi(sstr);
  12959. }
  12960. else
  12961. {
  12962. tempchargingProfileId = 0;
  12963. }
  12964. //***********transactionId **************/
  12965. c = 0;
  12966. loc = strstr(sLineWord, "transactionId");
  12967. //DEBUG_INFO("loc=%s\n",loc);
  12968. memset(sstr ,0, sizeof(sstr) );
  12969. if(loc != NULL)
  12970. {
  12971. while (loc[2+strlen("transactionId")+c] != '\"')
  12972. {
  12973. sstr[c] = loc[2+strlen("transactionId")+c];
  12974. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12975. c++;
  12976. }
  12977. sstr[c] = '\0';
  12978. temptransactionId = atoi(sstr);
  12979. }
  12980. else
  12981. {
  12982. temptransactionId = 0;
  12983. }
  12984. //***********stackLevel**************/
  12985. c = 0;
  12986. loc = strstr(sLineWord, "stackLevel");
  12987. //DEBUG_INFO("loc=%s\n",loc);
  12988. memset(sstr ,0, sizeof(sstr) );
  12989. if(loc != NULL)
  12990. {
  12991. while (loc[2+strlen("stackLevel")+c] != '\"')
  12992. {
  12993. sstr[c] = loc[2+strlen("stackLevel")+c];
  12994. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12995. c++;
  12996. }
  12997. sstr[c] = '\0';
  12998. tempstackLevel = atoi(sstr);
  12999. }
  13000. else
  13001. {
  13002. tempstackLevel = 0;
  13003. }
  13004. //***********chargingProfilePurpose **************/
  13005. c = 0;
  13006. loc = strstr(sLineWord, "chargingProfilePurpose");
  13007. //DEBUG_INFO("loc=%s\n",loc);
  13008. memset(sstr ,0, sizeof(sstr) );
  13009. if(loc != NULL)
  13010. {
  13011. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13012. {
  13013. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13014. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13015. c++;
  13016. }
  13017. sstr[c] = '\0';
  13018. strcpy(tempchargingProfilePurposeStr,sstr);
  13019. }
  13020. else
  13021. {
  13022. strcpy(tempchargingProfilePurposeStr,"");
  13023. }
  13024. //***********chargingProfileKind **************/
  13025. c = 0;
  13026. loc = strstr(sLineWord, "chargingProfileKind");
  13027. //DEBUG_INFO("loc=%s\n",loc);
  13028. memset(sstr ,0, sizeof(sstr) );
  13029. if(loc != NULL)
  13030. {
  13031. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13032. {
  13033. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13034. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13035. c++;
  13036. }
  13037. sstr[c] = '\0';
  13038. strcpy(tempchargingProfileKindStr,sstr);
  13039. }
  13040. else
  13041. {
  13042. strcpy(tempchargingProfileKindStr,"");
  13043. }
  13044. //***********recurrencyKind **************/
  13045. c = 0;
  13046. loc = strstr(sLineWord, "recurrencyKind");
  13047. //DEBUG_INFO("loc=%s\n",loc);
  13048. memset(sstr ,0, sizeof(sstr) );
  13049. if(loc != NULL)
  13050. {
  13051. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13052. {
  13053. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13054. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13055. c++;
  13056. }
  13057. sstr[c] = '\0';
  13058. strcpy(temprecurrencyKindStr,sstr);
  13059. }
  13060. else
  13061. {
  13062. strcpy(temprecurrencyKindStr,"");
  13063. }
  13064. //***********validFrom**************/
  13065. c = 0;
  13066. loc = strstr(sLineWord, "validFrom");
  13067. if(loc != NULL)
  13068. {
  13069. memset(sstr ,0, sizeof(sstr) );
  13070. while (loc[3+strlen("validFrom")+c] != '\"')
  13071. {
  13072. sstr[c] = loc[3+strlen("validFrom")+c];
  13073. c++;
  13074. }
  13075. sstr[c] = '\0';
  13076. strcpy(tempvalidFromStr,sstr);
  13077. }
  13078. else
  13079. {
  13080. strcpy(tempvalidFromStr,"");
  13081. }
  13082. //***********duration**************/
  13083. c = 0;
  13084. loc = strstr(sLineWord, "duration");
  13085. //DEBUG_INFO("loc=%s\n",loc);
  13086. memset(sstr ,0, sizeof(sstr) );
  13087. if(loc != NULL)
  13088. {
  13089. while (loc[2+strlen("duration")+c] != '\"')
  13090. {
  13091. sstr[c] = loc[2+strlen("duration")+c];
  13092. c++;
  13093. }
  13094. sstr[c] = '\0';
  13095. tempdurationInt = atoi(sstr);
  13096. }
  13097. else
  13098. {
  13099. tempdurationInt = 0;
  13100. }
  13101. //**********startSchedule**********/
  13102. c = 0;
  13103. loc = strstr(sLineWord, "startSchedule");
  13104. memset(sstr ,0, sizeof(sstr) );
  13105. while (loc[3+strlen("startSchedule")+c] != '\"')
  13106. {
  13107. sstr[c] = loc[3+strlen("startSchedule")+c];
  13108. c++;
  13109. }
  13110. sstr[c] = '\0';
  13111. strcpy(tempstartScheduleStr, sstr);
  13112. strcpy(TxProfileScheduleStr, sstr);
  13113. //**********chargingRateUnit**********/
  13114. c = 0;
  13115. loc = strstr(sLineWord, "chargingRateUnit");
  13116. memset(sstr ,0, sizeof(sstr) );
  13117. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13118. {
  13119. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13120. c++;
  13121. }
  13122. sstr[c] = '\0';
  13123. strcpy(tempchargingRateUnitStr, sstr);
  13124. //**********minChargingRate*******/
  13125. c = 0;
  13126. loc = strstr(sLineWord, "minChargingRate");
  13127. if(loc != NULL)
  13128. {
  13129. memset(sstr ,0, sizeof(sstr) );
  13130. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13131. {
  13132. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13133. c++;
  13134. }
  13135. sstr[c] = '\0';
  13136. tempminChargingRateFloat = atof(sstr);
  13137. }
  13138. else
  13139. {
  13140. tempminChargingRateFloat = 0.0;
  13141. }
  13142. //
  13143. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13144. tp.tm_isdst = -1;
  13145. time_t utc = mktime(&tp);
  13146. time_t t = time(NULL);
  13147. diff_t = difftime(t, utc);
  13148. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13149. //parsing strings to words
  13150. i = 0;
  13151. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13152. loc = loc+3+strlen("chargingSchedulePeriod");
  13153. pch = strtok(loc ,"{");
  13154. while (pch != NULL)
  13155. {
  13156. strcpy(SchedulePeriodList[i], pch);
  13157. pch = strtok (NULL, "{");
  13158. i = i + 1;
  13159. }
  13160. n_SchedulePeriods = i;
  13161. for(int i=0;i<n_SchedulePeriods;i++)
  13162. {
  13163. //*************startPeriod****************/
  13164. c = 0;
  13165. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13166. memset(sstr ,0, sizeof(sstr) );
  13167. while (loc[strlen("startPeriod")+2+c] != ',')
  13168. {
  13169. sstr[c] = loc[strlen("startPeriod")+2+c];
  13170. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13171. c++;
  13172. }
  13173. sstr[c] = '\0';
  13174. tempStartPeriodInt = atoi(sstr);
  13175. //*************limit****************/
  13176. c = 0;
  13177. loc = strstr(SchedulePeriodList[i], "limit");
  13178. memset(sstr ,0, sizeof(sstr) );
  13179. while (loc[strlen("limit")+2+c] != ',')
  13180. {
  13181. sstr[c] = loc[strlen("limit")+2+c];
  13182. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13183. c++;
  13184. }
  13185. sstr[c] = '\0';
  13186. tempLimitInt = atof(sstr);
  13187. //*************numberPhases****************/
  13188. c = 0;
  13189. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13190. memset(sstr ,0, sizeof(sstr) );
  13191. while (loc[strlen("numberPhases")+2+c] != '}')
  13192. {
  13193. sstr[c] = loc[strlen("numberPhases")+2+c];
  13194. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13195. c++;
  13196. }
  13197. sstr[c] = '\0';
  13198. tempNumberPhasesInt = atoi(sstr);
  13199. //TxProfile.Duration = durationInt;
  13200. TxProfile.TotalPeriod = n_SchedulePeriods;
  13201. TxProfile.Period[i].Limit = tempLimitInt;
  13202. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13203. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13204. }
  13205. if(MinChargingRate < tempminChargingRateFloat)
  13206. {
  13207. MinChargingRate = tempminChargingRateFloat;
  13208. }
  13209. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13210. if(confirmPeriods < n_SchedulePeriods)
  13211. confirmPeriods = n_SchedulePeriods;
  13212. if(j == 0)
  13213. {
  13214. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13215. TxProfile_TEMP.StackLevel = tempstackLevel;
  13216. TxProfile_TEMP.TransactionId = 0;
  13217. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13218. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13219. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13220. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13221. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13222. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13223. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13224. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13225. }
  13226. }
  13227. fclose(fptr1);
  13228. }
  13229. }// the end of ACCESS TxProfile
  13230. //CompositeSchedule
  13231. int period=0;
  13232. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13233. {
  13234. //TxProfile
  13235. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13236. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13237. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13238. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13239. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13240. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13241. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13242. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13243. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13244. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13245. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13246. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13247. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13248. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13249. {
  13250. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13251. {
  13252. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13253. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13254. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13255. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13256. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13257. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13258. period = period + 1;
  13259. }
  13260. else
  13261. {
  13262. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13263. {
  13264. }
  13265. else
  13266. {
  13267. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13268. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13269. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13270. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13271. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13272. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13273. period = period + 1;
  13274. }
  13275. }
  13276. }
  13277. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13278. {
  13279. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  13280. {
  13281. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13282. {
  13283. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13284. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13285. }
  13286. else
  13287. {
  13288. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13289. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13290. }
  13291. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13292. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13293. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13294. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13295. period = period + 1;
  13296. }
  13297. }
  13298. }
  13299. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13300. {
  13301. //TxDefaultProfile
  13302. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13303. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13304. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13305. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13306. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  13307. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13308. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13309. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13310. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13311. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13312. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13313. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13314. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13315. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13316. {
  13317. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13318. {
  13319. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13320. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13321. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13322. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13323. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13324. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13325. period = period + 1;
  13326. }
  13327. else
  13328. {
  13329. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13330. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13331. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13332. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13333. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13334. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13335. period = period + 1;
  13336. }
  13337. }
  13338. }
  13339. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  13340. {
  13341. //TxDefaultProfile
  13342. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13343. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13344. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13345. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13346. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  13347. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13348. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13349. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13350. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13351. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13352. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13353. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13354. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13355. {
  13356. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13357. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13358. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13359. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13360. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13361. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13362. period = period + 1;
  13363. }
  13364. }
  13365. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13366. {
  13367. //ChargePointMaxProfile
  13368. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  13369. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  13370. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13371. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  13372. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  13373. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13374. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  13375. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  13376. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  13377. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  13378. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  13379. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  13380. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  13381. {
  13382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  13383. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  13384. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  13385. period = period + 1;
  13386. }
  13387. }
  13388. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  13389. {
  13390. //TxProfile
  13391. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13393. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13394. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13395. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13396. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13397. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13398. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13399. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13400. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13401. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13402. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13403. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13404. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13405. {
  13406. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  13407. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  13408. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  13409. }
  13410. }
  13411. confirmPeriods = period;
  13412. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  13413. 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,"
  13414. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  13415. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  13416. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  13417. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  13418. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  13419. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  13420. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  13421. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  13422. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  13423. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  13424. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  13425. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  13426. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  13427. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  13428. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  13429. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  13430. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  13431. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  13432. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  13433. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  13434. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  13435. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  13436. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  13437. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  13438. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  13439. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  13440. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  13441. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  13442. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  13443. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  13444. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  13445. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  13446. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  13447. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  13448. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  13449. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  13450. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  13451. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  13452. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  13453. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  13454. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  13455. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  13456. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  13457. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  13458. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  13459. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  13460. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  13461. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  13462. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  13463. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  13464. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  13465. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  13466. }
  13467. void LWS_Send(char * str)
  13468. {
  13469. //=====================================================
  13470. // Check InternetConn 0: disconnected, 1: connected
  13471. //====================================================
  13472. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13473. {
  13474. DEBUG_INFO("\n offline now !!!\n");
  13475. return;
  13476. }
  13477. pthread_mutex_lock(&lock);
  13478. memset(SendBuffer,0,SendBufLen);
  13479. sprintf((char *)SendBuffer, "%s", str);
  13480. pthread_mutex_unlock(&lock);
  13481. lws_callback_on_writable(wsi_client);
  13482. lws_service(context, 10000);//timeout_ms
  13483. }