MessageHandler.c 609 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "define.h"
  21. #include <sys/socket.h>
  22. #include <netinet/in.h>
  23. #include <stdlib.h>
  24. /*for sendfile()*/
  25. #include <sys/sendfile.h>
  26. /*for O_RDONLY*/
  27. #include <fcntl.h>
  28. #include "sqlite3.h"
  29. #include <arpa/inet.h>
  30. #include <time.h>
  31. #include <assert.h>
  32. #include <pthread.h>
  33. #include <mcheck.h>
  34. #include "MessageHandler.h"
  35. #include "SystemLogMessage.h"
  36. #include "hashmap.h"
  37. #include "ShareMemory.h"
  38. #include "TransactionQueue.h"
  39. #define PASS 1
  40. #define FAIL -1
  41. #define FALSE 0
  42. #define TRUE 1 // Option 1
  43. //ChargePointMaxProfile
  44. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  45. //TxDefaultProfile
  46. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  47. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  48. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  49. //TxProfile
  50. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  51. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  52. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  53. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  54. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  55. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  56. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  57. //===================================
  58. // Define CP State constant
  59. //===================================
  60. #define CP_STATE_UNKNOWN 0
  61. #define CP_STATE_A 1
  62. #define CP_STATE_B 2
  63. #define CP_STATE_C 3
  64. #define CP_STATE_D 4
  65. #define CP_STATE_E 5
  66. #define CP_STATE_F 6
  67. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  68. struct StatusCodeData *ShmStatusCodeData;
  69. struct PsuData *ShmPsuData ;
  70. struct OCPP16Data *ShmOCPP16Data;
  71. // define Macro
  72. #define SystemLogMessage
  73. // OCPP Message Type
  74. #define MESSAGE_TYPE_CALL 2
  75. #define MESSAGE_TYPE_CALLRESULT 3
  76. #define MESSAGE_TYPE_CALLERROR 4
  77. //
  78. //#define server_cycle_Status 120
  79. #define MACROSTR(k) #k
  80. //ConfigurationMaxKeys
  81. #define GetConfigurationMaxKeysNUM 43
  82. //char guid[37];
  83. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  84. char queuedata[2600]={0};
  85. //=================================
  86. // StatusNotification cycle
  87. //=================================
  88. static int server_cycle_Status = 120;
  89. //===============================
  90. // Configuration: unknownkey
  91. //===============================
  92. static char unknownkey[10][20]={0};
  93. static int UnknownKeynum = 0;
  94. //===============================
  95. // Gun Total Numbers
  96. //===============================
  97. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  98. static int gunTotalNumber=0;
  99. //===============================
  100. // Local List Version
  101. //===============================
  102. static int localversion=0;
  103. static char idTagAuthorization[32]={0};
  104. //===============================
  105. // OCPP Path
  106. //===============================
  107. extern char OcppPath[160];
  108. extern char OcppProtocol[10];
  109. extern char OcppHost[50];
  110. extern char OcppTempPath[50];
  111. int OcppPort=0;
  112. //===============================
  113. // OCPP sign variable
  114. //===============================
  115. int server_sign = FALSE;
  116. int server_pending = FALSE;
  117. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  118. int BootNotificationInterval = 0;
  119. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  120. //===============================
  121. // OCPP auth variable
  122. //===============================
  123. int authenrequest = FALSE;
  124. int authorizeRetryTimes = 0; //number of Retry times
  125. //===============================
  126. // OCPP StartTransaction transactionId variables
  127. //===============================
  128. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  129. //===============================
  130. // OCPP other variables
  131. //===============================
  132. int isUpdateRequest = FALSE;
  133. static int HeartBeatWaitTime = 10;
  134. static int FirstHeartBeat = 0;
  135. static int FirmwareStatusNotificationStatus = 3; // Idle
  136. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  137. static char CurrentChargingProfileScheduleStr[30]={0};
  138. //========================================
  139. // OCPP status/previous related variables
  140. //========================================
  141. static int GunStatusInterval = 10;
  142. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  143. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  144. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  145. static int GbPreviousSystemStatus[GB_QUANTITY];
  146. static int AcPreviousSystemStatus[AC_QUANTITY];
  147. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  148. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  149. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  150. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  151. int TransactionMessageAttemptsValue = 0;
  152. int TransactionMessageRetryIntervalValue = 0;
  153. static struct OCPPAuthLocalElemet
  154. {
  155. int listVersionInt;
  156. char idTagstr[20];
  157. char parentIdTag[20];
  158. char expiryDate[30];
  159. char idTagstatus[16];
  160. }idTagQuery;
  161. //=============================================
  162. // OCPP HeartBeat Response Not Receive Counts
  163. //============================================
  164. static int HeartBeatWithNOResponse = 0;
  165. static int HeartBeatCountPerHour = 0;
  166. extern struct lws *wsi_client;
  167. extern struct lws_context *context;
  168. extern unsigned char SendBuffer[4096];
  169. extern int SendBufLen;
  170. extern char *random_uuid( char buf[37] );
  171. extern void split(char **arr, char *str, const char *del);
  172. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  173. extern int GetTransactionQueueNum(void);
  174. extern pthread_mutex_t mutex1;
  175. extern struct Charger_Info Charger;
  176. extern sqlite3 *db;
  177. int TransactionMessageAttemptsGet(void);
  178. int TransactionMessageRetryIntervalGet(void);
  179. int GetOcppConnStatus(void);
  180. void SetOcppConnStatus(uint8_t status);
  181. int updateSetting(char *key, char *value);
  182. int setKeyValue(char *key, char *value);
  183. void OCPP_get_TableAuthlocalAllData(void);
  184. void processUnkownKey(void);
  185. struct StructOCPPMeterValue
  186. {
  187. unsigned char TimeStamp[28];
  188. struct StructSampledValue SampledValue[10];
  189. };
  190. struct ClientTime
  191. {
  192. unsigned int Heartbeat;
  193. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  194. unsigned int StartTransaction;
  195. unsigned int StopTransaction;
  196. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  197. }clientTime;
  198. typedef union
  199. {
  200. //Operations Initiated by Central System
  201. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  202. struct
  203. {
  204. //CsMsgValue[0]
  205. unsigned char StatusNotificationReq :1; //bit 0,
  206. unsigned char StatusNotificationConf :1; //bit 0,
  207. unsigned char :6; //bit 2~7
  208. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  209. }CpinitiateMsg;
  210. CpinitiateMsg cpinitateMsg;
  211. //==========================================
  212. // Init all Enumeration & Mapping String
  213. //==========================================
  214. /*ChargePointErrorCode*/
  215. typedef enum {
  216. ConnectorLockFailure,
  217. EVCommunicationError,
  218. GroundFailure,
  219. HighTemperature,
  220. InternalError,
  221. LocalListConflict,
  222. NoError,
  223. OtherError,
  224. OverCurrentFailure,
  225. OverVoltage,
  226. PowerMeterFailure,
  227. PowerSwitchFailure,
  228. ReaderFailure,
  229. ResetFailure,
  230. UnderVoltage,
  231. WeakSignal
  232. } ChargePointErrorCode;
  233. #if 0
  234. static char *ChargePointErrorCodeStr[] = {
  235. MACROSTR(ConnectorLockFailure),
  236. MACROSTR(EVCommunicationError),
  237. MACROSTR(GroundFailure),
  238. MACROSTR(HighTemperature),
  239. MACROSTR(InternalError),
  240. MACROSTR(LocalListConflict),
  241. MACROSTR(NoError),
  242. MACROSTR(OtherError),
  243. MACROSTR(OverCurrentFailure),
  244. MACROSTR(OverVoltage),
  245. MACROSTR(PowerMeterFailure),
  246. MACROSTR(PowerSwitchFailure),
  247. MACROSTR(ReaderFailure),
  248. MACROSTR(ResetFailure),
  249. MACROSTR(UnderVoltage),
  250. MACROSTR(WeakSignal)
  251. };
  252. #endif
  253. /*ChargePointStatus*/
  254. typedef enum {
  255. Available =0,
  256. Preparing,
  257. Charging,
  258. SuspendedEVSE,
  259. SuspendedEV,
  260. Finishing,
  261. Reserved,
  262. Unavailable,
  263. Faulted
  264. } ChargePointStatus;
  265. static char * ChargePointStatusStr[] = {
  266. MACROSTR(Available),
  267. MACROSTR(Preparing),
  268. MACROSTR(Charging),
  269. MACROSTR(SuspendedEVSE),
  270. MACROSTR(SuspendedEV),
  271. MACROSTR(Finishing),
  272. MACROSTR(Reserved),
  273. MACROSTR(Unavailable),
  274. MACROSTR(Faulted)
  275. };
  276. /*AvailabilityType*/
  277. typedef enum {
  278. RegistrationStatus_Accepted,
  279. RegistrationStatus_Pending,
  280. RegistrationStatus_Rejected
  281. } RegistrationStatus;
  282. static char *RegistrationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Pending),
  285. MACROSTR(Rejected)
  286. };
  287. /*AvailabilityType*/
  288. typedef enum {
  289. Inoperative,
  290. Operative
  291. } AvailabilityType;
  292. static char *AvailabilityTypeStr[] = {
  293. MACROSTR(Inoperative),
  294. MACROSTR(Operative)
  295. };
  296. /*AvailabilityStatus*/
  297. typedef enum {
  298. Accepted,
  299. Rejected,
  300. Scheduled
  301. } AvailabilityStatus;
  302. static char *AvailabilityStatusStr[] = {
  303. MACROSTR(Accepted),
  304. MACROSTR(Rejected),
  305. MACROSTR(Scheduled)
  306. };
  307. /*ConfigurationStatus*/
  308. typedef enum {
  309. ConfigurationStatus_Accepted,
  310. ConfigurationStatus_Rejected,
  311. RebootRequired,
  312. NotSupported
  313. } ConfigurationStatus;
  314. static char *ConfigurationStatusStr[] = {
  315. MACROSTR(Accepted),
  316. MACROSTR(Rejected),
  317. MACROSTR(RebootRequired),
  318. MACROSTR(NotSupported)
  319. };
  320. /*ClearCacheStatus*/
  321. typedef enum {
  322. ClearCacheStatus_Accepted,
  323. ClearCacheStatus_Rejected
  324. } ClearCacheStatus;
  325. static char *ClearCacheStatusStr[] = {
  326. MACROSTR(Accepted),
  327. MACROSTR(Rejected)
  328. };
  329. /*ChargingProfilePurposeType*/
  330. typedef enum {
  331. ChargePointMaxProfile,
  332. TxDefaultProfile,
  333. TxProfile
  334. } ChargingProfilePurposeType;
  335. static char *ChargingProfilePurposeTypeStr[] = {
  336. MACROSTR(ChargePointMaxProfile),
  337. MACROSTR(TxDefaultProfile),
  338. MACROSTR(TxProfile)
  339. };
  340. /*ChargingProfileStatus*/
  341. typedef enum {
  342. ChargingProfileStatus_Accepted,
  343. ChargingProfileStatus_Rejected,
  344. ChargingProfileStatus_NotSupported
  345. } ChargingProfileStatus;
  346. static char *ChargingProfileStatusStr[] = {
  347. MACROSTR(Accepted),
  348. MACROSTR(Rejected),
  349. MACROSTR(NotSupported)
  350. };
  351. /*ClearChargingProfileStatus*/
  352. typedef enum {
  353. ClearChargingProfileStatus_Accepted,
  354. ClearChargingProfileStatus_Unknown
  355. } ClearChargingProfileStatus;
  356. static char *ClearChargingProfileStatusStr[] = {
  357. MACROSTR(Accepted),
  358. MACROSTR(Unknown)
  359. };
  360. /*GetCompositeScheduleStatus*/
  361. typedef enum {
  362. GetCompositeScheduleStatus_Accepted,
  363. GetCompositeScheduleStatus_Rejected
  364. } GetCompositeScheduleStatus;
  365. static char *GetCompositeScheduleStatusStr[] = {
  366. MACROSTR(Accepted),
  367. MACROSTR(Rejected)
  368. };
  369. /*ChargingRateUnitType*/
  370. typedef enum {
  371. ChargingRateUnitType_W,
  372. ChargingRateUnitType_A
  373. } ChargingRateUnitType;
  374. /*AuthorizationStatus*/
  375. typedef enum {
  376. AuthorizationStatus_Accepted ,
  377. AuthorizationStatus_Blocked ,
  378. AuthorizationStatus_Expired ,
  379. AuthorizationStatus_Invalid ,
  380. AuthorizationStatus_ConcurrentTx
  381. } AuthorizationStatus;
  382. /*UpdateType*/
  383. typedef enum {
  384. Differential ,
  385. Full
  386. } UpdateType;
  387. static char *UpdateTypeStr[] = {
  388. MACROSTR(Differential),
  389. MACROSTR(Full)
  390. };
  391. /*UpdateStatus*/
  392. typedef enum {
  393. UpdateStatus_Accepted ,
  394. UpdateStatus_Failed ,
  395. UpdateStatus_NotSupported ,
  396. UpdateStatus_VersionMismatch
  397. } UpdateStatus;
  398. static char *UpdateStatusStr[] = {
  399. MACROSTR(Accepted),
  400. MACROSTR(Failed),
  401. MACROSTR(NotSupported),
  402. MACROSTR(VersionMismatch)
  403. };
  404. /*RemoteStartStopStatus*/
  405. typedef enum {
  406. RemoteStartStopStatus_Accepted,
  407. RemoteStartStopStatus_Rejected
  408. } RemoteStartStopStatus;
  409. static char *RemoteStartStopStatusStr[] = {
  410. MACROSTR(Accepted),
  411. MACROSTR(Rejected)
  412. };
  413. /*ReservationStatus*/
  414. typedef enum {
  415. ReservationStatus_Accepted,
  416. ReservationStatus_Faulted,
  417. ReservationStatus_Occupied,
  418. ReservationStatus_Rejected,
  419. ReservationStatus_Unavailable
  420. } ReservationStatus;
  421. static char *ReservationStatusStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Faulted),
  424. MACROSTR(Occupied),
  425. MACROSTR(Rejected),
  426. MACROSTR(Unavailable)
  427. };
  428. /*ResetType*/
  429. typedef enum {
  430. Hard,
  431. Soft
  432. } ResetType;
  433. static char *ResetTypeStr[] = {
  434. MACROSTR(Hard),
  435. MACROSTR(Soft)
  436. };
  437. /*ResetStatus*/
  438. typedef enum {
  439. ResetStatus_Accepted,
  440. ResetStatus_Rejected
  441. } ResetStatus;
  442. static char *ResetStatusStr[] = {
  443. MACROSTR(Accepted),
  444. MACROSTR(Rejected)
  445. };
  446. /*DiagnosticsStatus*/
  447. typedef enum {
  448. DiagnosticsStatus_Idle,
  449. DiagnosticsStatus_Uploaded,
  450. DiagnosticsStatus_UploadFailed,
  451. DiagnosticsStatus_Uploading
  452. } DiagnosticsStatus;
  453. static char * DiagnosticsStatusStr[] = {
  454. MACROSTR(Idle),
  455. MACROSTR(Uploaded),
  456. MACROSTR(UploadFailed),
  457. MACROSTR(Uploading)
  458. };
  459. /*FirmwareStatus*/
  460. typedef enum {
  461. FirmwareStatus_Downloaded,
  462. FirmwareStatus_DownloadFailed,
  463. FirmwareStatus_Downloading,
  464. FirmwareStatus_Idle,
  465. FirmwareStatus_InstallationFailed,
  466. FirmwareStatus_Installing,
  467. FirmwareStatus_Installed
  468. } FirmwareStatus;
  469. static char * FirmwareStatusStr[] = {
  470. MACROSTR(Downloaded),
  471. MACROSTR(DownloadFailed),
  472. MACROSTR(Downloading),
  473. MACROSTR(Idle),
  474. MACROSTR(InstallationFailed),
  475. MACROSTR(Installing),
  476. MACROSTR(Installed)
  477. };
  478. /*MessageTrigger*/
  479. typedef enum {
  480. BootNotification,
  481. DiagnosticsStatusNotification,
  482. FirmwareStatusNotification,
  483. Heartbeat,
  484. MeterValues,
  485. StatusNotification
  486. } MessageTrigger;
  487. static char * MessageTriggerStr[] = {
  488. MACROSTR(BootNotification),
  489. MACROSTR(DiagnosticsStatusNotification),
  490. MACROSTR(FirmwareStatusNotification),
  491. MACROSTR(Heartbeat),
  492. MACROSTR(MeterValues),
  493. MACROSTR(StatusNotification)
  494. };
  495. /*TriggerMessageStatus*/
  496. typedef enum {
  497. TriggerMessageStatus_Accepted ,
  498. TriggerMessageStatus_Rejected ,
  499. TriggerMessageStatus_NotImplemented
  500. } TriggerMessageStatus;
  501. static char * TriggerMessageStatusStr[] = {
  502. MACROSTR(Accepted),
  503. MACROSTR(Rejected),
  504. MACROSTR(NotImplemented)
  505. };
  506. /*UnlockStatus*/
  507. typedef enum {
  508. Unlocked,
  509. UnlockFailed,
  510. UnlockStatus_NotSupported
  511. } UnlockStatus;
  512. static char * UnlockStatusStr[] = {
  513. MACROSTR(Unlocked),
  514. MACROSTR(UnlockFailed),
  515. MACROSTR(NotSupported)
  516. };
  517. /*StopTransactionReason*/
  518. typedef enum {
  519. EmergencyStop,
  520. EVDisconnected,
  521. HardReset,
  522. Local,
  523. Other,
  524. PowerLoss,
  525. Reboot,
  526. Remote,
  527. SoftReset,
  528. UnlockCommand,
  529. DeAuthorized
  530. } StopTransactionReason;
  531. #if 0
  532. static char * StopTransactionReasonStr[] = {
  533. MACROSTR(EmergencyStop),
  534. MACROSTR(EVDisconnected),
  535. MACROSTR(HardReset),
  536. MACROSTR(Local),
  537. MACROSTR(Other),
  538. MACROSTR(PowerLoss),
  539. MACROSTR(Reboot),
  540. MACROSTR(Remote),
  541. MACROSTR(SoftReset),
  542. MACROSTR(UnlockCommand),
  543. MACROSTR(DeAuthorized)
  544. };
  545. #endif
  546. /*CancelReservationStatus*/
  547. typedef enum {
  548. CancelReservationStatus_Accepted,
  549. CancelReservationStatus_Rejected
  550. } CancelReservationStatus;
  551. static char * CancelReservationStatusStr[] = {
  552. MACROSTR(Accepted),
  553. MACROSTR(Rejected)
  554. };
  555. /*ReadingContext*/
  556. typedef enum {
  557. ReadingContext_Interruption_Begin,
  558. ReadingContext_Interruption_End,
  559. ReadingContext_Other,
  560. ReadingContext_Sample_Clock,
  561. ReadingContext_Sample_Periodic ,
  562. ReadingContext_Transaction_Begin ,
  563. ReadingContext_Transaction_End,
  564. ReadingContext_Trigger
  565. } ReadingContext;
  566. static char * ReadingContextStr[] = {
  567. MACROSTR(Interruption.Begin),
  568. MACROSTR(Interruption.End),
  569. MACROSTR(Other),
  570. MACROSTR(Sample.Clock),
  571. MACROSTR(Sample.Periodic),
  572. MACROSTR(Transaction.Begin),
  573. MACROSTR(Transaction.End),
  574. MACROSTR(Trigger)
  575. };
  576. /*ValueFormat*/
  577. typedef enum {
  578. Raw,
  579. SignedData
  580. } ValueFormat;
  581. static char * ValueFormatStr[] = {
  582. MACROSTR(Raw),
  583. MACROSTR(SignedData)
  584. };
  585. /*Measurand*/
  586. typedef enum {
  587. Current_Export ,
  588. Current_Import,
  589. Current_Offered,
  590. Energy_Active_Export_Register,
  591. Energy_Active_Import_Register,
  592. Energy_Reactive_Export_Register,
  593. Energy_Reactive_Import_Register,
  594. Energy_Active_Export_Interval,
  595. Energy_Active_Import_Interval,
  596. Energy_Reactive_Export_Interval,
  597. Energy_Reactive_Import_Interval,
  598. Frequency,
  599. Power_Active_Export ,
  600. Power_Active_Import,
  601. Power_Factor,
  602. Power_Offered,
  603. Power_Reactive_Export,
  604. Power_Reactive_Import,
  605. RPM,
  606. SoC,
  607. Temperature ,
  608. Voltage
  609. } Measurand;
  610. static char * MeasurandStr[] = {
  611. MACROSTR(Current.Export),
  612. MACROSTR(Current.Import),
  613. MACROSTR(Current.Offered),
  614. MACROSTR(Energy.Active.Export.Register),
  615. MACROSTR(Energy.Active.Import.Register),
  616. MACROSTR(Energy.Reactive.Export.Register),
  617. MACROSTR(Energy.Reactive.Import.Register),
  618. MACROSTR(Energy.Active.Export.Interval),
  619. MACROSTR(Energy.Active.Import.Interval),
  620. MACROSTR(Energy.Reactive.Export.Interval),
  621. MACROSTR(Energy.Reactive.Import.Interval),
  622. MACROSTR(Frequency),
  623. MACROSTR(Power.Active.Export),
  624. MACROSTR(Power.Active.Import),
  625. MACROSTR(Power.Factor),
  626. MACROSTR(Power.Offered),
  627. MACROSTR(Power.Reactive.ExportMACROSTR),
  628. MACROSTR(Power.Reactive.Import),
  629. MACROSTR(RPM),
  630. MACROSTR(SoC),
  631. MACROSTR(Temperature),
  632. MACROSTR(Voltage)
  633. };
  634. /*Location*/
  635. typedef enum {
  636. Location_Body,
  637. Location_Cable,
  638. Location_EV,
  639. Location_Inlet ,
  640. Location_Outlet
  641. } Location;
  642. static char * LocationStr[] = {
  643. MACROSTR(Body),
  644. MACROSTR(Cable),
  645. MACROSTR(EV),
  646. MACROSTR(Inlet),
  647. MACROSTR(Outlet)
  648. };
  649. /*Phase*/
  650. typedef enum {
  651. L1,
  652. L2,
  653. L3,
  654. N,
  655. L1_N,
  656. L2_N,
  657. L3_N,
  658. L1_L2,
  659. L2_L3,
  660. L3_L1
  661. } Phase;
  662. static char * PhaseStr[] = {
  663. MACROSTR(L1),
  664. MACROSTR(L2),
  665. MACROSTR(L3),
  666. MACROSTR(N),
  667. MACROSTR(L1-N),
  668. MACROSTR(L2-N),
  669. MACROSTR(L3-N),
  670. MACROSTR(L1-L2),
  671. MACROSTR(L2-L3),
  672. MACROSTR(L3-L1)
  673. };
  674. /*UnitOfMeasure*/
  675. typedef enum {
  676. UnitOfMeasure_Wh,
  677. UnitOfMeasure_kWh ,
  678. UnitOfMeasure_varh ,
  679. UnitOfMeasure_kvarh ,
  680. UnitOfMeasure_W ,
  681. UnitOfMeasure_kW ,
  682. UnitOfMeasure_VA ,
  683. UnitOfMeasure_kVA ,
  684. UnitOfMeasure_var ,
  685. UnitOfMeasure_kvar ,
  686. UnitOfMeasure_A ,
  687. UnitOfMeasure_V ,
  688. UnitOfMeasure_Celsius ,
  689. UnitOfMeasure_Fahrenheit ,
  690. UnitOfMeasure_K ,
  691. UnitOfMeasure_Percent
  692. } UnitOfMeasure;
  693. static char * UnitOfMeasureStr[] = {
  694. MACROSTR(Wh),
  695. MACROSTR(kWh),
  696. MACROSTR(varh),
  697. MACROSTR(kvarh),
  698. MACROSTR(W),
  699. MACROSTR(kW),
  700. MACROSTR(VA),
  701. MACROSTR(kVA),
  702. MACROSTR(var),
  703. MACROSTR(kvar),
  704. MACROSTR(A),
  705. MACROSTR(V),
  706. MACROSTR(Celsius),
  707. MACROSTR(Fahrenheit),
  708. MACROSTR(K),
  709. MACROSTR(Percent)
  710. };
  711. #if 0
  712. /*Configuration enum*/
  713. enum CoreProfile {
  714. AllowOfflineTxForUnknownId=0,
  715. AuthorizationCacheEnabled,
  716. AuthorizeRemoteTxRequests,
  717. BlinkRepeat,
  718. ClockAlignedDataInterval,
  719. ConnectionTimeOut,
  720. GetConfigurationMaxKeys,
  721. HeartbeatInterval,
  722. LightIntensity,
  723. LocalAuthorizeOffline,
  724. LocalPreAuthorize,
  725. MaxEnergyOnInvalidId,
  726. MeterValuesAlignedData,
  727. MeterValuesAlignedDataMaxLength,
  728. MeterValuesSampledData,
  729. MeterValuesSampledDataMaxLength,
  730. MeterValueSampleInterval,
  731. MinimumStatusDuration,
  732. NumberOfConnectors,
  733. ResetRetries,
  734. ConnectorPhaseRotation,
  735. ConnectorPhaseRotationMaxLength,
  736. StopTransactionOnEVSideDisconnect,
  737. StopTransactionOnInvalidId,
  738. StopTxnAlignedData,
  739. StopTxnAlignedDataMaxLength,
  740. StopTxnSampledData,
  741. StopTxnSampledDataMaxLength,
  742. SupportedFeatureProfiles,
  743. SupportedFeatureProfilesMaxLength,
  744. TransactionMessageAttempts,
  745. TransactionMessageRetryInterval,
  746. UnlockConnectorOnEVSideDisconnect,
  747. WebSocketPingInterval,
  748. _CoreProfile_CNT
  749. };
  750. #endif
  751. enum LocalAuthListManagementProfile{
  752. LocalAuthListEnabled=0,
  753. LocalAuthListMaxLength,
  754. SendLocalListMaxLength,
  755. _LocalAuthListManagementProfile_CNT
  756. };
  757. enum ReservationProfile{
  758. ReserveConnectorZeroSupported
  759. };
  760. enum SmartChargingProfile{
  761. ChargeProfileMaxStackLevel,
  762. ChargingScheduleAllowedChargingRateUnit,
  763. ChargingScheduleMaxPeriods,
  764. ConnectorSwitch3to1PhaseSupported,
  765. MaxChargingProfilesInstalled
  766. };
  767. enum ChargerSystemStatus{
  768. ChargerSystemStatus_Booting,
  769. ChargerSystemStatus_Idle,
  770. ChargerSystemStatus_Authorizing,
  771. ChargerSystemStatus_Preparing,
  772. ChargerSystemStatus_Charging,
  773. ChargerSystemStatus_Terminating,
  774. ChargerSystemStatus_Alarm,
  775. ChargerSystemStatus_Fault
  776. };
  777. enum GetConfigurationKey {
  778. GetConfiguration_AllowOfflineTxForUnknownId=0,
  779. GetConfiguration_AuthorizationCacheEnabled,
  780. GetConfiguration_AuthorizeRemoteTxRequests,
  781. GetConfiguration_BlinkRepeat,
  782. GetConfiguration_ClockAlignedDataInterval,
  783. GetConfiguration_ConnectionTimeOut,
  784. GetConfiguration_GetConfigurationMaxKeys,
  785. GetConfiguration_HeartbeatInterval,
  786. GetConfiguration_LightIntensity,
  787. GetConfiguration_LocalAuthorizeOffline,
  788. GetConfiguration_LocalPreAuthorize,
  789. GetConfiguration_MaxEnergyOnInvalidId,
  790. GetConfiguration_MeterValuesAlignedData,
  791. GetConfiguration_MeterValuesAlignedDataMaxLength,
  792. GetConfiguration_MeterValuesSampledData,
  793. GetConfiguration_MeterValuesSampledDataMaxLength,
  794. GetConfiguration_MeterValueSampleInterval,
  795. GetConfiguration_MinimumStatusDuration,
  796. GetConfiguration_NumberOfConnectors,
  797. GetConfiguration_ResetRetries,
  798. GetConfiguration_ConnectorPhaseRotation,
  799. GetConfiguration_ConnectorPhaseRotationMaxLength,
  800. GetConfiguration_StopTransactionOnEVSideDisconnect,
  801. GetConfiguration_StopTransactionOnInvalidId,
  802. GetConfiguration_StopTxnAlignedData,
  803. GetConfiguration_StopTxnAlignedDataMaxLength,
  804. GetConfiguration_StopTxnSampledData,
  805. GetConfiguration_StopTxnSampledDataMaxLength,
  806. GetConfiguration_SupportedFeatureProfiles,
  807. GetConfiguration_SupportedFeatureProfilesMaxLength,
  808. GetConfiguration_TransactionMessageAttempts,
  809. GetConfiguration_TransactionMessageRetryInterval,
  810. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  811. GetConfiguration_WebSocketPingInterval,
  812. GetConfiguration_LocalAuthListEnabled,
  813. GetConfiguration_LocalAuthListMaxLength,
  814. GetConfiguration_SendLocalListMaxLength,
  815. GetConfiguration_ReserveConnectorZeroSupported,
  816. GetConfiguration_ChargeProfileMaxStackLevel,
  817. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  818. GetConfiguration_ChargingScheduleMaxPeriods,
  819. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  820. GetConfiguration_MaxChargingProfilesInstalled,
  821. };
  822. //GetConfiguration Array
  823. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  824. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  825. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  826. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  827. //==========================================
  828. // Init all share memory
  829. //==========================================
  830. int InitShareMemory()
  831. {
  832. int result = PASS;
  833. int MeterSMId;
  834. //creat ShmSysConfigAndInfo
  835. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  836. {
  837. #ifdef SystemLogMessage
  838. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  839. #endif
  840. result = FAIL;
  841. }
  842. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  843. {
  844. #ifdef SystemLogMessage
  845. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  846. #endif
  847. result = FAIL;
  848. }
  849. else
  850. {}
  851. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  852. {
  853. #ifdef SystemLogMessage
  854. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  855. #endif
  856. result = FAIL;
  857. }
  858. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  859. {
  860. #ifdef SystemLogMessage
  861. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  862. #endif
  863. result = FAIL;
  864. }
  865. else
  866. {}
  867. //creat ShmPsuData
  868. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmget ShmPsuData NG\n");
  872. #endif
  873. result = FAIL;
  874. }
  875. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  876. {
  877. #ifdef SystemLogMessage
  878. DEBUG_ERROR("shmat ShmPsuData NG\n");
  879. #endif
  880. result = FAIL;
  881. }
  882. else
  883. {}
  884. //creat ShmOCPP16Data
  885. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  886. {
  887. #ifdef SystemLogMessage
  888. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  889. #endif
  890. result = FAIL;
  891. }
  892. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  893. {
  894. #ifdef SystemLogMessage
  895. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  896. #endif
  897. result = FAIL;
  898. }
  899. else
  900. {}
  901. /****************************** For Initial Settings************************************************/
  902. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  903. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  904. {
  905. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  906. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  907. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  908. }
  909. // Charger PRE_SYS_MODE
  910. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  911. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  912. clientTime.Heartbeat=time((time_t*)NULL);
  913. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  914. {
  915. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  916. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  917. }
  918. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  919. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  920. // allocate Configuration memory address
  921. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  922. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  923. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  924. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  925. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  926. {
  927. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  928. DEBUG_INFO("DC ...\n");
  929. }
  930. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  931. {
  932. SystemInitial = AC_QUANTITY;
  933. DEBUG_INFO("AC ...\n");
  934. }
  935. //Status / ConnectorPlugIn Setting
  936. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  937. {
  938. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  939. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  940. }
  941. for (int index = 0; index < CCS_QUANTITY; index++)
  942. {
  943. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  944. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  945. }
  946. for (int index = 0; index < GB_QUANTITY; index++)
  947. {
  948. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  949. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  950. }
  951. for (int index = 0; index < AC_QUANTITY; index++)
  952. {
  953. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  954. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  955. }
  956. return result;
  957. }
  958. int ProcessShareMemory()
  959. {
  960. if(InitShareMemory() == FAIL)
  961. {
  962. #ifdef SystemLogMessage
  963. DEBUG_ERROR("InitShareMemory NG\n");
  964. #endif
  965. if(ShmStatusCodeData!=NULL)
  966. {
  967. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  968. }
  969. sleep(5);
  970. return FAIL;
  971. }
  972. return PASS;
  973. }
  974. //---------------------------------------------
  975. // new:
  976. // enum SYSTEM_STATUS
  977. // {
  978. // SYS_MODE_BOOTING = 0,
  979. // SYS_MODE_IDLE = 1,
  980. // SYS_MODE_AUTHORIZING = 2,
  981. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  982. // SYS_MODE_REASSIGN = 4,
  983. // SYS_MODE_PREPARING = 5,
  984. // SYS_MODE_PREPARE_FOR_EV = 6,
  985. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  986. // SYS_MODE_CHARGING = 8,
  987. // SYS_MODE_TERMINATING = 9,
  988. // SYS_MODE_COMPLETE = 10,
  989. // SYS_MODE_ALARM = 11,
  990. // SYS_MODE_FAULT = 12,
  991. // SYS_MODE_RESERVATION = 13,
  992. // SYS_MODE_BOOKING = 14,
  993. // SYS_MODE_MAINTAIN = 15,
  994. // SYS_MODE_DEBUG = 16,
  995. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  996. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  997. // SYS_MODE_UPDATE = 19
  998. // };
  999. //
  1000. //
  1001. //-----------------------------------------
  1002. void CheckSystemValue(void)
  1003. {
  1004. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1005. int IdleModeCnt = 0;
  1006. char filenmae[100]={0};
  1007. char str[100]={0};
  1008. //===============================
  1009. // send Heartbeat
  1010. //===============================
  1011. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1012. {
  1013. printf("Heartbeat !!!\n");
  1014. //parameter for test
  1015. sendHeartbeatRequest(0);
  1016. //==============================================
  1017. // Reset Waiting Time
  1018. //==============================================
  1019. clientTime.Heartbeat=time((time_t*)NULL);
  1020. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1021. }
  1022. //==============================================
  1023. // Update firmware request
  1024. //==============================================
  1025. if(isUpdateRequest == TRUE )
  1026. {
  1027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1028. {
  1029. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1030. {
  1031. //check SystemStatus
  1032. /*************************DC*******************************/
  1033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1034. {
  1035. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1036. {
  1037. IdleModeCnt = IdleModeCnt + 1;
  1038. }
  1039. }
  1040. for (int index = 0; index < CCS_QUANTITY; index++)
  1041. {
  1042. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1043. {
  1044. IdleModeCnt = IdleModeCnt + 1;
  1045. }
  1046. }
  1047. for (int index = 0; index < GB_QUANTITY; index++)
  1048. {
  1049. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1050. {
  1051. IdleModeCnt = IdleModeCnt + 1;
  1052. }
  1053. }
  1054. }
  1055. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1056. {
  1057. isUpdateRequest = FALSE;
  1058. }
  1059. }
  1060. else
  1061. {
  1062. /*************************AC*******************************/
  1063. for (int index = 0; index < AC_QUANTITY; index++)
  1064. {
  1065. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1066. {
  1067. IdleModeCnt = IdleModeCnt + 1;
  1068. }
  1069. }
  1070. if(IdleModeCnt == AC_QUANTITY)
  1071. {
  1072. isUpdateRequest = FALSE;
  1073. }
  1074. }
  1075. }
  1076. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1077. {
  1078. //===============================
  1079. // CSU Trigger Reset Conf
  1080. //===============================
  1081. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1082. {
  1083. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1084. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1085. {
  1086. server_sign = FALSE;
  1087. }
  1088. }
  1089. //===============================
  1090. // CSU Trigger Authorize Request
  1091. //===============================
  1092. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1093. {
  1094. sendAuthorizeRequest(0);
  1095. authorizeRetryTimes = authorizeRetryTimes + 1;
  1096. if(authorizeRetryTimes < 3)
  1097. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1098. }
  1099. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1100. {
  1101. authorizeRetryTimes = 0;
  1102. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1103. server_sign = FALSE;
  1104. }
  1105. else if((server_sign == FALSE) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  1106. {
  1107. sendAuthorizeRequest(0);
  1108. }
  1109. //===============================
  1110. // CSU Trigger Smart Charging Profilw
  1111. //===============================
  1112. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1113. {
  1114. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1115. GetChargingProfileRequest(gun_index);
  1116. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1117. }
  1118. //==============================================
  1119. // Charger start transaction
  1120. //==============================================
  1121. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1122. {
  1123. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1124. sendStartTransactionRequest(gun_index);
  1125. clientTime.StartTransaction = time((time_t*)NULL);
  1126. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1127. }
  1128. //==============================================
  1129. // Charger stop transaction
  1130. //==============================================
  1131. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1132. {
  1133. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1134. sendStopTransactionRequest(gun_index);
  1135. clientTime.StopTransaction = time((time_t*)NULL);
  1136. }
  1137. //==============================================
  1138. // Charger status report
  1139. //==============================================
  1140. /* Check Mode Change */
  1141. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1142. {
  1143. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1144. {
  1145. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1146. {
  1147. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1148. {
  1149. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1150. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1151. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1152. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1153. statusModeChage[gun_index] = TRUE;
  1154. }
  1155. }
  1156. }
  1157. for (int index = 0; index < CCS_QUANTITY; index++)
  1158. {
  1159. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1160. {
  1161. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1162. {
  1163. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1164. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1165. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1166. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1167. statusModeChage[gun_index] = TRUE;
  1168. }
  1169. }
  1170. }
  1171. for (int index = 0; index < GB_QUANTITY; index++)
  1172. {
  1173. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1174. {
  1175. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1176. {
  1177. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1178. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1179. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1180. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1181. statusModeChage[gun_index] = TRUE;
  1182. }
  1183. }
  1184. }
  1185. }
  1186. else //AC
  1187. {
  1188. for (int index = 0; index < AC_QUANTITY; index++)
  1189. {
  1190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1191. {
  1192. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1193. {
  1194. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1195. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1196. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1197. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1198. statusModeChage[gun_index] = TRUE;
  1199. }
  1200. }
  1201. }// END OF FOR
  1202. }// END OF ELSE
  1203. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1204. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1205. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1206. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1207. {
  1208. if(SystemInitial != 0)
  1209. SystemInitial = SystemInitial -1;
  1210. sendStatusNotificationRequest(gun_index);
  1211. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1212. statusModeChage[gun_index] = FALSE;
  1213. }
  1214. //==============================================
  1215. // Meter report
  1216. //==============================================
  1217. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1218. {
  1219. //check Transaction active
  1220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1221. {
  1222. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1223. {
  1224. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1225. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1226. {
  1227. meterValueSend[gun_index] =1;
  1228. }
  1229. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1230. {
  1231. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1232. if((access(filenmae,F_OK))!=-1)
  1233. {
  1234. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1235. sprintf(str,"rm -f %s",filenmae);
  1236. system(str);
  1237. }
  1238. }
  1239. }// End for CHAdeMO
  1240. for (int index = 0; index < CCS_QUANTITY; index++)
  1241. {
  1242. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1243. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1244. {
  1245. meterValueSend[gun_index] =1;
  1246. }
  1247. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1248. {
  1249. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1250. if((access(filenmae,F_OK))!=-1)
  1251. {
  1252. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1253. sprintf(str,"rm -f %s",filenmae);
  1254. system(str);
  1255. }
  1256. }
  1257. } // End for CCS
  1258. for (int index = 0; index < GB_QUANTITY; index++)
  1259. {
  1260. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1261. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1262. {
  1263. meterValueSend[gun_index] =1;
  1264. }
  1265. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1266. {
  1267. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1268. if((access(filenmae,F_OK))!=-1)
  1269. {
  1270. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1271. sprintf(str,"rm -f %s",filenmae);
  1272. system(str);
  1273. }
  1274. }
  1275. }// End for GB
  1276. }
  1277. else
  1278. {
  1279. for (int index = 0; index < AC_QUANTITY; index++)
  1280. {
  1281. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1282. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1283. {
  1284. meterValueSend[gun_index] =1;
  1285. }
  1286. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1287. {
  1288. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1289. if((access(filenmae,F_OK))!=-1)
  1290. {
  1291. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1292. sprintf(str,"rm -f %s",filenmae);
  1293. system(str);
  1294. }
  1295. }
  1296. }//End for AC
  1297. }//END OF ELSE
  1298. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1299. if(meterValueSend[gun_index] == 1)
  1300. sendMeterValuesRequest(gun_index);
  1301. }
  1302. //==============================================
  1303. // Check Connector reserved
  1304. //==============================================
  1305. //===============================
  1306. // Check if Reserve is expired
  1307. //===============================
  1308. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1309. {
  1310. double diff_t;
  1311. struct tm tp;
  1312. // current time
  1313. time_t t = time(NULL);
  1314. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1315. tp.tm_isdst = -1;
  1316. time_t utc = mktime(&tp);
  1317. diff_t = difftime(utc, t);
  1318. if(diff_t <= 0)
  1319. {
  1320. DEBUG_INFO("reserve expired !!! \n");
  1321. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1322. }
  1323. }//END OF Check if Reserve is expired
  1324. //==========================================
  1325. // csu trigger FirmwareStatusNotificationReq
  1326. //==========================================
  1327. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1328. {
  1329. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1330. }
  1331. //==========================================
  1332. // csu trigger CancelReservationConf
  1333. //==========================================
  1334. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1335. {
  1336. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1337. }
  1338. //==========================================
  1339. // csu trigger ChangeAvailabilityConf
  1340. //==========================================
  1341. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1342. {
  1343. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1344. }
  1345. //==========================================
  1346. // csu trigger UnlockConnectorConf
  1347. //==========================================
  1348. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1349. {
  1350. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1351. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1352. }
  1353. //==========================================
  1354. // csu trigger ReserveNowConf
  1355. //==========================================
  1356. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1357. {
  1358. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1359. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1360. }
  1361. //==========================================
  1362. // csu trigger DataTransferReq
  1363. //==========================================
  1364. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1365. {
  1366. sendDataTransferRequest(gun_index);
  1367. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1368. }
  1369. }
  1370. }
  1371. //==========================================
  1372. // send request routine
  1373. //==========================================
  1374. int sendAuthorizeRequest(int gun_index)
  1375. {
  1376. mtrace();
  1377. int result = FAIL;
  1378. char message[100]={0};
  1379. char guid[37];
  1380. char tempdata[65]={0};
  1381. DEBUG_INFO("sendAuthorizeRequest \n");
  1382. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1383. //Local Authorize
  1384. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1385. {
  1386. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1387. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1388. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1389. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1390. result = PASS;
  1391. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1392. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1393. authorizeRetryTimes = 0;
  1394. return result;
  1395. }
  1396. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  1397. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1398. {
  1399. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1400. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1401. {
  1402. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1403. {
  1404. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1405. }
  1406. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1407. {
  1408. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1409. }
  1410. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1411. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1412. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1413. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1414. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1415. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1416. authorizeRetryTimes = 0;
  1417. return result;
  1418. }
  1419. else
  1420. {
  1421. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1422. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1423. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1424. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1425. result = PASS;
  1426. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1427. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1428. authorizeRetryTimes = 0;
  1429. return result;
  1430. }
  1431. }
  1432. //initailize struct Authorize
  1433. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1434. //get data from shared memory
  1435. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1436. random_uuid(guid);
  1437. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1438. LWS_Send(message);
  1439. sprintf(tempdata, "Authorize,%d", gun_index);
  1440. if(hashmap_operation(0, guid, tempdata) == 1)
  1441. {
  1442. result = PASS;
  1443. DEBUG_ERROR("Authorize mapItem pass\n");
  1444. }
  1445. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1446. return result;
  1447. }
  1448. int sendBootNotificationRequest(void)
  1449. {
  1450. mtrace();
  1451. int result = FAIL;
  1452. char message[500]={0}, payload[700]={0};
  1453. char guid[37]={0};
  1454. char tempdata[65]={0};
  1455. int IsGunCharging = FALSE;
  1456. //check Transaction active
  1457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1458. {
  1459. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1460. {
  1461. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1462. {
  1463. IsGunCharging = TRUE;
  1464. }
  1465. }
  1466. for (int index = 0; index < CCS_QUANTITY; index++)
  1467. {
  1468. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1469. {
  1470. IsGunCharging = TRUE;
  1471. }
  1472. }
  1473. for (int index = 0; index < GB_QUANTITY; index++)
  1474. {
  1475. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1476. {
  1477. IsGunCharging = TRUE;
  1478. }
  1479. }
  1480. }
  1481. else
  1482. {
  1483. for (int index = 0; index < AC_QUANTITY; index++)
  1484. {
  1485. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1486. {
  1487. IsGunCharging = TRUE;
  1488. }
  1489. }
  1490. }
  1491. if(IsGunCharging == TRUE)
  1492. {
  1493. server_sign = TRUE;
  1494. return result;
  1495. }
  1496. // Fill BootNotification fields
  1497. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1498. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1499. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1500. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1501. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1502. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1503. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1504. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1505. ShmOCPP16Data->ChargeBoxId
  1506. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1507. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1508. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1509. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1510. ,ShmOCPP16Data->BootNotification.CpIccid
  1511. ,ShmOCPP16Data->BootNotification.CpImsi
  1512. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1513. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1514. random_uuid(guid);
  1515. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1516. LWS_Send(message);
  1517. sprintf(tempdata, "BootNotification,0");
  1518. 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*/)
  1519. {
  1520. result = PASS;
  1521. }
  1522. memset(queuedata, 0, sizeof(queuedata));
  1523. strcpy(queuedata,message);
  1524. return result;
  1525. }
  1526. int sendDataTransferRequest(int gun_index)
  1527. {
  1528. mtrace();
  1529. char message[1000]={0};
  1530. char guid[37]={0};
  1531. char tempdata[65]={0};
  1532. int result = FAIL;
  1533. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1534. random_uuid(guid);
  1535. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1536. MESSAGE_TYPE_CALL,
  1537. guid,
  1538. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1539. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1540. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1541. LWS_Send(message);
  1542. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1543. 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*/)
  1544. {
  1545. result = PASS;
  1546. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1547. }
  1548. return result;
  1549. }
  1550. int sendDiagnosticsStatusNotificationRequest(char *status)
  1551. {
  1552. mtrace();
  1553. int result = FAIL;
  1554. char message[110]={0};
  1555. char guid[37]={0};
  1556. char tempdata[65]={0};
  1557. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1558. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1559. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1560. random_uuid(guid);
  1561. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1562. LWS_Send(message);
  1563. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1564. if(hashmap_operation(0, guid, tempdata) == 1)
  1565. {
  1566. result = PASS;
  1567. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1568. }
  1569. //#ifdef SystemLogMessage
  1570. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1571. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1572. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1573. //#endif
  1574. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1575. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1576. //record status
  1577. if(strcmp(status,"Idle")==0)
  1578. {
  1579. DiagnosticsStatusNotificationStatus = 0;
  1580. }
  1581. else if(strcmp(status,"Uploaded")==0)
  1582. {
  1583. DiagnosticsStatusNotificationStatus = 1;
  1584. }
  1585. else if(strcmp(status,"UploadFailed")==0)
  1586. {
  1587. DiagnosticsStatusNotificationStatus = 2;
  1588. }
  1589. else if(strcmp(status,"Uploading")==0)
  1590. {
  1591. DiagnosticsStatusNotificationStatus = 3;
  1592. }
  1593. return result;
  1594. }
  1595. int sendFirmwareStatusNotificationRequest(char *status)
  1596. {
  1597. mtrace();
  1598. int result = FAIL;
  1599. char message[110]={0};
  1600. char guid[37]={0};
  1601. char tempdata[65]={0};
  1602. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1603. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1604. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1605. random_uuid(guid);
  1606. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1607. LWS_Send(message);
  1608. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1609. 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*/)
  1610. {
  1611. result = PASS;
  1612. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1613. }
  1614. //#ifdef SystemLogMessage
  1615. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1616. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1617. //#endif
  1618. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1619. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1620. //record status
  1621. if(strcmp(status,"Downloaded")==0)
  1622. {
  1623. FirmwareStatusNotificationStatus = 0;
  1624. }
  1625. else if(strcmp(status,"DownloadFailed")==0)
  1626. {
  1627. FirmwareStatusNotificationStatus = 1;
  1628. }
  1629. else if(strcmp(status,"Downloading")==0)
  1630. {
  1631. FirmwareStatusNotificationStatus = 2;
  1632. }
  1633. else if(strcmp(status,"Idle")==0)
  1634. {
  1635. FirmwareStatusNotificationStatus = 3;
  1636. }
  1637. else if(strcmp(status,"InstallationFailed")==0)
  1638. {
  1639. FirmwareStatusNotificationStatus = 4;
  1640. }
  1641. else if(strcmp(status,"Installing")==0)
  1642. {
  1643. FirmwareStatusNotificationStatus = 5;
  1644. }
  1645. else if(strcmp(status,"Installed")==0)
  1646. {
  1647. FirmwareStatusNotificationStatus = 6;
  1648. }
  1649. return result;
  1650. }
  1651. int sendHeartbeatRequest(int gun_index)
  1652. {
  1653. mtrace();
  1654. int result = FAIL;
  1655. char message[80]={0};
  1656. char guid[37]={0};
  1657. char tempdata[65]={0};
  1658. random_uuid(guid);
  1659. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1660. , MESSAGE_TYPE_CALL
  1661. , guid );
  1662. LWS_Send(message);
  1663. sprintf(tempdata, "Heartbeat,%d", 0);
  1664. 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*/)
  1665. {
  1666. result = PASS;
  1667. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1668. }
  1669. return result;
  1670. }
  1671. int sendStartTransactionRequest(int gun_index)
  1672. {
  1673. mtrace();
  1674. int result = FAIL;
  1675. char message[250]={0};
  1676. char guid[37]={0};
  1677. struct timeval tmnow;
  1678. struct tm *tm;
  1679. char buf[28];//, usec_buf[6];
  1680. char tempdata[65]={0};
  1681. DEBUG_INFO("sendStartTransactionRequest...");
  1682. gettimeofday(&tmnow, NULL);
  1683. time_t t;
  1684. t = time(NULL);
  1685. /*UTC time and date*/
  1686. tm = gmtime(&t);
  1687. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1688. #if 0 // remove temporally
  1689. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1690. strcat(buf,".");
  1691. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1692. strcat(buf,usec_buf);
  1693. #endif
  1694. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1695. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1696. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1697. // clear StartTransaction Response
  1698. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1699. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1700. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1701. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1703. {
  1704. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1705. {
  1706. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1707. {
  1708. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1709. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1710. }
  1711. }
  1712. for (int index = 0; index < CCS_QUANTITY; index++)
  1713. {
  1714. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1715. {
  1716. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1717. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1718. }
  1719. }
  1720. for (int index = 0; index < GB_QUANTITY; index++)
  1721. {
  1722. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1723. {
  1724. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1725. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1726. }
  1727. }
  1728. }
  1729. else
  1730. {
  1731. for (int index = 0; index < AC_QUANTITY; index++)
  1732. {
  1733. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1734. {
  1735. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1736. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1737. }
  1738. }
  1739. }//END OF ELSE
  1740. random_uuid(guid);
  1741. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1742. , MESSAGE_TYPE_CALL
  1743. , guid
  1744. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1745. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1746. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1747. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1748. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1749. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1750. 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*/)
  1751. {
  1752. result = PASS;
  1753. }
  1754. strcpy(queuedata, message);
  1755. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1756. if(GetTransactionQueueNum() == 1)
  1757. {
  1758. LWS_Send(message);
  1759. }
  1760. #if 0
  1761. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1762. 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*/)
  1763. {
  1764. result = PASS;
  1765. }
  1766. strcpy(queuedata, message);
  1767. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1768. #endif
  1769. //#ifdef SystemLogMessage
  1770. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1771. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1772. //#endif
  1773. return result;
  1774. }
  1775. int sendStatusNotificationRequest(int gun_index)
  1776. {
  1777. mtrace();
  1778. int result = FAIL;
  1779. char message[600]={0};
  1780. char guid[37];
  1781. int currentStatus = 0;
  1782. struct timeval tmnow;
  1783. struct tm *tm;
  1784. char buf[28];//, usec_buf[6];
  1785. char tempdata[65]={0};
  1786. gettimeofday(&tmnow, NULL);
  1787. time_t t;
  1788. t = time(NULL);
  1789. /*UTC time and date*/
  1790. tm = gmtime(&t);
  1791. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1792. #if 0 // remove temporally
  1793. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1794. strcat(buf,".");
  1795. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1796. strcat(buf,usec_buf);
  1797. #endif
  1798. printf("%s",buf);
  1799. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1800. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1801. // it's option
  1802. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1803. /*
  1804. enum _SYSTEM_STATUS
  1805. {
  1806. S_BOOTING = 0,
  1807. S_IDLE, = 1
  1808. S_AUTHORIZING, =2
  1809. S_REASSIGN_CHECK, =3
  1810. S_REASSIGN, =4
  1811. S_PRECHARGE, =5
  1812. S_PREPARING_FOR_EV, =6
  1813. S_PREPARING_FOR_EVSE, =7
  1814. S_CHARGING, =8
  1815. S_TERMINATING, =9
  1816. S_COMPLETE, =10
  1817. S_ALARM, =11
  1818. S_FAULT =12
  1819. }
  1820. */
  1821. //check Transaction active
  1822. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1823. {
  1824. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1825. {
  1826. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1827. {
  1828. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1829. {
  1830. currentStatus = 1; //OCPP Status: Preparing
  1831. }
  1832. else
  1833. {
  1834. currentStatus = 0; //OCPP Status: Available
  1835. }
  1836. }
  1837. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1838. {
  1839. currentStatus = 1; //OCPP Status: Preparing
  1840. }
  1841. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1842. {
  1843. currentStatus = 2; //OCPP Status: Charging
  1844. }
  1845. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1846. {
  1847. currentStatus = 5; //OCPP Status: Finishing
  1848. }
  1849. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1850. {
  1851. currentStatus = 4; //OCPP Status: SuspendedEV
  1852. }
  1853. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE) )) // ---> Unavailable
  1854. {
  1855. currentStatus = 7; //OCPP Status: Unavailable
  1856. }
  1857. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1858. {
  1859. currentStatus = 8; //OCPP Status: Faulted
  1860. }
  1861. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1862. {
  1863. currentStatus = 6; //OCPP Status: Reserved
  1864. }
  1865. }//end of for CHAdeMO_QUANTITY
  1866. for (int index = 0; index < CCS_QUANTITY; index++)
  1867. {
  1868. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1869. {
  1870. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1871. {
  1872. currentStatus = 1; //OCPP Status: Preparing
  1873. }
  1874. else
  1875. {
  1876. currentStatus = 0; //OCPP Status: Available
  1877. }
  1878. }
  1879. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1880. {
  1881. currentStatus = 1; //OCPP Status: Preparing
  1882. }
  1883. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1884. {
  1885. currentStatus = 2; //OCPP Status: Charging
  1886. }
  1887. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1888. {
  1889. currentStatus = 5; //OCPP Status: Finishing
  1890. }
  1891. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM ,S_TERMINATING ---> SuspendedEV
  1892. {
  1893. currentStatus = 4; //OCPP Status: SuspendedEV
  1894. }
  1895. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1896. {
  1897. currentStatus = 7; //OCPP Status : Unavailable
  1898. }
  1899. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1900. {
  1901. currentStatus = 8; //OCPP Status: Faulted
  1902. }
  1903. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1904. {
  1905. currentStatus = 6; //OCPP Status: Reserved
  1906. }
  1907. }
  1908. for (int index = 0; index < GB_QUANTITY; index++)
  1909. {
  1910. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1911. {
  1912. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1913. {
  1914. currentStatus = 1; //OCPP Status: Preparing
  1915. }
  1916. else
  1917. {
  1918. currentStatus = 0; //OCPP Status: Available
  1919. }
  1920. }
  1921. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1922. {
  1923. currentStatus = 1; //OCPP Status: Preparing
  1924. }
  1925. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1926. {
  1927. currentStatus = 2; //OCPP Status: Charging
  1928. }
  1929. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1930. {
  1931. currentStatus = 5; //OCPP Status: Finishing
  1932. }
  1933. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM , S_TERMINATING ---> SuspendedEV
  1934. {
  1935. currentStatus = 4; //OCPP Status: SuspendedEV
  1936. }
  1937. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1938. {
  1939. currentStatus = 7; //OCPP Status: Unavailable
  1940. }
  1941. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1942. {
  1943. currentStatus = 8; //OCPP Status: Faulted
  1944. }
  1945. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1946. {
  1947. currentStatus = 6; //OCPP Status: Reserved
  1948. }
  1949. }
  1950. }
  1951. else
  1952. {
  1953. for (int index = 0; index < AC_QUANTITY; index++)
  1954. {
  1955. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1956. {
  1957. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  1958. {
  1959. currentStatus = 1; //OCPP Status: Preparing
  1960. }
  1961. else
  1962. {
  1963. currentStatus = 0; //OCPP Status: Available
  1964. }
  1965. }
  1966. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1967. {
  1968. currentStatus = 1; //OCPP Status: Preparing
  1969. }
  1970. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1971. {
  1972. currentStatus = 2; //OCPP Status: Charging
  1973. }
  1974. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1975. {
  1976. currentStatus = 5; //OCPP Status: Finishing
  1977. }
  1978. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1979. {
  1980. currentStatus = 4; //OCPP Status: SuspendedEV
  1981. }
  1982. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1983. {
  1984. currentStatus = 7; //OCPP Status: Unavailable
  1985. }
  1986. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1987. {
  1988. currentStatus = 8; //OCPP Status: Faulted
  1989. }
  1990. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1991. {
  1992. currentStatus = 6; //OCPP Status: Reserved
  1993. }
  1994. }//end of for AC_QUANTITY
  1995. }//END OF ELSE
  1996. //it's option
  1997. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1998. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1999. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2000. random_uuid(guid);
  2001. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2002. , MESSAGE_TYPE_CALL
  2003. , guid
  2004. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2005. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2006. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2007. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2008. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2009. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2010. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2011. LWS_Send(message);
  2012. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2013. 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*/)
  2014. {
  2015. //DEBUG_ERROR("statusNotification mapitem pass");
  2016. result = PASS;
  2017. }
  2018. return result;
  2019. }
  2020. int sendStopTransactionRequest(int gun_index)
  2021. {
  2022. mtrace();
  2023. int result = FAIL;
  2024. //char message[1500]={0};
  2025. char guid[37]={0};
  2026. char tempdata[65]={0};
  2027. //int idx_sample=0;
  2028. DEBUG_ERROR("sendStopTransactionRequest \n");
  2029. memset(queuedata, 0, sizeof(queuedata));
  2030. //ENERGY_ACTIVE_IMPORT_REGISTER
  2031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2032. {
  2033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2034. {
  2035. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2036. {
  2037. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2038. }
  2039. }// END OF CHAdeMO_QUANTITY
  2040. for (int index = 0; index < CCS_QUANTITY; index++)
  2041. {
  2042. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2043. {
  2044. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2045. }
  2046. }// END OF CCS_QUANTITY
  2047. for (int index = 0; index < GB_QUANTITY; index++)
  2048. {
  2049. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2050. {
  2051. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2052. }
  2053. }// END OF GB_QUANTITY
  2054. }
  2055. else
  2056. {
  2057. for (int index = 0; index < AC_QUANTITY; index++)
  2058. {
  2059. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2060. {
  2061. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2062. }
  2063. }// END OF AC_QUANTITY
  2064. }//END OF ELSE
  2065. //Stop Transaction Time
  2066. struct timeval tmnow;
  2067. struct tm *tm;
  2068. char buf[28];//, usec_buf[6];
  2069. gettimeofday(&tmnow, NULL);
  2070. time_t t;
  2071. t = time(NULL);
  2072. /*UTC time and date*/
  2073. tm = gmtime(&t);
  2074. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  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. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2081. //=================================
  2082. // Transaction_Begin
  2083. //=================================
  2084. // Energy.Active.Export.Interval
  2085. //idx_sample=0;
  2086. 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
  2087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2089. 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*/]);
  2090. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2091. {
  2092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2093. }
  2094. else
  2095. {
  2096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2097. }
  2098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2100. //=================================
  2101. // Transaction_End
  2102. //=================================
  2103. //Current.Export
  2104. //idx_sample=1;
  2105. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2106. {
  2107. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2108. {
  2109. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2110. {
  2111. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2112. }
  2113. }
  2114. for (int index = 0; index < CCS_QUANTITY; index++)
  2115. {
  2116. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2117. {
  2118. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2119. }
  2120. }
  2121. for (int index = 0; index < GB_QUANTITY; index++)
  2122. {
  2123. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2124. {
  2125. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2126. }
  2127. }
  2128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2129. }
  2130. else
  2131. {
  2132. for (int index = 0; index < AC_QUANTITY; index++)
  2133. {
  2134. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2135. {
  2136. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2137. }
  2138. }
  2139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2140. }// END FOR AC ELSE
  2141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2144. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2147. //Energy.Active.Export.Interval
  2148. //idx_sample=2;
  2149. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2150. {
  2151. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2152. {
  2153. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2154. {
  2155. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2156. }
  2157. }
  2158. for (int index = 0; index < CCS_QUANTITY; index++)
  2159. {
  2160. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2161. {
  2162. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2163. }
  2164. }
  2165. for (int index = 0; index < GB_QUANTITY; index++)
  2166. {
  2167. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2168. {
  2169. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2170. }
  2171. }
  2172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2173. }
  2174. else
  2175. {
  2176. for (int index = 0; index < AC_QUANTITY; index++)
  2177. {
  2178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2179. {
  2180. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2181. }
  2182. }
  2183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2184. }// END FOR AC ELSE
  2185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2188. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2191. //Power.Active.Export
  2192. //idx_sample=3;
  2193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2194. {
  2195. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2196. {
  2197. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2198. {
  2199. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2200. }
  2201. }
  2202. for (int index = 0; index < CCS_QUANTITY; index++)
  2203. {
  2204. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2205. {
  2206. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2207. }
  2208. }
  2209. for (int index = 0; index < GB_QUANTITY; index++)
  2210. {
  2211. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2212. {
  2213. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2214. }
  2215. }
  2216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2217. }
  2218. else
  2219. {
  2220. for (int index = 0; index < AC_QUANTITY; index++)
  2221. {
  2222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2223. {
  2224. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2225. }
  2226. }
  2227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2228. }// END FOR AC ELSE
  2229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2232. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2235. //Voltage
  2236. //idx_sample=4;
  2237. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2238. {
  2239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2240. {
  2241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2242. {
  2243. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2244. }
  2245. }
  2246. for (int index = 0; index < CCS_QUANTITY; index++)
  2247. {
  2248. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2249. {
  2250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2251. }
  2252. }
  2253. for (int index = 0; index < GB_QUANTITY; index++)
  2254. {
  2255. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2256. {
  2257. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2258. }
  2259. }
  2260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2261. }
  2262. else
  2263. {
  2264. for (int index = 0; index < AC_QUANTITY; index++)
  2265. {
  2266. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2267. {
  2268. 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
  2269. }
  2270. }
  2271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2272. }// END FOR AC ELSE
  2273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2276. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2279. //SoC
  2280. //idx_sample=5;
  2281. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2282. {
  2283. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2284. {
  2285. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2286. {
  2287. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2288. }
  2289. }
  2290. for (int index = 0; index < CCS_QUANTITY; index++)
  2291. {
  2292. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2293. {
  2294. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2295. }
  2296. }
  2297. for (int index = 0; index < GB_QUANTITY; index++)
  2298. {
  2299. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2300. {
  2301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2302. }
  2303. }
  2304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2310. } // END FOR DC CASE
  2311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2312. {
  2313. 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\"}]}]}]"
  2314. ,MESSAGE_TYPE_CALL
  2315. ,guid
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2321. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2336. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2340. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2341. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2342. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2343. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2344. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2345. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2346. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2347. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2348. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2349. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2364. );
  2365. }
  2366. else
  2367. {
  2368. 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\"}]}]}]"
  2369. ,MESSAGE_TYPE_CALL
  2370. ,guid
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2376. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2385. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2386. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2387. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2388. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2390. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2391. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2392. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2393. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2394. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2395. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2396. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2397. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2398. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2399. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2400. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2401. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2402. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2403. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2404. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2405. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2406. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2407. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2408. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2409. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2410. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2411. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2412. );
  2413. }
  2414. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2415. if(hashmap_operation(0, guid, tempdata) == 1)
  2416. {
  2417. result = PASS;
  2418. DEBUG_INFO("StopTransaction mapitem pass\n");
  2419. }
  2420. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2421. if(GetTransactionQueueNum() == 1)
  2422. {
  2423. LWS_Send(queuedata);
  2424. }
  2425. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2426. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2427. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2428. {
  2429. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2430. }
  2431. #if 0
  2432. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2433. if(hashmap_operation(0, guid, tempdata) == 1)
  2434. {
  2435. result = PASS;
  2436. DEBUG_INFO("StopTransaction mapitem pass\n");
  2437. }
  2438. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2439. #endif
  2440. //for test
  2441. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2442. return result;
  2443. }
  2444. int sendMeterValuesRequest(int gun_index)
  2445. {
  2446. mtrace();
  2447. int result = FAIL;
  2448. // char message[1500]={0};
  2449. char guid[37]={0};
  2450. //int idx_sample=0;
  2451. //int length = 0;
  2452. char tempdata[65]={0};
  2453. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2454. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2455. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2456. {
  2457. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2458. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2459. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2460. return result;
  2461. }
  2462. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2463. {
  2464. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2465. }
  2466. memset(queuedata, 0, sizeof(queuedata));
  2467. //set value
  2468. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2469. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2470. random_uuid(guid);
  2471. //UTC Date time
  2472. struct timeval tmnow;
  2473. struct tm *tm;
  2474. char buf[28];//, usec_buf[6];
  2475. gettimeofday(&tmnow, NULL);
  2476. time_t t;
  2477. t = time(NULL);
  2478. /*UTC time and date*/
  2479. tm = gmtime(&t);
  2480. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2482. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2483. //idx_sample=0;
  2484. //********************************(1)Current.Export************************************************/
  2485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2486. {
  2487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2488. {
  2489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2490. {
  2491. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2492. }
  2493. }
  2494. for (int index = 0; index < CCS_QUANTITY; index++)
  2495. {
  2496. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2497. {
  2498. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2499. }
  2500. }
  2501. for (int index = 0; index < GB_QUANTITY; index++)
  2502. {
  2503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2504. {
  2505. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2506. }
  2507. }
  2508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2509. }
  2510. else
  2511. {
  2512. for (int index = 0; index < AC_QUANTITY; index++)
  2513. {
  2514. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2515. {
  2516. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2517. }
  2518. }
  2519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2520. }// END FOR AC ELSE
  2521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2524. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2527. //idx_sample=1;
  2528. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2530. {
  2531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2532. {
  2533. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2534. {
  2535. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2536. }
  2537. }
  2538. for (int index = 0; index < CCS_QUANTITY; index++)
  2539. {
  2540. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2541. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2542. {
  2543. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2545. }
  2546. }
  2547. for (int index = 0; index < GB_QUANTITY; index++)
  2548. {
  2549. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2550. {
  2551. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2552. }
  2553. }
  2554. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2555. }
  2556. else
  2557. {
  2558. for (int index = 0; index < AC_QUANTITY; index++)
  2559. {
  2560. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2561. {
  2562. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2563. }
  2564. }
  2565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2566. }//END FOR AC ELSE
  2567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2568. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2570. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2572. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2573. //idx_sample=2;
  2574. //********************************(4)Power.Active.Export************************************************/
  2575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2576. {
  2577. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2578. {
  2579. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2580. {
  2581. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2582. }
  2583. }
  2584. for (int index = 0; index < CCS_QUANTITY; index++)
  2585. {
  2586. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2587. {
  2588. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2589. }
  2590. }
  2591. for (int index = 0; index < GB_QUANTITY; index++)
  2592. {
  2593. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2594. {
  2595. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2596. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2597. }
  2598. }
  2599. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2600. }
  2601. else
  2602. {
  2603. for (int index = 0; index < AC_QUANTITY; index++)
  2604. {
  2605. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2606. {
  2607. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2608. }
  2609. }
  2610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2611. }// END FOR AC ELSE
  2612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2615. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2618. //idx_sample=3;
  2619. //***********************************************(5)VOLTAGE******************************************************/
  2620. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2621. {
  2622. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2623. {
  2624. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2625. {
  2626. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2627. }
  2628. }
  2629. for (int index = 0; index < CCS_QUANTITY; index++)
  2630. {
  2631. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2632. {
  2633. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2634. }
  2635. }
  2636. for (int index = 0; index < GB_QUANTITY; index++)
  2637. {
  2638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2639. {
  2640. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2641. }
  2642. }
  2643. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2644. }
  2645. else
  2646. {
  2647. for (int index = 0; index < AC_QUANTITY; index++)
  2648. {
  2649. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2650. {
  2651. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2652. }
  2653. }
  2654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2655. }//END FOR AC ELSE
  2656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2658. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2659. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2663. {
  2664. //idx_sample=4;
  2665. //sampledValue = NULL;
  2666. //***********************************************(6)SOC******************************************************/
  2667. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2668. {
  2669. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2670. {
  2671. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2672. }
  2673. }
  2674. for (int index = 0; index < CCS_QUANTITY; index++)
  2675. {
  2676. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2677. {
  2678. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2679. }
  2680. }
  2681. for (int index = 0; index < GB_QUANTITY; index++)
  2682. {
  2683. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2684. {
  2685. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2686. }
  2687. }
  2688. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2689. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2690. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2691. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2692. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2693. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2694. }
  2695. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2696. {
  2697. 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\"}]}]}]"
  2698. ,MESSAGE_TYPE_CALL
  2699. ,guid
  2700. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2701. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2702. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2738. );
  2739. }
  2740. else
  2741. {
  2742. 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\"}]}]}]"
  2743. ,MESSAGE_TYPE_CALL
  2744. ,guid
  2745. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2746. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2747. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2758. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2776. );
  2777. }
  2778. // Put request guid to hash map
  2779. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2780. 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*/)
  2781. {
  2782. result = PASS;
  2783. DEBUG_INFO("MeterValues mapitem pass\n");
  2784. }
  2785. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2786. if(GetTransactionQueueNum() == 1)
  2787. {
  2788. LWS_Send(queuedata);
  2789. }
  2790. #if 0
  2791. // Put request guid to hash map
  2792. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2793. 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*/)
  2794. {
  2795. result = PASS;
  2796. DEBUG_INFO("MeterValues mapitem pass\n");
  2797. }
  2798. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2799. #endif
  2800. return result;
  2801. }
  2802. //==========================================
  2803. // send confirm routine
  2804. //==========================================
  2805. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2806. {
  2807. mtrace();
  2808. int result = FAIL;
  2809. char message[100]={0};
  2810. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2811. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2812. LWS_Send(message);
  2813. result = TRUE;
  2814. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2815. return result;
  2816. }
  2817. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2818. {
  2819. mtrace();
  2820. int result = FAIL;
  2821. char message[100]={0};
  2822. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\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 sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2829. {
  2830. mtrace();
  2831. int result = FAIL;
  2832. char message[100]={0};
  2833. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2834. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2835. LWS_Send(message);
  2836. result = TRUE;
  2837. return result;
  2838. }
  2839. int sendClearCacheConfirmation(char *uuid,char *payload)
  2840. {
  2841. mtrace();
  2842. int result = FAIL;
  2843. char message[500]={0};
  2844. // int count = 0;
  2845. // int gun_index = 0;
  2846. // char guid[37];
  2847. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2848. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2849. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2850. LWS_Send(message);
  2851. return result;
  2852. }
  2853. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2854. {
  2855. mtrace();
  2856. int result = FAIL;
  2857. char message[500]={0};
  2858. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2859. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2860. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2861. LWS_Send(message);
  2862. return result;
  2863. }
  2864. int sendDataTransferConfirmation(char *uuid,char *payload)
  2865. {
  2866. mtrace();
  2867. char statusStr[20]={0};
  2868. char dataStr[10]={0};
  2869. char sstr[20]={0};
  2870. int c = 0;
  2871. char *loc;
  2872. int result = FAIL;
  2873. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2874. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2875. /**********************status**************************/
  2876. loc = strstr(payload, "status");
  2877. memset(sstr ,0, sizeof(sstr) );
  2878. c = 0;
  2879. while (loc[3+strlen("status")+c] != '\"')
  2880. {
  2881. sstr[c] = loc[3+strlen("status")+c];
  2882. c++;
  2883. }
  2884. sstr[c] = '\0';
  2885. strcpy(statusStr, sstr);
  2886. /**********************data**************************/
  2887. loc = strstr(payload, "data");
  2888. memset(sstr ,0, sizeof(sstr) );
  2889. c = 0;
  2890. while (loc[3+strlen("data")+c] != '\"')
  2891. {
  2892. sstr[c] = loc[3+strlen("data")+c];
  2893. c++;
  2894. }
  2895. sstr[c] = '\0';
  2896. strcpy(dataStr, sstr);
  2897. return result;
  2898. }
  2899. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2900. {
  2901. mtrace();
  2902. int result = FAIL;
  2903. char message[1000]={0};
  2904. double diff_f = 0.0;
  2905. int diff_i = 0;
  2906. int diffSeconds = 0;
  2907. struct tm tp;
  2908. int TimeZero = FALSE;
  2909. int CompositeScheduleIndex = 0;
  2910. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2911. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2912. {
  2913. TimeZero = TRUE;
  2914. }
  2915. else
  2916. {
  2917. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2918. }
  2919. if(TimeZero == FALSE)
  2920. {
  2921. tp.tm_isdst = -1;
  2922. time_t utc = mktime(&tp);
  2923. time_t t = time(NULL);
  2924. diff_f = difftime(t, utc);
  2925. diff_i = (int)diff_f;
  2926. diffSeconds = diff_i % 86400;//86400 seconds/day
  2927. }
  2928. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2929. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2930. #if 0 //remove temporally
  2931. 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}"
  2932. ,MESSAGE_TYPE_CALLRESULT
  2933. ,uuid
  2934. ,payload
  2935. ,connectorIdInt
  2936. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2937. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2938. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2939. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2940. #endif
  2941. if(nPeriod == 0)
  2942. {
  2943. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  2944. {
  2945. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  2946. ,MESSAGE_TYPE_CALLRESULT
  2947. ,uuid
  2948. ,payload
  2949. ,connectorIdInt);
  2950. }
  2951. else
  2952. {
  2953. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2954. ,MESSAGE_TYPE_CALLRESULT
  2955. ,uuid
  2956. ,payload
  2957. ,connectorIdInt
  2958. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2959. }
  2960. }
  2961. else
  2962. {
  2963. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2964. ,MESSAGE_TYPE_CALLRESULT
  2965. ,uuid
  2966. ,payload
  2967. ,connectorIdInt
  2968. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2969. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2970. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2971. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2972. int len = nPeriod;
  2973. //Last Period StartPriod is less than diffSeconds
  2974. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds)
  2975. {
  2976. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2977. , 0
  2978. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2979. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2980. }
  2981. else
  2982. {
  2983. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2984. {
  2985. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) < diffSeconds) && ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod % 86400) > diffSeconds))//if (idx_sample == 0)
  2986. {
  2987. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2988. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2989. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2990. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2991. }
  2992. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2993. {
  2994. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2995. , ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)) //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
  2996. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2997. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2998. }
  2999. }
  3000. }
  3001. sprintf(message + strlen(message), "]}}]");
  3002. }
  3003. LWS_Send(message);
  3004. result = TRUE;
  3005. return result;
  3006. }
  3007. int sendGetConfigurationConfirmation(char *uuid)
  3008. {
  3009. mtrace();
  3010. int result = FAIL;
  3011. int MaxKeySupported = 0;
  3012. int sentConfigurationNumber= 0;
  3013. int sentunConfigurationNumber= 0;
  3014. char message[4000]={0};
  3015. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3016. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3017. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3018. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3019. ,MESSAGE_TYPE_CALLRESULT
  3020. ,uuid );
  3021. //configuration key
  3022. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3023. {
  3024. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3025. {
  3026. if (sentConfigurationNumber == 0)
  3027. {
  3028. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3029. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3030. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3031. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3032. }
  3033. else
  3034. {
  3035. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3036. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3037. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3038. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3039. }
  3040. sentConfigurationNumber = sentConfigurationNumber + 1;
  3041. }
  3042. }
  3043. sprintf(message + strlen(message), "]");
  3044. if(UnknownKeynum != 0)
  3045. {
  3046. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3047. //unkown key
  3048. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3049. {
  3050. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3051. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3052. if(sentunConfigurationNumber == 0)
  3053. {
  3054. sprintf(message + strlen(message), "\"%s\""
  3055. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3056. }
  3057. else
  3058. {
  3059. sprintf(message + strlen(message), ",\"%s\""
  3060. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3061. }
  3062. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3063. }
  3064. sprintf(message + strlen(message), "]");
  3065. }
  3066. sprintf(message + strlen(message), "}]");
  3067. LWS_Send(message);
  3068. return result;
  3069. }
  3070. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3071. {
  3072. mtrace();
  3073. int result = FAIL;
  3074. char message[400]={0};
  3075. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3076. if(strcmp(payload,"")==0)
  3077. {
  3078. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3079. }
  3080. else
  3081. {
  3082. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3083. }
  3084. LWS_Send(message);
  3085. result = TRUE;
  3086. return result;
  3087. }
  3088. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3089. {
  3090. mtrace();
  3091. int result = FAIL;
  3092. char message[80]={0};
  3093. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3094. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3095. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3096. LWS_Send(message);
  3097. result = TRUE;
  3098. return result;
  3099. }
  3100. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3101. {
  3102. mtrace();
  3103. int result = FAIL;
  3104. char message[80]={0};
  3105. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3106. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3107. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3108. LWS_Send(message);
  3109. result = TRUE;
  3110. return result;
  3111. }
  3112. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3113. {
  3114. mtrace();
  3115. int result = FAIL;
  3116. char message[80]={0};
  3117. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3118. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3119. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3120. LWS_Send(message);
  3121. result = TRUE;
  3122. return result;
  3123. }
  3124. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3125. {
  3126. mtrace();
  3127. int result = FAIL;
  3128. char message[80]={0};
  3129. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3130. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3131. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3132. LWS_Send(message);
  3133. result = TRUE;
  3134. return result;
  3135. }
  3136. int sendResetConfirmation(char *uuid,char *payload)
  3137. {
  3138. mtrace();
  3139. int result = FAIL;
  3140. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3141. char message[80]={0};
  3142. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3143. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3144. LWS_Send(message);
  3145. result = TRUE;
  3146. return result;
  3147. }
  3148. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3149. {
  3150. mtrace();
  3151. int result = FAIL;
  3152. char message[500]={0};
  3153. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3154. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3155. LWS_Send(message);
  3156. result = TRUE;
  3157. return result;
  3158. }
  3159. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3160. {
  3161. mtrace();
  3162. int result = FAIL;
  3163. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3164. char message[80]={0};
  3165. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3166. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3167. LWS_Send(message);
  3168. result = TRUE;
  3169. return result;
  3170. }
  3171. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3172. {
  3173. mtrace();
  3174. int result = FAIL;
  3175. char message[80]={0};
  3176. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3177. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3178. LWS_Send(message);
  3179. result = TRUE;
  3180. return result;
  3181. }
  3182. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3183. {
  3184. mtrace();
  3185. int result = FAIL;
  3186. char message[80]={0};
  3187. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3188. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3189. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3190. LWS_Send(message);
  3191. result = TRUE;
  3192. return result;
  3193. }
  3194. int sendUpdateFirmwareConfirmation(char *uuid)
  3195. {
  3196. mtrace();
  3197. int result = FAIL;
  3198. char message[60]={0};
  3199. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3200. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3201. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3202. LWS_Send(message);
  3203. result = TRUE;
  3204. return result;
  3205. }
  3206. //==========================================
  3207. // send CallError routine
  3208. //==========================================
  3209. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3210. {
  3211. mtrace();
  3212. //int result = FAIL;
  3213. char message[220]={0};
  3214. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3215. #ifdef SystemLogMessage
  3216. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3217. uniqueId, action, errorCode, errorDescription);
  3218. #endif
  3219. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3220. LWS_Send(message);
  3221. //result = TRUE;
  3222. }
  3223. //==========================================
  3224. // Handle server request routine Start
  3225. //==========================================
  3226. #define GUN_NUM 1
  3227. int handleCancelReservationRequest(char *uuid, char *payload)
  3228. {
  3229. mtrace();
  3230. int result = FAIL;
  3231. int gunNO = 0;
  3232. int reservationIdInt =0;
  3233. char comfirmstr[20];
  3234. int c = 0;
  3235. char *loc;
  3236. char sstr[100]={0};
  3237. DEBUG_INFO("handle CancelReservationRequest\n");
  3238. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3239. c = 0;
  3240. loc = strstr(payload, "reservationId");
  3241. memset(sstr ,0, sizeof(sstr) );
  3242. while (loc[strlen("reservationId")+2+c] != '}')
  3243. {
  3244. sstr[c] = loc[strlen("reservationId")+2+c];
  3245. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3246. c++;
  3247. }
  3248. sstr[c] = '\0';
  3249. reservationIdInt = atoi(sstr);
  3250. memset(comfirmstr, 0, sizeof comfirmstr);
  3251. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3252. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3253. //check Transaction active
  3254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3255. {
  3256. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3257. {
  3258. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3259. {
  3260. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3261. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3262. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3263. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3264. goto end;
  3265. }
  3266. }
  3267. for (int index = 0; index < CCS_QUANTITY; index++)
  3268. {
  3269. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3270. {
  3271. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3272. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3273. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3274. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3275. goto end;
  3276. }
  3277. }
  3278. for (int index = 0; index < GB_QUANTITY; index++)
  3279. {
  3280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3281. {
  3282. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3283. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3284. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3285. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3286. goto end;
  3287. }
  3288. }
  3289. }
  3290. else
  3291. {
  3292. for (int index = 0; index < AC_QUANTITY; index++)
  3293. {
  3294. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3295. {
  3296. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3297. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3298. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3299. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3300. goto end;
  3301. }
  3302. }
  3303. }// END FOR AC ELSE
  3304. //The reservationId does NOT match the reservationId
  3305. sendCancelReservationConfirmation(uuid, comfirmstr);
  3306. end:
  3307. // Fill in ocpp packet uuid
  3308. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3309. return result;
  3310. }
  3311. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3312. {
  3313. mtrace();
  3314. int result = FAIL;
  3315. int gunIndex = 0;
  3316. char sstr[90]={0};
  3317. char typeStr[16]={0};
  3318. char comfirmstr[20];
  3319. int specificId = FALSE;
  3320. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3321. char *loc;
  3322. //int intervalInt = 0;
  3323. int c = 0;
  3324. /*** connectorId ****/
  3325. c = 0;
  3326. loc = strstr(payload, "connectorId");
  3327. memset(sstr ,0, sizeof(sstr) );
  3328. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3329. {
  3330. sstr[c] = loc[strlen("connectorId")+2+c];
  3331. c++;
  3332. }
  3333. sstr[c] = '\0';
  3334. gunIndex = atoi(sstr);
  3335. /***type ****/
  3336. loc = strstr(payload, "type");
  3337. memset(sstr ,0, sizeof(sstr) );
  3338. c = 0;
  3339. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3340. {
  3341. sstr[c] = loc[3+strlen("type")+c];
  3342. c++;
  3343. }
  3344. sstr[c] = '\0';
  3345. strcpy(typeStr, sstr);
  3346. if(gunIndex != 0)
  3347. {
  3348. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3349. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3350. }
  3351. else
  3352. {
  3353. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3354. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3355. }
  3356. memset(comfirmstr, 0, sizeof comfirmstr);
  3357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3358. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3359. {
  3360. specificId = TRUE;
  3361. }
  3362. if(specificId == FALSE)
  3363. goto end;
  3364. if(gunIndex != 0)
  3365. {
  3366. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3367. }
  3368. else
  3369. {
  3370. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3371. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3372. }
  3373. /*
  3374. enum SYSTEM_STATUS
  3375. {
  3376. SYS_MODE_BOOTING = 0,
  3377. SYS_MODE_IDLE = 1,
  3378. SYS_MODE_AUTHORIZING = 2,
  3379. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3380. SYS_MODE_REASSIGN = 4,
  3381. SYS_MODE_PREPARING = 5,
  3382. SYS_MODE_PREPARE_FOR_EV = 6,
  3383. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3384. SYS_MODE_CHARGING = 8,
  3385. SYS_MODE_TERMINATING = 9,
  3386. SYS_MODE_COMPLETE = 10,
  3387. SYS_MODE_ALARM = 11,
  3388. SYS_MODE_FAULT = 12,
  3389. SYS_MODE_RESERVATION = 13,
  3390. SYS_MODE_BOOKING = 14,
  3391. SYS_MODE_MAINTAIN = 15,
  3392. SYS_MODE_DEBUG = 16,
  3393. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3394. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3395. SYS_MODE_UPDATE = 19
  3396. };
  3397. */
  3398. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3399. {
  3400. //check Transaction active
  3401. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3402. {
  3403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3404. {
  3405. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3406. {
  3407. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3408. {
  3409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3410. }
  3411. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3412. {
  3413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3414. }
  3415. else
  3416. {
  3417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3418. }
  3419. goto end;
  3420. }
  3421. }//END FOR CHAdeMO_QUANTITY
  3422. for (int index = 0; index < CCS_QUANTITY; index++)
  3423. {
  3424. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3425. {
  3426. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3427. {
  3428. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3429. }
  3430. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3431. {
  3432. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3433. }
  3434. else
  3435. {
  3436. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3437. }
  3438. goto end;
  3439. }
  3440. }//END FOR CCS_QUANTITY
  3441. for (int index = 0; index < GB_QUANTITY; index++)
  3442. {
  3443. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3444. {
  3445. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3446. {
  3447. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3448. }
  3449. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[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 GB_QUANTITY
  3460. }
  3461. else
  3462. {
  3463. for (int index = 0; index < AC_QUANTITY; index++)
  3464. {
  3465. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3466. {
  3467. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3468. {
  3469. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3470. }
  3471. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3472. {
  3473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3474. }
  3475. else
  3476. {
  3477. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3478. }
  3479. goto end;
  3480. }
  3481. }//END FOR AC_QUANTITY
  3482. }// END FOR AC ELSE
  3483. }//END FOR AvailabilityTypeStr[Inoperative]
  3484. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3485. {
  3486. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3487. //check Transaction active
  3488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3489. {
  3490. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3491. {
  3492. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3493. {
  3494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3495. goto end;
  3496. }
  3497. }//END FOR CHAdeMO_QUANTITY
  3498. for (int index = 0; index < CCS_QUANTITY; index++)
  3499. {
  3500. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3501. {
  3502. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3503. goto end;
  3504. }
  3505. }//END FOR CCS_QUANTITY
  3506. for (int index = 0; index < GB_QUANTITY; index++)
  3507. {
  3508. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3509. {
  3510. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3512. goto end;
  3513. }
  3514. }// END FOR GB_QUANTITY
  3515. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3516. }
  3517. else
  3518. {
  3519. for (int index = 0; index < AC_QUANTITY; index++)
  3520. {
  3521. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3522. {
  3523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3524. goto end;
  3525. }
  3526. }//END FOR CHAdeMO_QUANTITY
  3527. }//END FOR AC ELSE
  3528. }//END FOR AvailabilityTypeStr[Operative]
  3529. end:
  3530. if(gunIndex != 0)
  3531. {
  3532. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3533. }
  3534. else
  3535. {
  3536. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3537. }
  3538. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3539. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3540. return result;
  3541. }
  3542. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3543. {
  3544. mtrace();
  3545. int result = FAIL;
  3546. char sstr[100]={0};
  3547. char keystr[40]={0};
  3548. char valuestr[100]={0};
  3549. char *loc;
  3550. int c = 0;
  3551. char comfirmstr[20]={0};
  3552. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3553. /***key ****/
  3554. loc = strstr(payload, "key");
  3555. memset(sstr ,0, sizeof(sstr) );
  3556. c = 0;
  3557. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3558. {
  3559. sstr[c] = loc[3+strlen("key")+c];
  3560. c++;
  3561. }
  3562. sstr[c] = '\0';
  3563. strcpy(keystr, sstr);
  3564. //DEBUG_INFO( "keystr=%s\n",keystr);
  3565. /***value ****/
  3566. loc = strstr(payload, "value");
  3567. memset(sstr ,0, sizeof(sstr) );
  3568. c = 0;
  3569. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3570. {
  3571. sstr[c] = loc[3+strlen("value")+c];
  3572. c++;
  3573. }
  3574. sstr[c] = '\0';
  3575. strcpy(valuestr, sstr);
  3576. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3577. if((uuid==NULL) || (payload ==NULL) )
  3578. {
  3579. #ifdef Debug
  3580. DEBUG_INFO("payload is null\n");
  3581. #endif
  3582. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3583. }
  3584. else
  3585. {
  3586. int status = setKeyValue(keystr, valuestr);
  3587. switch(status)
  3588. {
  3589. case ConfigurationStatus_Accepted:
  3590. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3591. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3592. StoreConfigurationTable();
  3593. break;
  3594. case ConfigurationStatus_Rejected:
  3595. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3596. break;
  3597. case RebootRequired:
  3598. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3599. StoreConfigurationTable();
  3600. break;
  3601. case NotSupported:
  3602. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3603. break;
  3604. default:
  3605. break;
  3606. }
  3607. }
  3608. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3609. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3610. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3611. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3612. {
  3613. ChageWebSocketPingInterval(atoi(valuestr));
  3614. }
  3615. return result;
  3616. }
  3617. int handleClearCacheRequest(char *uuid, char *payload)
  3618. {
  3619. mtrace();
  3620. int result = FAIL;
  3621. char comfirmstr[20];
  3622. int fd;
  3623. char rmFileCmd[100]={0};
  3624. struct stat stats;
  3625. DEBUG_INFO("handle ClearCacheRequest\n");
  3626. stat("/Storage/OCPP", &stats);
  3627. // Check for directory existence
  3628. if (S_ISDIR(stats.st_mode) == 1)
  3629. {
  3630. //DEBUG_ERROR("\n OCPP directory exist \n");
  3631. }
  3632. else
  3633. {
  3634. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3635. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3636. system(rmFileCmd);
  3637. }
  3638. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3639. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3640. {
  3641. DEBUG_INFO("AuthorizationCache file exist.\n");
  3642. }
  3643. else
  3644. {
  3645. DEBUG_INFO("AuthorizationCache file not exist\n");
  3646. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3647. if(log == NULL)
  3648. {
  3649. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3650. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3651. goto end;
  3652. }
  3653. else
  3654. {
  3655. fclose(log);
  3656. }
  3657. }
  3658. fd = open(AuthorizationCache_JSON,O_RDWR);
  3659. if(fd < 0)
  3660. {
  3661. DEBUG_INFO("open AuthorizationCache file failed\n");
  3662. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3663. }
  3664. else
  3665. {
  3666. DEBUG_INFO("open AuthorizationCache file successful\n");
  3667. //* 清空? 件 */
  3668. ftruncate(fd,0);
  3669. //* ? 新设置? 件? 移??*/
  3670. lseek(fd,0,SEEK_SET);
  3671. close(fd);
  3672. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3673. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3674. }
  3675. end:
  3676. sendClearCacheConfirmation(uuid, comfirmstr);
  3677. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3678. return result;
  3679. }
  3680. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3681. {
  3682. mtrace();
  3683. int result = FAIL;
  3684. int resultRename;
  3685. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3686. char chargingProfilePurposeStr[26]={0};
  3687. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3688. char tempchargingProfilePurposeStr[26]={0};
  3689. char sstr[160]={0};//sstr[200]={ 0 };
  3690. char str[100]={0};
  3691. int c = 0;
  3692. //int i = 0;
  3693. //char * pch;
  3694. char *loc;
  3695. char fname[200]={0};
  3696. char comfirmstr[20]={0};
  3697. char word[1600]={0};
  3698. int clearflag = FALSE;
  3699. int chargingProfileIdIsNULL = FALSE;
  3700. int connectorIsNULL = FALSE;
  3701. int chargingProfilePurposeIsNULL = FALSE;
  3702. int stackLevelIsNULL = FALSE;
  3703. //int GotoEnd = FALSE;
  3704. FILE *fptr1, *fptr2;
  3705. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3706. int n_chargingProfile=0;
  3707. int isEmptyFile = FALSE;
  3708. char sLineWord[1600]={0};
  3709. char chargingProfiles[10][100]={0};
  3710. int ChargeProfileCount = 0;
  3711. char ch;
  3712. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3713. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3714. //***id ****/
  3715. c = 0;
  3716. loc = strstr(payload, "id");
  3717. memset(sstr ,0, sizeof(sstr) );
  3718. if(loc == NULL)
  3719. {
  3720. chargingProfileIdIsNULL = TRUE;
  3721. }
  3722. else
  3723. {
  3724. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3725. {
  3726. sstr[c] = loc[strlen("id")+2+c];
  3727. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3728. c++;
  3729. }
  3730. sstr[c] = '\0';
  3731. chargingProfileIdInt = atoi(sstr);
  3732. }
  3733. //***connectorId ****/
  3734. c=0;
  3735. loc = strstr(payload, "connectorId");
  3736. memset(sstr ,0, sizeof(sstr) );
  3737. if(loc == NULL)
  3738. {
  3739. connectorIsNULL = TRUE;
  3740. }
  3741. else
  3742. {
  3743. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3744. {
  3745. sstr[c] = loc[strlen("connectorId")+2+c];
  3746. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3747. c++;
  3748. }
  3749. sstr[c] = '\0';
  3750. connectorIdInt = atoi(sstr);
  3751. }
  3752. //***chargingProfilePurpose ****/
  3753. loc = strstr(payload, "chargingProfilePurpose");
  3754. memset(sstr ,0, sizeof(sstr) );
  3755. c = 0;
  3756. if(loc == NULL)
  3757. {
  3758. chargingProfilePurposeIsNULL = TRUE;
  3759. }
  3760. else
  3761. {
  3762. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3763. {
  3764. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3765. c++;
  3766. }
  3767. sstr[c] = '\0';
  3768. strcpy(chargingProfilePurposeStr, sstr);
  3769. }
  3770. //***stackLevel ****/
  3771. c=0;
  3772. loc = strstr(payload, "stackLevel");
  3773. memset(sstr ,0, sizeof(sstr) );
  3774. if(loc == NULL)
  3775. {
  3776. stackLevelIsNULL = TRUE;
  3777. }
  3778. else
  3779. {
  3780. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3781. {
  3782. sstr[c] = loc[strlen("stackLevel")+2+c];
  3783. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3784. c++;
  3785. }
  3786. sstr[c] = '\0';
  3787. stackLevelInt = atoi(sstr);
  3788. }
  3789. if(connectorIsNULL == FALSE)
  3790. {
  3791. switch(connectorIdInt)
  3792. {
  3793. case 0:
  3794. if(chargingProfilePurposeIsNULL == TRUE)
  3795. {
  3796. int l = 0;
  3797. strcpy(fname, ChargePointMaxProfile_JSON);
  3798. if((access(fname,F_OK))!=-1)
  3799. {
  3800. strcpy(chargingProfiles[l], fname);
  3801. l = l + 1;
  3802. }
  3803. strcpy(fname, TxDefaultProfile_0_JSON);
  3804. if((access(fname,F_OK))!=-1)
  3805. {
  3806. strcpy(chargingProfiles[l], fname);
  3807. l = l + 1;
  3808. }
  3809. ChargeProfileCount = l;
  3810. }
  3811. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3812. {
  3813. strcpy(fname, ChargePointMaxProfile_JSON);
  3814. if((access(fname,F_OK))!=-1)
  3815. {
  3816. strcpy(chargingProfiles[0], fname);
  3817. ChargeProfileCount = 1;
  3818. }
  3819. }
  3820. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3821. {
  3822. strcpy(fname, TxDefaultProfile_0_JSON);
  3823. if((access(fname,F_OK))!=-1)
  3824. {
  3825. strcpy(chargingProfiles[0], fname);
  3826. ChargeProfileCount = 1;
  3827. }
  3828. }
  3829. break;
  3830. default:
  3831. if(chargingProfilePurposeIsNULL == TRUE)
  3832. {
  3833. int m = 0;
  3834. memset(fname, 0, sizeof fname);
  3835. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3836. if((access(fname,F_OK))!=-1)
  3837. {
  3838. strcpy(chargingProfiles[m], fname);
  3839. m = m + 1;
  3840. }
  3841. memset(fname, 0, sizeof fname);
  3842. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3843. if((access(fname,F_OK))!=-1)
  3844. {
  3845. strcpy(chargingProfiles[m], fname);
  3846. m = m + 1;
  3847. }
  3848. ChargeProfileCount = m;
  3849. }
  3850. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3851. {
  3852. //strcpy(fname, TxDefaultProfile_1_JSON);
  3853. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3854. if((access(fname,F_OK))!=-1)
  3855. {
  3856. strcpy(chargingProfiles[0], fname);
  3857. ChargeProfileCount = 1;
  3858. }
  3859. }
  3860. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3861. {
  3862. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3863. if((access(fname,F_OK))!=-1)
  3864. {
  3865. strcpy(chargingProfiles[0], fname);
  3866. ChargeProfileCount = 1;
  3867. }
  3868. //strcpy(fname, TxProfile_1_JSON);
  3869. }
  3870. //strcpy(fname, ChargePointMaxProfile_JSON );
  3871. break;
  3872. }
  3873. }
  3874. else // Check all Charging Profiles
  3875. {
  3876. int i = 0;
  3877. char fnametemp[200]={0};
  3878. ChargeProfileCount = 0;
  3879. //Check ChargePointMaxProfile.json exit
  3880. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3881. {
  3882. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3883. i = i + 1;
  3884. }
  3885. //Check TxDefaultProfile_0.json exit
  3886. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3887. {
  3888. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3889. i = i + 1;
  3890. }
  3891. //Check TxDefaultProfile_%d.json
  3892. for(int j=1; j <= gunTotalNumber; j++)
  3893. {
  3894. memset(fnametemp, 0, sizeof fnametemp);
  3895. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3896. if((access(fnametemp,F_OK))!=-1)
  3897. {
  3898. strcpy(chargingProfiles[i], fnametemp);
  3899. i = i + 1;
  3900. }
  3901. }
  3902. //Check TxProfile_%d.json
  3903. for(int j=1; j <= gunTotalNumber; j++)
  3904. {
  3905. memset(fnametemp, 0, sizeof fnametemp);
  3906. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3907. if((access(fnametemp,F_OK))!=-1)
  3908. {
  3909. strcpy(chargingProfiles[i], fnametemp);
  3910. i = i + 1;
  3911. }
  3912. }
  3913. ChargeProfileCount = i;
  3914. }// End connectorIsNULL is TRUE
  3915. if(ChargeProfileCount == 0)
  3916. {
  3917. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3918. goto end;
  3919. }
  3920. #if 0
  3921. fptr1 = fopen(fname, "r");
  3922. if (!fptr1)
  3923. {
  3924. //file not exist
  3925. DEBUG_INFO("Unable to open the input file!!\n");
  3926. fptr1 = fopen(fname, "w+");
  3927. }
  3928. fclose(fptr1);
  3929. #endif
  3930. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3931. {
  3932. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3933. goto end;
  3934. }
  3935. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3936. {
  3937. memset(str, 0, sizeof str);
  3938. // clear temp file
  3939. sprintf(str,"rm -f %s",temp);
  3940. system(str);
  3941. for(int k=0; k < ChargeProfileCount; k++)
  3942. {
  3943. memset(str, 0, sizeof str);
  3944. //clear file in C
  3945. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3946. system(str);
  3947. }
  3948. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3949. goto end;
  3950. }
  3951. else if(connectorIsNULL == TRUE)
  3952. {
  3953. for(int k=0; k < ChargeProfileCount; k++)
  3954. {
  3955. fptr1 = fopen(chargingProfiles[k], "r");
  3956. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  3957. //Check Charging Profile Count
  3958. while(fscanf(fptr1, "%s", word) != EOF)
  3959. {
  3960. //DEBUG_INFO("word=%s\n",word);
  3961. if(strstr(word, "chargingProfileId")!= NULL)
  3962. {
  3963. //DEBUG_INFO("test chargingProfileId \n");
  3964. n_chargingProfile = n_chargingProfile + 1;
  3965. //DEBUG_INFO("chargingProfileId Found\n");
  3966. }
  3967. }
  3968. rewind(fptr1);
  3969. //search Charging Profile Element
  3970. //int i= 0;
  3971. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3972. {
  3973. //------------------------tempconnectorIdInt------------------------//
  3974. loc = strstr(sLineWord, "connectorId");
  3975. c = 0;
  3976. memset(sstr ,0, sizeof(sstr) );
  3977. while (loc[strlen("connectorId")+2+c] != ',')
  3978. {
  3979. sstr[c] = loc[strlen("connectorId")+2+c];
  3980. c++;
  3981. }
  3982. sstr[c] = '\0';
  3983. tempconnectorIdInt = atoi(sstr);
  3984. printf("file's gun number is %d\n", tempconnectorIdInt);
  3985. //--------------------------chargingProfileId--------------------//
  3986. c = 0;
  3987. loc = strstr(sLineWord, "chargingProfileId");
  3988. memset(sstr ,0, sizeof(sstr) );
  3989. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3990. {
  3991. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3992. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3993. c++;
  3994. }
  3995. sstr[c] = '\0';
  3996. tempchargingProfileIdInt = atoi(sstr);
  3997. //stackLevel
  3998. c = 0;
  3999. loc = strstr(sLineWord, "stackLevel");
  4000. memset(sstr ,0, sizeof(sstr) );
  4001. while (loc[strlen("stackLevel")+2+c] != ',')
  4002. {
  4003. sstr[c] = loc[strlen("stackLevel")+2+c];
  4004. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4005. c++;
  4006. }
  4007. sstr[c] = '\0';
  4008. tempstackLevelInt = atoi(sstr);
  4009. c = 0;
  4010. loc = strstr(sLineWord, "chargingProfilePurpose");
  4011. memset(sstr ,0, sizeof(sstr) );
  4012. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4013. {
  4014. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4015. c++;
  4016. }
  4017. sstr[c] = '\0';
  4018. strcpy(tempchargingProfilePurposeStr, sstr);
  4019. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4020. {
  4021. //------- not write to fptr2-------//
  4022. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4023. //clearflag = TRUE;
  4024. }
  4025. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4026. {
  4027. //------- not write to fptr2-------//
  4028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4029. }
  4030. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4031. {
  4032. //------- not write to fptr2-------//
  4033. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4034. }
  4035. else
  4036. {
  4037. fprintf(fptr2, sLineWord);//writing data into file
  4038. }
  4039. memset(sLineWord, 0, sizeof sLineWord);
  4040. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4041. if(clearflag == TRUE)
  4042. {
  4043. fclose(fptr1);
  4044. fclose(fptr2);
  4045. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4046. system(str);
  4047. // clear temp file
  4048. sprintf(str,"rm -f %s",temp);
  4049. system(str);
  4050. }
  4051. else
  4052. {
  4053. fclose(fptr1);
  4054. fclose(fptr2);
  4055. memset(str, 0, sizeof str);
  4056. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4057. system(str);
  4058. resultRename = rename(temp, chargingProfiles[k]);
  4059. if(resultRename == 0)
  4060. {
  4061. DEBUG_INFO("File ChargingProfile renamed successfully");
  4062. }
  4063. else
  4064. {
  4065. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4066. }
  4067. if(comfirmstr[0]== 0)
  4068. {
  4069. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4070. }
  4071. //Check chargingProfile is empty file
  4072. /*------ Read the file ----------------*/
  4073. fptr1=fopen(chargingProfiles[k],"r");
  4074. ch=fgetc(fptr1);
  4075. rewind(fptr1);
  4076. memset(sLineWord, 0, sizeof sLineWord);
  4077. if(ch!=EOF)
  4078. {
  4079. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4080. {
  4081. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4082. if(sLineWord[0]=='\0')
  4083. {
  4084. isEmptyFile = TRUE;
  4085. break;
  4086. }
  4087. else
  4088. {
  4089. isEmptyFile = FALSE;
  4090. break;
  4091. }
  4092. }
  4093. }
  4094. fclose(fptr1);
  4095. if(isEmptyFile == TRUE)
  4096. {
  4097. memset(str, 0, sizeof str);
  4098. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4099. system(str);
  4100. }
  4101. }
  4102. }// End of while(int k=0; k < ChargePointCount; k++)
  4103. }
  4104. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4105. {
  4106. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4107. for(int k=0; k < ChargeProfileCount; k++)
  4108. {
  4109. fptr1 = fopen(chargingProfiles[k], "r");
  4110. fptr2 = fopen(temp, "w+");
  4111. //Check Charging Profile Count
  4112. while(fscanf(fptr1, "%s", word) != EOF)
  4113. {
  4114. //DEBUG_INFO("word=%s\n",word);
  4115. if(strstr(word, "chargingProfileId")!= NULL)
  4116. {
  4117. //DEBUG_INFO("test chargingProfileId \n");
  4118. n_chargingProfile = n_chargingProfile + 1;
  4119. //DEBUG_INFO("chargingProfileId Found\n");
  4120. }
  4121. }
  4122. rewind(fptr1);
  4123. //search Charging Profile Element
  4124. //int i= 0;
  4125. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4126. {
  4127. //*************************tempconnectorIdInt*********************************/
  4128. loc = strstr(sLineWord, "connectorId");
  4129. c = 0;
  4130. memset(sstr ,0, sizeof(sstr) );
  4131. while (loc[strlen("connectorId")+2+c] != ',')
  4132. {
  4133. sstr[c] = loc[strlen("connectorId")+2+c];
  4134. c++;
  4135. }
  4136. sstr[c] = '\0';
  4137. tempconnectorIdInt = atoi(sstr);
  4138. //chargingProfileId
  4139. c = 0;
  4140. loc = strstr(sLineWord, "chargingProfileId");
  4141. memset(sstr ,0, sizeof(sstr) );
  4142. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4143. {
  4144. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4145. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4146. c++;
  4147. }
  4148. sstr[c] = '\0';
  4149. tempchargingProfileIdInt = atoi(sstr);
  4150. //stackLevel
  4151. c = 0;
  4152. loc = strstr(sLineWord, "stackLevel");
  4153. memset(sstr ,0, sizeof(sstr) );
  4154. while (loc[strlen("stackLevel")+2+c] != ',')
  4155. {
  4156. sstr[c] = loc[strlen("stackLevel")+2+c];
  4157. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4158. c++;
  4159. }
  4160. sstr[c] = '\0';
  4161. tempstackLevelInt = atoi(sstr);
  4162. c = 0;
  4163. loc = strstr(sLineWord, "chargingProfilePurpose");
  4164. memset(sstr ,0, sizeof(sstr) );
  4165. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4166. {
  4167. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4168. c++;
  4169. }
  4170. sstr[c] = '\0';
  4171. strcpy(tempchargingProfilePurposeStr, sstr);
  4172. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4173. {
  4174. //------- not write to fptr2-------//
  4175. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4176. //clearflag = TRUE;
  4177. }
  4178. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4179. {
  4180. //------- not write to fptr2-------//
  4181. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4182. }
  4183. else if(stackLevelIsNULL == TRUE)
  4184. {
  4185. //Clear Whole File
  4186. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4187. clearflag = TRUE;
  4188. break;
  4189. }
  4190. else
  4191. {
  4192. fprintf(fptr2, sLineWord);//writing data into file
  4193. }
  4194. memset(sLineWord, 0, sizeof sLineWord);
  4195. }
  4196. if(clearflag == TRUE)
  4197. {
  4198. fclose(fptr1);
  4199. fclose(fptr2);
  4200. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4201. system(str);
  4202. // clear temp file
  4203. sprintf(str,"rm -f %s",temp);
  4204. system(str);
  4205. }
  4206. else
  4207. {
  4208. fclose(fptr1);
  4209. fclose(fptr2);
  4210. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4211. system(str);
  4212. resultRename = rename(temp, chargingProfiles[k]);
  4213. if(resultRename == 0)
  4214. {
  4215. DEBUG_INFO("File ChargingProfile renamed successfully");
  4216. }
  4217. else
  4218. {
  4219. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4220. }
  4221. if(comfirmstr[0]== 0)
  4222. {
  4223. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4224. }
  4225. //Check chargingProfile is empty file
  4226. /*------ Read the file ----------------*/
  4227. fptr1=fopen(chargingProfiles[k],"r");
  4228. ch=fgetc(fptr1);
  4229. rewind(fptr1);
  4230. memset(sLineWord, 0, sizeof sLineWord);
  4231. if(ch!=EOF)
  4232. {
  4233. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4234. {
  4235. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4236. if(sLineWord[0]=='\0')
  4237. {
  4238. isEmptyFile = TRUE;
  4239. break;
  4240. }
  4241. else
  4242. {
  4243. isEmptyFile = FALSE;
  4244. break;
  4245. }
  4246. }
  4247. }
  4248. fclose(fptr1);
  4249. if(isEmptyFile == TRUE)
  4250. {
  4251. memset(str, 0, sizeof str);
  4252. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4253. system(str);
  4254. }
  4255. /*------- End of reading ---------------*/
  4256. }
  4257. } // while(int k=0; k < ChargeProfileCount; k++)
  4258. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4259. end:
  4260. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4261. return result;
  4262. }
  4263. int handleDataTransferRequest(char *uuid, char *payload)
  4264. {
  4265. mtrace();
  4266. int result = FAIL;
  4267. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4268. char tempvendorId[255]={0};
  4269. char tempmessageId[50]={0};
  4270. char tempdata[50]={0};
  4271. char sstr[160]={0};//sstr[200]={ 0 };
  4272. char message[80]={0};
  4273. int c = 0;
  4274. char *loc;
  4275. DEBUG_INFO("handle DataTransferRequest\n");
  4276. if((uuid != NULL) && (payload != NULL))
  4277. {
  4278. //===============================
  4279. // vendorId
  4280. //===============================
  4281. c = 0;
  4282. loc = strstr(payload, "vendorId");
  4283. while (loc[strlen("vendorId")+3+c] != '\"')
  4284. {
  4285. sstr[c] = loc[strlen("vendorId")+3+c];
  4286. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4287. c++;
  4288. }
  4289. sstr[c] = '\0';
  4290. strcpy(tempvendorId,sstr);
  4291. //===============================
  4292. // messageId
  4293. //===============================
  4294. memset(sstr ,0, sizeof(sstr) );
  4295. c = 0;
  4296. loc = strstr(payload, "messageId");
  4297. while (loc[strlen("messageId")+3+c] != '\"')
  4298. {
  4299. sstr[c] = loc[strlen("messageId")+3+c];
  4300. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4301. c++;
  4302. }
  4303. sstr[c] = '\0';
  4304. strcpy(tempmessageId,sstr);
  4305. //===============================
  4306. // data
  4307. //===============================
  4308. memset(sstr ,0, sizeof(sstr) );
  4309. c = 0;
  4310. loc = strstr(payload, "data");
  4311. printf("loc=%s\n",loc);
  4312. while (loc[strlen("data")+3+c] != '\"')
  4313. {
  4314. sstr[c] = loc[strlen("data")+3+c];
  4315. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4316. c++;
  4317. }
  4318. sstr[c] = '\0';
  4319. strcpy(tempdata,sstr);
  4320. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4321. }
  4322. else
  4323. {
  4324. char guid[37]={0};
  4325. random_uuid(guid);
  4326. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4327. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4328. }
  4329. LWS_Send(message);
  4330. return result;
  4331. }
  4332. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4333. {
  4334. mtrace();
  4335. int result = FAIL;
  4336. int connectorIdInt, durationInt;
  4337. char chargingRateUnitStr[4]={0};
  4338. //int tempconnectorIdInt,
  4339. int tempdurationInt;
  4340. float tempminChargingRateFloat = 0.0;
  4341. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4342. int tempStartPeriodInt=0;
  4343. float tempLimitInt=0.0;//0.1;
  4344. int tempNumberPhasesInt=0;
  4345. char fname[200];
  4346. char comfirmstr[20];
  4347. //float totallimit =0.0;
  4348. float MinChargingRate =0.0;
  4349. //double diff_t;
  4350. //struct tm tp;
  4351. FILE *fptr1;
  4352. int c = 0;
  4353. //int i = 0;
  4354. char * pch;
  4355. char *loc;
  4356. char sstr[200]={ 0 };
  4357. int n_chargingProfile = 0;
  4358. int n_SchedulePeriods = 0;
  4359. char SchedulePeriodList[10][200]={0};
  4360. char sLineWord[1600]={0};
  4361. //int n_periods = 0;
  4362. char word[1000]={0};
  4363. int confirmPeriods = 0;
  4364. struct StructProfile ChargePointMaxProfile;
  4365. struct StructProfile TxDefaultProfile;
  4366. struct StructProfile TxProfile;
  4367. struct StructProfile TxDefaultProfiletemp[2]={0};
  4368. int TxDefaultProfileFileIsNull=FALSE;
  4369. int ChargePointMaxProfileIsNull=FALSE;
  4370. int TxProfileIsNull=FALSE;
  4371. int CompositeSceduleIndex = 0;
  4372. char ChargePointMaxProfileScheduleStr[30]={0};
  4373. char TxDefaultProfileScheduleStr[30]={0};
  4374. char TxProfileScheduleStr[30]={0};
  4375. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4376. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4377. memset(&TxProfile,0,sizeof(struct StructProfile));
  4378. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4379. c=0;
  4380. loc = strstr(payload, "connectorId");
  4381. memset(sstr ,0, sizeof(sstr) );
  4382. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4383. {
  4384. sstr[c] = loc[strlen("connectorId")+2+c];
  4385. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4386. c++;
  4387. }
  4388. sstr[c] = '\0';
  4389. connectorIdInt = atoi(sstr);
  4390. c=0;
  4391. loc = strstr(payload, "duration");
  4392. memset(sstr ,0, sizeof(sstr) );
  4393. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4394. {
  4395. sstr[c] = loc[strlen("duration")+2+c];
  4396. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4397. c++;
  4398. }
  4399. sstr[c] = '\0';
  4400. durationInt = atoi(sstr);
  4401. c = 0;
  4402. loc = strstr(payload, "chargingRateUnit");
  4403. memset(sstr ,0, sizeof(sstr) );
  4404. if(loc == NULL)
  4405. {
  4406. }
  4407. else
  4408. {
  4409. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4410. {
  4411. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4412. c++;
  4413. }
  4414. sstr[c] = '\0';
  4415. strcpy(chargingRateUnitStr, sstr);
  4416. }
  4417. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4418. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4419. if(connectorIdInt==0) // connectorId is 0
  4420. {
  4421. //******************************ChargePointMaxProfile*****************************************************/
  4422. strcpy(fname, ChargePointMaxProfile_JSON );
  4423. char word[30]={0};
  4424. char sLineWord[1060]={0};
  4425. int n_chargingProfile=0;
  4426. ChargePointMaxProfileIsNull=TRUE;
  4427. if((access(fname,F_OK))!=-1)
  4428. {
  4429. fptr1 = fopen(fname, "r");
  4430. int c;
  4431. c = fgetc(fptr1);
  4432. //DEBUG_INFO("c:%d\n",c);
  4433. rewind(fptr1);
  4434. if(c == EOF)
  4435. {
  4436. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4437. ChargePointMaxProfileIsNull=TRUE;
  4438. fclose(fptr1);
  4439. }
  4440. else
  4441. {
  4442. ChargePointMaxProfileIsNull=FALSE;
  4443. while(fscanf(fptr1, "%s", word) != EOF)
  4444. {
  4445. if(strcmp(word, "chargingProfileId") == 0)
  4446. {
  4447. n_chargingProfile = n_chargingProfile + 1;
  4448. printf("Found\n");
  4449. }
  4450. }
  4451. rewind(fptr1);
  4452. //search Charging Profile Element
  4453. int i= 0;
  4454. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4455. #if 0
  4456. /***********connectorId****************/
  4457. c = 0;
  4458. loc = strstr(sLineWord, "connectorId");
  4459. // printf("loc=%s\n",loc);
  4460. memset(sstr ,0, sizeof(sstr) );
  4461. while (loc[strlen("connectorId")+2+c] != ',')
  4462. {
  4463. sstr[c] = loc[strlen("connectorId")+2+c];
  4464. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4465. c++;
  4466. }
  4467. sstr[c] = '\0';
  4468. tempconnectorIdInt = atoi(sstr);
  4469. #endif
  4470. //***********validFrom**************/
  4471. c = 0;
  4472. loc = strstr(sLineWord, "validFrom");
  4473. //DEBUG_INFO("loc=%s\n",loc);
  4474. memset(sstr ,0, sizeof(sstr) );
  4475. if(loc != NULL)
  4476. {
  4477. while (loc[3+strlen("validFrom")+c] != '\"')
  4478. {
  4479. sstr[c] = loc[3+strlen("validFrom")+c];
  4480. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4481. c++;
  4482. }
  4483. sstr[c] = '\0';
  4484. DEBUG_INFO("validFrom=%s\n",sstr);
  4485. strcpy(tempvalidFromStr,sstr);
  4486. }
  4487. else
  4488. {
  4489. strcpy(tempvalidFromStr,"");
  4490. }
  4491. //**********startSchedule**********/
  4492. c = 0;
  4493. loc = strstr(sLineWord, "startSchedule");
  4494. //DEBUG_INFO("loc=%s\n",loc);
  4495. memset(sstr ,0, sizeof(sstr) );
  4496. while (loc[3+strlen("startSchedule")+c] != '\"')
  4497. {
  4498. sstr[c] = loc[3+strlen("startSchedule")+c];
  4499. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4500. c++;
  4501. }
  4502. sstr[c] = '\0';
  4503. strcpy(tempstartScheduleStr, sstr);
  4504. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4505. //**********chargingRateUnit**********/
  4506. c = 0;
  4507. loc = strstr(sLineWord, "chargingRateUnit");
  4508. memset(sstr ,0, sizeof(sstr) );
  4509. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4510. {
  4511. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4512. c++;
  4513. }
  4514. sstr[c] = '\0';
  4515. strcpy(tempchargingRateUnitStr, sstr);
  4516. //**********minChargingRate*******/
  4517. c = 0;
  4518. loc = strstr(sLineWord, "minChargingRate");
  4519. //printf("loc=%s\n",loc);
  4520. if(loc != NULL)
  4521. {
  4522. memset(sstr ,0, sizeof(sstr) );
  4523. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4524. {
  4525. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4526. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4527. c++;
  4528. }
  4529. sstr[c] = '\0';
  4530. tempminChargingRateFloat = atof(sstr);
  4531. }
  4532. else
  4533. {
  4534. tempminChargingRateFloat = 0.0;
  4535. }
  4536. //
  4537. #if 0
  4538. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4539. tp.tm_isdst = -1;
  4540. time_t utc = mktime(&tp);
  4541. // current time
  4542. time_t t = time(NULL);
  4543. #endif
  4544. //diff_t = difftime(t, utc);
  4545. //parsing strings to words
  4546. i = 0;
  4547. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4548. loc = loc+3+strlen("chargingSchedulePeriod");
  4549. pch = strtok(loc ,"{");
  4550. while (pch != NULL)
  4551. {
  4552. strcpy(SchedulePeriodList[i], pch);
  4553. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4554. //printf ("%s\n",pch);
  4555. pch = strtok (NULL, "{");
  4556. i = i + 1;
  4557. }
  4558. n_SchedulePeriods = i;
  4559. for(int i=0;i<n_SchedulePeriods;i++)
  4560. {
  4561. //*************startPeriod****************/
  4562. c = 0;
  4563. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4564. memset(sstr ,0, sizeof(sstr) );
  4565. while (loc[strlen("startPeriod")+2+c] != ',')
  4566. {
  4567. sstr[c] = loc[strlen("startPeriod")+2+c];
  4568. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4569. c++;
  4570. }
  4571. sstr[c] = '\0';
  4572. tempStartPeriodInt = atoi(sstr);
  4573. //*************limit****************/
  4574. c = 0;
  4575. loc = strstr(SchedulePeriodList[i], "limit");
  4576. memset(sstr ,0, sizeof(sstr) );
  4577. while (loc[strlen("limit")+2+c] != ',')
  4578. {
  4579. sstr[c] = loc[strlen("limit")+2+c];
  4580. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4581. c++;
  4582. }
  4583. sstr[c] = '\0';
  4584. tempLimitInt = atof(sstr);
  4585. //*************numberPhases****************/
  4586. c = 0;
  4587. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4588. memset(sstr ,0, sizeof(sstr) );
  4589. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4590. {
  4591. sstr[c] = loc[strlen("numberPhases")+2+c];
  4592. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4593. c++;
  4594. }
  4595. sstr[c] = '\0';
  4596. tempNumberPhasesInt = atoi(sstr);
  4597. ChargePointMaxProfile.Duration = durationInt;
  4598. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4599. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4600. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4601. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4602. }
  4603. if(MinChargingRate < tempminChargingRateFloat)
  4604. MinChargingRate = tempminChargingRateFloat;
  4605. }
  4606. }// End of file ChargingProfile
  4607. } //THE END OF ACCESS ChargePointMaxProfile
  4608. //******************************TxDefaultProfile***********************************************/
  4609. strcpy(fname, TxDefaultProfile_0_JSON);
  4610. memset(word, 0, 30);
  4611. memset(sLineWord, 0, 1060);
  4612. //char word[30]={0};
  4613. //char sLineWord[1060]={0};
  4614. n_chargingProfile=0;
  4615. TxDefaultProfileFileIsNull=TRUE;
  4616. if((access(fname,F_OK))!=-1)
  4617. {
  4618. fptr1 = fopen(fname, "r");
  4619. c = 0;
  4620. c = fgetc(fptr1);
  4621. //DEBUG_INFO("c:%d\n",c);
  4622. rewind(fptr1);
  4623. if(c == EOF)
  4624. {
  4625. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4626. TxDefaultProfileFileIsNull=TRUE;
  4627. fclose(fptr1);
  4628. }
  4629. else
  4630. {
  4631. TxDefaultProfileFileIsNull=FALSE;
  4632. while(fscanf(fptr1, "%s", word) != EOF)
  4633. {
  4634. if(strcmp(word, "chargingProfileId") == 0)
  4635. {
  4636. n_chargingProfile = n_chargingProfile + 1;
  4637. printf("Found\n");
  4638. }
  4639. }
  4640. rewind(fptr1);
  4641. //search Charging Profile Element
  4642. int i= 0;
  4643. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4644. #if 0
  4645. /***********connectorId****************/
  4646. c = 0;
  4647. loc = strstr(sLineWord, "connectorId");
  4648. // printf("loc=%s\n",loc);
  4649. memset(sstr ,0, sizeof(sstr) );
  4650. while (loc[strlen("connectorId")+2+c] != ',')
  4651. {
  4652. sstr[c] = loc[strlen("connectorId")+2+c];
  4653. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4654. c++;
  4655. }
  4656. sstr[c] = '\0';
  4657. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4658. tempconnectorIdInt = atoi(sstr);
  4659. #endif
  4660. //***********validFrom**************/
  4661. c = 0;
  4662. loc = strstr(sLineWord, "validFrom");
  4663. //DEBUG_INFO("loc=%s\n",loc);
  4664. memset(sstr ,0, sizeof(sstr) );
  4665. if(loc != NULL)
  4666. {
  4667. while (loc[3+strlen("validFrom")+c] != '\"')
  4668. {
  4669. sstr[c] = loc[3+strlen("validFrom")+c];
  4670. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4671. c++;
  4672. }
  4673. sstr[c] = '\0';
  4674. DEBUG_INFO("validFrom=%s\n",sstr);
  4675. strcpy(tempvalidFromStr,sstr);
  4676. }
  4677. else
  4678. {
  4679. strcpy(tempvalidFromStr,"");
  4680. }
  4681. //**********startSchedule**********/
  4682. c = 0;
  4683. loc = strstr(sLineWord, "startSchedule");
  4684. //DEBUG_INFO("loc=%s\n",loc);
  4685. memset(sstr ,0, sizeof(sstr) );
  4686. while (loc[3+strlen("startSchedule")+c] != '\"')
  4687. {
  4688. sstr[c] = loc[3+strlen("startSchedule")+c];
  4689. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4690. c++;
  4691. }
  4692. sstr[c] = '\0';
  4693. strcpy(tempstartScheduleStr, sstr);
  4694. strcpy(TxDefaultProfileScheduleStr, sstr);
  4695. //**********chargingRateUnit**********/
  4696. c = 0;
  4697. loc = strstr(sLineWord, "chargingRateUnit");
  4698. memset(sstr ,0, sizeof(sstr) );
  4699. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4700. {
  4701. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4702. c++;
  4703. }
  4704. sstr[c] = '\0';
  4705. strcpy(tempchargingRateUnitStr, sstr);
  4706. //**********minChargingRate*******/
  4707. c = 0;
  4708. loc = strstr(sLineWord, "minChargingRate");
  4709. //printf("loc=%s\n",loc);
  4710. if(loc != NULL)
  4711. {
  4712. memset(sstr ,0, sizeof(sstr) );
  4713. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4714. {
  4715. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4716. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4717. c++;
  4718. }
  4719. sstr[c] = '\0';
  4720. tempminChargingRateFloat = atof(sstr);
  4721. }
  4722. else
  4723. {
  4724. tempminChargingRateFloat = 0.0;
  4725. }
  4726. #if 0
  4727. //
  4728. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4729. tp.tm_isdst = -1;
  4730. time_t utc = mktime(&tp);
  4731. // current time
  4732. time_t t = time(NULL);
  4733. //diff_t = difftime(t, utc);
  4734. #endif
  4735. //parsing strings to words
  4736. i = 0;
  4737. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4738. loc = loc+3+strlen("chargingSchedulePeriod");
  4739. pch = strtok(loc ,"{");
  4740. while (pch != NULL)
  4741. {
  4742. strcpy(SchedulePeriodList[i], pch);
  4743. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4744. //printf ("%s\n",pch);
  4745. pch = strtok (NULL, "{");
  4746. i = i + 1;
  4747. }
  4748. n_SchedulePeriods = i;
  4749. for(int i=0;i<n_SchedulePeriods;i++)
  4750. {
  4751. //*************startPeriod****************/
  4752. c = 0;
  4753. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4754. memset(sstr ,0, sizeof(sstr) );
  4755. while (loc[strlen("startPeriod")+2+c] != ',')
  4756. {
  4757. sstr[c] = loc[strlen("startPeriod")+2+c];
  4758. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4759. c++;
  4760. }
  4761. sstr[c] = '\0';
  4762. tempStartPeriodInt = atoi(sstr);
  4763. //*************limit****************/
  4764. c = 0;
  4765. loc = strstr(SchedulePeriodList[i], "limit");
  4766. memset(sstr ,0, sizeof(sstr) );
  4767. while (loc[strlen("limit")+2+c] != ',')
  4768. {
  4769. sstr[c] = loc[strlen("limit")+2+c];
  4770. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4771. c++;
  4772. }
  4773. sstr[c] = '\0';
  4774. tempLimitInt = atof(sstr);
  4775. //*************numberPhases****************/
  4776. c = 0;
  4777. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4778. memset(sstr ,0, sizeof(sstr) );
  4779. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4780. {
  4781. sstr[c] = loc[strlen("numberPhases")+2+c];
  4782. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4783. c++;
  4784. }
  4785. sstr[c] = '\0';
  4786. tempNumberPhasesInt = atoi(sstr);
  4787. TxDefaultProfile.Duration = durationInt;
  4788. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4789. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4790. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4791. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4792. }
  4793. if(MinChargingRate < tempminChargingRateFloat)
  4794. MinChargingRate = tempminChargingRateFloat;
  4795. }
  4796. }
  4797. }// the end of ACCESS TxDefaultProfile
  4798. //--------------------- Composite Schedule-----------------------------//
  4799. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4800. {
  4801. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4802. struct tm tp;
  4803. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4804. tp.tm_isdst = -1;
  4805. time_t utc = mktime(&tp);
  4806. time_t t = time(NULL);
  4807. double diff_f = difftime(t, utc);
  4808. int diff_i; //= (int)diff_f;
  4809. int quotient; //= diff_i / 86400;//86400 seconds/day
  4810. int period = 0;
  4811. if(diff_f >= 0)
  4812. {
  4813. diff_i = (int)diff_f;
  4814. quotient = diff_i / 86400;
  4815. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4816. {
  4817. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4818. {
  4819. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4820. {
  4821. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4822. }
  4823. else
  4824. {
  4825. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  4826. }
  4827. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4828. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4829. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4830. period = period + 1;
  4831. }
  4832. }
  4833. }
  4834. confirmPeriods = period;
  4835. }
  4836. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  4837. {
  4838. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4839. struct tm tp;
  4840. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4841. tp.tm_isdst = -1;
  4842. time_t utc = mktime(&tp);
  4843. time_t t = time(NULL);
  4844. double diff_f = difftime(t, utc);
  4845. int diff_i; // = (int)diff_f;
  4846. int quotient; // = diff_i / 86400;//86400 seconds/day
  4847. int period = 0;
  4848. if(diff_f >= 0)
  4849. {
  4850. diff_i = (int)diff_f;
  4851. quotient = diff_i / 86400;//86400 seconds/day
  4852. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4853. {
  4854. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4855. {
  4856. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4857. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4858. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4859. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4860. period = period + 1;
  4861. }
  4862. }
  4863. }
  4864. confirmPeriods = period;
  4865. }
  4866. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  4867. {
  4868. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  4869. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  4870. {
  4871. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  4872. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  4873. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  4874. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4875. }
  4876. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  4877. }
  4878. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  4879. {
  4880. confirmPeriods = 0;
  4881. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  4882. goto end;
  4883. }
  4884. //* Define temporary variables */
  4885. struct tm *gtime;
  4886. time_t now;
  4887. char buf[28];
  4888. /* Read the current system time */
  4889. time(&now);
  4890. /* Convert the system time to GMT (now UTC) */
  4891. gtime = gmtime(&now);
  4892. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4893. // make .conf
  4894. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4895. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  4896. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  4897. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4898. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4899. }
  4900. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4901. {
  4902. //*****************************ChargePointMaxProfile******************************************/
  4903. strcpy(fname, ChargePointMaxProfile_JSON);
  4904. ChargePointMaxProfileIsNull=TRUE;
  4905. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4906. {
  4907. fptr1 = fopen(fname, "r");
  4908. int c;
  4909. c = fgetc(fptr1);
  4910. //DEBUG_INFO("c:%d\n",c);
  4911. rewind(fptr1);
  4912. if(c == EOF)
  4913. {
  4914. DEBUG_INFO("\n End of file reached.");
  4915. ChargePointMaxProfileIsNull=TRUE;
  4916. fclose(fptr1);
  4917. }
  4918. else
  4919. {
  4920. ChargePointMaxProfileIsNull=FALSE;
  4921. while(fscanf(fptr1, "%s", word) != EOF)
  4922. {
  4923. if(strcmp(word, "chargingProfileId") == 0)
  4924. {
  4925. n_chargingProfile = n_chargingProfile + 1;
  4926. }
  4927. }
  4928. rewind(fptr1);
  4929. //search Charging Profile Element
  4930. int i = 0;
  4931. int j = 0;
  4932. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4933. #if 0
  4934. /***********connectorId****************/
  4935. c = 0;
  4936. loc = strstr(sLineWord, "connectorId");
  4937. memset(sstr ,0, sizeof(sstr) );
  4938. while (loc[strlen("connectorId")+2+c] != ',')
  4939. {
  4940. sstr[c] = loc[strlen("connectorId")+2+c];
  4941. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4942. c++;
  4943. }
  4944. sstr[c] = '\0';
  4945. tempconnectorIdInt = atoi(sstr);
  4946. #endif
  4947. //***********validFrom**************/
  4948. c = 0;
  4949. loc = strstr(sLineWord, "validFrom");
  4950. if(loc != NULL)
  4951. {
  4952. memset(sstr ,0, sizeof(sstr) );
  4953. while (loc[3+strlen("validFrom")+c] != '\"')
  4954. {
  4955. sstr[c] = loc[3+strlen("validFrom")+c];
  4956. c++;
  4957. }
  4958. sstr[c] = '\0';
  4959. strcpy(tempvalidFromStr,sstr);
  4960. }
  4961. else
  4962. {
  4963. strcpy(tempvalidFromStr,"");
  4964. }
  4965. //***********validFrom**************/
  4966. c = 0;
  4967. loc = strstr(sLineWord, "duration");
  4968. if(loc != NULL)
  4969. {
  4970. memset(sstr ,0, sizeof(sstr) );
  4971. while (loc[2+strlen("duration")+c] != ',')
  4972. {
  4973. sstr[c] = loc[2+strlen("duration")+c];
  4974. c++;
  4975. }
  4976. sstr[c] = '\0';
  4977. tempdurationInt = atoi(sstr);
  4978. }
  4979. else
  4980. {
  4981. tempdurationInt = 0;
  4982. }
  4983. //**********startSchedule**********/
  4984. c = 0;
  4985. loc = strstr(sLineWord, "startSchedule");
  4986. memset(sstr ,0, sizeof(sstr) );
  4987. while (loc[3+strlen("startSchedule")+c] != '\"')
  4988. {
  4989. sstr[c] = loc[3+strlen("startSchedule")+c];
  4990. c++;
  4991. }
  4992. sstr[c] = '\0';
  4993. strcpy(tempstartScheduleStr, sstr);
  4994. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4995. //**********chargingRateUnit**********/
  4996. c = 0;
  4997. loc = strstr(sLineWord, "chargingRateUnit");
  4998. memset(sstr ,0, sizeof(sstr) );
  4999. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5000. {
  5001. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5002. c++;
  5003. }
  5004. sstr[c] = '\0';
  5005. strcpy(tempchargingRateUnitStr, sstr);
  5006. //**********minChargingRate*******/
  5007. c = 0;
  5008. loc = strstr(sLineWord, "minChargingRate");
  5009. if(loc != NULL)
  5010. {
  5011. memset(sstr ,0, sizeof(sstr) );
  5012. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5013. {
  5014. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5015. c++;
  5016. }
  5017. sstr[c] = '\0';
  5018. tempminChargingRateFloat = atof(sstr);
  5019. }
  5020. else
  5021. {
  5022. tempminChargingRateFloat = 0.0;
  5023. }
  5024. #if 0
  5025. //
  5026. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5027. tp.tm_isdst = -1;
  5028. time_t utc = mktime(&tp);
  5029. time_t t = time(NULL);
  5030. //diff_t = difftime(t, utc);
  5031. #endif
  5032. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5033. //DEBUG_INFO(" debug 5 -1\n");
  5034. //parsing strings to words
  5035. i = 0;
  5036. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5037. loc = loc+3+strlen("chargingSchedulePeriod");
  5038. pch = strtok(loc ,"{");
  5039. while (pch != NULL)
  5040. {
  5041. strcpy(SchedulePeriodList[i], pch);
  5042. pch = strtok (NULL, "{");
  5043. i = i + 1;
  5044. }
  5045. n_SchedulePeriods = i;
  5046. for(int i=0;i<n_SchedulePeriods;i++)
  5047. {
  5048. //*************startPeriod****************/
  5049. c = 0;
  5050. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5051. memset(sstr ,0, sizeof(sstr) );
  5052. while (loc[strlen("startPeriod")+2+c] != ',')
  5053. {
  5054. sstr[c] = loc[strlen("startPeriod")+2+c];
  5055. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5056. c++;
  5057. }
  5058. sstr[c] = '\0';
  5059. tempStartPeriodInt = atoi(sstr);
  5060. //*************limit****************/
  5061. c = 0;
  5062. loc = strstr(SchedulePeriodList[i], "limit");
  5063. memset(sstr ,0, sizeof(sstr) );
  5064. while (loc[strlen("limit")+2+c] != ',')
  5065. {
  5066. sstr[c] = loc[strlen("limit")+2+c];
  5067. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5068. c++;
  5069. }
  5070. sstr[c] = '\0';
  5071. tempLimitInt = atof(sstr);
  5072. //*************numberPhases****************/
  5073. c = 0;
  5074. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5075. memset(sstr ,0, sizeof(sstr) );
  5076. while (loc[strlen("numberPhases")+2+c] != '}')
  5077. {
  5078. sstr[c] = loc[strlen("numberPhases")+2+c];
  5079. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5080. c++;
  5081. }
  5082. sstr[c] = '\0';
  5083. tempNumberPhasesInt = atoi(sstr);
  5084. if(j == 0)
  5085. {
  5086. ChargePointMaxProfile.Duration = tempdurationInt;
  5087. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5088. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5089. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5090. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5091. }
  5092. }
  5093. if(MinChargingRate < tempminChargingRateFloat)
  5094. {
  5095. MinChargingRate = tempminChargingRateFloat;
  5096. }
  5097. if(confirmPeriods < n_SchedulePeriods)
  5098. {
  5099. confirmPeriods = n_SchedulePeriods;
  5100. }
  5101. j = j + 1;
  5102. }
  5103. fclose(fptr1);
  5104. }
  5105. }// the end of access file ChargePointMaxProfile
  5106. //****************************TxDefaultProfile************************************************/
  5107. #if 0
  5108. switch(connectorIdInt)
  5109. {
  5110. case 0:
  5111. break;
  5112. case 1:
  5113. strcpy(fname, TxDefaultProfile_1_JSON );
  5114. break;
  5115. case 2:
  5116. strcpy(fname, TxDefaultProfile_2_JSON );
  5117. break;
  5118. default:
  5119. strcpy(fname, TxDefaultProfile_1_JSON );
  5120. break;
  5121. }
  5122. #endif
  5123. memset(fname, 0, sizeof fname);
  5124. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5125. TxDefaultProfileFileIsNull=TRUE;
  5126. if((access(fname,F_OK))!=-1)
  5127. {
  5128. fptr1 = fopen(fname, "r");
  5129. c = 0;
  5130. c = fgetc(fptr1);
  5131. //DEBUG_INFO("c:%d\n",c);
  5132. rewind(fptr1);
  5133. if(c == EOF)
  5134. {
  5135. DEBUG_INFO("\n End of file reached.");
  5136. TxDefaultProfileFileIsNull=TRUE;
  5137. fclose(fptr1);
  5138. }
  5139. else
  5140. {
  5141. TxDefaultProfileFileIsNull=FALSE;
  5142. while(fscanf(fptr1, "%s", word) != EOF)
  5143. {
  5144. if(strcmp(word, "chargingProfileId") == 0)
  5145. {
  5146. n_chargingProfile = n_chargingProfile + 1;
  5147. }
  5148. }
  5149. rewind(fptr1);
  5150. //search Charging Profile Element
  5151. int i = 0;
  5152. int j = 0;
  5153. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5154. //DEBUG_INFO(" 1-1\n");
  5155. #if 0
  5156. /***********connectorId****************/
  5157. c = 0;
  5158. loc = strstr(sLineWord, "connectorId");
  5159. memset(sstr ,0, sizeof(sstr) );
  5160. while (loc[strlen("connectorId")+2+c] != ',')
  5161. {
  5162. sstr[c] = loc[strlen("connectorId")+2+c];
  5163. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5164. c++;
  5165. }
  5166. sstr[c] = '\0';
  5167. tempconnectorIdInt = atoi(sstr);
  5168. #endif
  5169. //***********validFrom**************/
  5170. c = 0;
  5171. loc = strstr(sLineWord, "validFrom");
  5172. if(loc != NULL)
  5173. {
  5174. memset(sstr ,0, sizeof(sstr) );
  5175. while (loc[3+strlen("validFrom")+c] != '\"')
  5176. {
  5177. sstr[c] = loc[3+strlen("validFrom")+c];
  5178. c++;
  5179. }
  5180. sstr[c] = '\0';
  5181. strcpy(tempvalidFromStr,sstr);
  5182. }
  5183. else
  5184. {
  5185. strcpy(tempvalidFromStr,"");
  5186. }
  5187. //***********validFrom**************/
  5188. c = 0;
  5189. loc = strstr(sLineWord, "duration");
  5190. if(loc != NULL)
  5191. {
  5192. memset(sstr ,0, sizeof(sstr) );
  5193. while (loc[2+strlen("duration")+c] != ',')
  5194. {
  5195. sstr[c] = loc[2+strlen("duration")+c];
  5196. c++;
  5197. }
  5198. sstr[c] = '\0';
  5199. tempdurationInt = atoi(sstr);
  5200. }
  5201. else
  5202. {
  5203. tempdurationInt = 0;
  5204. }
  5205. //**********startSchedule**********/
  5206. c = 0;
  5207. loc = strstr(sLineWord, "startSchedule");
  5208. memset(sstr ,0, sizeof(sstr) );
  5209. while (loc[3+strlen("startSchedule")+c] != '\"')
  5210. {
  5211. sstr[c] = loc[3+strlen("startSchedule")+c];
  5212. c++;
  5213. }
  5214. sstr[c] = '\0';
  5215. strcpy(tempstartScheduleStr, sstr);
  5216. strcpy(TxDefaultProfileScheduleStr, sstr);
  5217. //**********chargingRateUnit**********/
  5218. c = 0;
  5219. loc = strstr(sLineWord, "chargingRateUnit");
  5220. memset(sstr ,0, sizeof(sstr) );
  5221. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5222. {
  5223. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5224. c++;
  5225. }
  5226. sstr[c] = '\0';
  5227. strcpy(tempchargingRateUnitStr, sstr);
  5228. //**********minChargingRate*******/
  5229. c = 0;
  5230. loc = strstr(sLineWord, "minChargingRate");
  5231. if(loc != NULL)
  5232. {
  5233. memset(sstr ,0, sizeof(sstr) );
  5234. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5235. {
  5236. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5237. c++;
  5238. }
  5239. sstr[c] = '\0';
  5240. tempminChargingRateFloat = atof(sstr);
  5241. }
  5242. else
  5243. {
  5244. tempminChargingRateFloat = 0.0;
  5245. }
  5246. #if 0
  5247. //
  5248. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5249. tp.tm_isdst = -1;
  5250. time_t utc = mktime(&tp);
  5251. time_t t = time(NULL);
  5252. //diff_t = difftime(t, utc);
  5253. #endif
  5254. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5255. //parsing strings to words
  5256. i = 0;
  5257. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5258. loc = loc+3+strlen("chargingSchedulePeriod");
  5259. pch = strtok(loc ,"{");
  5260. while (pch != NULL)
  5261. {
  5262. strcpy(SchedulePeriodList[i], pch);
  5263. pch = strtok (NULL, "{");
  5264. i = i + 1;
  5265. }
  5266. n_SchedulePeriods = i;
  5267. for(int i=0;i<n_SchedulePeriods;i++)
  5268. {
  5269. //*************startPeriod****************/
  5270. c = 0;
  5271. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5272. memset(sstr ,0, sizeof(sstr) );
  5273. while (loc[strlen("startPeriod")+2+c] != ',')
  5274. {
  5275. sstr[c] = loc[strlen("startPeriod")+2+c];
  5276. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5277. c++;
  5278. }
  5279. sstr[c] = '\0';
  5280. tempStartPeriodInt = atoi(sstr);
  5281. //*************limit****************/
  5282. c = 0;
  5283. loc = strstr(SchedulePeriodList[i], "limit");
  5284. memset(sstr ,0, sizeof(sstr) );
  5285. while (loc[strlen("limit")+2+c] != ',')
  5286. {
  5287. sstr[c] = loc[strlen("limit")+2+c];
  5288. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5289. c++;
  5290. }
  5291. sstr[c] = '\0';
  5292. tempLimitInt = atof(sstr);
  5293. //*************numberPhases****************/
  5294. c = 0;
  5295. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5296. memset(sstr ,0, sizeof(sstr) );
  5297. while (loc[strlen("numberPhases")+2+c] != '}')
  5298. {
  5299. sstr[c] = loc[strlen("numberPhases")+2+c];
  5300. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5301. c++;
  5302. }
  5303. sstr[c] = '\0';
  5304. tempNumberPhasesInt = atoi(sstr);
  5305. if(j == 0)
  5306. {
  5307. TxDefaultProfile.Duration = tempdurationInt;
  5308. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5309. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5310. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5311. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5312. }
  5313. else
  5314. {
  5315. //other stack level charging Profile
  5316. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5317. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5318. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5319. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5320. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5321. }
  5322. }
  5323. if(MinChargingRate < tempminChargingRateFloat)
  5324. MinChargingRate = tempminChargingRateFloat;
  5325. if(confirmPeriods < n_SchedulePeriods)
  5326. confirmPeriods = n_SchedulePeriods;
  5327. j = j + 1;
  5328. //DEBUG_INFO(" 1-2\n");
  5329. }
  5330. fclose(fptr1);
  5331. //Stacking Charging Profiles
  5332. for(int l=0; l <(j-1) ;l++)
  5333. {
  5334. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5335. {
  5336. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5337. {
  5338. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5339. {
  5340. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5341. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5342. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5343. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5344. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5345. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5346. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5347. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5348. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5349. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5350. }
  5351. else
  5352. {
  5353. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5354. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5355. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5356. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5357. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5358. }
  5359. }
  5360. }
  5361. }
  5362. //end of Stacking Charging Profiles
  5363. }
  5364. }// the end of ACCESS TxDefaultProfile
  5365. //****************************TxProfile************************************************/
  5366. #if 0
  5367. switch(connectorIdInt)
  5368. {
  5369. case 0:
  5370. break;
  5371. case 1:
  5372. strcpy(fname, TxProfile_1_JSON );
  5373. break;
  5374. case 2:
  5375. strcpy(fname, TxProfile_2_JSON );
  5376. break;
  5377. default:
  5378. strcpy(fname, TxProfile_1_JSON );
  5379. break;
  5380. }
  5381. #endif
  5382. memset(fname, 0, sizeof fname);
  5383. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5384. TxProfileIsNull=TRUE;
  5385. if((access(fname,F_OK))!=-1)
  5386. {
  5387. fptr1 = fopen(fname, "r");
  5388. c = 0;
  5389. c = fgetc(fptr1);
  5390. //DEBUG_INFO("c:%d\n",c);
  5391. rewind(fptr1);
  5392. if(c == EOF)
  5393. {
  5394. DEBUG_INFO("\n End of file reached.");
  5395. TxProfileIsNull=TRUE;
  5396. fclose(fptr1);
  5397. }
  5398. else
  5399. {
  5400. TxProfileIsNull=FALSE;
  5401. while(fscanf(fptr1, "%s", word) != EOF)
  5402. {
  5403. if(strcmp(word, "chargingProfileId") == 0)
  5404. {
  5405. n_chargingProfile = n_chargingProfile + 1;
  5406. }
  5407. }
  5408. rewind(fptr1);
  5409. //search Charging Profile Element
  5410. int i= 0;
  5411. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5412. #if 0
  5413. /***********connectorId****************/
  5414. c = 0;
  5415. loc = strstr(sLineWord, "connectorId");
  5416. memset(sstr ,0, sizeof(sstr) );
  5417. while (loc[strlen("connectorId")+2+c] != ',')
  5418. {
  5419. sstr[c] = loc[strlen("connectorId")+2+c];
  5420. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5421. c++;
  5422. }
  5423. sstr[c] = '\0';
  5424. tempconnectorIdInt = atoi(sstr);
  5425. #endif
  5426. //***********validFrom**************/
  5427. c = 0;
  5428. loc = strstr(sLineWord, "validFrom");
  5429. if(loc != NULL)
  5430. {
  5431. memset(sstr ,0, sizeof(sstr) );
  5432. while (loc[3+strlen("validFrom")+c] != '\"')
  5433. {
  5434. sstr[c] = loc[3+strlen("validFrom")+c];
  5435. c++;
  5436. }
  5437. sstr[c] = '\0';
  5438. strcpy(tempvalidFromStr,sstr);
  5439. }
  5440. else
  5441. {
  5442. strcpy(tempvalidFromStr,"");
  5443. }
  5444. //**********startSchedule**********/
  5445. c = 0;
  5446. loc = strstr(sLineWord, "startSchedule");
  5447. memset(sstr ,0, sizeof(sstr) );
  5448. while (loc[3+strlen("startSchedule")+c] != '\"')
  5449. {
  5450. sstr[c] = loc[3+strlen("startSchedule")+c];
  5451. c++;
  5452. }
  5453. sstr[c] = '\0';
  5454. strcpy(tempstartScheduleStr, sstr);
  5455. strcpy(TxProfileScheduleStr, sstr);
  5456. //**********chargingRateUnit**********/
  5457. c = 0;
  5458. loc = strstr(sLineWord, "chargingRateUnit");
  5459. memset(sstr ,0, sizeof(sstr) );
  5460. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5461. {
  5462. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5463. c++;
  5464. }
  5465. sstr[c] = '\0';
  5466. strcpy(tempchargingRateUnitStr, sstr);
  5467. //**********minChargingRate*******/
  5468. c = 0;
  5469. loc = strstr(sLineWord, "minChargingRate");
  5470. if(loc != NULL)
  5471. {
  5472. memset(sstr ,0, sizeof(sstr) );
  5473. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5474. {
  5475. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5476. c++;
  5477. }
  5478. sstr[c] = '\0';
  5479. tempminChargingRateFloat = atof(sstr);
  5480. }
  5481. else
  5482. {
  5483. tempminChargingRateFloat = 0.0;
  5484. }
  5485. #if 0
  5486. //
  5487. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5488. tp.tm_isdst = -1;
  5489. time_t utc = mktime(&tp);
  5490. time_t t = time(NULL);
  5491. //diff_t = difftime(t, utc);
  5492. #endif
  5493. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5494. //parsing strings to words
  5495. i = 0;
  5496. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5497. loc = loc+3+strlen("chargingSchedulePeriod");
  5498. pch = strtok(loc ,"{");
  5499. while (pch != NULL)
  5500. {
  5501. strcpy(SchedulePeriodList[i], pch);
  5502. pch = strtok (NULL, "{");
  5503. i = i + 1;
  5504. }
  5505. n_SchedulePeriods = i;
  5506. for(int i=0;i<n_SchedulePeriods;i++)
  5507. {
  5508. //*************startPeriod****************/
  5509. c = 0;
  5510. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5511. memset(sstr ,0, sizeof(sstr) );
  5512. while (loc[strlen("startPeriod")+2+c] != ',')
  5513. {
  5514. sstr[c] = loc[strlen("startPeriod")+2+c];
  5515. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5516. c++;
  5517. }
  5518. sstr[c] = '\0';
  5519. tempStartPeriodInt = atoi(sstr);
  5520. //*************limit****************/
  5521. c = 0;
  5522. loc = strstr(SchedulePeriodList[i], "limit");
  5523. memset(sstr ,0, sizeof(sstr) );
  5524. while (loc[strlen("limit")+2+c] != ',')
  5525. {
  5526. sstr[c] = loc[strlen("limit")+2+c];
  5527. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5528. c++;
  5529. }
  5530. sstr[c] = '\0';
  5531. tempLimitInt = atof(sstr);
  5532. //*************numberPhases****************/
  5533. c = 0;
  5534. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5535. memset(sstr ,0, sizeof(sstr) );
  5536. while (loc[strlen("numberPhases")+2+c] != '}')
  5537. {
  5538. sstr[c] = loc[strlen("numberPhases")+2+c];
  5539. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5540. c++;
  5541. }
  5542. sstr[c] = '\0';
  5543. tempNumberPhasesInt = atoi(sstr);
  5544. TxProfile.Duration = durationInt;
  5545. TxProfile.TotalPeriod = n_SchedulePeriods;
  5546. TxProfile.Period[i].Limit = tempLimitInt;
  5547. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5548. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5549. }
  5550. if(MinChargingRate < tempminChargingRateFloat)
  5551. MinChargingRate = tempminChargingRateFloat;
  5552. if(confirmPeriods < n_SchedulePeriods)
  5553. confirmPeriods = n_SchedulePeriods;
  5554. }
  5555. fclose(fptr1);
  5556. }
  5557. }// the end of ACCESS TxProfile
  5558. //CompositeSchedule
  5559. int period=0;
  5560. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5561. {
  5562. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5563. struct tm tp;
  5564. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5565. tp.tm_isdst = -1;
  5566. time_t utc = mktime(&tp);
  5567. time_t t = time(NULL);
  5568. double diff_f = difftime(t, utc);
  5569. int diff_i; // = (int)diff_f;
  5570. int quotient; // = diff_i / 86400;//86400 seconds/day
  5571. //int remainder = diff_i % 86400;
  5572. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5573. {
  5574. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5575. {
  5576. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5577. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5578. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5579. period = period + 1;
  5580. }
  5581. else
  5582. {
  5583. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5584. {
  5585. }
  5586. else
  5587. {
  5588. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5589. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5590. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5591. period = period + 1;
  5592. }
  5593. }
  5594. }
  5595. if( diff_f >= 0)
  5596. {
  5597. diff_i = (int)diff_f;
  5598. quotient = diff_i / 86400;//86400 seconds/day
  5599. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5600. {
  5601. if(((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)&& ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod %86400) > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5602. {
  5603. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5604. {
  5605. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5606. }
  5607. else
  5608. {
  5609. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5610. }
  5611. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5612. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  5613. period = period + 1;
  5614. }
  5615. }
  5616. // Check Last Period
  5617. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5618. {
  5619. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5620. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5621. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5622. period = period + 1;
  5623. }
  5624. } // diff_f >= 0
  5625. }
  5626. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5627. {
  5628. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5629. struct tm tp;
  5630. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5631. tp.tm_isdst = -1;
  5632. time_t utc = mktime(&tp);
  5633. time_t t = time(NULL);
  5634. double diff_f = difftime(t, utc);
  5635. int diff_i;// = (int)diff_f;
  5636. int quotient; // = diff_i / 86400;//86400 seconds/day
  5637. //int remainder = diff_i % 86400;
  5638. if(diff_f >= 0)
  5639. {
  5640. diff_i = (int)diff_f;
  5641. quotient = diff_i / 86400;//86400 seconds/day
  5642. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5643. {
  5644. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5645. {
  5646. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5647. {
  5648. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5649. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5650. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5651. period = period + 1;
  5652. }
  5653. else
  5654. {
  5655. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5656. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5657. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5658. period = period + 1;
  5659. }
  5660. }
  5661. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5662. {
  5663. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5664. {
  5665. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5666. {
  5667. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5668. {
  5669. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5670. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5671. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5672. period = period + 1;
  5673. }
  5674. else
  5675. {
  5676. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5677. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5678. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5679. period = period + 1;
  5680. }
  5681. }
  5682. }
  5683. }
  5684. }
  5685. } // end diff_f >= 0
  5686. }
  5687. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5688. {
  5689. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5690. struct tm tp;
  5691. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5692. tp.tm_isdst = -1;
  5693. time_t utc = mktime(&tp);
  5694. time_t t = time(NULL);
  5695. double diff_f = difftime(t, utc);
  5696. int diff_i; // = (int)diff_f;
  5697. int quotient; // = diff_i / 86400;//86400 seconds/day
  5698. //int remainder = diff_i % 86400;
  5699. if(diff_f >= 0)
  5700. {
  5701. diff_i = (int)diff_f;
  5702. quotient = diff_i / 86400;//86400 seconds/day
  5703. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5704. {
  5705. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5706. {
  5707. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5708. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5709. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5710. period = period + 1;
  5711. }
  5712. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5713. {
  5714. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5715. {
  5716. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5717. {
  5718. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5719. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5720. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5721. period = period + 1;
  5722. }
  5723. }
  5724. }
  5725. }
  5726. } // diff_f >= 0
  5727. }
  5728. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  5729. {
  5730. confirmPeriods = 0;
  5731. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5732. goto end;
  5733. }
  5734. confirmPeriods = period;
  5735. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5736. //---- Define StartSchedule----/
  5737. struct tm *gtime;
  5738. time_t now;
  5739. char buf[28];
  5740. //---Read the current system time---/
  5741. time(&now);
  5742. //---Convert the system time to GMT (now UTC)---/
  5743. gtime = gmtime(&now);
  5744. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5745. // make .conf
  5746. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5747. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5748. //DEBUG_INFO(" debug 11\n");
  5749. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5750. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5751. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5752. }
  5753. else
  5754. {
  5755. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5756. }
  5757. end:
  5758. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5759. return result;
  5760. }
  5761. int handleGetConfigurationRequest(char *uuid, char *payload)
  5762. {
  5763. mtrace();
  5764. int result = FAIL;
  5765. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5766. //struct json_object *jsonitem;
  5767. int MaxKeySupported = 0;
  5768. int n_keys = 0;
  5769. char requestKey[43][50]={0};
  5770. char search[]="[";
  5771. char sstr[500]={ 0 };
  5772. //int pos;
  5773. int l, c = 0;
  5774. int i = 0;
  5775. char *delim = "\",\"";
  5776. char * pch;
  5777. char *loc = strstr(payload, search);
  5778. //********************* Parsing String ***********************************/
  5779. if(loc == NULL) {
  5780. DEBUG_INFO("no key match in Configuration \n");
  5781. }
  5782. else {
  5783. //pos = loc - payload;
  5784. l = strlen(loc)-4;
  5785. while (c < l)
  5786. {
  5787. sstr[c] = loc[c+2];
  5788. c++;
  5789. }
  5790. sstr[c] = '\0';
  5791. //parsing strings to words
  5792. pch = strtok(sstr,delim);
  5793. if(pch == NULL)
  5794. {
  5795. strcpy(requestKey[0], sstr);
  5796. }
  5797. else
  5798. {
  5799. while (pch != NULL)
  5800. {
  5801. strcpy(requestKey[i], pch);
  5802. pch = strtok (NULL, delim);
  5803. i = i + 1;
  5804. }
  5805. n_keys = i;
  5806. }
  5807. }
  5808. UnknownKeynum = 0;
  5809. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5810. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5811. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5812. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5813. if(n_keys != 0)
  5814. {
  5815. for(int i=0;i<n_keys;i++)
  5816. {
  5817. getKeyValue(requestKey[i]);
  5818. //json_object_put(jsonitem);
  5819. }
  5820. }
  5821. else
  5822. {
  5823. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5824. getKeyValue("");
  5825. }
  5826. processUnkownKey();
  5827. sendGetConfigurationConfirmation(uuid);
  5828. return result;
  5829. }
  5830. static char fnamePlusPath[100]={0};
  5831. static char fnamePWithNoPath[60]={0};
  5832. void checkUploadLog(void)
  5833. {
  5834. FILE *fp;
  5835. /* Open the command for reading. */
  5836. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5837. if (fp == NULL) {
  5838. printf("Failed to run command\n" );
  5839. exit(1);
  5840. }
  5841. int ftppathlen = 0;
  5842. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5843. int i = 0;
  5844. /* Read the output a line at a time - output it. */
  5845. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5846. if(i==0)
  5847. {
  5848. ftppathlen = strlen(fnamePlusPath);
  5849. printf("%s\n", fnamePlusPath);
  5850. fnamePlusPath[ftppathlen]='\0';
  5851. break;
  5852. }
  5853. i= i+1;
  5854. }
  5855. /* close */
  5856. pclose(fp);
  5857. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5858. {
  5859. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5860. {
  5861. fnamePlusPath[k]='\0';
  5862. }
  5863. }
  5864. i=1;
  5865. //char fname[60]={0};
  5866. while(i < ftppathlen)
  5867. {
  5868. int len=ftppathlen-i;
  5869. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5870. {
  5871. printf("compare '/' all right\n");
  5872. break;
  5873. }
  5874. i=i+1;
  5875. }
  5876. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5877. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5878. fnamePWithNoPath[i+1] = '\0';
  5879. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5880. {
  5881. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5882. {
  5883. fnamePWithNoPath[j]='\0';
  5884. }
  5885. }
  5886. FILE* fp1 = fopen(fnamePlusPath, "r");
  5887. if (fp1)
  5888. {
  5889. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5890. // file exists
  5891. fclose(fp1);
  5892. }
  5893. else
  5894. {
  5895. // file doesn't exist
  5896. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5897. }
  5898. }
  5899. static char GetDiagnosticspayloadData[300]={0};
  5900. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5901. {
  5902. mtrace();
  5903. int result = FAIL;
  5904. pthread_t t; // pthread 變數
  5905. system("exec /root/logPackTools 'log' 6");
  5906. #if 0
  5907. //char buffer [128];
  5908. time (&rawtime);
  5909. //printf("%ld\n", rawtime);
  5910. timeinfo = localtime (&rawtime);
  5911. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5912. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5913. if((access(fnamePlusPath,F_OK))!=-1)
  5914. {
  5915. DEBUG_INFO("fnamePlusPath exist.\n");
  5916. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5917. }
  5918. else
  5919. {
  5920. DEBUG_INFO("fnamePlusPath not exist!\n");
  5921. }
  5922. #endif
  5923. checkUploadLog();
  5924. memset(GetDiagnosticspayloadData, 0, 300);
  5925. strcpy(GetDiagnosticspayloadData, payload);
  5926. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5927. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5928. return result;
  5929. }
  5930. void* GetDiagnosticsProcess(void* data)
  5931. {
  5932. pthread_detach(pthread_self());
  5933. mtrace();
  5934. int retriesInt=0, retryIntervalInt=0;
  5935. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5936. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5937. 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};
  5938. int port=0;
  5939. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5940. int c = 0;
  5941. char *loc;
  5942. int isSuccess = FALSE;
  5943. char ftpbuf[200]={0};
  5944. //char temp[100]={0};
  5945. char * pch;
  5946. // [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"}]
  5947. char str[300]={ 0 };
  5948. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5949. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5950. DEBUG_INFO("GetDiagnosticsProcess\n");
  5951. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5952. //****************location*******************/
  5953. c = 0;
  5954. memset(sstr ,0, sizeof(sstr) );
  5955. loc = strstr(str, "location");
  5956. while (loc[3+strlen("location")+c] != '\"')
  5957. {
  5958. sstr[c] = loc[3+strlen("location")+c];
  5959. c++;
  5960. }
  5961. sstr[c] = '\0';
  5962. strcpy(locationstr,sstr);
  5963. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5964. if(strcmp(locationstr,"")==0)
  5965. {
  5966. DEBUG_INFO("location is <Empty>!\n");
  5967. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5968. goto end;
  5969. }
  5970. //****************retries*******************/
  5971. c = 0;
  5972. loc = strstr(str, "retries");
  5973. if(loc == NULL)
  5974. {
  5975. retriesIsNULL = TRUE;
  5976. }
  5977. else
  5978. {
  5979. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5980. {
  5981. sstr[c] = loc[strlen("retries")+2+c];
  5982. c++;
  5983. }
  5984. sstr[c] = '\0';
  5985. retriesInt = atoi(sstr);
  5986. }
  5987. if(retriesIsNULL == TRUE)
  5988. {
  5989. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5990. }
  5991. //****************retryInterval*******************/
  5992. c = 0;
  5993. loc = strstr(str, "retryInterval");
  5994. if(loc == NULL)
  5995. {
  5996. retryIntervalIsNULL = TRUE;
  5997. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5998. }
  5999. else
  6000. {
  6001. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6002. {
  6003. sstr[c] = loc[strlen("retryInterval")+2+c];
  6004. c++;
  6005. }
  6006. sstr[c] = '\0';
  6007. retryIntervalInt = atoi(sstr);
  6008. }
  6009. //****************startTime*******************/
  6010. c = 0;
  6011. memset(sstr ,0, sizeof(sstr) );
  6012. loc = strstr(str, "startTime");
  6013. if(loc == NULL)
  6014. {
  6015. startTimeIsNULL = TRUE;
  6016. }
  6017. else
  6018. {
  6019. while (loc[3+strlen("startTime")+c] != '\"')
  6020. {
  6021. sstr[c] = loc[3+strlen("startTime")+c];
  6022. c++;
  6023. }
  6024. sstr[c] = '\0';
  6025. strcpy(startTimestr,sstr);
  6026. }
  6027. //****************stopTime*******************/
  6028. c = 0;
  6029. memset(sstr ,0, sizeof(sstr) );
  6030. loc = strstr(str, "stopTime");
  6031. if(loc == NULL)
  6032. {
  6033. stopTimeIsNULL = TRUE;
  6034. }
  6035. else
  6036. {
  6037. while (loc[3+strlen("stopTime")+c] != '\"')
  6038. {
  6039. sstr[c] = loc[3+strlen("stopTime")+c];
  6040. c++;
  6041. }
  6042. sstr[c] = '\0';
  6043. strcpy(stopTimestr,sstr);
  6044. }
  6045. memset(protocol, 0, sizeof(protocol));
  6046. memset(user, 0, sizeof(user) );
  6047. memset(password, 0, sizeof(password));
  6048. memset(host, 0, sizeof(host));
  6049. memset(path, 0, sizeof(path));
  6050. memset(ftppath, 0, sizeof(ftppath));
  6051. memset(host1, 0, sizeof(host1));
  6052. memset(path1, 0, sizeof(path1));
  6053. /*location: ftp://user:password@host:port/path*/
  6054. #if 0
  6055. time_t rawtime;
  6056. struct tm * timeinfo;
  6057. //char buffer [128];
  6058. time (&rawtime);
  6059. //printf("%ld\n", rawtime);
  6060. timeinfo = localtime (&rawtime);
  6061. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6062. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6063. #endif
  6064. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6065. if((access(fnamePlusPath,F_OK))!=-1)
  6066. {
  6067. DEBUG_INFO("fnamePlusPath exist.\n");
  6068. }
  6069. else
  6070. {
  6071. DEBUG_INFO("fnamePlusPath not exist!\n");
  6072. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6073. goto end;
  6074. }
  6075. pch=strchr(locationstr,'@');
  6076. if(pch==NULL)
  6077. {
  6078. sscanf(locationstr,
  6079. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6080. protocol, host, &port, path);
  6081. strcpy(user,"anonymous");
  6082. strcpy(password,"");
  6083. }
  6084. else
  6085. {
  6086. //DEBUG_INFO("pch=%s\n", pch);
  6087. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6088. protocol, user, password, host, &port, path);
  6089. }
  6090. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6091. {
  6092. DEBUG_INFO("protocol is not ftp/http ! \n");
  6093. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6094. goto end;
  6095. }
  6096. if(strncmp(locationstr,"http", 4) == 0)
  6097. {
  6098. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6099. sprintf(ftppath,"/%s", path);
  6100. do{
  6101. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6102. sleep(retryIntervalInt);
  6103. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6104. if(!isSuccess)
  6105. {
  6106. DEBUG_INFO("Diagnostics fail.\n");
  6107. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6108. }
  6109. else
  6110. {
  6111. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6112. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6113. }
  6114. }
  6115. else
  6116. {
  6117. sscanf(host,"%[^/]%s",host1, path1);
  6118. sprintf(ftppath,"%s", path1);
  6119. int ftppathlen=strlen(ftppath);
  6120. int i=1;
  6121. char filenametemp[50];
  6122. while(i < ftppathlen)
  6123. {
  6124. int len=ftppathlen-i;
  6125. if(ftppath[len]== 47) // '/' ascll code: 47
  6126. {
  6127. DEBUG_INFO("find '/' all right\n");
  6128. break;
  6129. }
  6130. i=i+1;
  6131. }
  6132. memset(filenametemp, 0, sizeof(filenametemp));
  6133. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6134. filenametemp[i+1] = 0;
  6135. memset(ftpbuf, 0, sizeof(ftpbuf));
  6136. if(port == 0)
  6137. port = 21;
  6138. do{
  6139. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6140. sleep(retryIntervalInt);
  6141. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6142. if(!isSuccess)
  6143. {
  6144. DEBUG_INFO("Diagnostics fail.\n");
  6145. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6146. }
  6147. else
  6148. {
  6149. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6150. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6151. }
  6152. }
  6153. end:
  6154. DiagnosticsStatusNotificationStatus = 0; //Idle
  6155. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6156. }
  6157. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6158. {
  6159. mtrace();
  6160. int result = FAIL;
  6161. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6162. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6163. {
  6164. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6165. localversion = -1;
  6166. }
  6167. else
  6168. {
  6169. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6170. OCPP_getListVerion();
  6171. }
  6172. //from db.OCPP_getListVerion
  6173. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6174. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6175. sendGetLocalListVersionConfirmation(uuid,"");
  6176. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6177. return result;
  6178. }
  6179. int handleRemoteStartRequest(char *uuid, char *payload)
  6180. {
  6181. mtrace();
  6182. int result = FAIL;
  6183. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6184. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6185. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6186. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6187. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6188. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6189. int chargingSchedulePeriodCount = 0;
  6190. char sstr[30]={ 0 };//sstr[200]={ 0 };
  6191. int c = 0;
  6192. char *loc;
  6193. char comfirmstr[20]={0};
  6194. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6195. if(server_pending == TRUE)
  6196. {
  6197. return 0;
  6198. }
  6199. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6200. //**********connectorId****************/
  6201. c = 0;
  6202. memset(sstr ,0, sizeof(sstr) );
  6203. loc = strstr(payload, "connectorId");
  6204. if(loc == NULL)
  6205. {
  6206. connectorIdIsNULL = TRUE;
  6207. }
  6208. else
  6209. {
  6210. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6211. {
  6212. sstr[c] = loc[strlen("connectorId")+2+c];
  6213. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6214. c++;
  6215. }
  6216. sstr[c] = '\0';
  6217. connectorIdInt = atoi(sstr);
  6218. }
  6219. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6220. {
  6221. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6222. goto end;
  6223. }
  6224. //****************idTag*******************/
  6225. c = 0;
  6226. memset(sstr ,0, sizeof(sstr) );
  6227. loc = strstr(payload, "idTag");
  6228. while (loc[3+strlen("idTag")+c] != '\"')
  6229. {
  6230. sstr[c] = loc[3+strlen("idTag")+c];
  6231. c++;
  6232. }
  6233. sstr[c] = '\0';
  6234. strcpy(idTagstr,sstr);
  6235. //****************chargingProfile*******************/
  6236. c = 0;
  6237. memset(sstr ,0, sizeof(sstr) );
  6238. loc = strstr(payload, "chargingProfile");
  6239. if(loc == NULL)
  6240. {
  6241. chargingProfileIsNULL = TRUE;
  6242. }
  6243. else
  6244. {
  6245. //****************chargingProfileId*******************/
  6246. c=0;
  6247. loc = strstr(payload, "chargingProfileId");
  6248. memset(sstr ,0, sizeof(sstr) );
  6249. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6250. {
  6251. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6252. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6253. c++;
  6254. }
  6255. sstr[c] = '\0';
  6256. chargingProfileIdInt = atoi(sstr);
  6257. //****************transactionId*******************/
  6258. loc = strstr(payload, "transactionId");
  6259. if(loc == NULL)
  6260. {
  6261. transactionIdIsNULL = TRUE;
  6262. }
  6263. else
  6264. {
  6265. c=0;
  6266. memset(sstr ,0, sizeof(sstr) );
  6267. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6268. {
  6269. sstr[c] = loc[strlen("transactionId")+2+c];
  6270. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6271. c++;
  6272. }
  6273. sstr[c] = '\0';
  6274. transactionIdInt = atoi(sstr);
  6275. }
  6276. //****************stackLevel*******************/
  6277. c=0;
  6278. loc = strstr(payload, "stackLevel");
  6279. memset(sstr ,0, sizeof(sstr) );
  6280. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6281. {
  6282. sstr[c] = loc[strlen("stackLevel")+2+c];
  6283. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6284. c++;
  6285. }
  6286. sstr[c] = '\0';
  6287. stackLevelInt = atoi(sstr);
  6288. //****************chargingProfilePurpose*******************/
  6289. c = 0;
  6290. memset(sstr ,0, sizeof(sstr) );
  6291. loc = strstr(payload, "chargingProfilePurpose");
  6292. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6293. {
  6294. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6295. c++;
  6296. }
  6297. sstr[c] = '\0';
  6298. strcpy(chargingProfilePurposestr,sstr);
  6299. //****************chargingProfileKind*******************/
  6300. c = 0;
  6301. memset(sstr ,0, sizeof(sstr) );
  6302. loc = strstr(payload, "chargingProfileKind");
  6303. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6304. {
  6305. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6306. c++;
  6307. }
  6308. sstr[c] = '\0';
  6309. strcpy(chargingProfileKindstr,sstr);
  6310. //****************recurrencyKind*******************/
  6311. loc = strstr(payload, "recurrencyKind");
  6312. if(loc == NULL)
  6313. {
  6314. recurrencyKindIsNULL = TRUE;
  6315. }
  6316. else
  6317. {
  6318. c = 0;
  6319. memset(sstr ,0, sizeof(sstr) );
  6320. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6321. {
  6322. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6323. c++;
  6324. }
  6325. sstr[c] = '\0';
  6326. strcpy(recurrencyKindstr,sstr);
  6327. }
  6328. //****************validFrom*******************/
  6329. loc = strstr(payload, "validFrom");
  6330. if(loc == NULL)
  6331. {
  6332. validFromIsNULL = TRUE;
  6333. }
  6334. else
  6335. {
  6336. c = 0;
  6337. memset(sstr ,0, sizeof(sstr) );
  6338. while (loc[3+strlen("validFrom")+c] != '\"')
  6339. {
  6340. sstr[c] = loc[3+strlen("validFrom")+c];
  6341. c++;
  6342. }
  6343. sstr[c] = '\0';
  6344. strcpy(validFromstr,sstr);
  6345. }
  6346. //****************validTo*******************/
  6347. loc = strstr(payload, "validTo");
  6348. if(loc == NULL)
  6349. {
  6350. validToIsNULL = TRUE;
  6351. }
  6352. else
  6353. {
  6354. c = 0;
  6355. memset(sstr ,0, sizeof(sstr) );
  6356. while (loc[3+strlen("validTo")+c] != '\"')
  6357. {
  6358. sstr[c] = loc[3+strlen("validTo")+c];
  6359. c++;
  6360. }
  6361. sstr[c] = '\0';
  6362. strcpy(validTostr,sstr);
  6363. }
  6364. //****************chargingSchedule*******************/
  6365. loc = strstr(payload, "chargingSchedule");
  6366. if(loc != NULL)
  6367. {
  6368. //****************duration*******************/
  6369. loc = strstr(payload, "duration");
  6370. if(loc == NULL)
  6371. {
  6372. durationIsNULL = TRUE;
  6373. }
  6374. else
  6375. {
  6376. c=0;
  6377. memset(sstr ,0, sizeof(sstr) );
  6378. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6379. {
  6380. sstr[c] = loc[strlen("duration")+2+c];
  6381. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6382. c++;
  6383. }
  6384. sstr[c] = '\0';
  6385. durationInt = atoi(sstr);
  6386. }
  6387. //****************startSchedule******************/
  6388. loc = strstr(payload, "startSchedule");
  6389. if(loc == NULL)
  6390. {
  6391. startScheduleIsNULL = TRUE;
  6392. }
  6393. else
  6394. {
  6395. c = 0;
  6396. memset(sstr ,0, sizeof(sstr) );
  6397. while (loc[3+strlen("startSchedule")+c] != '\"')
  6398. {
  6399. sstr[c] = loc[3+strlen("startSchedule")+c];
  6400. c++;
  6401. }
  6402. sstr[c] = '\0';
  6403. strcpy(startSchedulestr,sstr);
  6404. }
  6405. //****************chargingRateUnit*******************/
  6406. c = 0;
  6407. memset(sstr ,0, sizeof(sstr) );
  6408. loc = strstr(payload, "chargingRateUnit");
  6409. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6410. {
  6411. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6412. c++;
  6413. }
  6414. sstr[c] = '\0';
  6415. strcpy(chargingRateUnitstr,sstr);
  6416. //****************minChargingRate*******************/
  6417. loc = strstr(payload, "minChargingRate");
  6418. if(loc == NULL)
  6419. {
  6420. minChargingRateIsNULL = TRUE;
  6421. }
  6422. else
  6423. {
  6424. c=0;
  6425. memset(sstr ,0, sizeof(sstr) );
  6426. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6427. {
  6428. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6429. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6430. c++;
  6431. }
  6432. sstr[c] = '\0';
  6433. minChargingRateflaot = atof(sstr);
  6434. }
  6435. //****************chargingSchedulePeriod count*******************/
  6436. int what_len = strlen("startPeriod");
  6437. char *where = payload;
  6438. while ((where = strstr(where, "startPeriod"))) {
  6439. where += what_len;
  6440. chargingSchedulePeriodCount++;
  6441. }
  6442. where = payload;
  6443. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6444. {
  6445. //****************startPeriod*******************/
  6446. c=0;
  6447. loc = strstr(where, "startPeriod");
  6448. memset(sstr ,0, sizeof(sstr) );
  6449. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6450. {
  6451. sstr[c] = loc[strlen("startPeriod")+2+c];
  6452. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6453. c++;
  6454. }
  6455. sstr[c] = '\0';
  6456. startPeriodInt[periodNums] = atoi(sstr);
  6457. //****************limit*******************/
  6458. c=0;
  6459. loc = strstr(where, "limit");
  6460. memset(sstr ,0, sizeof(sstr) );
  6461. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6462. {
  6463. sstr[c] = loc[strlen("limit")+2+c];
  6464. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6465. c++;
  6466. }
  6467. sstr[c] = '\0';
  6468. limitflaot[periodNums] = atof(sstr);
  6469. //****************numberPhases*******************/
  6470. loc = strstr(where, "numberPhases");
  6471. if(loc == NULL)
  6472. {
  6473. numberPhasesIsNULL = TRUE;
  6474. }
  6475. else
  6476. {
  6477. c=0;
  6478. memset(sstr ,0, sizeof(sstr) );
  6479. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6480. {
  6481. sstr[c] = loc[strlen("numberPhases")+2+c];
  6482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6483. c++;
  6484. }
  6485. sstr[c] = '\0';
  6486. numberPhasesInt[periodNums] = atoi(sstr);
  6487. }
  6488. where = loc;
  6489. }
  6490. }
  6491. }
  6492. /*
  6493. enum _SYSTEM_STATUS
  6494. {
  6495. S_BOOTING = 0,
  6496. S_IDLE, = 1
  6497. S_AUTHORIZING, =2
  6498. S_REASSIGN_CHECK, =3
  6499. S_REASSIGN, =4
  6500. S_PRECHARGE, =5
  6501. S_PREPARING_FOR_EV, =6
  6502. S_PREPARING_FOR_EVSE, =7
  6503. S_CHARGING, =8
  6504. S_TERMINATING, =9
  6505. S_COMPLETE, =10
  6506. S_ALARM, =11
  6507. S_FAULT =12
  6508. }
  6509. */
  6510. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6511. {
  6512. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6513. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6514. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6515. //check Transaction active
  6516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6517. {
  6518. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6519. {
  6520. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6521. {
  6522. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6523. {
  6524. //Reserved
  6525. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6526. }
  6527. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6528. {
  6529. //Reserved
  6530. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6531. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6532. goto end;
  6533. }
  6534. else
  6535. {
  6536. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6537. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6538. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6539. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6540. {
  6541. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6542. goto end;
  6543. }
  6544. }//END FOR ELSE
  6545. }
  6546. }// END FOR CHAdeMO_QUANTITY
  6547. for (int index = 0; index < CCS_QUANTITY; index++)
  6548. {
  6549. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6550. {
  6551. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6552. {
  6553. //Reserved
  6554. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6555. }
  6556. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6557. {
  6558. //Reserved
  6559. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6560. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6561. goto end;
  6562. }
  6563. else
  6564. {
  6565. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6566. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6567. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6568. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6569. {
  6570. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6571. goto end;
  6572. }
  6573. }// END FOR ELSE
  6574. }
  6575. }// END FOR CCS_QUANTITY
  6576. for (int index = 0; index < GB_QUANTITY; index++)
  6577. {
  6578. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6579. {
  6580. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6581. {
  6582. //Reserved
  6583. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6584. }
  6585. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6586. {
  6587. //Reserved
  6588. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6589. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6590. goto end;
  6591. }
  6592. else
  6593. {
  6594. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6595. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6596. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6597. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6598. {
  6599. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6600. goto end;
  6601. }
  6602. }// END FOR ELSE
  6603. }
  6604. } // END FOR GB_QUANTITY
  6605. }
  6606. else
  6607. {
  6608. for (int index = 0; index < AC_QUANTITY; index++)
  6609. {
  6610. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6611. {
  6612. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6613. {
  6614. //Reserved
  6615. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6616. }
  6617. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6618. {
  6619. //Reserved
  6620. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6621. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6622. goto end;
  6623. }
  6624. else
  6625. {
  6626. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6627. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6628. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6629. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6630. {
  6631. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6632. goto end;
  6633. }
  6634. }//END FOR ELSE
  6635. }
  6636. }// END FOR AC_QUANTITY
  6637. }
  6638. if(chargingProfileIsNULL == FALSE)
  6639. {
  6640. //ChargingProfile
  6641. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6642. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6643. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6644. if(recurrencyKindIsNULL == FALSE) //OPTION
  6645. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6646. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6647. if(transactionIdIsNULL == FALSE) // OPTION
  6648. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6649. if(validFromIsNULL == FALSE) // OPTION
  6650. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6651. if(validToIsNULL == FALSE) //OPTION
  6652. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6653. //ChargingSchedule
  6654. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6655. if(durationIsNULL == FALSE) //OPTION
  6656. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6657. if(minChargingRateIsNULL == FALSE) //OPTION
  6658. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6659. if(startScheduleIsNULL == FALSE) //OPTION
  6660. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6661. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6662. {
  6663. //ChargingSchedulePeriod
  6664. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6665. if(numberPhasesIsNULL == FALSE)
  6666. {
  6667. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6668. }
  6669. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6670. }
  6671. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6672. {
  6673. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6674. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6675. //memset idTag
  6676. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6677. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6678. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6679. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6680. }
  6681. else
  6682. {
  6683. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6684. }
  6685. }
  6686. else
  6687. {
  6688. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6689. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6690. //memset idTag
  6691. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6692. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6693. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6694. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6695. }
  6696. }
  6697. else
  6698. {
  6699. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6700. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6701. }
  6702. end:
  6703. if(connectorIdIsNULL == FALSE)
  6704. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6705. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6706. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6707. //OCPP send RemoteStartConfirmation by first.
  6708. sendRemoteStartConfirmation(uuid, comfirmstr);
  6709. return result;
  6710. }
  6711. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6712. {
  6713. mtrace();
  6714. int result = FAIL;
  6715. int match = FALSE;
  6716. int GunNO = 0;
  6717. int transactionIdInt=0;
  6718. int transactionIdIsNULL= FALSE;
  6719. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6720. int c = 0;
  6721. char *loc;
  6722. char comfirmstr[20];
  6723. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6724. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6725. if(server_pending == TRUE)
  6726. {
  6727. return 0;
  6728. }
  6729. c=0;
  6730. loc = strstr(payload, "transactionId");
  6731. if(loc == NULL)
  6732. {
  6733. transactionIdIsNULL= TRUE;
  6734. }
  6735. else
  6736. {
  6737. memset(sstr ,0, sizeof(sstr) );
  6738. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6739. {
  6740. sstr[c] = loc[strlen("transactionId")+2+c];
  6741. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6742. c++;
  6743. }
  6744. sstr[c] = '\0';
  6745. transactionIdInt = atoi(sstr);
  6746. }
  6747. if(transactionIdIsNULL == FALSE)
  6748. {
  6749. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6750. {
  6751. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6752. {
  6753. //check Transaction active
  6754. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6755. {
  6756. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6757. {
  6758. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6759. {
  6760. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6761. {
  6762. match = TRUE;
  6763. GunNO = gun_index;
  6764. }
  6765. }
  6766. }// END FOR CHAdeMO_QUANTITY
  6767. for (int index = 0; index < CCS_QUANTITY; index++)
  6768. {
  6769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6770. {
  6771. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6772. {
  6773. match = TRUE;
  6774. GunNO = gun_index;
  6775. }
  6776. }
  6777. }// END FOR CCS_QUANTITY
  6778. for (int index = 0; index < GB_QUANTITY; index++)
  6779. {
  6780. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6781. {
  6782. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6783. {
  6784. match = TRUE;
  6785. GunNO = gun_index;
  6786. }
  6787. }
  6788. }// END FOR GB_QUANTITY
  6789. }
  6790. else
  6791. {
  6792. for (int index = 0; index < AC_QUANTITY; index++)
  6793. {
  6794. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6795. {
  6796. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6797. {
  6798. match = TRUE;
  6799. GunNO = gun_index;
  6800. }
  6801. }
  6802. }// END FOR CHAdeMO_QUANTITY
  6803. }// END FOR AC ELSE
  6804. }// CHECK IF ResponseTransactionId == transactionIdInt
  6805. }//END FOR
  6806. if( match == TRUE)
  6807. {
  6808. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6809. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6810. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6811. }
  6812. else
  6813. {
  6814. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6815. }
  6816. }
  6817. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6818. return result;
  6819. }
  6820. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6821. {
  6822. mtrace();
  6823. int result = FAIL;
  6824. int connectorIdInt=0, reservationIdInt=0;
  6825. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6826. char comfirmstr[20]={0};
  6827. char sstr[180]={ 0 };
  6828. int c = 0;
  6829. char *loc;
  6830. //char *ptr;
  6831. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6832. //***(1)connectorId ****/
  6833. c=0;
  6834. loc = strstr(payload, "connectorId");
  6835. memset(sstr ,0, sizeof(sstr) );
  6836. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6837. {
  6838. sstr[c] = loc[strlen("connectorId")+2+c];
  6839. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6840. c++;
  6841. }
  6842. sstr[c] = '\0';
  6843. connectorIdInt = atoi(sstr);
  6844. //***(2)expiryDate ****/
  6845. loc = strstr(payload, "expiryDate");
  6846. memset(sstr ,0, sizeof(sstr) );
  6847. c = 0;
  6848. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6849. {
  6850. sstr[c] = loc[3+strlen("expiryDate")+c];
  6851. c++;
  6852. }
  6853. sstr[c] = '\0';
  6854. strcpy(expiryDatestr, sstr);
  6855. //***(3)idTag ****/
  6856. loc = strstr(payload, "idTag");
  6857. memset(sstr ,0, sizeof(sstr) );
  6858. c = 0;
  6859. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6860. {
  6861. sstr[c] = loc[3+strlen("idTag")+c];
  6862. c++;
  6863. }
  6864. sstr[c] = '\0';
  6865. strcpy(idTagstr, sstr);
  6866. //***(4)parentIdTag ****/
  6867. loc = strstr(payload, "parentIdTag");
  6868. memset(sstr ,0, sizeof(sstr) );
  6869. c = 0;
  6870. if(loc == NULL)
  6871. {
  6872. strcpy(parentIdTagstr, "");
  6873. }
  6874. else
  6875. {
  6876. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6877. {
  6878. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6879. c++;
  6880. }
  6881. sstr[c] = '\0';
  6882. strcpy(parentIdTagstr, sstr);
  6883. }
  6884. //***(5)reservationId ****/
  6885. c=0;
  6886. loc = strstr(payload, "reservationId");
  6887. memset(sstr ,0, sizeof(sstr) );
  6888. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6889. {
  6890. sstr[c] = loc[strlen("reservationId")+2+c];
  6891. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6892. c++;
  6893. }
  6894. sstr[c] = '\0';
  6895. reservationIdInt = atoi(sstr);
  6896. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6897. /*
  6898. enum SYSTEM_STATUS
  6899. {
  6900. SYS_MODE_BOOTING = 0,
  6901. SYS_MODE_IDLE = 1,
  6902. SYS_MODE_AUTHORIZING = 2,
  6903. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6904. SYS_MODE_REASSIGN = 4,
  6905. SYS_MODE_PREPARING = 5,
  6906. SYS_MODE_PREPARE_FOR_EV = 6,
  6907. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6908. SYS_MODE_CHARGING = 8,
  6909. SYS_MODE_TERMINATING = 9,
  6910. SYS_MODE_COMPLETE = 10,
  6911. SYS_MODE_ALARM = 11,
  6912. SYS_MODE_FAULT = 12,
  6913. SYS_MODE_RESERVATION = 13,
  6914. SYS_MODE_BOOKING = 14,
  6915. SYS_MODE_MAINTAIN = 15,
  6916. SYS_MODE_DEBUG = 16,
  6917. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6918. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6919. SYS_MODE_UPDATE = 19
  6920. };
  6921. */
  6922. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6923. {
  6924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6925. goto end;
  6926. }
  6927. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6928. {
  6929. //check Transaction active
  6930. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6931. {
  6932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6933. {
  6934. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6935. {
  6936. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6937. {
  6938. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6939. {
  6940. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6941. {
  6942. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6944. }
  6945. 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'))
  6946. {
  6947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6948. }
  6949. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6950. {
  6951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6952. }
  6953. else
  6954. {
  6955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6956. }
  6957. }
  6958. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6959. {
  6960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6961. }
  6962. }
  6963. else
  6964. {
  6965. //replace reservation
  6966. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6968. }
  6969. }
  6970. } // END FOR CHAdeMO_QUANTITY
  6971. for (int index = 0; index < CCS_QUANTITY; index++)
  6972. {
  6973. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6974. {
  6975. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6976. {
  6977. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6978. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6979. {
  6980. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6981. {
  6982. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6984. }
  6985. 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'))
  6986. {
  6987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6988. }
  6989. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6990. {
  6991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6992. }
  6993. else
  6994. {
  6995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6996. }
  6997. }
  6998. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6999. {
  7000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7001. }
  7002. }
  7003. else
  7004. {
  7005. //replace reservation
  7006. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7008. }
  7009. }
  7010. } // END FOR CCS_QUANTITY
  7011. for (int index = 0; index < GB_QUANTITY; index++)
  7012. {
  7013. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  7014. {
  7015. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7016. {
  7017. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7018. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7019. {
  7020. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7021. {
  7022. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7024. }
  7025. 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'))
  7026. {
  7027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7028. }
  7029. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7030. {
  7031. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7032. }
  7033. else
  7034. {
  7035. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7036. }
  7037. }
  7038. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7039. {
  7040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7041. }
  7042. }
  7043. else
  7044. {
  7045. //replace reservation
  7046. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7048. }
  7049. }
  7050. }// END FOR GB_QUANTITY
  7051. }
  7052. else
  7053. {
  7054. for (int index = 0; index < AC_QUANTITY; index++)
  7055. {
  7056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  7057. {
  7058. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7059. {
  7060. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7061. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7062. {
  7063. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7064. {
  7065. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7067. }
  7068. 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'))
  7069. {
  7070. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7071. }
  7072. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7073. {
  7074. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7075. }
  7076. else
  7077. {
  7078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7079. }
  7080. }
  7081. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7082. {
  7083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7084. }
  7085. }
  7086. else
  7087. {
  7088. //replace reservation
  7089. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7091. }
  7092. }
  7093. } // END FOR AC_QUANTITY
  7094. }//END FOR AC ELSE
  7095. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7096. }
  7097. else if(connectorIdInt == 0)
  7098. {
  7099. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7100. {
  7101. //check Transaction active
  7102. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7103. {
  7104. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7105. {
  7106. 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'))
  7107. {
  7108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7109. goto end;
  7110. }
  7111. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7112. {
  7113. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7114. goto end;
  7115. }
  7116. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7117. {
  7118. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7119. goto end;
  7120. }
  7121. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7122. {
  7123. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7124. goto end;
  7125. }
  7126. }
  7127. }// END FOR CHAdeMO_QUANTITY
  7128. for (int index = 0; index < CCS_QUANTITY; index++)
  7129. {
  7130. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7131. {
  7132. 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'))
  7133. {
  7134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7135. }
  7136. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7137. {
  7138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7139. }
  7140. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7141. {
  7142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7143. }
  7144. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7145. {
  7146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7147. }
  7148. }
  7149. } // END FOR CCS_QUANTITY
  7150. for (int index = 0; index < GB_QUANTITY; index++)
  7151. {
  7152. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7153. {
  7154. 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'))
  7155. {
  7156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7157. }
  7158. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7159. {
  7160. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7161. }
  7162. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7163. {
  7164. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7165. }
  7166. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7167. {
  7168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7169. }
  7170. }
  7171. } // END FOR GB_QUANTITY
  7172. }
  7173. else
  7174. {
  7175. for (int index = 0; index < AC_QUANTITY; index++)
  7176. {
  7177. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7178. {
  7179. 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'))
  7180. {
  7181. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7182. goto end;
  7183. }
  7184. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7185. {
  7186. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7187. goto end;
  7188. }
  7189. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7190. {
  7191. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7192. goto end;
  7193. }
  7194. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7195. {
  7196. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7197. goto end;
  7198. }
  7199. }
  7200. }// END FOR AC_QUANTITY
  7201. }
  7202. //The connectorId is 0
  7203. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7204. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7205. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7206. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7207. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7208. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7209. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7210. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7211. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7212. result = TRUE;
  7213. return result;
  7214. }
  7215. else
  7216. {
  7217. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7218. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7219. }
  7220. if(strcmp(comfirmstr,"Accepted") == 0)
  7221. {
  7222. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7223. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7224. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7225. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7226. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7227. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7228. result = TRUE;
  7229. return result;
  7230. }
  7231. end:
  7232. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7233. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7234. return result;
  7235. }
  7236. int handleResetRequest(char *uuid, char *payload)
  7237. {
  7238. mtrace();
  7239. int result = FAIL;
  7240. char sstr[10]={0};
  7241. char typestr[10]={0};
  7242. char comfirmstr[20]={0};
  7243. int c = 0;
  7244. char *loc;
  7245. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7246. DEBUG_INFO("handleResetRequest ...\n");
  7247. loc = strstr(payload, "type");
  7248. memset(sstr ,0, sizeof(sstr) );
  7249. c = 0;
  7250. while (loc[3+strlen("type")+c] != '\"')
  7251. {
  7252. sstr[c] = loc[3+strlen("type")+c];
  7253. c++;
  7254. }
  7255. sstr[c] = '\0';
  7256. strcpy(typestr,sstr);
  7257. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7258. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7259. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7260. {
  7261. //check Transaction active
  7262. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7263. {
  7264. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7265. {
  7266. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7267. {
  7268. //0: unplug, 1: Plug-in
  7269. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7270. }
  7271. }
  7272. for (int index = 0; index < CCS_QUANTITY; index++)
  7273. {
  7274. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7275. {
  7276. //0: unplug, 1: Plug-in
  7277. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7278. }
  7279. }
  7280. for (int index = 0; index < GB_QUANTITY; index++)
  7281. {
  7282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7283. {
  7284. //0: unplug, 1: Plug-in
  7285. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7286. }
  7287. }
  7288. }
  7289. else
  7290. {
  7291. for (int index = 0; index < AC_QUANTITY; index++)
  7292. {
  7293. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7294. {
  7295. //0: unplug, 1: Plug-in
  7296. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7297. }
  7298. }
  7299. }// END FOR AC ELSE
  7300. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7301. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7302. result = TRUE;
  7303. return result;
  7304. }
  7305. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7306. {
  7307. //check Transaction active
  7308. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7309. {
  7310. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7311. {
  7312. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7313. {
  7314. //0: unplug, 1: Plug-in
  7315. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7316. }
  7317. }
  7318. for (int index = 0; index < CCS_QUANTITY; index++)
  7319. {
  7320. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7321. {
  7322. //0: unplug, 1: Plug-in
  7323. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7324. }
  7325. }
  7326. for (int index = 0; index < GB_QUANTITY; index++)
  7327. {
  7328. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7329. {
  7330. //0: unplug, 1: Plug-in
  7331. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7332. }
  7333. }
  7334. }
  7335. else
  7336. {
  7337. for (int index = 0; index < AC_QUANTITY; index++)
  7338. {
  7339. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7340. {
  7341. //0: unplug, 1: Plug-in
  7342. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7343. }
  7344. }
  7345. }// END FOR AC ELSE
  7346. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7347. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7348. result = TRUE;
  7349. return result;
  7350. }
  7351. else
  7352. {
  7353. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7354. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7355. goto errorend;
  7356. }
  7357. errorend:
  7358. sendResetConfirmation(uuid, comfirmstr);
  7359. return result;
  7360. }
  7361. int handleSendLocalListRequest(char *uuid, char *payload)
  7362. {
  7363. mtrace();
  7364. int result = FAIL;
  7365. int listVersionInt;
  7366. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7367. char listsearch[]="listVersion";
  7368. char updateTypesearch[]="updateType";
  7369. char localAuthorizationListsearch[]="localAuthorizationList";
  7370. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7371. char CardList[500][160]={0};
  7372. char updateTypestr[15]={0};
  7373. char idTagstr[20]={0};
  7374. char parentIdTag[20]={0};
  7375. char expiryDate[30]={0};
  7376. char idTagstatus[16]={0};
  7377. int c = 0;
  7378. int i = 0;
  7379. char *delim1 = "}";
  7380. char * pch;
  7381. char *loc;
  7382. //char *ptr;
  7383. char comfirmstr[20];
  7384. //int n_localAuthorizations = 0;
  7385. int checkState_Faulted = FALSE;
  7386. DEBUG_INFO("handleSendLocalListRequest\n");
  7387. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7388. {
  7389. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7390. goto end;
  7391. }
  7392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7393. {
  7394. //check Charge Point state
  7395. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7396. {
  7397. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7398. {
  7399. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7400. }
  7401. }
  7402. for (int index = 0; index < CCS_QUANTITY; index++)
  7403. {
  7404. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7405. {
  7406. checkState_Faulted = TRUE; //OCPP Status
  7407. }
  7408. }
  7409. for (int index = 0; index < GB_QUANTITY; index++)
  7410. {
  7411. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7412. {
  7413. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7414. }
  7415. }
  7416. }
  7417. else
  7418. {
  7419. //check Charge Point state
  7420. for (int index = 0; index < AC_QUANTITY; index++)
  7421. {
  7422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7423. {
  7424. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7425. }
  7426. }
  7427. }// END FOR AC ELSE
  7428. if(checkState_Faulted == TRUE)
  7429. {
  7430. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7431. goto end;
  7432. }
  7433. //listVersion
  7434. c = 0;
  7435. loc = strstr(payload, listsearch);
  7436. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7437. {
  7438. sstr[c] = loc[strlen("listVersion")+2+c];
  7439. c++;
  7440. }
  7441. sstr[c] = '\0';
  7442. listVersionInt = atoi(sstr);
  7443. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7444. //updateType
  7445. loc = strstr(payload, updateTypesearch);
  7446. c = 0;
  7447. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7448. {
  7449. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7450. c++;
  7451. }
  7452. sstr[c] = '\0';
  7453. strcpy(updateTypestr, sstr);
  7454. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7455. //localAuthorizationList
  7456. memset(sstr ,0, sizeof(sstr) );
  7457. loc = strstr(payload, localAuthorizationListsearch);
  7458. if(loc != NULL) // localAuthorizationList is not NULL
  7459. {
  7460. //Check UpdateType
  7461. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7462. {
  7463. //Local list full update
  7464. printf("Local list full update.\n");
  7465. OCPP_cleanLocalList();
  7466. }
  7467. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7468. {
  7469. //Local list different update
  7470. printf("Local list different update.\n");
  7471. OCPP_getListVerion();
  7472. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7473. {
  7474. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7475. goto end;
  7476. }
  7477. }
  7478. else
  7479. {
  7480. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7481. goto end;
  7482. }
  7483. c = 0;
  7484. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7485. {
  7486. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7487. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7488. c++;
  7489. }
  7490. sstr[c] = '\0';
  7491. //DEBUG_INFO("sstr=%s\n", sstr);
  7492. //parsing strings to words
  7493. i = 0;
  7494. pch = strtok(sstr,delim1);
  7495. while (pch != NULL)
  7496. {
  7497. strcpy(CardList[i], pch);
  7498. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7499. pch = strtok (NULL, delim1);
  7500. i = i + 1;
  7501. }
  7502. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7503. //local Authorizations List Numbers
  7504. //n_localAuthorizations = i;
  7505. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7506. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7507. c= 0;
  7508. while(c < i) // i is CardList Number
  7509. {
  7510. //Search "IdToken"
  7511. memset(sstr ,0, sizeof(sstr) );
  7512. loc = strstr(CardList[c], "idTag");
  7513. int j = 0;
  7514. while (loc[3+strlen("idTag")+j] != '\"')
  7515. {
  7516. sstr[j] = loc[3+strlen("idTag")+j];
  7517. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7518. j++;
  7519. }
  7520. sstr[j] = '\0';
  7521. strcpy(idTagstr, sstr);
  7522. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7523. //Search "expiryDate"
  7524. memset(sstr ,0, sizeof(sstr) );
  7525. loc = strstr(CardList[c], "expiryDate");
  7526. j = 0;
  7527. if(loc != NULL)
  7528. {
  7529. while (loc[3+strlen("expiryDate")+j] != '\"')
  7530. {
  7531. sstr[j] = loc[3+strlen("expiryDate")+j];
  7532. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7533. j++;
  7534. }
  7535. sstr[j] = '\0';
  7536. strcpy(expiryDate, sstr);
  7537. }
  7538. else
  7539. {
  7540. strcpy(expiryDate, "");
  7541. }
  7542. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7543. //Search "parentIdTag"
  7544. memset(sstr ,0, sizeof(sstr) );
  7545. loc = strstr(CardList[c], "parentIdTag");
  7546. j = 0;
  7547. if(loc != NULL)
  7548. {
  7549. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7550. {
  7551. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7552. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7553. j++;
  7554. }
  7555. sstr[j] = '\0';
  7556. strcpy(parentIdTag, sstr);
  7557. }
  7558. else
  7559. {
  7560. strcpy(parentIdTag, "");
  7561. }
  7562. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7563. //Search "status"
  7564. memset(sstr ,0, sizeof(sstr) );
  7565. loc = strstr(CardList[c], "status");
  7566. j = 0;
  7567. while (loc[3+strlen("status")+j] != '\"')
  7568. {
  7569. sstr[j] = loc[3+strlen("status")+j];
  7570. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7571. j++;
  7572. }
  7573. sstr[j] = '\0';
  7574. strcpy(idTagstatus, sstr);
  7575. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7576. OCPP_getIdTag(idTagstr);
  7577. //OCPP_getIdTag("test"); For Test
  7578. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7579. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7580. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7581. {
  7582. //Local list full update
  7583. DEBUG_INFO("Local list full update.\n");
  7584. // update list
  7585. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7586. //DEBUG_INFO("Local list full update. 1\n");
  7587. //OCPP_get_TableAuthlocalAllData();
  7588. //DEBUG_INFO("Local list full update. 2\n");
  7589. }
  7590. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7591. {
  7592. #if 0
  7593. if(strcmp(idTagstr, idTagAuthorization) == 0)
  7594. {
  7595. //OCPP_deleteIdTag(idTagstr);
  7596. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7597. }
  7598. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  7599. {
  7600. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7601. }
  7602. #endif
  7603. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7604. }
  7605. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7606. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7607. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7608. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7609. c++;
  7610. }
  7611. }
  7612. else
  7613. {
  7614. //Check UpdateType
  7615. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7616. {
  7617. //Local list full update
  7618. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7619. OCPP_cleanLocalList();
  7620. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7621. goto end;
  7622. }
  7623. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7624. {
  7625. //Local list different update
  7626. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7627. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7628. goto end;
  7629. }
  7630. }
  7631. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7632. end:
  7633. sendSendLocalListConfirmation(uuid, comfirmstr);
  7634. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7635. return result;
  7636. }
  7637. #define MAX 200
  7638. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7639. {
  7640. mtrace();
  7641. int result = FAIL;
  7642. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7643. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7644. char chargingProfilePurposeStr[30]={0};
  7645. char chargingProfileKindStr[16]={0};
  7646. char recurrencyKindStr[10]={0};
  7647. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7648. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7649. int chargingSchedulePeriodCount = 0;
  7650. //int updateflag = FALSE;
  7651. char comfirmstr[20]={0};
  7652. int meet= FALSE;
  7653. char sstr[10]={0};
  7654. int c = 0;
  7655. char *loc;
  7656. FILE *fptr1;//, *fptr2;
  7657. //int lno=0;//, linectr = 0;
  7658. //int modifyflag = FALSE;
  7659. char filename[MAX]={0};
  7660. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  7661. //int resultRename=0;
  7662. char rmFileCmd[50]={0};
  7663. char tempchargingProfilePurposeStr[30]={0};
  7664. char word[1600]={0};
  7665. int n_chargingProfile = 0;
  7666. //[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}}}]
  7667. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7668. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7669. //*********************connectorId***************************/
  7670. loc = strstr(payload, "connectorId");
  7671. c = 0;
  7672. memset(sstr ,0, sizeof(sstr) );
  7673. while (loc[strlen("connectorId")+2+c] != ',')
  7674. {
  7675. sstr[c] = loc[strlen("connectorId")+2+c];
  7676. c++;
  7677. }
  7678. sstr[c] = '\0';
  7679. connectorIdInt = atoi(sstr);
  7680. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7681. {
  7682. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7683. }
  7684. else
  7685. {
  7686. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7687. }
  7688. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7689. //*********************chargingProfileId***************************/
  7690. loc = strstr(payload, "chargingProfileId");
  7691. c = 0;
  7692. memset(sstr ,0, sizeof(sstr) );
  7693. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7694. {
  7695. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7696. c++;
  7697. }
  7698. sstr[c] = '\0';
  7699. chargingProfileIdInt = atoi(sstr);
  7700. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7701. {
  7702. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7703. }
  7704. else
  7705. {
  7706. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7707. }
  7708. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7709. //*********************transactionId***************************/
  7710. loc = strstr(payload, "transactionId");
  7711. if(loc != NULL)
  7712. {
  7713. c = 0;
  7714. memset(sstr ,0, sizeof(sstr) );
  7715. while (loc[strlen("transactionId")+2+c] != ',')
  7716. {
  7717. sstr[c] = loc[strlen("transactionId")+2+c];
  7718. c++;
  7719. }
  7720. sstr[c] = '\0';
  7721. transactionIdInt = atoi(sstr);
  7722. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7723. {
  7724. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7725. }
  7726. else
  7727. {
  7728. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7729. }
  7730. }
  7731. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7732. //*********************stackLevel***************************/
  7733. loc = strstr(payload, "stackLevel");
  7734. c = 0;
  7735. memset(sstr ,0, sizeof(sstr) );
  7736. while (loc[strlen("stackLevel")+2+c] != ',')
  7737. {
  7738. sstr[c] = loc[strlen("stackLevel")+2+c];
  7739. c++;
  7740. }
  7741. sstr[c] = '\0';
  7742. stackLevelInt = atoi(sstr);
  7743. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7744. {
  7745. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7746. }
  7747. else
  7748. {
  7749. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7750. }
  7751. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7752. //*********************chargingProfilePurpose***************************/
  7753. loc = strstr(payload, "chargingProfilePurpose");
  7754. c = 0;
  7755. memset(sstr ,0, sizeof(sstr) );
  7756. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7757. {
  7758. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7759. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7760. c++;
  7761. }
  7762. sstr[c] = '\0';
  7763. strcpy(chargingProfilePurposeStr,sstr);
  7764. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7765. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7766. {
  7767. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7768. }
  7769. else
  7770. {
  7771. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7772. }
  7773. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7774. //*********************chargingProfileKind***************************/
  7775. loc = strstr(payload, "chargingProfileKind");
  7776. c = 0;
  7777. memset(sstr ,0, sizeof(sstr) );
  7778. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7779. {
  7780. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7781. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7782. c++;
  7783. }
  7784. sstr[c] = '\0';
  7785. strcpy(chargingProfileKindStr,sstr);
  7786. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7787. {
  7788. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7789. }
  7790. else
  7791. {
  7792. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7793. }
  7794. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7795. //*********************recurrencyKind***************************/
  7796. loc = strstr(payload, "recurrencyKind");
  7797. if(loc != NULL)
  7798. {
  7799. c = 0;
  7800. memset(sstr ,0, sizeof(sstr) );
  7801. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7802. {
  7803. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7804. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7805. c++;
  7806. }
  7807. sstr[c] = '\0';
  7808. strcpy(recurrencyKindStr,sstr);
  7809. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7810. {
  7811. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7812. }
  7813. else
  7814. {
  7815. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7816. }
  7817. }
  7818. else
  7819. {
  7820. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7821. {
  7822. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7823. }
  7824. else
  7825. {
  7826. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7827. }
  7828. }
  7829. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7830. //*********************validFrom***************************/
  7831. loc = strstr(payload, "validFrom");
  7832. if(loc != NULL)
  7833. {
  7834. c = 0;
  7835. memset(sstr ,0, sizeof(sstr) );
  7836. while (loc[3+strlen("validFrom")+c] != '\"')
  7837. {
  7838. sstr[c] = loc[3+strlen("validFrom")+c];
  7839. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7840. c++;
  7841. }
  7842. sstr[c] = '\0';
  7843. strcpy(validFromStr,sstr);
  7844. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7845. {
  7846. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7847. }
  7848. else
  7849. {
  7850. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7851. }
  7852. }
  7853. else
  7854. {
  7855. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7856. {
  7857. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7858. }
  7859. else
  7860. {
  7861. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7862. }
  7863. }
  7864. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7865. //*********************validTo***************************/
  7866. loc = strstr(payload, "validTo");
  7867. if(loc != NULL)
  7868. {
  7869. c = 0;
  7870. memset(sstr ,0, sizeof(sstr) );
  7871. while (loc[3+strlen("validTo")+c] != '\"')
  7872. {
  7873. sstr[c] = loc[3+strlen("validTo")+c];
  7874. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7875. c++;
  7876. }
  7877. sstr[c] = '\0';
  7878. strcpy(validToStr,sstr);
  7879. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7880. {
  7881. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7882. }
  7883. else
  7884. {
  7885. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7886. }
  7887. }
  7888. else
  7889. {
  7890. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7891. {
  7892. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7893. }
  7894. else
  7895. {
  7896. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7897. }
  7898. }
  7899. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7900. //*********************duration***************************/
  7901. loc = strstr(payload, "duration");
  7902. if(loc != NULL)
  7903. {
  7904. c = 0;
  7905. memset(sstr ,0, sizeof(sstr) );
  7906. while (loc[strlen("duration")+2+c] != ',')
  7907. {
  7908. sstr[c] = loc[strlen("duration")+2+c];
  7909. c++;
  7910. }
  7911. sstr[c] = '\0';
  7912. durationInt = atoi(sstr);
  7913. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7914. {
  7915. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7916. }
  7917. else
  7918. {
  7919. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7920. }
  7921. }
  7922. else
  7923. {
  7924. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7925. {
  7926. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7927. }
  7928. else
  7929. {
  7930. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7931. }
  7932. }
  7933. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7934. //*********************startSchedule***************************/
  7935. loc = strstr(payload, "startSchedule");
  7936. if(loc != NULL)
  7937. {
  7938. c = 0;
  7939. memset(sstr ,0, sizeof(sstr) );
  7940. while (loc[3+strlen("startSchedule")+c] != '\"')
  7941. {
  7942. sstr[c] = loc[3+strlen("startSchedule")+c];
  7943. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7944. c++;
  7945. }
  7946. sstr[c] = '\0';
  7947. strcpy(startScheduleStr,sstr);
  7948. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7949. {
  7950. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7951. }
  7952. else
  7953. {
  7954. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7955. }
  7956. }
  7957. else
  7958. {
  7959. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7960. {
  7961. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7962. }
  7963. else
  7964. {
  7965. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7966. }
  7967. }
  7968. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7969. //*********************chargingRateUnit***************************/
  7970. loc = strstr(payload, "chargingRateUnit");
  7971. if(loc != NULL)
  7972. {
  7973. c = 0;
  7974. memset(sstr ,0, sizeof(sstr) );
  7975. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7976. {
  7977. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7978. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7979. c++;
  7980. }
  7981. sstr[c] = '\0';
  7982. strcpy(chargingRateUnitStr,sstr);
  7983. #if 0
  7984. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  7985. {
  7986. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7987. goto end;
  7988. }
  7989. #endif
  7990. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7991. {
  7992. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7993. }
  7994. else
  7995. {
  7996. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7997. }
  7998. }
  7999. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8000. //****************chargingSchedulePeriod count start*******************/
  8001. int what_len = strlen("startPeriod");
  8002. char tempChargingProfile[1000]={0};
  8003. strcpy(tempChargingProfile,(const char*)payload);
  8004. char *where = tempChargingProfile;
  8005. if (what_len)
  8006. {
  8007. while ((where = strstr(where, "startPeriod"))) {
  8008. where += what_len;
  8009. chargingSchedulePeriodCount++;
  8010. }
  8011. }
  8012. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8013. {
  8014. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8015. goto end;
  8016. }
  8017. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8018. //where = payload;
  8019. int templength = 0;
  8020. //int searchstart = 0;
  8021. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8022. {
  8023. //****************startPeriod*******************/
  8024. c=0;
  8025. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8026. memset(sstr ,0, sizeof(sstr) );
  8027. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8028. {
  8029. sstr[c] = loc[strlen("startPeriod")+2+c];
  8030. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8031. c++;
  8032. }
  8033. sstr[c] = '\0';
  8034. startPeriodInt[periodNums] = atoi(sstr);
  8035. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8036. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8037. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8038. {
  8039. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8040. }
  8041. else
  8042. {
  8043. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8044. }
  8045. templength = strlen("startPeriod")+2+c;
  8046. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8047. //****************limit*******************/
  8048. c=0;
  8049. loc = strstr(tempChargingProfile + templength, "limit");
  8050. memset(sstr ,0, sizeof(sstr) );
  8051. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8052. {
  8053. sstr[c] = loc[strlen("limit")+2+c];
  8054. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8055. c++;
  8056. }
  8057. sstr[c] = '\0';
  8058. limitflaot[periodNums] = atof(sstr);
  8059. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8060. {
  8061. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8062. }
  8063. else
  8064. {
  8065. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8066. }
  8067. templength = templength + strlen("limit")+2+c;
  8068. //****************numberPhases*******************/
  8069. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8070. if(loc != NULL)
  8071. {
  8072. c=0;
  8073. memset(sstr ,0, sizeof(sstr) );
  8074. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8075. {
  8076. sstr[c] = loc[strlen("numberPhases")+2+c];
  8077. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8078. c++;
  8079. }
  8080. sstr[c] = '\0';
  8081. numberPhasesInt[periodNums] = atoi(sstr);
  8082. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8083. {
  8084. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8085. }
  8086. else
  8087. {
  8088. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8089. }
  8090. templength = templength + strlen("numberPhases")+2+c;
  8091. }
  8092. //where = loc;
  8093. }
  8094. //****************chargingSchedulePeriod count end*******************/
  8095. //*********************minChargingRate***************************/
  8096. loc = strstr(payload, "minChargingRate");
  8097. if(loc != NULL)
  8098. {
  8099. c = 0;
  8100. memset(sstr ,0, sizeof(sstr) );
  8101. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8102. {
  8103. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8104. c++;
  8105. }
  8106. sstr[c] = '\0';
  8107. minChargingRateFloat = atof(sstr);
  8108. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8109. {
  8110. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8111. }
  8112. else
  8113. {
  8114. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8115. }
  8116. }
  8117. else
  8118. {
  8119. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8120. {
  8121. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8122. }
  8123. else
  8124. {
  8125. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8126. }
  8127. }
  8128. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8129. {
  8130. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8131. if(connectorIdInt != 0)
  8132. {
  8133. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8134. goto end;
  8135. }
  8136. strcpy(filename, ChargePointMaxProfile_JSON );
  8137. fptr1 = fopen(filename, "r");
  8138. if (!fptr1)
  8139. {
  8140. //file not exist
  8141. DEBUG_INFO("Unable to open the input file!!\n");
  8142. fptr1 = fopen(filename, "w+");
  8143. }
  8144. else
  8145. {
  8146. //Check Charging Profile Count
  8147. while(fscanf(fptr1, "%s", word) != EOF)
  8148. {
  8149. //DEBUG_INFO("word=%s\n",word);
  8150. if(strstr(word, "chargingProfileId")!= NULL)
  8151. {
  8152. //DEBUG_INFO("test chargingProfileId \n");
  8153. n_chargingProfile = n_chargingProfile + 1;
  8154. //DEBUG_INFO("chargingProfileId Found\n");
  8155. }
  8156. }
  8157. }
  8158. fclose(fptr1);
  8159. }
  8160. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8161. {
  8162. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8163. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8164. {
  8165. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8166. goto end;
  8167. }
  8168. #if 0
  8169. switch(connectorIdInt)
  8170. {
  8171. case 0:
  8172. strcpy(filename, TxDefaultProfile_0_JSON );
  8173. break;
  8174. case 1:
  8175. strcpy(filename, TxDefaultProfile_1_JSON );
  8176. break;
  8177. case 2:
  8178. strcpy(filename, TxDefaultProfile_2_JSON );
  8179. break;
  8180. default:
  8181. strcpy(filename, TxDefaultProfile_0_JSON );
  8182. break;
  8183. }
  8184. #endif
  8185. memset(filename, 0, sizeof filename);
  8186. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8187. fptr1 = fopen(filename, "r");
  8188. if (!fptr1)
  8189. {
  8190. //file not exist
  8191. //DEBUG_INFO("Unable to open the input file!!\n");
  8192. fptr1 = fopen(filename, "w+");
  8193. }
  8194. else
  8195. {
  8196. //Check Charging Profile Count
  8197. while(fscanf(fptr1, "%s", word) != EOF)
  8198. {
  8199. //DEBUG_INFO("word=%s\n",word);
  8200. if(strstr(word, "chargingProfileId")!= NULL)
  8201. {
  8202. //DEBUG_INFO("test chargingProfileId \n");
  8203. n_chargingProfile = n_chargingProfile + 1;
  8204. //DEBUG_INFO("chargingProfileId Found\n");
  8205. }
  8206. }
  8207. }
  8208. fclose(fptr1);
  8209. }
  8210. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8211. {
  8212. //printf("set chargingProfile 1-4\n");
  8213. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8214. //check Transaction active
  8215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8216. {
  8217. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8218. {
  8219. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8220. {
  8221. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8222. {
  8223. meet = TRUE;
  8224. break;
  8225. }
  8226. }
  8227. }
  8228. }
  8229. for (int index = 0; index < CCS_QUANTITY; index++)
  8230. {
  8231. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8232. {
  8233. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8234. {
  8235. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8236. {
  8237. meet = TRUE;
  8238. break;
  8239. }
  8240. }
  8241. }
  8242. }
  8243. for (int index = 0; index < GB_QUANTITY; index++)
  8244. {
  8245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8246. {
  8247. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8248. {
  8249. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8250. {
  8251. meet = TRUE;
  8252. break;
  8253. }
  8254. }
  8255. }
  8256. }
  8257. if(meet == FALSE)
  8258. {
  8259. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8260. goto end;
  8261. }
  8262. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8263. {
  8264. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8265. goto end;
  8266. }
  8267. #if 0
  8268. switch(connectorIdInt)
  8269. {
  8270. case 0:
  8271. break;
  8272. case 1:
  8273. strcpy(filename, TxProfile_1_JSON);
  8274. break;
  8275. case 2:
  8276. strcpy(filename, TxProfile_2_JSON);
  8277. break;
  8278. default:
  8279. strcpy(filename, TxProfile_1_JSON);
  8280. break;
  8281. }
  8282. #endif
  8283. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8284. fptr1 = fopen(filename, "r");
  8285. if (!fptr1)
  8286. {
  8287. //file not exist
  8288. DEBUG_INFO("Unable to open the input file!!\n");
  8289. fptr1 = fopen(filename, "w+");
  8290. }
  8291. else
  8292. {
  8293. //Check Charging Profile Count
  8294. while(fscanf(fptr1, "%s", word) != EOF)
  8295. {
  8296. //DEBUG_INFO("word=%s\n",word);
  8297. if(strstr(word, "chargingProfileId")!= NULL)
  8298. {
  8299. //DEBUG_INFO("test chargingProfileId \n");
  8300. n_chargingProfile = n_chargingProfile + 1;
  8301. //DEBUG_INFO("chargingProfileId Found\n");
  8302. }
  8303. }
  8304. }
  8305. fclose(fptr1);
  8306. DEBUG_INFO("n_chargingProfile_3=%d\n",n_chargingProfile);
  8307. }
  8308. // Check ChargeProfileMaxStackLevel
  8309. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8310. {
  8311. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8312. goto end;
  8313. }
  8314. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8315. {
  8316. int i = 0;
  8317. char fnametemp[200]={0};
  8318. n_chargingProfile = 0;
  8319. //Check ChargePointMaxProfile.json exit
  8320. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8321. {
  8322. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8323. //Check Charging Profile Count
  8324. while(fscanf(fptr1, "%s", word) != EOF)
  8325. {
  8326. //DEBUG_INFO("word=%s\n",word);
  8327. if(strstr(word, "chargingProfileId")!= NULL)
  8328. {
  8329. //DEBUG_INFO("test chargingProfileId \n");
  8330. n_chargingProfile = n_chargingProfile + 1;
  8331. i = i + 1;
  8332. //DEBUG_INFO("chargingProfileId Found\n");
  8333. }
  8334. memset(word, 0, sizeof word);
  8335. }
  8336. fclose(fptr1);
  8337. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8338. }
  8339. //Check TxDefaultProfile_0.json exit
  8340. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8341. {
  8342. i = 0;
  8343. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8344. //Check Charging Profile Count
  8345. while(fscanf(fptr1, "%s", word) != EOF)
  8346. {
  8347. //DEBUG_INFO("word=%s\n",word);
  8348. if(strstr(word, "chargingProfileId")!= NULL)
  8349. {
  8350. //DEBUG_INFO("test chargingProfileId \n");
  8351. n_chargingProfile = n_chargingProfile + 1;
  8352. i = i + 1;
  8353. //DEBUG_INFO("chargingProfileId Found\n");
  8354. }
  8355. memset(word, 0, sizeof word);
  8356. }
  8357. fclose(fptr1);
  8358. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8359. }
  8360. //Check TxDefaultProfile_%d.json
  8361. for(int j=1; j <= gunTotalNumber; j++)
  8362. {
  8363. memset(fnametemp, 0, sizeof fnametemp);
  8364. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8365. if((access(fnametemp,F_OK))!=-1)
  8366. {
  8367. i = 0;
  8368. fptr1 = fopen(fnametemp, "r");
  8369. //Check Charging Profile Count
  8370. while(fscanf(fptr1, "%s", word) != EOF)
  8371. {
  8372. //DEBUG_INFO("word=%s\n",word);
  8373. if(strstr(word, "chargingProfileId")!= NULL)
  8374. {
  8375. //DEBUG_INFO("test chargingProfileId \n");
  8376. n_chargingProfile = n_chargingProfile + 1;
  8377. i = i + 1;
  8378. //DEBUG_INFO("chargingProfileId Found\n");
  8379. }
  8380. memset(word, 0, sizeof word);
  8381. }
  8382. fclose(fptr1);
  8383. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8384. }
  8385. }
  8386. //Check TxProfile_%d.json
  8387. for(int j=1; j <= gunTotalNumber; j++)
  8388. {
  8389. memset(fnametemp, 0, sizeof fnametemp);
  8390. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8391. if((access(fnametemp,F_OK))!=-1)
  8392. {
  8393. i = 0;
  8394. fptr1 = fopen(fnametemp, "r");
  8395. //Check Charging Profile Count
  8396. while(fscanf(fptr1, "%s", word) != EOF)
  8397. {
  8398. //DEBUG_INFO("word=%s\n",word);
  8399. if(strstr(word, "chargingProfileId")!= NULL)
  8400. {
  8401. //DEBUG_INFO("test chargingProfileId \n");
  8402. n_chargingProfile = n_chargingProfile + 1;
  8403. i = i + 1;
  8404. //DEBUG_INFO("chargingProfileId Found\n");
  8405. }
  8406. memset(word, 0, sizeof word);
  8407. }
  8408. fclose(fptr1);
  8409. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8410. }
  8411. }
  8412. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8413. {
  8414. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8415. goto end;
  8416. }
  8417. }
  8418. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8419. //**********************************Write to File********************************************************/
  8420. FILE *infile;
  8421. FILE *outfile;
  8422. // open file for writing
  8423. infile = fopen (filename, "r");
  8424. outfile = fopen (tempfile, "w");
  8425. int d =0;
  8426. d = fgetc(infile);
  8427. //DEBUG_INFO("d:%d\n",d);
  8428. rewind(infile);
  8429. //*检测到文件结束标识返回1,否则返回0。*/
  8430. if(d == EOF)
  8431. {
  8432. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8433. fprintf(outfile,"%s\n",payload);
  8434. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8435. fclose(infile);
  8436. fclose(outfile);
  8437. sprintf(rmFileCmd,"rm -f %s",filename);
  8438. system(rmFileCmd);
  8439. rename(tempfile, filename);
  8440. #if 0
  8441. resultRename = rename(tempfile, filename);
  8442. if(resultRename == 0)
  8443. {
  8444. DEBUG_INFO("File chargingProfile renamed successfully");
  8445. }
  8446. else
  8447. {
  8448. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8449. }
  8450. #endif
  8451. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8452. //system(rmFileCmd);
  8453. }
  8454. else
  8455. {
  8456. char buf[1000]={0};
  8457. int ChargingProfileAdded = FALSE;
  8458. while (fgets(buf, sizeof(buf), infile) != NULL)
  8459. {
  8460. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8461. //*************************tempconnectorIdInt*********************************/
  8462. loc = strstr(buf, "connectorId");
  8463. c = 0;
  8464. memset(sstr ,0, sizeof(sstr) );
  8465. while (loc[strlen("connectorId")+2+c] != ',')
  8466. {
  8467. sstr[c] = loc[strlen("connectorId")+2+c];
  8468. c++;
  8469. }
  8470. sstr[c] = '\0';
  8471. tempconnectorIdInt = atoi(sstr);
  8472. //*************************tempchargingProfileIdInt*********************************/
  8473. loc = strstr(buf, "chargingProfileId");
  8474. c = 0;
  8475. memset(sstr ,0, sizeof(sstr) );
  8476. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8477. {
  8478. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8479. c++;
  8480. }
  8481. sstr[c] = '\0';
  8482. tempchargingProfileIdInt = atoi(sstr);
  8483. //*************************tempstackLevelInt*********************************/
  8484. loc = strstr(buf, "stackLevel");
  8485. c = 0;
  8486. memset(sstr ,0, sizeof(sstr) );
  8487. while (loc[strlen("stackLevel")+2+c] != ',')
  8488. {
  8489. sstr[c] = loc[strlen("stackLevel")+2+c];
  8490. c++;
  8491. }
  8492. sstr[c] = '\0';
  8493. tempstackLevelInt = atoi(sstr);
  8494. //*************************tempchargingProfilePurposeStr*********************************/
  8495. loc = strstr(payload, "chargingProfilePurpose");
  8496. c = 0;
  8497. memset(sstr ,0, sizeof(sstr) );
  8498. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8499. {
  8500. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8501. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8502. c++;
  8503. }
  8504. sstr[c] = '\0';
  8505. strcpy(tempchargingProfilePurposeStr,sstr);
  8506. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8507. {
  8508. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8509. {
  8510. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8511. if(ChargingProfileAdded == FALSE)
  8512. {
  8513. fprintf(outfile,"%s\n",payload);
  8514. ChargingProfileAdded = TRUE;
  8515. }
  8516. }
  8517. else
  8518. {
  8519. if(tempstackLevelInt < stackLevelInt)
  8520. {
  8521. if(ChargingProfileAdded == FALSE)
  8522. {
  8523. fprintf(outfile,"%s\n",payload);
  8524. ChargingProfileAdded = TRUE;
  8525. fprintf(outfile,"%s\n",buf);
  8526. }
  8527. else
  8528. {
  8529. fprintf(outfile,"%s\n",buf);
  8530. }
  8531. }
  8532. else
  8533. {
  8534. if(ChargingProfileAdded == FALSE)
  8535. {
  8536. fprintf(outfile,"%s\n",buf);
  8537. fprintf(outfile,"%s\n",payload);
  8538. ChargingProfileAdded = TRUE;
  8539. }
  8540. else
  8541. {
  8542. fprintf(outfile,"%s\n",buf);
  8543. }
  8544. }
  8545. }
  8546. }
  8547. else
  8548. {
  8549. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8550. {
  8551. if(ChargingProfileAdded == FALSE)
  8552. {
  8553. fprintf(outfile,"%s\n",payload);
  8554. ChargingProfileAdded = TRUE;
  8555. fprintf(outfile,"%s\n",buf);
  8556. }
  8557. else
  8558. {
  8559. fprintf(outfile,"%s\n",buf);
  8560. }
  8561. }
  8562. else if(tempstackLevelInt < stackLevelInt)
  8563. {
  8564. if(ChargingProfileAdded == FALSE)
  8565. {
  8566. fprintf(outfile,"%s\n",payload);
  8567. ChargingProfileAdded = TRUE;
  8568. fprintf(outfile,"%s\n",buf);
  8569. }
  8570. else
  8571. {
  8572. fprintf(outfile,"%s\n",buf);
  8573. }
  8574. }
  8575. else
  8576. {
  8577. if(ChargingProfileAdded == FALSE)
  8578. {
  8579. fprintf(outfile,"%s\n",buf);
  8580. fprintf(outfile,"%s\n",payload);
  8581. ChargingProfileAdded = TRUE;
  8582. }
  8583. else
  8584. {
  8585. fprintf(outfile,"%s\n",buf);
  8586. }
  8587. }
  8588. }
  8589. } // end of while loop
  8590. fclose(infile);
  8591. fclose(outfile);
  8592. sprintf(rmFileCmd,"rm -f %s",filename);
  8593. system(rmFileCmd);
  8594. rename(tempfile, filename);
  8595. #if 0
  8596. resultRename = rename(tempfile, filename);
  8597. if(resultRename == 0)
  8598. {
  8599. DEBUG_INFO("File chargingProfile renamed successfully");
  8600. }
  8601. else
  8602. {
  8603. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8604. }
  8605. #endif
  8606. result = TRUE;
  8607. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8608. }
  8609. end:
  8610. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8611. return result;
  8612. return result;
  8613. }
  8614. int handleTriggerMessageRequest(char *uuid, char *payload)
  8615. {
  8616. mtrace();
  8617. int result = FAIL;
  8618. int connectorIdIsNULL = FALSE;
  8619. int connectorIdInt =0;
  8620. char sstr[40]={0};
  8621. char requestedMessagestr[40]={0};
  8622. char comfirmstr[20]={0};
  8623. int c = 0;
  8624. char *loc;
  8625. DEBUG_INFO("handleTriggerMessageRequest\n");
  8626. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8627. c = 0;
  8628. loc = strstr(payload, "requestedMessage");
  8629. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8630. {
  8631. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8632. c++;
  8633. }
  8634. sstr[c] = '\0';
  8635. strcpy(requestedMessagestr, sstr);
  8636. c = 0;
  8637. loc = strstr(payload, "connectorId");
  8638. if(loc == NULL)
  8639. {
  8640. connectorIdIsNULL = TRUE;
  8641. }
  8642. else
  8643. {
  8644. memset(sstr ,0, sizeof(sstr) );
  8645. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8646. {
  8647. sstr[c] = loc[strlen("connectorId")+2+c];
  8648. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8649. c++;
  8650. }
  8651. sstr[c] = '\0';
  8652. connectorIdInt = atoi(sstr);
  8653. }
  8654. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8655. {
  8656. //connectorIdInt = json_object_get_int(connectorId);
  8657. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8658. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8659. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8660. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8661. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8662. }
  8663. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8664. {
  8665. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8666. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8667. return TRUE;
  8668. }
  8669. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8670. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8671. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8672. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8673. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8674. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8675. {
  8676. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8677. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8678. return TRUE;
  8679. }
  8680. else
  8681. {
  8682. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8683. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8684. }
  8685. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8686. {
  8687. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8688. {
  8689. FirmwareStatusNotificationStatus = 3;
  8690. }
  8691. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8692. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8693. }
  8694. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8695. {
  8696. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8697. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8698. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8699. }
  8700. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8701. {
  8702. sendBootNotificationRequest();
  8703. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8704. }
  8705. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8706. {
  8707. sendHeartbeatRequest(connectorIdInt);
  8708. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8709. }
  8710. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8711. {
  8712. if(connectorIdIsNULL == FALSE)
  8713. {
  8714. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8715. {
  8716. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8717. sendMeterValuesRequest(connectorIdInt -1);
  8718. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8719. }
  8720. }
  8721. else
  8722. {
  8723. for(int idx=0;idx< gunTotalNumber;idx++)
  8724. {
  8725. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8726. sendMeterValuesRequest(idx);
  8727. }
  8728. }
  8729. }
  8730. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8731. {
  8732. if(connectorIdIsNULL == FALSE)
  8733. {
  8734. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8735. {
  8736. sendStatusNotificationRequest(connectorIdInt -1);
  8737. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8738. }
  8739. }
  8740. else
  8741. {
  8742. for(int idx=0;idx< gunTotalNumber;idx++)
  8743. sendStatusNotificationRequest(idx);
  8744. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8745. }
  8746. }
  8747. return result;
  8748. }
  8749. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8750. {
  8751. mtrace();
  8752. int result = FAIL;
  8753. char sstr[6]={0};
  8754. int connectorIdInt =0;
  8755. char comfirmstr[20]={0};
  8756. int c = 0;
  8757. char *loc;
  8758. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8759. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8760. c = 0;
  8761. loc = strstr(payload, "connectorId");
  8762. memset(sstr ,0, sizeof(sstr) );
  8763. while (loc[strlen("connectorId")+2+c] != '}')
  8764. {
  8765. sstr[c] = loc[strlen("connectorId")+2+c];
  8766. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8767. c++;
  8768. }
  8769. sstr[c] = '\0';
  8770. connectorIdInt = atoi(sstr);
  8771. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8772. if(gunTotalNumber == 0)
  8773. {
  8774. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8775. goto end;
  8776. }
  8777. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8778. {
  8779. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8780. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8781. goto end;
  8782. }
  8783. else
  8784. {
  8785. //check Transaction active
  8786. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8787. {
  8788. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8789. {
  8790. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8791. {
  8792. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8793. }
  8794. }
  8795. for (int index = 0; index < CCS_QUANTITY; index++)
  8796. {
  8797. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8798. {
  8799. //stop Transaction
  8800. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8801. }
  8802. }
  8803. for (int index = 0; index < GB_QUANTITY; index++)
  8804. {
  8805. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8806. {
  8807. //stop Transaction
  8808. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8809. }
  8810. }
  8811. }
  8812. else
  8813. {
  8814. for (int index = 0; index < AC_QUANTITY; index++)
  8815. {
  8816. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8817. {
  8818. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8819. }
  8820. }
  8821. }// END FOR AC ELSE
  8822. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8823. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8824. result = TRUE;
  8825. return result;
  8826. }
  8827. end:
  8828. //json_object_put(obj); --- remove temporally
  8829. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8830. return result;
  8831. }
  8832. static char UpdateFirmwarepayloadData[300]={0};
  8833. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8834. {
  8835. mtrace();
  8836. int result = FAIL;
  8837. pthread_t t;
  8838. sendUpdateFirmwareConfirmation(uuid);
  8839. memset(UpdateFirmwarepayloadData, 0, 300);
  8840. strcpy(UpdateFirmwarepayloadData, payload);
  8841. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8842. ////pthread_join(t, NULL); //
  8843. //pthread_detach(t);
  8844. //sendUpdateFirmwareConfirmation(uuid);
  8845. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8846. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8847. return result;
  8848. }
  8849. void *UpdateFirmwareProcess(void *data)
  8850. {
  8851. pthread_detach(pthread_self());
  8852. mtrace();
  8853. int retriesInt =0, retryIntervalInt=0;
  8854. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8855. int port=0;
  8856. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8857. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8858. //char comfirmstr[20];
  8859. int isSuccess = 0;
  8860. char ftpbuf[200];
  8861. char temp[100];
  8862. char * pch;
  8863. int retriesISNULL=FALSE;
  8864. int retryInterval=FALSE;
  8865. int c = 0;
  8866. //int i = 0;
  8867. char *loc;
  8868. char sstr[300]={ 0 };
  8869. char str[300]={ 0 };
  8870. //char *str = (char*) data; // ? ?輸入資 ?
  8871. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8872. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8873. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8874. //***************location **************/
  8875. loc = strstr(str, "location");
  8876. memset(sstr ,0, sizeof(sstr) );
  8877. c = 0;
  8878. while (loc[3+strlen("location")+c] != '\"')
  8879. {
  8880. sstr[c] = loc[3+strlen("location")+c];
  8881. c++;
  8882. }
  8883. sstr[c] = '\0';
  8884. strcpy(locationstr, sstr);
  8885. //***************retries**************/
  8886. c = 0;
  8887. loc = strstr(str, "retries");
  8888. if(loc == NULL)
  8889. {
  8890. retriesISNULL=TRUE;
  8891. }
  8892. else
  8893. {
  8894. memset(sstr ,0, sizeof(sstr) );
  8895. while (loc[strlen("retries")+2+c] != ',')
  8896. {
  8897. sstr[c] = loc[strlen("retries")+2+c];
  8898. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8899. c++;
  8900. }
  8901. sstr[c] = '\0';
  8902. }
  8903. if(retriesISNULL == FALSE)
  8904. {
  8905. retriesInt = atoi(sstr);
  8906. }
  8907. //***************retrieveDate **************/
  8908. loc = strstr(str, "retrieveDate");
  8909. memset(sstr ,0, sizeof(sstr) );
  8910. c = 0;
  8911. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8912. {
  8913. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8914. c++;
  8915. }
  8916. sstr[c] = '\0';
  8917. strcpy(retrieveDatestr, sstr);
  8918. //***************retryInterval **************/
  8919. c = 0;
  8920. loc = strstr(str, "retryInterval");
  8921. memset(sstr ,0, sizeof(sstr) );
  8922. if(loc == NULL)
  8923. {
  8924. retryInterval=TRUE;
  8925. }
  8926. else
  8927. {
  8928. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8929. {
  8930. sstr[c] = loc[strlen("retryInterval")+2+c];
  8931. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8932. c++;
  8933. }
  8934. sstr[c] = '\0';
  8935. }
  8936. if(retryInterval==FALSE)
  8937. {
  8938. retryIntervalInt = atoi(sstr);
  8939. }
  8940. memset(ftppath, 0, sizeof(ftppath));
  8941. memset(path, 0, sizeof(path));
  8942. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8943. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8944. if(strncmp(locationstr,"http", 4) == 0)
  8945. {
  8946. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8947. protocol, host, path);
  8948. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8949. // protocol, user, password, host, path);
  8950. sprintf(ftppath,"/%s", path);
  8951. //DEBUG_INFO("protocol =%s\n",protocol);
  8952. //DEBUG_INFO("host =%s\n",host);
  8953. //DEBUG_INFO("path =%s\n",path);
  8954. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8955. int ftppathlen=strlen(ftppath);
  8956. int i=1;
  8957. char filenametemp[50];
  8958. while(i < ftppathlen)
  8959. {
  8960. int len=ftppathlen-i;
  8961. if(ftppath[len]== 47) // '/' ascll code: 47
  8962. {
  8963. DEBUG_INFO("compare '/' all right\n");
  8964. break;
  8965. }
  8966. i=i+1;
  8967. }
  8968. memset(filenametemp, 0, sizeof(filenametemp));
  8969. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8970. filenametemp[i+1] = 0;
  8971. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8972. do{
  8973. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8974. sleep(retryIntervalInt);
  8975. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8976. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8977. if(!isSuccess)
  8978. {
  8979. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8980. }
  8981. else
  8982. {
  8983. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8984. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8985. isUpdateRequest = TRUE;
  8986. }
  8987. }
  8988. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8989. {
  8990. memset(ftpbuf, 0, sizeof(ftpbuf));
  8991. memset(temp, 0, sizeof(temp));
  8992. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8993. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8994. int ftppathlen=strlen(ftpbuf);
  8995. int i=1;
  8996. char filenametemp[50];
  8997. while(i < ftppathlen)
  8998. {
  8999. int len=ftppathlen-i;
  9000. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9001. {
  9002. DEBUG_INFO(" compare '/' all right\n");
  9003. break;
  9004. }
  9005. i=i+1;
  9006. }
  9007. memset(filenametemp, 0, sizeof(filenametemp));
  9008. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9009. filenametemp[i+1] = 0;
  9010. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9011. pch=strchr(temp,'@');
  9012. if(pch==NULL)
  9013. {
  9014. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9015. protocol, host, &port, path);
  9016. strcpy(user,"anonymous");
  9017. strcpy(password,"");
  9018. }
  9019. else
  9020. {
  9021. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9022. protocol, user, password, host, &port, path);
  9023. }
  9024. sscanf(host,"%[^/]%s",host1, path1);
  9025. sprintf(ftppath,"%s", path1);
  9026. //DEBUG_INFO("protocol =%s\n",protocol);
  9027. //DEBUG_INFO("user =%s\n",user);
  9028. //DEBUG_INFO("password =%s\n",password);
  9029. //DEBUG_INFO("host1 =%s\n",host1);
  9030. //DEBUG_INFO("port =%d\n",port);
  9031. //DEBUG_INFO("path1 =%s\n",path1);
  9032. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9033. //ftpFile(host, user, password, port, ftppath, fname);
  9034. //download firmware pthred
  9035. if(port == 0)
  9036. {
  9037. port = 21;
  9038. }
  9039. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9040. do{
  9041. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9042. sleep(retryIntervalInt);
  9043. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9044. if(!isSuccess)
  9045. {
  9046. //BulldogUtil.sleepMs(interval*1000);
  9047. DEBUG_INFO("Update firmware request and download file fail.\n");
  9048. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9049. }
  9050. else
  9051. {
  9052. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9053. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9054. isUpdateRequest = TRUE;
  9055. }
  9056. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9057. }
  9058. else
  9059. {
  9060. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9061. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9062. }
  9063. pthread_exit(NULL);
  9064. }
  9065. //==========================================
  9066. // Handle server response routine
  9067. //==========================================
  9068. void handleAuthorizeResponse(char *payload, int gun_index)
  9069. {
  9070. mtrace();
  9071. char expiryDatestr[30]={0};
  9072. char parentIdTagstr[20]={0};
  9073. char statusstr[20]={0};
  9074. char expiryDatestrtemp[30]={0};
  9075. char parentIdTagstrtemp[20]={0};
  9076. char IdTagstrtemp[20]={0};
  9077. char statusstrtemp[20]={0};
  9078. int expiryDateISNULL=FALSE;
  9079. int parentIdTagISNULL=FALSE;
  9080. char sstr[160]={ 0 };
  9081. char* filename = AuthorizationCache_JSON;
  9082. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9083. int c = 0;
  9084. char *loc;
  9085. int resultRename=0;
  9086. int responseIdTagInfoAsZero= 0;
  9087. char rmFileCmd[50]={0};
  9088. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9089. //***********expiryDate*************/
  9090. loc = strstr(payload, "expiryDate");
  9091. memset(sstr ,0, sizeof(sstr) );
  9092. c = 0;
  9093. if(loc == NULL)
  9094. {
  9095. expiryDateISNULL = TRUE;
  9096. }
  9097. else
  9098. {
  9099. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9100. {
  9101. sstr[c] = loc[3+strlen("expiryDate")+c];
  9102. c++;
  9103. }
  9104. sstr[c] = '\0';
  9105. strcpy(expiryDatestr, sstr);
  9106. }
  9107. //***********parentIdTag*************/
  9108. loc = strstr(payload, "parentIdTag");
  9109. memset(sstr ,0, sizeof(sstr) );
  9110. c = 0;
  9111. if(loc == NULL)
  9112. {
  9113. parentIdTagISNULL = TRUE;
  9114. }
  9115. else
  9116. {
  9117. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9118. {
  9119. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9120. c++;
  9121. }
  9122. sstr[c] = '\0';
  9123. strcpy(parentIdTagstr, sstr);
  9124. }
  9125. //***********status*************/
  9126. loc = strstr(payload, "status");
  9127. memset(sstr ,0, sizeof(sstr) );
  9128. c = 0;
  9129. while (loc[3+strlen("status")+c] != '\"')
  9130. {
  9131. sstr[c] = loc[3+strlen("status")+c];
  9132. c++;
  9133. }
  9134. sstr[c] = '\0';
  9135. strcpy(statusstr, sstr);
  9136. if(expiryDateISNULL == FALSE)
  9137. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9138. if(parentIdTagISNULL == FALSE)
  9139. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9140. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9141. //Update idTag information to authorization cache if supproted
  9142. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9143. {
  9144. if((access(filename,F_OK))!=-1)
  9145. {
  9146. printf("AuthorizationCache exist.\n");
  9147. }
  9148. else
  9149. {
  9150. printf("AuthorizationCache not exist\n");
  9151. FILE *log = fopen(filename, "w+");
  9152. if(log == NULL)
  9153. {
  9154. printf("log is NULL\n");
  9155. goto out;
  9156. }
  9157. else
  9158. {
  9159. fclose(log);
  9160. }
  9161. }
  9162. FILE *infile;
  9163. FILE *outfile;
  9164. // open file for writing
  9165. infile = fopen (filename, "r");
  9166. outfile = fopen (tempfile, "w");
  9167. //*检测到文件结束标识返回1,否则返回0。*/
  9168. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9169. int c;
  9170. c = fgetc(infile);
  9171. //DEBUG_INFO("c:%d\n",c);
  9172. rewind(infile);
  9173. if(c == EOF)
  9174. {
  9175. DEBUG_INFO("Orignal File is NULL\n");
  9176. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9177. {
  9178. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9179. }
  9180. else
  9181. {
  9182. strcpy(expiryDatestrtemp, "");
  9183. }
  9184. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9185. {
  9186. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9187. }
  9188. else
  9189. {
  9190. //write Authorize IdTag
  9191. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9192. }
  9193. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9194. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9195. fclose(infile);
  9196. fclose(outfile);
  9197. sprintf(rmFileCmd,"rm -f %s",filename);
  9198. system(rmFileCmd);
  9199. resultRename = rename(tempfile, filename);
  9200. if(resultRename == 0)
  9201. {
  9202. printf("File renamed successfully");
  9203. }
  9204. else
  9205. {
  9206. printf("Error: unable to rename the file");
  9207. }
  9208. }
  9209. else
  9210. {
  9211. char buf[160]={0};
  9212. while (fgets(buf, sizeof(buf), infile) != NULL)
  9213. {
  9214. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9215. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9216. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9217. memset(statusstr, 0, sizeof(statusstrtemp));
  9218. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9219. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9220. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9221. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9222. //------------------IdTag-----------------------
  9223. loc = strstr(buf, "idTag");
  9224. memset(sstr ,0, sizeof(sstr) );
  9225. c = 0;
  9226. while (loc[3+strlen("idTag")+c] != '\"')
  9227. {
  9228. sstr[c] = loc[3+strlen("idTag")+c];
  9229. c++;
  9230. }
  9231. sstr[c] = '\0';
  9232. strcpy(IdTagstrtemp,sstr);
  9233. //*********************expiryDate***************/
  9234. loc = strstr(buf, "expiryDate");
  9235. memset(sstr ,0, sizeof(sstr) );
  9236. c = 0;
  9237. while (loc[3+strlen("expiryDate")+c] != '\"')
  9238. {
  9239. sstr[c] = loc[3+strlen("expiryDate")+c];
  9240. c++;
  9241. }
  9242. sstr[c] = '\0';
  9243. strcpy(expiryDatestr,sstr);
  9244. //*********************parentIdTag***************/
  9245. loc = strstr(buf, "parentIdTag");
  9246. memset(sstr ,0, sizeof(sstr) );
  9247. c = 0;
  9248. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9249. {
  9250. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9251. c++;
  9252. }
  9253. sstr[c] = '\0';
  9254. strcpy(parentIdTagstr,sstr);
  9255. //*********************status***************/
  9256. loc = strstr(buf, "status");
  9257. memset(sstr ,0, sizeof(sstr) );
  9258. c = 0;
  9259. while (loc[3+strlen("status")+c] != '\"')
  9260. {
  9261. sstr[c] = loc[3+strlen("status")+c];
  9262. c++;
  9263. }
  9264. sstr[c] = '\0';
  9265. strcpy(statusstr,sstr);
  9266. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9267. {
  9268. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9269. responseIdTagInfoAsZero = 1;
  9270. }
  9271. else
  9272. {
  9273. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9274. }
  9275. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9276. {
  9277. //modify item
  9278. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9279. {
  9280. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9281. }
  9282. else
  9283. {
  9284. strcpy(expiryDatestrtemp, "");
  9285. }
  9286. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9287. {
  9288. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9289. }
  9290. else
  9291. {
  9292. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9293. }
  9294. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9295. }
  9296. else
  9297. {
  9298. //wrie original item
  9299. strcpy(expiryDatestrtemp, expiryDatestr);
  9300. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9301. strcpy(statusstrtemp, statusstr);
  9302. }
  9303. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9304. }
  9305. fclose(infile);
  9306. fclose(outfile);
  9307. sprintf(rmFileCmd,"rm -f %s",filename);
  9308. system(rmFileCmd);
  9309. resultRename = rename(tempfile, filename);
  9310. if(resultRename == 0)
  9311. {
  9312. DEBUG_INFO("File renamed successfully");
  9313. }
  9314. else
  9315. {
  9316. DEBUG_INFO("Error: unable to rename the file");
  9317. }
  9318. }
  9319. }
  9320. out:
  9321. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9322. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9323. authorizeRetryTimes = 0;
  9324. }
  9325. void handleBootNotificationResponse(char *payload, int gun_index)
  9326. {
  9327. mtrace();
  9328. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9329. char statusStr[12]={0};
  9330. char currentTimeStr[30]={0};
  9331. char *loc;
  9332. int intervalInt = 0;
  9333. int c = 0;
  9334. //double diff_t;
  9335. struct tm tp;
  9336. char buf[28]={0};
  9337. char timebuf[50]={0};
  9338. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9339. //*** interval ****/
  9340. c = 0;
  9341. loc = strstr(payload, "interval");
  9342. //printf("loc=%s\n",loc);
  9343. memset(sstr ,0, sizeof(sstr) );
  9344. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9345. {
  9346. sstr[c] = loc[strlen("interval")+2+c];
  9347. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9348. c++;
  9349. }
  9350. sstr[c] = '\0';
  9351. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9352. intervalInt = atoi(sstr);
  9353. //***status ****/
  9354. loc = strstr(payload, "status");
  9355. memset(sstr ,0, sizeof(sstr) );
  9356. c = 0;
  9357. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9358. {
  9359. sstr[c] = loc[3+strlen("status")+c];
  9360. c++;
  9361. }
  9362. sstr[c] = '\0';
  9363. strcpy(statusStr, sstr);
  9364. //***currentTime ****/
  9365. loc = strstr(payload, "currentTime");
  9366. //printf("loc=%s\n",loc);
  9367. memset(sstr ,0, sizeof(sstr) );
  9368. c = 0;
  9369. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9370. {
  9371. sstr[c] = loc[3+strlen("currentTime")+c];
  9372. c++;
  9373. }
  9374. sstr[c] = '\0';
  9375. strcpy(currentTimeStr, sstr);
  9376. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9377. HeartBeatWaitTime = BootNotificationInterval;
  9378. clientTime.Heartbeat=time((time_t*)NULL);
  9379. //write back to ShmOCPP16Data->BootNotification
  9380. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9381. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9382. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9383. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9384. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9385. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9386. {
  9387. server_sign = TRUE;
  9388. server_pending =FALSE;
  9389. }
  9390. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9391. {
  9392. server_pending = TRUE;
  9393. }
  9394. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9395. tp.tm_isdst = -1;
  9396. //time_t utc = mktime(&tp);
  9397. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9398. memset(timebuf, 0, sizeof timebuf);
  9399. sprintf(timebuf,"date -s '%s'",buf);
  9400. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9401. system(timebuf);
  9402. //==============================================
  9403. // RTC sync
  9404. //==============================================
  9405. system("/sbin/hwclock -w --systohc");
  9406. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9407. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9408. }
  9409. void handleDataTransferResponse(char *payload, int gun_index)
  9410. {
  9411. char sstr[160]={0};//sstr[200]={ 0 };
  9412. int c = 0;
  9413. char *loc;
  9414. DEBUG_INFO("handleDataTransferResponse ...\n");
  9415. loc = strstr(payload, "status");
  9416. printf("loc=%s\n",loc);
  9417. c = 0;
  9418. while (loc[3+strlen("status")+c] != '\"')
  9419. {
  9420. sstr[c] = loc[3+strlen("status")+c];
  9421. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9422. c++;
  9423. }
  9424. sstr[c] = '\0';
  9425. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9426. }
  9427. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9428. {
  9429. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9430. //struct json_object *obj;
  9431. // obj = json_tokener_parse(payload);
  9432. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9433. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9434. //No fields are defined.
  9435. }
  9436. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9437. {
  9438. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9439. //struct json_object *obj;
  9440. // obj = json_tokener_parse(payload);
  9441. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9442. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9443. //No fields are defined.
  9444. }
  9445. void handleHeartbeatResponse(char *payload, int gun_index)
  9446. {
  9447. mtrace();
  9448. //double diff_t;
  9449. struct tm tp;
  9450. char buf[28]={0};
  9451. char timebuf[50]={0};
  9452. char sstr[30]={ 0 };
  9453. int c = 0;
  9454. char *loc;
  9455. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9456. c = 0;
  9457. loc = strstr(payload, "currentTime");
  9458. memset(sstr ,0, sizeof(sstr) );
  9459. while (loc[3+strlen("currentTime")+c] != '\"')
  9460. {
  9461. sstr[c] = loc[3+strlen("currentTime")+c];
  9462. c++;
  9463. }
  9464. sstr[c] = '\0';
  9465. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9466. // #ifdef SystemLogMessage
  9467. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9468. // #endif
  9469. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9470. tp.tm_isdst = -1;
  9471. //time_t utc = mktime(&tp);
  9472. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9473. memset(timebuf, 0, sizeof timebuf);
  9474. sprintf(timebuf,"date -s '%s'",buf);
  9475. system(timebuf);
  9476. //==============================================
  9477. // RTC sync
  9478. //==============================================
  9479. system("/sbin/hwclock -w --systohc");
  9480. if(FirstHeartBeat == 0)
  9481. {
  9482. FirstHeartBeat = 1;
  9483. }
  9484. HeartBeatWithNOResponse = 0;
  9485. //--------Print Out HeartBeat log
  9486. {
  9487. double diff_t;
  9488. struct tm tp,tp1;
  9489. // BootNotification Receive Time
  9490. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9491. tp.tm_isdst = -1;
  9492. time_t BootNotificationReceiveTime = mktime(&tp);
  9493. //HeartBeat Receive Time
  9494. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9495. tp1.tm_isdst = -1;
  9496. time_t HeartBeatReceiveTime = mktime(&tp1);
  9497. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9498. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9499. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9500. {
  9501. HeartBeatCountPerHour = (int)diff_t / 3600;
  9502. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9503. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9504. }
  9505. }
  9506. }
  9507. void handleMeterValuesResponse(char *payload, int gun_index)
  9508. {
  9509. mtrace();
  9510. //struct json_object *obj;
  9511. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9512. //No fields are defined.
  9513. }
  9514. void handleStartTransactionResponse(char *payload, int gun_index)
  9515. {
  9516. mtrace();
  9517. char sstr[28]={ 0 };
  9518. int c = 0;
  9519. char *loc;
  9520. int transactionIdInt = 0;
  9521. FILE *outfile;
  9522. char data[100]={0};
  9523. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9524. DEBUG_INFO("handleStartTransactionResponse\n");
  9525. //****************expiryDate********************/
  9526. loc = strstr(payload, "expiryDate");
  9527. if(loc == NULL)
  9528. {
  9529. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9530. }
  9531. else
  9532. {
  9533. c = 0;
  9534. memset(sstr ,0, sizeof(sstr) );
  9535. while (loc[3+strlen("expiryDate")+c] != '\"')
  9536. {
  9537. sstr[c] = loc[3+strlen("expiryDate")+c];
  9538. c++;
  9539. }
  9540. sstr[c] = '\0';
  9541. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9542. }
  9543. //****************parentIdTag********************/
  9544. loc = strstr(payload, "parentIdTag");
  9545. if(loc == NULL)
  9546. {
  9547. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9548. }
  9549. else
  9550. {
  9551. c = 0;
  9552. memset(sstr ,0, sizeof(sstr) );
  9553. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9554. {
  9555. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9556. c++;
  9557. }
  9558. sstr[c] = '\0';
  9559. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9560. }
  9561. //****************status********************/
  9562. loc = strstr(payload, "status");
  9563. if(loc == NULL)
  9564. {
  9565. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9566. }
  9567. else
  9568. {
  9569. c = 0;
  9570. memset(sstr ,0, sizeof(sstr) );
  9571. while (loc[3+strlen("status")+c] != '\"')
  9572. {
  9573. sstr[c] = loc[3+strlen("status")+c];
  9574. c++;
  9575. }
  9576. sstr[c] = '\0';
  9577. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9578. }
  9579. //****************transactionId********************/
  9580. c=0;
  9581. loc = strstr(payload, "transactionId");
  9582. memset(sstr ,0, sizeof(sstr) );
  9583. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9584. {
  9585. sstr[c] = loc[strlen("transactionId")+2+c];
  9586. c++;
  9587. }
  9588. sstr[c] = '\0';
  9589. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9590. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9591. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9592. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9593. //-----------Start : write to the Queue TransactionId file -----------------//
  9594. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9595. {
  9596. //DEBUG_INFO("QueueTransactionId exist.\n");
  9597. }
  9598. else
  9599. {
  9600. //DEBUG_INFO("QueueTransactionId not exist\n");
  9601. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9602. if(log == NULL)
  9603. {
  9604. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9605. return ;
  9606. }
  9607. else
  9608. {
  9609. fclose(log);
  9610. }
  9611. }
  9612. // open file for writing
  9613. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9614. //DEBUG_INFO("data=%s\n",data);
  9615. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9616. fputs(data, outfile);
  9617. //fputs("\n", outfile);
  9618. fclose (outfile);
  9619. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9620. TransactionId[gun_index] = transactionIdInt;
  9621. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9622. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9623. #ifdef SystemLogMessage
  9624. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9625. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9626. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9627. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9628. #endif
  9629. //if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  9630. //{
  9631. // //add Charging Record
  9632. // SettingChargingRecord(gun_index, transactionIdInt);
  9633. //}
  9634. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  9635. }
  9636. void handleStatusNotificationResponse(char *payload, int gun_index)
  9637. {
  9638. mtrace();
  9639. printf("handleStatusNotificationResponse\n");
  9640. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9641. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9642. }
  9643. void handleStopTransactionnResponse(char *payload, int gun_index)
  9644. {
  9645. mtrace();
  9646. char sstr[30]={ 0 };
  9647. int c = 0;
  9648. char *loc;
  9649. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9650. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9651. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9652. loc = strstr(payload, "idTagInfo");
  9653. //***********************idTagInfo************************/
  9654. if(loc != NULL)
  9655. {
  9656. //***********************expiryDate************************/
  9657. loc = strstr(payload, "expiryDate");
  9658. if(loc != NULL)
  9659. {
  9660. memset(sstr ,0, sizeof(sstr) );
  9661. c = 0;
  9662. while (loc[3+strlen("expiryDate")+c] != '\"')
  9663. {
  9664. sstr[c] = loc[3+strlen("expiryDate")+c];
  9665. c++;
  9666. }
  9667. sstr[c] = '\0';
  9668. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9669. }
  9670. //***********************parentIdTag************************/
  9671. loc = strstr(payload, "parentIdTag");
  9672. if(loc != NULL)
  9673. {
  9674. memset(sstr ,0, sizeof(sstr) );
  9675. c = 0;
  9676. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9677. {
  9678. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9679. c++;
  9680. }
  9681. sstr[c] = '\0';
  9682. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9683. }
  9684. //***********************status************************/
  9685. loc = strstr(payload, "status");
  9686. memset(sstr ,0, sizeof(sstr) );
  9687. c = 0;
  9688. while (loc[3+strlen("status")+c] != '\"')
  9689. {
  9690. sstr[c] = loc[3+strlen("status")+c];
  9691. c++;
  9692. }
  9693. sstr[c] = '\0';
  9694. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9695. }
  9696. #ifdef SystemLogMessage
  9697. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9698. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9699. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9700. #endif
  9701. }
  9702. //==========================================
  9703. // Handle Error routine
  9704. //==========================================
  9705. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9706. {
  9707. mtrace();
  9708. #ifdef SystemLogMessage
  9709. DEBUG_INFO("errorCode: %s\n", errorCode);
  9710. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9711. DEBUG_INFO("errorDetails: %s\n", payload);
  9712. #endif
  9713. }
  9714. //===============================================
  9715. // Common routine
  9716. //===============================================
  9717. int initialConfigurationTable(void)
  9718. {
  9719. FILE *fp;
  9720. FILE *outfile;
  9721. char str[200]={0};
  9722. char sstr[100]={0};
  9723. int c = 0;
  9724. char *loc;
  9725. printf("initialConfigurationTable \n");
  9726. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9727. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9728. {
  9729. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9730. if(outfile == NULL) {
  9731. DEBUG_INFO("Error opening file");
  9732. return FALSE;
  9733. }
  9734. /*Core Profile*/
  9735. //AllowOfflineTxForUnknownId
  9736. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 0;
  9737. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "true", "FALSE");
  9741. //AuthorizationCacheEnabled
  9742. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9746. //AuthorizeRemoteTxRequests
  9747. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9751. //BlinkRepeat
  9752. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9756. //ClockAlignedDataInterval
  9757. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9761. //ConnectionTimeOut
  9762. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9766. //GetConfigurationMaxKeys
  9767. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9771. // HeartbeatInterval
  9772. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9776. // LightIntensity
  9777. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9781. // LocalAuthorizeOffline
  9782. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9786. // LocalPreAuthorize
  9787. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9791. // MaxEnergyOnInvalidId
  9792. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9795. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9797. // MeterValuesAlignedData
  9798. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9802. // MeterValuesAlignedDataMaxLength
  9803. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9807. // MeterValuesSampledData
  9808. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9812. // MeterValuesSampledDataMaxLength
  9813. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9817. // MeterValueSampleInterval
  9818. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9822. // MinimumStatusDuration
  9823. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9826. server_cycle_Status = 120; //StatusNotification cycle
  9827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  9828. // NumberOfConnectors
  9829. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9831. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9832. {
  9833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9834. }
  9835. else
  9836. {
  9837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9838. }
  9839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9840. // ResetRetries
  9841. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9845. // ConnectorPhaseRotation
  9846. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9850. // ConnectorPhaseRotationMaxLength
  9851. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9855. // StopTransactionOnEVSideDisconnect
  9856. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9860. // StopTransactionOnInvalidId
  9861. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  9862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  9865. // StopTxnAlignedData
  9866. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9870. // StopTxnAlignedDataMaxLength
  9871. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9875. // StopTxnSampledData
  9876. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9880. // StopTxnSampledDataMaxLength
  9881. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9884. {
  9885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9886. }
  9887. else
  9888. {
  9889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9890. }
  9891. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9893. // SupportedFeatureProfiles
  9894. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9898. // SupportedFeatureProfilesMaxLength
  9899. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9903. // TransactionMessageAttempts
  9904. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9907. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9909. // TransactionMessageRetryInterval
  9910. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9913. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9915. // UnlockConnectorOnEVSideDisconnect
  9916. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9920. // WebSocketPingInterval
  9921. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9925. //* Local Auth List Management Profile*/
  9926. #if 0
  9927. //For OCTT Test Case
  9928. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9931. #endif
  9932. #if 1
  9933. //LocalAuthListEnabled
  9934. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9938. #endif
  9939. //LocalAuthListMaxLength
  9940. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9944. //SendLocalListMaxLength
  9945. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9949. //ReserveConnectorZeroSupported
  9950. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9954. //* Smart Charging Profile */
  9955. //ChargeProfileMaxStackLevel
  9956. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9960. // ChargingScheduleAllowedChargingRateUnit
  9961. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9965. // ChargingScheduleMaxPeriods
  9966. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9970. // ConnectorSwitch3to1PhaseSupported
  9971. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9975. // MaxChargingProfilesInstalled
  9976. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9980. fclose(outfile);
  9981. }
  9982. else
  9983. {
  9984. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9985. char keystr[60]={0};
  9986. char readonlystr[10]={0};
  9987. char valuestr[100]={0};
  9988. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9989. if(fp == NULL) {
  9990. DEBUG_INFO("Error opening file");
  9991. return FALSE;
  9992. }
  9993. while( fgets (str, sizeof(str), fp)!=NULL )
  9994. {
  9995. //DEBUG_INFO("Get Configuration \n");
  9996. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9997. //*************************key*********************************/
  9998. loc = strstr(str, "key");
  9999. c = 0;
  10000. memset(sstr ,0, sizeof(sstr) );
  10001. while (loc[strlen("key")+3+c] != '\"')
  10002. {
  10003. sstr[c] = loc[strlen("key")+3+c];
  10004. c++;
  10005. }
  10006. sstr[c] = '\0';
  10007. strcpy(keystr,sstr);
  10008. //*************************readonly*********************************/
  10009. loc = strstr(str, "readonly");
  10010. c = 0;
  10011. memset(sstr ,0, sizeof(sstr) );
  10012. while (loc[strlen("readonly")+2+c] != ',')
  10013. {
  10014. sstr[c] = loc[strlen("readonly")+2+c];
  10015. c++;
  10016. }
  10017. sstr[c] = '\0';
  10018. strcpy(readonlystr,sstr);
  10019. //*************************value*********************************/
  10020. loc = strstr(str, "value");
  10021. c = 0;
  10022. memset(sstr ,0, sizeof(sstr) );
  10023. while (loc[strlen("value")+3+c] != '\"')
  10024. {
  10025. sstr[c] = loc[strlen("value")+3+c];
  10026. c++;
  10027. }
  10028. sstr[c] = '\0';
  10029. strcpy(valuestr,sstr);
  10030. // DEBUG_INFO("keystr=%s\n",keystr);
  10031. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10032. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10033. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10034. {
  10035. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10036. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10038. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10039. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10040. }
  10041. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10042. {
  10043. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10044. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10046. }
  10047. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10048. {
  10049. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10050. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10051. }
  10052. if(strcmp(keystr, "BlinkRepeat") == 0)
  10053. {
  10054. //Charger.BlinkRepeat = Integer.parseInt(value);
  10055. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10057. }
  10058. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10059. {
  10060. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10062. }
  10063. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10064. {
  10065. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10067. }
  10068. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10069. {
  10070. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10072. }
  10073. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10074. {
  10075. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10077. HeartBeatWaitTime = atoi(valuestr);
  10078. }
  10079. if(strcmp(keystr, "LightIntensity") == 0)
  10080. {
  10081. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10083. }
  10084. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10085. {
  10086. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10088. }
  10089. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10090. {
  10091. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10093. }
  10094. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10095. {
  10096. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10098. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10099. }
  10100. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10101. {
  10102. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10104. }
  10105. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10106. {
  10107. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10109. }
  10110. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10111. {
  10112. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10114. }
  10115. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10116. {
  10117. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10119. }
  10120. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10121. {
  10122. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10124. }
  10125. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10126. {
  10127. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10129. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10130. }
  10131. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10132. {
  10133. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10135. }
  10136. if(strcmp(keystr, "ResetRetries") == 0)
  10137. {
  10138. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10140. }
  10141. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10142. {
  10143. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10145. }
  10146. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10147. {
  10148. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10150. }
  10151. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10152. {
  10153. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10155. }
  10156. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10157. {
  10158. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10160. }
  10161. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10162. {
  10163. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10165. }
  10166. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10167. {
  10168. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10170. }
  10171. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10172. {
  10173. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10175. }
  10176. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10177. {
  10178. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10180. }
  10181. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10182. {
  10183. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10185. }
  10186. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10187. {
  10188. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10190. }
  10191. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10192. {
  10193. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10195. TransactionMessageAttemptsValue = atoi(valuestr);
  10196. }
  10197. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10198. {
  10199. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10201. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10202. }
  10203. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10204. {
  10205. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10207. }
  10208. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10209. {
  10210. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10212. }
  10213. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10214. {
  10215. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10217. }
  10218. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10219. {
  10220. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10222. }
  10223. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10224. {
  10225. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10227. }
  10228. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10229. {
  10230. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10232. }
  10233. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10234. {
  10235. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10237. }
  10238. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10239. {
  10240. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10242. }
  10243. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10244. {
  10245. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10247. }
  10248. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10249. {
  10250. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10252. }
  10253. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10254. {
  10255. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10257. }
  10258. }
  10259. fclose(fp);
  10260. }
  10261. return 0;
  10262. }
  10263. void StoreConfigurationTable(void)
  10264. {
  10265. FILE *outfile;
  10266. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10267. if(outfile == NULL)
  10268. {
  10269. DEBUG_INFO("Error opening file");
  10270. return ;
  10271. }
  10272. /*Core Profile*/
  10273. //AllowOfflineTxForUnknownId
  10274. /*
  10275. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10276. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10279. */
  10280. //DEBUG_INFO("data=%s\n",data);
  10281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10282. //AuthorizationCacheEnabled
  10283. /*
  10284. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10287. */
  10288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10289. //AuthorizeRemoteTxRequests
  10290. /*
  10291. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10294. */
  10295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10296. //BlinkRepeat
  10297. /*
  10298. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10301. */
  10302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10303. //ClockAlignedDataInterval
  10304. /*
  10305. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10308. */
  10309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10310. //ConnectionTimeOut
  10311. /*
  10312. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10315. */
  10316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10317. //GetConfigurationMaxKeys
  10318. /*
  10319. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10322. */
  10323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10324. // HeartbeatInterval
  10325. /*
  10326. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10329. */
  10330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10331. // LightIntensity
  10332. /*
  10333. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10336. */
  10337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10338. // LocalAuthorizeOffline
  10339. /*
  10340. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10343. */
  10344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10345. // LocalPreAuthorize
  10346. /*
  10347. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10350. */
  10351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10352. // MaxEnergyOnInvalidId
  10353. /*
  10354. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10357. */
  10358. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10360. // MeterValuesAlignedData
  10361. /*
  10362. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10365. */
  10366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10367. // MeterValuesAlignedDataMaxLength
  10368. /*
  10369. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10372. */
  10373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10374. // MeterValuesSampledData
  10375. /*
  10376. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10379. */
  10380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10381. // MeterValuesSampledDataMaxLength
  10382. /*
  10383. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10386. */
  10387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10388. // MeterValueSampleInterval
  10389. /*
  10390. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10393. */
  10394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10395. // MinimumStatusDuration
  10396. /*
  10397. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10400. */
  10401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10402. // NumberOfConnectors
  10403. /*
  10404. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10407. {
  10408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10409. }
  10410. else
  10411. {
  10412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10413. }
  10414. */
  10415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10416. // ResetRetries
  10417. /*
  10418. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10421. */
  10422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10423. // ConnectorPhaseRotation
  10424. /*
  10425. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10428. */
  10429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10430. // ConnectorPhaseRotationMaxLength
  10431. /*
  10432. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10435. */
  10436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10437. // StopTransactionOnEVSideDisconnect
  10438. /*
  10439. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10442. */
  10443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10444. // StopTransactionOnInvalidId
  10445. /*
  10446. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10449. */
  10450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10451. // StopTxnAlignedData
  10452. /*
  10453. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10456. */
  10457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10458. // StopTxnAlignedDataMaxLength
  10459. /*
  10460. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10463. */
  10464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10465. // StopTxnSampledData
  10466. /*
  10467. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10470. */
  10471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10472. // StopTxnSampledDataMaxLength
  10473. /*
  10474. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10477. */
  10478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10479. // SupportedFeatureProfiles
  10480. /*
  10481. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10484. */
  10485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10486. // SupportedFeatureProfilesMaxLength
  10487. /*
  10488. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10491. */
  10492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10493. // TransactionMessageAttempts
  10494. /*
  10495. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10498. */
  10499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10500. // TransactionMessageRetryInterval
  10501. /*
  10502. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10505. */
  10506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10507. // UnlockConnectorOnEVSideDisconnect
  10508. /*
  10509. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10512. */
  10513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10514. // WebSocketPingInterval
  10515. /*
  10516. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10519. */
  10520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10521. //* Local Auth List Management Profile*/
  10522. //LocalAuthListEnabled
  10523. /*
  10524. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10527. */
  10528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10529. //LocalAuthListMaxLength
  10530. /*
  10531. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10534. */
  10535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10536. //SendLocalListMaxLength
  10537. /*
  10538. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10541. */
  10542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10543. //ReserveConnectorZeroSupported
  10544. /*
  10545. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10548. */
  10549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10550. //* Smart Charging Profile */
  10551. //ChargeProfileMaxStackLevel
  10552. /*
  10553. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10556. */
  10557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10558. // ChargingScheduleAllowedChargingRateUnit
  10559. /*
  10560. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10563. */
  10564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10565. // ChargingScheduleMaxPeriods
  10566. /*
  10567. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10570. */
  10571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10572. // ConnectorSwitch3to1PhaseSupported
  10573. /*
  10574. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10577. */
  10578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10579. // MaxChargingProfilesInstalled
  10580. /*
  10581. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10584. */
  10585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10586. fclose(outfile);
  10587. }
  10588. void getKeyValue(char *keyReq)
  10589. {
  10590. int isEmpty = FALSE;
  10591. int isKnowKey = FALSE;
  10592. //int unKnowIndex = 0;
  10593. DEBUG_INFO("getKeyValue \n");
  10594. DEBUG_INFO("keyReq=%s \n",keyReq);
  10595. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10596. isEmpty = TRUE;
  10597. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10598. {
  10599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10602. {
  10603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10604. }
  10605. else
  10606. {
  10607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10608. }
  10609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10610. isKnowKey = TRUE;
  10611. }
  10612. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10613. {
  10614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10617. {
  10618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10619. }
  10620. else
  10621. {
  10622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10623. }
  10624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10625. isKnowKey = TRUE;
  10626. }
  10627. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10628. {
  10629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10632. {
  10633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10634. }
  10635. else
  10636. {
  10637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10638. }
  10639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10640. isKnowKey = TRUE;
  10641. }
  10642. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10643. {
  10644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10647. {
  10648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10649. }
  10650. else
  10651. {
  10652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10653. }
  10654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10655. isKnowKey = TRUE;
  10656. }
  10657. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10658. {
  10659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10662. {
  10663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10664. }
  10665. else
  10666. {
  10667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10668. }
  10669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10670. isKnowKey = TRUE;
  10671. }
  10672. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10673. {
  10674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10677. {
  10678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10679. }
  10680. else
  10681. {
  10682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10683. }
  10684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10685. isKnowKey = TRUE;
  10686. }
  10687. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10688. {
  10689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10692. {
  10693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10694. }
  10695. else
  10696. {
  10697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10698. }
  10699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10700. isKnowKey = TRUE;
  10701. }
  10702. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10703. {
  10704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10707. {
  10708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10709. }
  10710. else
  10711. {
  10712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10713. }
  10714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10715. isKnowKey = TRUE;
  10716. }
  10717. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10718. {
  10719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10722. {
  10723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10724. }
  10725. else
  10726. {
  10727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10728. }
  10729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10730. isKnowKey = TRUE;
  10731. }
  10732. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10733. {
  10734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10737. {
  10738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10739. }
  10740. else
  10741. {
  10742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10743. }
  10744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10745. isKnowKey = TRUE;
  10746. }
  10747. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10748. {
  10749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10752. {
  10753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10754. }
  10755. else
  10756. {
  10757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10758. }
  10759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10760. isKnowKey = TRUE;
  10761. }
  10762. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10763. {
  10764. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10767. {
  10768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10769. }
  10770. else
  10771. {
  10772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10773. }
  10774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10775. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10776. isKnowKey = TRUE;
  10777. }
  10778. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10779. {
  10780. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10783. {
  10784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10785. }
  10786. else
  10787. {
  10788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10789. }
  10790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10791. isKnowKey = TRUE;
  10792. }
  10793. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10794. {
  10795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10798. {
  10799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10800. }
  10801. else
  10802. {
  10803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10804. }
  10805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10806. isKnowKey = TRUE;
  10807. }
  10808. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10809. {
  10810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10813. {
  10814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10815. }
  10816. else
  10817. {
  10818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10819. }
  10820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10821. isKnowKey = TRUE;
  10822. }
  10823. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10824. {
  10825. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10828. {
  10829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10830. }
  10831. else
  10832. {
  10833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10834. }
  10835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10836. isKnowKey = TRUE;
  10837. }
  10838. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10839. {
  10840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10843. {
  10844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10845. }
  10846. else
  10847. {
  10848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10849. }
  10850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10851. isKnowKey = TRUE;
  10852. }
  10853. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10854. {
  10855. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10858. {
  10859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10860. }
  10861. else
  10862. {
  10863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10864. }
  10865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10866. isKnowKey = TRUE;
  10867. }
  10868. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10869. {
  10870. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10873. {
  10874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10875. }
  10876. else
  10877. {
  10878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10879. }
  10880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10881. isKnowKey = TRUE;
  10882. }
  10883. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10884. {
  10885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10888. {
  10889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10890. }
  10891. else
  10892. {
  10893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10894. }
  10895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10896. isKnowKey = TRUE;
  10897. }
  10898. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10899. {
  10900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10903. {
  10904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10905. }
  10906. else
  10907. {
  10908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10909. }
  10910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10911. isKnowKey = TRUE;
  10912. }
  10913. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10914. {
  10915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10917. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10918. {
  10919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10920. }
  10921. else
  10922. {
  10923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10924. }
  10925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10926. isKnowKey = TRUE;
  10927. }
  10928. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10929. {
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10933. {
  10934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10935. }
  10936. else
  10937. {
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10939. }
  10940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10941. isKnowKey = TRUE;
  10942. }
  10943. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10944. {
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10948. {
  10949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10950. }
  10951. else
  10952. {
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10954. }
  10955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10956. isKnowKey = TRUE;
  10957. }
  10958. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10959. {
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10963. {
  10964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10965. }
  10966. else
  10967. {
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10969. }
  10970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10971. isKnowKey = TRUE;
  10972. }
  10973. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10974. {
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10978. {
  10979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10980. }
  10981. else
  10982. {
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10984. }
  10985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10986. isKnowKey = TRUE;
  10987. }
  10988. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10989. {
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10993. {
  10994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10995. }
  10996. else
  10997. {
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10999. }
  11000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11001. isKnowKey = TRUE;
  11002. }
  11003. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11004. {
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11008. {
  11009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11010. }
  11011. else
  11012. {
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11014. }
  11015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11016. isKnowKey = TRUE;
  11017. }
  11018. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11019. {
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11023. {
  11024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11025. }
  11026. else
  11027. {
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11029. }
  11030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11031. isKnowKey = TRUE;
  11032. }
  11033. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11034. {
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11038. {
  11039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11040. }
  11041. else
  11042. {
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11044. }
  11045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11046. isKnowKey = TRUE;
  11047. }
  11048. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11049. {
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11053. {
  11054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11055. }
  11056. else
  11057. {
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11059. }
  11060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11061. isKnowKey = TRUE;
  11062. }
  11063. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11068. {
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11070. }
  11071. else
  11072. {
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11074. }
  11075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11076. isKnowKey = TRUE;
  11077. }
  11078. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11079. {
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11083. {
  11084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11085. }
  11086. else
  11087. {
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11089. }
  11090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11091. isKnowKey = TRUE;
  11092. }
  11093. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11094. {
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11098. {
  11099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11100. }
  11101. else
  11102. {
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11104. }
  11105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11106. isKnowKey = TRUE;
  11107. }
  11108. #if 0
  11109. //For OCTT Test Case
  11110. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11111. {
  11112. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11114. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11115. {
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11117. }
  11118. else
  11119. {
  11120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11121. }
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11123. isKnowKey = TRUE;
  11124. }
  11125. #endif
  11126. #if 1
  11127. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11128. {
  11129. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11131. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11132. {
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11134. }
  11135. else
  11136. {
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11138. }
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11140. isKnowKey = TRUE;
  11141. }
  11142. #endif
  11143. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11144. {
  11145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11147. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11148. {
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11150. }
  11151. else
  11152. {
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11154. }
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11156. isKnowKey = TRUE;
  11157. }
  11158. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11159. {
  11160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11162. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11163. {
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11165. }
  11166. else
  11167. {
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11169. }
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11171. isKnowKey = TRUE;
  11172. }
  11173. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11174. {
  11175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11177. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11178. {
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11180. }
  11181. else
  11182. {
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11184. }
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11186. isKnowKey = TRUE;
  11187. }
  11188. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11189. {
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11192. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11193. {
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11195. }
  11196. else
  11197. {
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11199. }
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11201. isKnowKey = TRUE;
  11202. }
  11203. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11204. {
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11207. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11208. {
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11210. }
  11211. else
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11214. }
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11216. isKnowKey = TRUE;
  11217. }
  11218. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11219. {
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11222. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11223. {
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11225. }
  11226. else
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11229. }
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11231. isKnowKey = TRUE;
  11232. }
  11233. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11234. {
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11237. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11240. }
  11241. else
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11244. }
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11246. isKnowKey = TRUE;
  11247. }
  11248. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11249. {
  11250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11252. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11253. {
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11255. }
  11256. else
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11259. }
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11261. isKnowKey = TRUE;
  11262. }
  11263. //=========================================================
  11264. if(!isEmpty && !isKnowKey)
  11265. {
  11266. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11267. strcpy(unknownkey[UnknownKeynum], keyReq);
  11268. UnknownKeynum = UnknownKeynum + 1;
  11269. }
  11270. }
  11271. void processUnkownKey(void)
  11272. {
  11273. DEBUG_INFO("processUnkownKey\n");
  11274. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11275. for(int index=0; index < UnknownKeynum; index++)
  11276. {
  11277. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11278. {
  11279. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11280. }
  11281. }
  11282. }
  11283. int setKeyValue(char *key, char *value)
  11284. {
  11285. int isSuccess = NotSupported;
  11286. int check_ascii=0;
  11287. char str[10]={0};
  11288. #ifdef Debug
  11289. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11290. #endif
  11291. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11292. {
  11293. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11295. {
  11296. strcpy(str, (const char*)value);
  11297. for(int i = 0; str[i]; i++){
  11298. str[i] = tolower(str[i]);
  11299. }
  11300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11301. isSuccess = ConfigurationStatus_Accepted;
  11302. }
  11303. else
  11304. {
  11305. isSuccess = ConfigurationStatus_Rejected;
  11306. }
  11307. }
  11308. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11309. {
  11310. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11312. {
  11313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  11314. isSuccess = ConfigurationStatus_Accepted;
  11315. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11316. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11317. }
  11318. else
  11319. {
  11320. isSuccess = ConfigurationStatus_Rejected;
  11321. }
  11322. }
  11323. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11324. {
  11325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11326. {
  11327. strcpy(str, (const char*)value);
  11328. for(int i = 0; str[i]; i++)
  11329. {
  11330. str[i] = tolower(str[i]);
  11331. }
  11332. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11334. isSuccess = ConfigurationStatus_Accepted;
  11335. }
  11336. else
  11337. {
  11338. isSuccess = ConfigurationStatus_Rejected;
  11339. }
  11340. }
  11341. if(strcmp(key, "BlinkRepeat") == 0)
  11342. {
  11343. //Charger.BlinkRepeat = Integer.parseInt(value);
  11344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11345. {
  11346. check_ascii = value[0];
  11347. if( (check_ascii < 48) || (check_ascii > 57) )
  11348. {
  11349. isSuccess = ConfigurationStatus_Rejected;
  11350. }
  11351. else
  11352. {
  11353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11354. isSuccess = ConfigurationStatus_Accepted;
  11355. }
  11356. }
  11357. else
  11358. {
  11359. isSuccess = ConfigurationStatus_Rejected;
  11360. }
  11361. }
  11362. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11363. {
  11364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11365. {
  11366. check_ascii = value[0];
  11367. if( (check_ascii < 48) || (check_ascii > 57) )
  11368. {
  11369. isSuccess = ConfigurationStatus_Rejected;
  11370. }
  11371. else
  11372. {
  11373. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11375. isSuccess = ConfigurationStatus_Accepted;
  11376. }
  11377. }
  11378. else
  11379. {
  11380. isSuccess = ConfigurationStatus_Rejected;
  11381. }
  11382. }
  11383. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11384. {
  11385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11386. {
  11387. check_ascii = value[0];
  11388. if( (check_ascii < 48) || (check_ascii > 57) )
  11389. {
  11390. isSuccess = ConfigurationStatus_Rejected;
  11391. }
  11392. else
  11393. {
  11394. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11396. isSuccess = ConfigurationStatus_Accepted;
  11397. }
  11398. }
  11399. else
  11400. {
  11401. isSuccess = ConfigurationStatus_Rejected;
  11402. }
  11403. }
  11404. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11405. {
  11406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11407. {
  11408. check_ascii = value[0];
  11409. if( (check_ascii < 48) || (check_ascii > 57) )
  11410. {
  11411. isSuccess = ConfigurationStatus_Rejected;
  11412. }
  11413. else
  11414. {
  11415. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11417. isSuccess = ConfigurationStatus_Accepted;
  11418. }
  11419. }
  11420. else
  11421. {
  11422. isSuccess = ConfigurationStatus_Rejected;
  11423. }
  11424. }
  11425. if(strcmp(key, "HeartbeatInterval") == 0)
  11426. {
  11427. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11428. {
  11429. check_ascii = value[0];
  11430. if( (check_ascii < 48) || (check_ascii > 57) )
  11431. {
  11432. isSuccess = ConfigurationStatus_Rejected;
  11433. }
  11434. else
  11435. {
  11436. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11438. HeartBeatWaitTime = atoi(value);
  11439. isSuccess = ConfigurationStatus_Accepted;
  11440. }
  11441. }
  11442. else
  11443. {
  11444. isSuccess = ConfigurationStatus_Rejected;
  11445. }
  11446. }
  11447. if(strcmp(key, "LightIntensity") == 0)
  11448. {
  11449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11450. {
  11451. check_ascii = value[0];
  11452. if( (check_ascii < 48) || (check_ascii > 57) )
  11453. {
  11454. isSuccess = ConfigurationStatus_Rejected;
  11455. }
  11456. else
  11457. {
  11458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11459. isSuccess = ConfigurationStatus_Accepted;
  11460. }
  11461. }
  11462. else
  11463. {
  11464. isSuccess = ConfigurationStatus_Rejected;
  11465. }
  11466. }
  11467. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11468. {
  11469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11470. {
  11471. strcpy(str, (const char*)value);
  11472. for(int i = 0; str[i]; i++)
  11473. {
  11474. str[i] = tolower(str[i]);
  11475. }
  11476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11477. isSuccess = ConfigurationStatus_Accepted;
  11478. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11479. }
  11480. else
  11481. {
  11482. isSuccess = ConfigurationStatus_Rejected;
  11483. }
  11484. }
  11485. if(strcmp(key, "LocalPreAuthorize") == 0)
  11486. {
  11487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11488. {
  11489. strcpy(str, (const char*)value);
  11490. for(int i = 0; str[i]; i++)
  11491. {
  11492. str[i] = tolower(str[i]);
  11493. }
  11494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11495. isSuccess = ConfigurationStatus_Accepted;
  11496. }
  11497. else
  11498. {
  11499. isSuccess = ConfigurationStatus_Rejected;
  11500. }
  11501. }
  11502. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11503. {
  11504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11505. {
  11506. check_ascii = value[0];
  11507. if( (check_ascii < 48) || (check_ascii > 57) )
  11508. {
  11509. isSuccess = ConfigurationStatus_Rejected;
  11510. }
  11511. else
  11512. {
  11513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11514. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11515. isSuccess = ConfigurationStatus_Accepted;
  11516. }
  11517. }
  11518. else
  11519. {
  11520. isSuccess = ConfigurationStatus_Rejected;
  11521. }
  11522. }
  11523. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11524. {
  11525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11526. {
  11527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11528. isSuccess = ConfigurationStatus_Accepted;
  11529. }
  11530. else
  11531. {
  11532. isSuccess = ConfigurationStatus_Rejected;
  11533. }
  11534. }
  11535. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11536. {
  11537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11538. {
  11539. check_ascii = value[0];
  11540. if( (check_ascii < 48) || (check_ascii > 57) )
  11541. {
  11542. isSuccess = ConfigurationStatus_Rejected;
  11543. }
  11544. else
  11545. {
  11546. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11548. isSuccess = ConfigurationStatus_Accepted;
  11549. }
  11550. }
  11551. else
  11552. {
  11553. isSuccess = ConfigurationStatus_Rejected;
  11554. }
  11555. }
  11556. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11557. {
  11558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11559. {
  11560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11561. isSuccess = ConfigurationStatus_Accepted;
  11562. }
  11563. else
  11564. {
  11565. isSuccess = ConfigurationStatus_Rejected;
  11566. }
  11567. }
  11568. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11569. {
  11570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11571. {
  11572. check_ascii = value[0];
  11573. if( (check_ascii < 48) || (check_ascii > 57) )
  11574. {
  11575. isSuccess = ConfigurationStatus_Rejected;
  11576. }
  11577. else
  11578. {
  11579. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11581. isSuccess = ConfigurationStatus_Accepted;
  11582. }
  11583. }
  11584. else
  11585. {
  11586. isSuccess = ConfigurationStatus_Rejected;
  11587. }
  11588. }
  11589. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11590. {
  11591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11592. {
  11593. check_ascii = value[0];
  11594. if( (check_ascii < 48) || (check_ascii > 57) )
  11595. {
  11596. isSuccess = ConfigurationStatus_Rejected;
  11597. }
  11598. else
  11599. {
  11600. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11602. isSuccess = ConfigurationStatus_Accepted;
  11603. }
  11604. }
  11605. else
  11606. {
  11607. isSuccess = ConfigurationStatus_Rejected;
  11608. }
  11609. }
  11610. if(strcmp(key, "MinimumStatusDuration") == 0)
  11611. {
  11612. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11613. {
  11614. check_ascii = value[0];
  11615. if( (check_ascii < 48) || (check_ascii > 57) )
  11616. {
  11617. isSuccess = ConfigurationStatus_Rejected;
  11618. }
  11619. else
  11620. {
  11621. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11623. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11624. isSuccess = ConfigurationStatus_Accepted;
  11625. }
  11626. }
  11627. else
  11628. {
  11629. isSuccess = ConfigurationStatus_Rejected;
  11630. }
  11631. }
  11632. if(strcmp(key, "NumberOfConnectors") == 0)
  11633. {
  11634. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11635. {
  11636. check_ascii = value[0];
  11637. if( (check_ascii < 48) || (check_ascii > 57) )
  11638. {
  11639. isSuccess = ConfigurationStatus_Rejected;
  11640. }
  11641. else
  11642. {
  11643. //Charger.ResetRetries = Integer.parseInt(value);
  11644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11645. isSuccess = ConfigurationStatus_Accepted;
  11646. }
  11647. }
  11648. else
  11649. {
  11650. isSuccess = ConfigurationStatus_Rejected;
  11651. }
  11652. }
  11653. if(strcmp(key, "ResetRetries") == 0)
  11654. {
  11655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11656. {
  11657. check_ascii = value[0];
  11658. if( (check_ascii < 48) || (check_ascii > 57) )
  11659. {
  11660. isSuccess = ConfigurationStatus_Rejected;
  11661. }
  11662. else
  11663. {
  11664. //Charger.ResetRetries = Integer.parseInt(value);
  11665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11666. isSuccess = ConfigurationStatus_Accepted;
  11667. }
  11668. }
  11669. else
  11670. {
  11671. isSuccess = ConfigurationStatus_Rejected;
  11672. }
  11673. }
  11674. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11675. {
  11676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11677. {
  11678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  11679. isSuccess = ConfigurationStatus_Accepted;
  11680. }
  11681. else
  11682. {
  11683. isSuccess = ConfigurationStatus_Rejected;
  11684. }
  11685. }
  11686. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11687. {
  11688. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11689. {
  11690. check_ascii = value[0];
  11691. if( (check_ascii < 48) || (check_ascii > 57) )
  11692. {
  11693. isSuccess = ConfigurationStatus_Rejected;
  11694. }
  11695. else
  11696. {
  11697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11698. isSuccess = ConfigurationStatus_Accepted;
  11699. }
  11700. }
  11701. else
  11702. {
  11703. isSuccess = ConfigurationStatus_Rejected;
  11704. }
  11705. }
  11706. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11707. {
  11708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11709. {
  11710. strcpy(str, (const char*)value);
  11711. for(int i = 0; str[i]; i++)
  11712. {
  11713. str[i] = tolower(str[i]);
  11714. }
  11715. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11717. isSuccess = ConfigurationStatus_Accepted;
  11718. }
  11719. else
  11720. {
  11721. isSuccess = ConfigurationStatus_Rejected;
  11722. }
  11723. }
  11724. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11725. {
  11726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11727. {
  11728. strcpy(str, (const char*)value);
  11729. for(int i = 0; str[i]; i++)
  11730. {
  11731. str[i] = tolower(str[i]);
  11732. }
  11733. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11735. isSuccess = ConfigurationStatus_Accepted;
  11736. }
  11737. else
  11738. {
  11739. isSuccess = ConfigurationStatus_Rejected;
  11740. }
  11741. }
  11742. if(strcmp(key, "StopTxnAlignedData") == 0)
  11743. {
  11744. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11745. {
  11746. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11747. isSuccess = ConfigurationStatus_Accepted;
  11748. }
  11749. else
  11750. {
  11751. isSuccess = ConfigurationStatus_Rejected;
  11752. }
  11753. }
  11754. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11755. {
  11756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11757. {
  11758. check_ascii = value[0];
  11759. if( (check_ascii < 48) || (check_ascii > 57) )
  11760. {
  11761. isSuccess = ConfigurationStatus_Rejected;
  11762. }
  11763. else
  11764. {
  11765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11766. isSuccess = ConfigurationStatus_Accepted;
  11767. }
  11768. }
  11769. else
  11770. {
  11771. isSuccess = ConfigurationStatus_Rejected;
  11772. }
  11773. }
  11774. if(strcmp(key, "StopTxnSampledData") == 0)
  11775. {
  11776. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11777. {
  11778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11779. isSuccess = ConfigurationStatus_Accepted;
  11780. }
  11781. else
  11782. {
  11783. isSuccess = ConfigurationStatus_Rejected;
  11784. }
  11785. }
  11786. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11787. {
  11788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11789. {
  11790. check_ascii = value[0];
  11791. if( (check_ascii < 48) || (check_ascii > 57) )
  11792. {
  11793. isSuccess = ConfigurationStatus_Rejected;
  11794. }
  11795. else
  11796. {
  11797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11798. isSuccess = ConfigurationStatus_Accepted;
  11799. }
  11800. }
  11801. else
  11802. {
  11803. isSuccess = ConfigurationStatus_Rejected;
  11804. }
  11805. }
  11806. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11807. {
  11808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11809. {
  11810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11811. isSuccess = ConfigurationStatus_Accepted;
  11812. }
  11813. else
  11814. {
  11815. isSuccess = ConfigurationStatus_Rejected;
  11816. }
  11817. }
  11818. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11819. {
  11820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11821. {
  11822. check_ascii = value[0];
  11823. if( (check_ascii < 48) || (check_ascii > 57) )
  11824. {
  11825. isSuccess = ConfigurationStatus_Rejected;
  11826. }
  11827. else
  11828. {
  11829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11830. isSuccess = ConfigurationStatus_Accepted;
  11831. }
  11832. }
  11833. else
  11834. {
  11835. isSuccess = ConfigurationStatus_Rejected;
  11836. }
  11837. }
  11838. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11839. {
  11840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11841. {
  11842. check_ascii = value[0];
  11843. if( (check_ascii < 48) || (check_ascii > 57) )
  11844. {
  11845. isSuccess = ConfigurationStatus_Rejected;
  11846. }
  11847. else
  11848. {
  11849. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11851. TransactionMessageAttemptsValue = atoi(value);
  11852. isSuccess = ConfigurationStatus_Accepted;
  11853. }
  11854. }
  11855. else
  11856. {
  11857. isSuccess = ConfigurationStatus_Rejected;
  11858. }
  11859. }
  11860. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11861. {
  11862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11863. {
  11864. check_ascii = value[0];
  11865. if( (check_ascii < 48) || (check_ascii > 57) )
  11866. {
  11867. isSuccess = ConfigurationStatus_Rejected;
  11868. }
  11869. else
  11870. {
  11871. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11873. TransactionMessageRetryIntervalValue = atoi(value);
  11874. isSuccess = ConfigurationStatus_Accepted;
  11875. }
  11876. }
  11877. else
  11878. {
  11879. isSuccess = ConfigurationStatus_Rejected;
  11880. }
  11881. }
  11882. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11883. {
  11884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11885. {
  11886. strcpy(str, (const char*)value);
  11887. for(int i = 0; str[i]; i++)
  11888. {
  11889. str[i] = tolower(str[i]);
  11890. }
  11891. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11893. isSuccess = ConfigurationStatus_Accepted;
  11894. }
  11895. else
  11896. {
  11897. isSuccess = ConfigurationStatus_Rejected;
  11898. }
  11899. }
  11900. if(strcmp(key, "WebSocketPingInterval") == 0)
  11901. {
  11902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11903. {
  11904. check_ascii = value[0];
  11905. if( (check_ascii < 48) || (check_ascii > 57) )
  11906. {
  11907. isSuccess = ConfigurationStatus_Rejected;
  11908. }
  11909. else
  11910. {
  11911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11912. isSuccess = ConfigurationStatus_Accepted;
  11913. }
  11914. }
  11915. else
  11916. {
  11917. isSuccess = ConfigurationStatus_Rejected;
  11918. }
  11919. }
  11920. #if 0
  11921. //For OCPP Test Case
  11922. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11923. {
  11924. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11925. {
  11926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11927. isSuccess = ConfigurationStatus_Accepted;
  11928. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11929. }
  11930. else
  11931. {
  11932. isSuccess = ConfigurationStatus_Rejected;
  11933. }
  11934. }
  11935. #endif
  11936. #if 1
  11937. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11938. {
  11939. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11940. {
  11941. strcpy(str, (const char*)value);
  11942. for(int i = 0; str[i]; i++)
  11943. {
  11944. str[i] = tolower(str[i]);
  11945. }
  11946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11947. isSuccess = ConfigurationStatus_Accepted;
  11948. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11949. }
  11950. else
  11951. {
  11952. isSuccess = ConfigurationStatus_Rejected;
  11953. }
  11954. }
  11955. #endif
  11956. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11957. {
  11958. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11959. {
  11960. check_ascii = value[0];
  11961. if( (check_ascii < 48) || (check_ascii > 57) )
  11962. {
  11963. isSuccess = ConfigurationStatus_Rejected;
  11964. }
  11965. else
  11966. {
  11967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11968. isSuccess = ConfigurationStatus_Accepted;
  11969. }
  11970. }
  11971. else
  11972. {
  11973. isSuccess = ConfigurationStatus_Rejected;
  11974. }
  11975. }
  11976. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11977. {
  11978. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11979. {
  11980. check_ascii = value[0];
  11981. if( (check_ascii < 48) || (check_ascii > 57) )
  11982. {
  11983. isSuccess = ConfigurationStatus_Rejected;
  11984. }
  11985. else
  11986. {
  11987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11988. isSuccess = ConfigurationStatus_Accepted;
  11989. }
  11990. }
  11991. else
  11992. {
  11993. isSuccess = ConfigurationStatus_Rejected;
  11994. }
  11995. }
  11996. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11997. {
  11998. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11999. {
  12000. strcpy(str, (const char*)value);
  12001. for(int i = 0; str[i]; i++)
  12002. {
  12003. str[i] = tolower(str[i]);
  12004. }
  12005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12006. isSuccess = ConfigurationStatus_Accepted;
  12007. }
  12008. else
  12009. {
  12010. isSuccess = ConfigurationStatus_Rejected;
  12011. }
  12012. }
  12013. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12014. {
  12015. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12016. {
  12017. check_ascii = value[0];
  12018. if( (check_ascii < 48) || (check_ascii > 57) )
  12019. {
  12020. isSuccess = ConfigurationStatus_Rejected;
  12021. }
  12022. else
  12023. {
  12024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12025. isSuccess = ConfigurationStatus_Accepted;
  12026. }
  12027. }
  12028. else
  12029. {
  12030. isSuccess = ConfigurationStatus_Rejected;
  12031. }
  12032. }
  12033. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12034. {
  12035. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12036. {
  12037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12038. isSuccess = ConfigurationStatus_Accepted;
  12039. }
  12040. else
  12041. {
  12042. isSuccess = ConfigurationStatus_Rejected;
  12043. }
  12044. }
  12045. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12046. {
  12047. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12048. {
  12049. check_ascii = value[0];
  12050. if( (check_ascii < 48) || (check_ascii > 57) )
  12051. {
  12052. isSuccess = ConfigurationStatus_Rejected;
  12053. }
  12054. else
  12055. {
  12056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12057. isSuccess = ConfigurationStatus_Accepted;
  12058. }
  12059. }
  12060. else
  12061. {
  12062. isSuccess = ConfigurationStatus_Rejected;
  12063. }
  12064. }
  12065. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12066. {
  12067. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12068. {
  12069. strcpy(str, (const char*)value);
  12070. for(int i = 0; str[i]; i++)
  12071. {
  12072. str[i] = tolower(str[i]);
  12073. }
  12074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12075. isSuccess = ConfigurationStatus_Accepted;
  12076. }
  12077. else
  12078. {
  12079. isSuccess = ConfigurationStatus_Rejected;
  12080. }
  12081. }
  12082. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12083. {
  12084. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12085. {
  12086. check_ascii = value[0];
  12087. if( (check_ascii < 48) || (check_ascii > 57) )
  12088. {
  12089. isSuccess = ConfigurationStatus_Rejected;
  12090. }
  12091. else
  12092. {
  12093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12094. isSuccess = ConfigurationStatus_Accepted;
  12095. }
  12096. }
  12097. else
  12098. {
  12099. isSuccess = ConfigurationStatus_Rejected;
  12100. }
  12101. }
  12102. return isSuccess;
  12103. }
  12104. int updateSetting(char *key, char *value)
  12105. {
  12106. mtrace();
  12107. int isSuccess = FALSE;
  12108. char string[1000]={0}, buffer[1000]={0};
  12109. char strtemp[50]={0};
  12110. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12111. int pos, c = 0;
  12112. char *loc;
  12113. int pos1=0;
  12114. FILE *f = fopen("/var/www/settings1", "r");
  12115. if(f == NULL)
  12116. {
  12117. #ifdef Debug
  12118. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12119. #endif
  12120. return isSuccess;
  12121. }
  12122. fseek(f, 0, SEEK_END);
  12123. long fsize = ftell(f);
  12124. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12125. fread(string, 1, fsize, f);
  12126. fclose(f);
  12127. string[fsize] = 0;
  12128. loc = strstr(string, key);
  12129. if(loc != NULL)
  12130. {
  12131. DEBUG_INFO("key exist!\n");
  12132. pos = loc - string-1;
  12133. f = fopen("/var/www/settings1", "w");
  12134. strncpy(buffer, string, pos);
  12135. fprintf(f, "%s", buffer);
  12136. memset(sstr ,0, sizeof(sstr) );
  12137. c = 0;
  12138. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12139. {
  12140. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12141. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12142. c++;
  12143. }
  12144. sstr[c] = '\0';
  12145. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12146. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12147. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12148. memset(buffer ,0, sizeof(buffer) );
  12149. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12150. //printf("buffer=%s",buffer);
  12151. fprintf(f, "%s", buffer);
  12152. fclose(f);
  12153. }
  12154. else
  12155. {
  12156. printf("key not exist!\n");
  12157. f = fopen("/var/www/settings1", "w+");
  12158. fputs(string, f);
  12159. fseek(f, -1, SEEK_CUR);
  12160. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12161. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12162. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12163. fclose(f);
  12164. }
  12165. isSuccess = TRUE;
  12166. return isSuccess;
  12167. }
  12168. int TransactionMessageAttemptsGet(void)
  12169. {
  12170. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12171. }
  12172. int FirstHeartBeatResponse(void)
  12173. {
  12174. return FirstHeartBeat;
  12175. }
  12176. int TransactionMessageRetryIntervalGet(void)
  12177. {
  12178. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12179. }
  12180. #define SA struct sockaddr
  12181. #define MAXBUF 1024
  12182. //static int m_socket_data;
  12183. //static int sockfd;
  12184. int ReadHttpStatus(int sock){
  12185. //char c;
  12186. char buff[1024]="",*ptr=buff+1;
  12187. int bytes_received, status;
  12188. DEBUG_INFO("Begin Response ..\n");
  12189. while((bytes_received = recv(sock, ptr, 1, 0))){
  12190. if(bytes_received==-1){
  12191. perror("ReadHttpStatus");
  12192. exit(1);
  12193. }
  12194. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12195. ptr++;
  12196. }
  12197. *ptr=0;
  12198. ptr=buff+1;
  12199. sscanf(ptr,"%*s %d ", &status);
  12200. DEBUG_INFO("%s\n",ptr);
  12201. DEBUG_INFO("status=%d\n",status);
  12202. DEBUG_INFO("End Response ..\n");
  12203. return (bytes_received>0)?status:0;
  12204. }
  12205. //the only filed that it parsed is 'Content-Length'
  12206. int ParseHeader(int sock){
  12207. //char c;
  12208. char buff[1024]="",*ptr=buff+4;
  12209. int bytes_received;
  12210. DEBUG_INFO("Begin HEADER ..\n");
  12211. while((bytes_received = recv(sock, ptr, 1, 0))){
  12212. if(bytes_received==-1){
  12213. perror("Parse Header");
  12214. exit(1);
  12215. }
  12216. if(
  12217. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12218. (ptr[-1]=='\r') && (*ptr=='\n' )
  12219. ) break;
  12220. ptr++;
  12221. }
  12222. *ptr=0;
  12223. ptr=buff+4;
  12224. //printf("%s",ptr);
  12225. if(bytes_received){
  12226. ptr=strstr(ptr,"Content-Length:");
  12227. if(ptr){
  12228. sscanf(ptr,"%*s %d",&bytes_received);
  12229. }else
  12230. bytes_received=-1; //unknown size
  12231. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12232. }
  12233. DEBUG_INFO("End HEADER ..\n");
  12234. return bytes_received ;
  12235. }
  12236. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12237. {
  12238. char rmFileCmd[100]={0};
  12239. char FilePath[100]={0};
  12240. char ftpbuf[200];
  12241. int systemresult;
  12242. //DEBUG_INFO("filename=%s\n",filename);
  12243. //DEBUG_INFO("url=%s\n",url);
  12244. sprintf(FilePath,"/mnt/%s",filename);
  12245. if((access(FilePath,F_OK))!=-1)
  12246. {
  12247. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12248. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12249. system(rmFileCmd);
  12250. }
  12251. memset(ftpbuf, 0, sizeof(ftpbuf));
  12252. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12253. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12254. systemresult = system(ftpbuf);
  12255. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12256. if(systemresult != 0)
  12257. {
  12258. DEBUG_INFO("http DownLoad error!\n");
  12259. return FALSE;
  12260. }
  12261. return TRUE;
  12262. }
  12263. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12264. {
  12265. char rmFileCmd[100]={0};
  12266. char FilePath[100]={0};
  12267. char ftpbuf[200];
  12268. int systemresult;
  12269. //char temp[100];
  12270. #if 0
  12271. struct hostent* server;
  12272. char *IPbuffer;
  12273. server = gethostbyname(location);
  12274. // To convert an Internet network
  12275. // address into ASCII string
  12276. IPbuffer = inet_ntoa(*((struct in_addr*)
  12277. server->h_addr_list[0]));
  12278. #endif
  12279. sprintf(FilePath,"/mnt/%s",filename);
  12280. if((access(FilePath,F_OK))!=-1)
  12281. {
  12282. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12283. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12284. system(rmFileCmd);
  12285. }
  12286. memset(ftpbuf, 0, sizeof(ftpbuf));
  12287. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12288. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12289. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12290. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12291. systemresult = system(ftpbuf);
  12292. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12293. if(systemresult != 0)
  12294. {
  12295. printf("wget error!\n");
  12296. return FALSE;
  12297. }
  12298. return TRUE;
  12299. }
  12300. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12301. {
  12302. char rmFileCmd[100]={0};
  12303. char FilePath[100]={0};
  12304. char ftpbuf[200];
  12305. char filenametemp[60]={0};
  12306. int systemresult;
  12307. //DEBUG_INFO("filename=%s\n",filename);
  12308. //DEBUG_INFO("url=%s\n",url);
  12309. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12310. if((access(FilePath,F_OK))!=-1)
  12311. {
  12312. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12313. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12314. system(rmFileCmd);
  12315. }
  12316. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12317. if(fp == NULL)
  12318. {
  12319. DEBUG_INFO("log is NULL\n");
  12320. return FALSE;
  12321. }
  12322. else
  12323. {
  12324. fprintf(fp, "%s\n", url);
  12325. sscanf(filename, "%*2[.]%s", filenametemp);
  12326. fprintf(fp, "%s\n", filenametemp);
  12327. fclose(fp);
  12328. }
  12329. memset(ftpbuf, 0, sizeof(ftpbuf));
  12330. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12331. systemresult = system(ftpbuf);
  12332. DEBUG_INFO("systemresult=%d\n",systemresult);
  12333. if(systemresult != 0)
  12334. {
  12335. DEBUG_INFO("http upload error!\n");
  12336. return FALSE;
  12337. }
  12338. return TRUE;
  12339. }
  12340. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12341. {
  12342. struct hostent* server;
  12343. char *IPbuffer;
  12344. char ftpbuf[200];
  12345. int systemresult;
  12346. // To retrieve host information
  12347. server = gethostbyname(location);
  12348. // To convert an Internet network
  12349. // address into ASCII string
  12350. IPbuffer = inet_ntoa(*((struct in_addr*)
  12351. server->h_addr_list[0]));
  12352. memset(ftpbuf, 0, sizeof(ftpbuf));
  12353. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12354. /* format : ftpput -u username -p passwd IP target source*/
  12355. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12356. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12357. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12358. systemresult = system(ftpbuf);
  12359. DEBUG_INFO("systemresult=%d\n",systemresult);
  12360. if(systemresult != 0)
  12361. {
  12362. DEBUG_INFO("ftpput error!\n");
  12363. return FALSE;
  12364. }
  12365. return TRUE;
  12366. }
  12367. int SettingChargingRecord(int target, int transactionId)
  12368. {
  12369. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12370. {
  12371. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12372. {
  12373. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12374. {
  12375. addBuff(target, transactionId, 0);
  12376. return TRUE;
  12377. }
  12378. }
  12379. for (int index = 0; index < CCS_QUANTITY; index++)
  12380. {
  12381. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12382. {
  12383. addBuff(target, transactionId, 0);
  12384. return TRUE;
  12385. }
  12386. }
  12387. for (int index = 0; index < GB_QUANTITY; index++)
  12388. {
  12389. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12390. {
  12391. addBuff(target, transactionId, 0);
  12392. return TRUE;
  12393. }
  12394. }
  12395. }
  12396. else
  12397. {
  12398. for (int index = 0; index < AC_QUANTITY; index++)
  12399. {
  12400. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12401. {
  12402. addBuff(target, transactionId, 0);
  12403. return TRUE;
  12404. }
  12405. }
  12406. }
  12407. return FALSE;
  12408. }
  12409. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12410. {
  12411. int isSuccess = FALSE;
  12412. //char *query = NULL;
  12413. sqlite3_stmt *stmt;
  12414. int rc; // return code
  12415. char str[20];
  12416. sprintf(str,"%d",user_id);
  12417. 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 */
  12418. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12419. rc = sqlite3_step(stmt); /* 3 */
  12420. if (rc != SQLITE_DONE) {
  12421. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12422. goto out;
  12423. }
  12424. sqlite3_finalize(stmt);
  12425. // free(query);
  12426. out:
  12427. //----------------------
  12428. // close SQLite database
  12429. //----------------------
  12430. sqlite3_close(db);
  12431. printf("database closed.\n");
  12432. return isSuccess;
  12433. }
  12434. /**
  12435. * Place the contents of the specified file into a memory buffer
  12436. *
  12437. * @param[in] filename The path and name of the file to read
  12438. * @param[out] filebuffer A pointer to the contents in memory
  12439. * @return status 0 success, 1 on failure
  12440. */
  12441. int get_file_contents(const char* filename, char** outbuffer) {
  12442. FILE* file = NULL;
  12443. long filesize;
  12444. const int blocksize = 1;
  12445. size_t readsize;
  12446. char* filebuffer;
  12447. // Open the file
  12448. file = fopen(filename, "r");
  12449. if (NULL == file)
  12450. {
  12451. printf("'%s' not opened\n", filename);
  12452. exit(EXIT_FAILURE);
  12453. }
  12454. // Determine the file size
  12455. fseek(file, 0, SEEK_END);
  12456. filesize = ftell(file);
  12457. rewind (file);
  12458. // Allocate memory for the file contents
  12459. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12460. *outbuffer = filebuffer;
  12461. if (filebuffer == NULL)
  12462. {
  12463. fputs ("malloc out-of-memory", stderr);
  12464. exit(EXIT_FAILURE);
  12465. }
  12466. // Read in the file
  12467. readsize = fread(filebuffer, blocksize, filesize, file);
  12468. if (readsize != filesize)
  12469. {
  12470. fputs ("didn't read file completely",stderr);
  12471. exit(EXIT_FAILURE);
  12472. }
  12473. // Clean exit
  12474. fclose(file);
  12475. return EXIT_SUCCESS;
  12476. }
  12477. static int selectSqlCount = 0;
  12478. static int callback(void *data, int argc, char **argv, char **azColName){
  12479. int i;
  12480. //printf("%s: ", (const char*)data);
  12481. selectSqlCount = argc;
  12482. for(i = 0; i<argc; i++){
  12483. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12484. }
  12485. //printf("\n");
  12486. return 0;
  12487. }
  12488. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12489. //int i;
  12490. //printf("%s:\n", (const char*)data);
  12491. localversion = argv[5] ? atoi(argv[5]) : 0;
  12492. //printf("localversion=%d\n", localversion);
  12493. return 0;
  12494. }
  12495. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12496. //int i;
  12497. //printf("%s:\n", (const char*)data);
  12498. //idTag
  12499. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12500. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12501. //parentIdTag
  12502. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12503. //expir_date
  12504. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12505. //status
  12506. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12507. //version
  12508. idTagQuery.listVersionInt = atoi(argv[5]);
  12509. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12510. return 0;
  12511. }
  12512. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12513. #if 0
  12514. int i;
  12515. //printf("%s:\n", (const char*)data);
  12516. for(i=0; i<argc; i++){
  12517. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12518. }
  12519. //printf("");
  12520. #endif
  12521. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12522. // printf("localversion=%d\n", localversion);
  12523. return 0;
  12524. }
  12525. /** sqlite3_exec的回调。
  12526. *
  12527. * 向控制台打印查询的结果。
  12528. *
  12529. * @param in data 传递给回调函数的数据。
  12530. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12531. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12532. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12533. * @return 状态码。
  12534. */
  12535. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12536. {
  12537. for (int i = 0; i < n_columns; i++)
  12538. {
  12539. DEBUG_INFO("%s/t", col_values[i]);
  12540. }
  12541. DEBUG_INFO("/n");
  12542. return 0;
  12543. }
  12544. void OCPP_getListVerion()
  12545. {
  12546. int rc = 0;
  12547. // const char* data = "Callback function called";
  12548. char sql[100];
  12549. char zErrMsg[100];
  12550. memset(sql, 0, 100);
  12551. memset(zErrMsg, 0, 100);
  12552. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12553. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12554. /* Execute SQL statement */
  12555. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12556. DEBUG_INFO("rc=%d\n",rc);
  12557. if( rc != SQLITE_OK ){
  12558. DEBUG_INFO("SQL error: %s", zErrMsg);
  12559. //sqlite3_free(zErrMsg);
  12560. }
  12561. }
  12562. void OCPP_getIdTag(char idTag[])
  12563. {
  12564. int rc = 0;
  12565. // const char* data = "Callback function called";
  12566. char sql[100];
  12567. char zErrMsg[100];
  12568. memset(sql, 0, 100);
  12569. memset(zErrMsg, 0, 100);
  12570. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12571. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12572. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12573. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12574. /* Execute SQL statement */
  12575. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12576. if( rc != SQLITE_OK ){
  12577. DEBUG_INFO("SQL error: %s", zErrMsg);
  12578. //sqlite3_free(zErrMsg);
  12579. }
  12580. //return ver;
  12581. }
  12582. void OCPP_get_TableAuthlocalAllData(void)
  12583. {
  12584. int rc = 0;
  12585. // const char* data = "Callback function called";
  12586. char sql[100];
  12587. char zErrMsg[100];
  12588. memset(sql, 0, 100);
  12589. memset(zErrMsg, 0, 100);
  12590. sprintf(sql,"select * from ocpp_auth_local ");
  12591. /* Execute SQL statement */
  12592. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12593. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12594. if( rc != SQLITE_OK ){
  12595. DEBUG_INFO("SQL error: %s", zErrMsg);
  12596. //sqlite3_free(zErrMsg);
  12597. }
  12598. //return ver;
  12599. }
  12600. int OCPP_cleanLocalList()
  12601. {
  12602. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12603. char *errMsg = 0;
  12604. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12605. if (SQLITE_OK != rc)
  12606. {
  12607. DEBUG_INFO("%s\n",errMsg);
  12608. return FALSE;
  12609. }
  12610. else
  12611. {
  12612. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12613. }
  12614. return TRUE;
  12615. }
  12616. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12617. {
  12618. int isSuccess = FALSE;
  12619. int ret = 0;
  12620. //const char* data = "Callback function called";
  12621. char sql[300];
  12622. char zErrMsg[200];
  12623. memset(sql, 0, 300);
  12624. memset(zErrMsg, 0, 200);
  12625. 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);
  12626. //* Execute SQL statement */
  12627. //zErrMsg = 0;
  12628. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12629. if( ret != SQLITE_OK ){
  12630. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12631. // free(zErrMsg);
  12632. // free(sql);
  12633. return isSuccess;
  12634. }
  12635. memset(sql, 0, 300);
  12636. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12637. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12638. if( ret != SQLITE_OK ){
  12639. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12640. // free(zErrMsg);
  12641. // free(sql);
  12642. return isSuccess;
  12643. }
  12644. // DEBUG_INFO("successfully Insert records created\n");
  12645. isSuccess = TRUE;
  12646. return isSuccess;
  12647. }
  12648. void OCPP_deleteIdTag(char idTag[])
  12649. {
  12650. //int ver = 0;
  12651. //int isSuccess = FALSE;
  12652. int rc = 0;
  12653. char sql[100];
  12654. char zErrMsg[100];
  12655. memset(sql, 0, 100);
  12656. memset(zErrMsg, 0, 100);
  12657. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12658. //* Execute SQL statement */
  12659. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12660. if( rc != SQLITE_OK ){
  12661. DEBUG_INFO("SQL error: %s", zErrMsg);
  12662. //sqlite3_free(zErrMsg);
  12663. }
  12664. }
  12665. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12666. {
  12667. int isSuccess = FALSE;
  12668. int ret = 0;
  12669. const char* data = "Callback function called";
  12670. char sql[200];
  12671. char zErrMsg[100];
  12672. memset(sql, 0, 200);
  12673. memset(zErrMsg, 0, 100);
  12674. //* selectFromTable */
  12675. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12676. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12677. //* Execute SQL statement */
  12678. selectSqlCount = 0;
  12679. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12680. if( ret != SQLITE_OK ){
  12681. printf("Error SQL: %s\n", zErrMsg);
  12682. }
  12683. printf("successfully select operation done\n");
  12684. memset(sql, 0, 200);
  12685. memset(zErrMsg, 0, 100);
  12686. if(selectSqlCount == 0)
  12687. {
  12688. //Insert
  12689. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12690. 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);
  12691. DEBUG_INFO("sql:%s\n", sql);
  12692. //* Execute SQL statement */
  12693. //zErrMsg = 0;
  12694. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12695. if( ret != SQLITE_OK ){
  12696. printf("SQL error: %s\n", zErrMsg);
  12697. return isSuccess;
  12698. }
  12699. DEBUG_INFO("successfully Insert records created\n");
  12700. isSuccess = TRUE;
  12701. }
  12702. else
  12703. {
  12704. //Update
  12705. //* Create merged SQL statement */
  12706. 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);
  12707. /* Execute SQL statement */
  12708. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12709. if( ret != SQLITE_OK ){
  12710. printf("SQL error: %s\n", zErrMsg);
  12711. //sqlite3_free(zErrMsg);
  12712. //sqlite3_free(sql);
  12713. return isSuccess;
  12714. }
  12715. DEBUG_INFO("Successfully operation done \n");
  12716. isSuccess = TRUE;
  12717. }
  12718. return isSuccess;
  12719. }
  12720. int GetOcppServerURL()
  12721. {
  12722. int result = FALSE;
  12723. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12724. memset(OcppHost, 0, sizeof(OcppHost));
  12725. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12726. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12727. {
  12728. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12729. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12730. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12731. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12732. result = TRUE;
  12733. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12734. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12735. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12736. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12737. goto End;
  12738. }
  12739. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12740. {
  12741. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12742. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12743. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12744. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12745. result = TRUE;
  12746. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12747. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12748. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12749. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12750. goto End;
  12751. }
  12752. else
  12753. {
  12754. strcpy(OcppHost,"");
  12755. }
  12756. End:
  12757. return result;
  12758. }
  12759. int GetOcppPath()
  12760. {
  12761. int result = FALSE;
  12762. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12763. {
  12764. if(OcppTempPath == NULL)
  12765. {
  12766. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12767. }
  12768. else
  12769. {
  12770. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12771. }
  12772. result = TRUE;
  12773. goto End;
  12774. }
  12775. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12776. {
  12777. if(OcppTempPath == NULL)
  12778. {
  12779. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12780. }
  12781. else
  12782. {
  12783. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12784. }
  12785. result = TRUE;
  12786. goto End;
  12787. }
  12788. else
  12789. {
  12790. strcpy(OcppPath,"");
  12791. }
  12792. End:
  12793. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12794. return result;
  12795. }
  12796. int GetOcppPort()
  12797. {
  12798. return OcppPort;
  12799. }
  12800. int GetOcppConnStatus(void)
  12801. {
  12802. return ShmOCPP16Data->OcppConnStatus;
  12803. }
  12804. void SetOcppConnStatus(uint8_t status)
  12805. {
  12806. ShmOCPP16Data->OcppConnStatus = status;
  12807. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12808. if(status == FALSE)
  12809. {
  12810. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12811. {
  12812. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12813. }
  12814. else
  12815. {
  12816. SystemInitial = AC_QUANTITY;
  12817. }
  12818. }
  12819. }
  12820. int GetHeartBeatWithNOResponse(void)
  12821. {
  12822. return HeartBeatWithNOResponse;
  12823. }
  12824. void SetHeartBeatWithNOResponse(void)
  12825. {
  12826. HeartBeatWithNOResponse = 0;
  12827. }
  12828. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12829. /*
  12830. src 源字串的首地址(buf的地址)
  12831. separator 指定的分割字元
  12832. dest 接收子字串的陣列
  12833. num 分割後子字串的個數
  12834. */
  12835. char *pNext;
  12836. int count = 0;
  12837. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12838. return;
  12839. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12840. return;
  12841. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12842. while(pNext != NULL) {
  12843. *dest++ = pNext;
  12844. ++count;
  12845. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12846. }
  12847. *num = count;
  12848. }
  12849. int GetTransactionId(int gunindex, unsigned char idTag[])
  12850. {
  12851. char ch;
  12852. FILE *fptr1;
  12853. int temptransactionId;
  12854. char str[100]={0};
  12855. temptransactionId = 0;
  12856. /*------ Read the file ----------------*/
  12857. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12858. if (!fptr1)
  12859. {
  12860. printf(" File not found or unable to open the input file!!\n");
  12861. return temptransactionId;
  12862. }
  12863. ch=fgetc(fptr1);
  12864. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12865. rewind(fptr1);
  12866. if(ch!=EOF)
  12867. {
  12868. // printf("%c",ch);
  12869. while (fgets(str, 100, fptr1) != NULL)
  12870. {
  12871. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12872. if(str[0]=='\0')
  12873. {
  12874. break;
  12875. }
  12876. char *revbuf[8] = {0}; //存放分割後的子字串
  12877. int num = 0;//分割後子字串的個數
  12878. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12879. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  12880. {
  12881. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12882. {
  12883. temptransactionId = atoi(revbuf[2]);
  12884. break;
  12885. }
  12886. }
  12887. }
  12888. }
  12889. fclose(fptr1);
  12890. /*------- End of reading ---------------*/
  12891. return temptransactionId;
  12892. }
  12893. void SetTransactionIdZero(int transactionId)
  12894. {
  12895. //TransactionId[gunindex] = 0;
  12896. char ch;
  12897. FILE *fptr1, *fptr2;
  12898. int temptransactionId = 0;
  12899. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  12900. printf("\n\n Delete a specific line from a file :\n");
  12901. printf("-----------------------------------------\n");
  12902. //scanf("%s",fname);
  12903. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12904. if (!fptr1)
  12905. {
  12906. printf(" File not found or unable to open the input file!!\n");
  12907. return ;
  12908. }
  12909. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12910. if (!fptr2)
  12911. {
  12912. printf("Unable to open a temporary file to write!!\n");
  12913. fclose(fptr1);
  12914. return ;
  12915. }
  12916. ch=fgetc(fptr1);
  12917. //printf(" Now the content of the file %s is : \n",fname);
  12918. rewind(fptr1);
  12919. if(ch!=EOF)
  12920. {
  12921. // copy all contents to the temporary file except the specific line
  12922. while (fgets(str, 100, fptr1) != NULL)
  12923. {
  12924. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12925. if(str[0]=='\0')
  12926. {
  12927. break;
  12928. }
  12929. char *revbuf[8] = {0}; //存放分割後的子字串
  12930. int num = 0;//分割後子字串的個數
  12931. strcpy(strtemp, str);
  12932. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12933. if(revbuf[2][0] != '\0')
  12934. {
  12935. temptransactionId = atoi(revbuf[2]);
  12936. if(transactionId != temptransactionId)
  12937. {
  12938. fprintf(fptr2, "%s", strtemp);
  12939. }
  12940. }
  12941. }
  12942. }
  12943. fclose(fptr1);
  12944. fclose(fptr2);
  12945. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12946. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12947. /*------ Read the file ----------------*/
  12948. }
  12949. int InternetDisconnect(void)
  12950. {
  12951. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12952. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12953. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12954. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12955. }
  12956. void GetChargingProfileRequest(int gunindex)
  12957. {
  12958. mtrace();
  12959. //int connectorIdInt, durationInt;
  12960. //char chargingRateUnitStr[4]={0};
  12961. int tempdurationInt = 0;
  12962. int tempchargingProfileId = 0;
  12963. int tempstackLevel = 0;
  12964. int temptransactionId = 0;
  12965. float tempminChargingRateFloat = 0.0;
  12966. char tempchargingProfilePurposeStr[24]={0};
  12967. char tempchargingProfileKindStr[12]={0};
  12968. char temprecurrencyKindStr[8]={0};
  12969. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12970. char tempvalidToStr[28]={0};
  12971. int tempStartPeriodInt = 0;
  12972. float tempLimitInt = 0.0;//0.1;
  12973. int tempNumberPhasesInt=0;
  12974. char fname[200];
  12975. //char comfirmstr[20];
  12976. float MinChargingRate =0.0;
  12977. double diff_t;
  12978. struct tm tp;
  12979. FILE *fptr1;//, *fptr2;
  12980. int c = 0;
  12981. char * pch;
  12982. char *loc;
  12983. char sstr[200]={ 0 };
  12984. int n_chargingProfile = 0;
  12985. int n_SchedulePeriods = 0;
  12986. char SchedulePeriodList[10][200]={0};
  12987. char sLineWord[1600]={0};
  12988. char word[1000]={0};
  12989. int confirmPeriods = 0;
  12990. struct StructProfile ChargePointMaxProfile;
  12991. struct StructProfile TxDefaultProfile;
  12992. struct StructProfile TxProfile;
  12993. struct StructProfile TxDefaultProfiletemp[2]={0};
  12994. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12995. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12996. struct StructChargingProfile TxProfile_TEMP={0};
  12997. int TxDefaultProfileFileIsNull=FALSE;
  12998. int ChargePointMaxProfileIsNull=FALSE;
  12999. int TxProfileIsNull=FALSE;
  13000. // int CompositeSceduleIndex = 0;
  13001. char ChargePointMaxProfileScheduleStr[30]={0};
  13002. char TxDefaultProfileScheduleStr[30]={0};
  13003. char TxProfileScheduleStr[30]={0};
  13004. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13005. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13006. memset(&TxProfile,0,sizeof(struct StructProfile));
  13007. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13008. DEBUG_INFO("GetChargingProfileRequest\n");
  13009. //*****************************ChargePointMaxProfile******************************************/
  13010. strcpy(fname, ChargePointMaxProfile_JSON);
  13011. ChargePointMaxProfileIsNull=TRUE;
  13012. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13013. {
  13014. fptr1 = fopen(fname, "r");
  13015. int c;
  13016. c = fgetc(fptr1);
  13017. //DEBUG_INFO("c:%d\n",c);
  13018. rewind(fptr1);
  13019. if(c == EOF)
  13020. {
  13021. DEBUG_INFO("\n End of file reached.");
  13022. ChargePointMaxProfileIsNull=TRUE;
  13023. fclose(fptr1);
  13024. }
  13025. else
  13026. {
  13027. ChargePointMaxProfileIsNull=FALSE;
  13028. while(fscanf(fptr1, "%s", word) != EOF)
  13029. {
  13030. if(strcmp(word, "chargingProfileId") == 0)
  13031. {
  13032. n_chargingProfile = n_chargingProfile + 1;
  13033. }
  13034. }
  13035. rewind(fptr1);
  13036. //search Charging Profile Element
  13037. int i = 0;
  13038. int j = 0;
  13039. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13040. //***********chargingProfileId**************/
  13041. c = 0;
  13042. loc = strstr(sLineWord, "chargingProfileId");
  13043. //DEBUG_INFO("loc=%s\n",loc);
  13044. memset(sstr ,0, sizeof(sstr) );
  13045. if(loc != NULL)
  13046. {
  13047. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13048. {
  13049. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13050. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13051. c++;
  13052. }
  13053. sstr[c] = '\0';
  13054. tempchargingProfileId = atoi(sstr);
  13055. }
  13056. else
  13057. {
  13058. tempchargingProfileId = 0;
  13059. }
  13060. //***********stackLevel**************/
  13061. c = 0;
  13062. loc = strstr(sLineWord, "stackLevel");
  13063. //DEBUG_INFO("loc=%s\n",loc);
  13064. memset(sstr ,0, sizeof(sstr) );
  13065. if(loc != NULL)
  13066. {
  13067. while (loc[2+strlen("stackLevel")+c] != '\"')
  13068. {
  13069. sstr[c] = loc[2+strlen("stackLevel")+c];
  13070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13071. c++;
  13072. }
  13073. sstr[c] = '\0';
  13074. tempstackLevel = atoi(sstr);
  13075. }
  13076. else
  13077. {
  13078. tempstackLevel = 0;
  13079. }
  13080. //***********chargingProfilePurpose **************/
  13081. c = 0;
  13082. loc = strstr(sLineWord, "chargingProfilePurpose");
  13083. //DEBUG_INFO("loc=%s\n",loc);
  13084. memset(sstr ,0, sizeof(sstr) );
  13085. if(loc != NULL)
  13086. {
  13087. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13088. {
  13089. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13090. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13091. c++;
  13092. }
  13093. sstr[c] = '\0';
  13094. strcpy(tempchargingProfilePurposeStr,sstr);
  13095. }
  13096. else
  13097. {
  13098. strcpy(tempchargingProfilePurposeStr,"");
  13099. }
  13100. //***********chargingProfileKind **************/
  13101. c = 0;
  13102. loc = strstr(sLineWord, "chargingProfileKind");
  13103. //DEBUG_INFO("loc=%s\n",loc);
  13104. memset(sstr ,0, sizeof(sstr) );
  13105. if(loc != NULL)
  13106. {
  13107. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13108. {
  13109. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13110. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13111. c++;
  13112. }
  13113. sstr[c] = '\0';
  13114. strcpy(tempchargingProfileKindStr,sstr);
  13115. }
  13116. else
  13117. {
  13118. strcpy(tempchargingProfileKindStr,"");
  13119. }
  13120. //***********recurrencyKind **************/
  13121. c = 0;
  13122. loc = strstr(sLineWord, "recurrencyKind");
  13123. //DEBUG_INFO("loc=%s\n",loc);
  13124. memset(sstr ,0, sizeof(sstr) );
  13125. if(loc != NULL)
  13126. {
  13127. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13128. {
  13129. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13130. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13131. c++;
  13132. }
  13133. sstr[c] = '\0';
  13134. strcpy(temprecurrencyKindStr,sstr);
  13135. }
  13136. else
  13137. {
  13138. strcpy(temprecurrencyKindStr,"");
  13139. }
  13140. //***********validFrom**************/
  13141. c = 0;
  13142. loc = strstr(sLineWord, "validFrom");
  13143. //DEBUG_INFO("loc=%s\n",loc);
  13144. memset(sstr ,0, sizeof(sstr) );
  13145. if(loc != NULL)
  13146. {
  13147. while (loc[3+strlen("validFrom")+c] != '\"')
  13148. {
  13149. sstr[c] = loc[3+strlen("validFrom")+c];
  13150. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13151. c++;
  13152. }
  13153. sstr[c] = '\0';
  13154. strcpy(tempvalidFromStr,sstr);
  13155. }
  13156. else
  13157. {
  13158. strcpy(tempvalidFromStr,"");
  13159. }
  13160. //***********validTo **************/
  13161. c = 0;
  13162. loc = strstr(sLineWord, "validTo");
  13163. //DEBUG_INFO("loc=%s\n",loc);
  13164. memset(sstr ,0, sizeof(sstr) );
  13165. if(loc != NULL)
  13166. {
  13167. while (loc[3+strlen("validTo")+c] != '\"')
  13168. {
  13169. sstr[c] = loc[3+strlen("validTo")+c];
  13170. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13171. c++;
  13172. }
  13173. sstr[c] = '\0';
  13174. strcpy(tempvalidToStr,sstr);
  13175. }
  13176. else
  13177. {
  13178. strcpy(tempvalidToStr,"");
  13179. }
  13180. //***********validFrom**************/
  13181. c = 0;
  13182. loc = strstr(sLineWord, "validFrom");
  13183. if(loc != NULL)
  13184. {
  13185. memset(sstr ,0, sizeof(sstr) );
  13186. while (loc[3+strlen("validFrom")+c] != '\"')
  13187. {
  13188. sstr[c] = loc[3+strlen("validFrom")+c];
  13189. c++;
  13190. }
  13191. sstr[c] = '\0';
  13192. strcpy(tempvalidFromStr,sstr);
  13193. }
  13194. else
  13195. {
  13196. strcpy(tempvalidFromStr,"");
  13197. }
  13198. //***********validTo **************/
  13199. c = 0;
  13200. loc = strstr(sLineWord, "validTo");
  13201. if(loc != NULL)
  13202. {
  13203. memset(sstr ,0, sizeof(sstr) );
  13204. while (loc[3+strlen("validTo")+c] != '\"')
  13205. {
  13206. sstr[c] = loc[3+strlen("validTo")+c];
  13207. c++;
  13208. }
  13209. sstr[c] = '\0';
  13210. strcpy(tempvalidToStr,sstr);
  13211. }
  13212. else
  13213. {
  13214. strcpy(tempvalidToStr,"");
  13215. }
  13216. //***********duration**************/
  13217. c = 0;
  13218. loc = strstr(sLineWord, "duration");
  13219. if(loc != NULL)
  13220. {
  13221. memset(sstr ,0, sizeof(sstr) );
  13222. while (loc[2+strlen("duration")+c] != ',')
  13223. {
  13224. sstr[c] = loc[2+strlen("duration")+c];
  13225. c++;
  13226. }
  13227. sstr[c] = '\0';
  13228. tempdurationInt = atoi(sstr);
  13229. }
  13230. else
  13231. {
  13232. tempdurationInt = 0;
  13233. }
  13234. //**********startSchedule**********/
  13235. c = 0;
  13236. loc = strstr(sLineWord, "startSchedule");
  13237. memset(sstr ,0, sizeof(sstr) );
  13238. while (loc[3+strlen("startSchedule")+c] != '\"')
  13239. {
  13240. sstr[c] = loc[3+strlen("startSchedule")+c];
  13241. c++;
  13242. }
  13243. sstr[c] = '\0';
  13244. strcpy(tempstartScheduleStr, sstr);
  13245. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  13246. //**********chargingRateUnit**********/
  13247. c = 0;
  13248. loc = strstr(sLineWord, "chargingRateUnit");
  13249. memset(sstr ,0, sizeof(sstr) );
  13250. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13251. {
  13252. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13253. c++;
  13254. }
  13255. sstr[c] = '\0';
  13256. strcpy(tempchargingRateUnitStr, sstr);
  13257. //**********minChargingRate*******/
  13258. c = 0;
  13259. loc = strstr(sLineWord, "minChargingRate");
  13260. if(loc != NULL)
  13261. {
  13262. memset(sstr ,0, sizeof(sstr) );
  13263. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13264. {
  13265. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13266. c++;
  13267. }
  13268. sstr[c] = '\0';
  13269. tempminChargingRateFloat = atof(sstr);
  13270. }
  13271. else
  13272. {
  13273. tempminChargingRateFloat = 0.0;
  13274. }
  13275. //
  13276. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13277. tp.tm_isdst = -1;
  13278. time_t utc = mktime(&tp);
  13279. time_t t = time(NULL);
  13280. diff_t = difftime(t, utc);
  13281. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13282. //parsing strings to words
  13283. i = 0;
  13284. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13285. loc = loc+3+strlen("chargingSchedulePeriod");
  13286. pch = strtok(loc ,"{");
  13287. while (pch != NULL)
  13288. {
  13289. strcpy(SchedulePeriodList[i], pch);
  13290. pch = strtok (NULL, "{");
  13291. i = i + 1;
  13292. }
  13293. n_SchedulePeriods = i;
  13294. for(int i=0;i<n_SchedulePeriods;i++)
  13295. {
  13296. //*************startPeriod****************/
  13297. c = 0;
  13298. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13299. memset(sstr ,0, sizeof(sstr) );
  13300. while (loc[strlen("startPeriod")+2+c] != ',')
  13301. {
  13302. sstr[c] = loc[strlen("startPeriod")+2+c];
  13303. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13304. c++;
  13305. }
  13306. sstr[c] = '\0';
  13307. tempStartPeriodInt = atoi(sstr);
  13308. //*************limit****************/
  13309. c = 0;
  13310. loc = strstr(SchedulePeriodList[i], "limit");
  13311. memset(sstr ,0, sizeof(sstr) );
  13312. while (loc[strlen("limit")+2+c] != ',')
  13313. {
  13314. sstr[c] = loc[strlen("limit")+2+c];
  13315. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13316. c++;
  13317. }
  13318. sstr[c] = '\0';
  13319. tempLimitInt = atof(sstr);
  13320. //*************numberPhases****************/
  13321. c = 0;
  13322. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13323. memset(sstr ,0, sizeof(sstr) );
  13324. while (loc[strlen("numberPhases")+2+c] != '}')
  13325. {
  13326. sstr[c] = loc[strlen("numberPhases")+2+c];
  13327. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13328. c++;
  13329. }
  13330. sstr[c] = '\0';
  13331. tempNumberPhasesInt = atoi(sstr);
  13332. if(j == 0)
  13333. {
  13334. ChargePointMaxProfile.Duration = tempdurationInt;
  13335. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13336. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13337. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13338. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13339. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13340. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13341. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13342. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13343. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13344. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13345. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13346. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13347. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13348. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13349. }
  13350. }
  13351. if(MinChargingRate < tempminChargingRateFloat)
  13352. {
  13353. MinChargingRate = tempminChargingRateFloat;
  13354. }
  13355. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13356. if(confirmPeriods < n_SchedulePeriods)
  13357. {
  13358. confirmPeriods = n_SchedulePeriods;
  13359. }
  13360. j = j + 1;
  13361. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13362. fclose(fptr1);
  13363. }// end else
  13364. }// the end of access file ChargePointMaxProfile
  13365. //****************************TxDefaultProfile************************************************/
  13366. #if 0
  13367. switch(gunindex + 1)
  13368. {
  13369. case 0:
  13370. strcpy(fname, TxDefaultProfile_0_JSON );
  13371. break;
  13372. case 1:
  13373. strcpy(fname, TxDefaultProfile_1_JSON );
  13374. break;
  13375. case 2:
  13376. strcpy(fname, TxDefaultProfile_2_JSON );
  13377. break;
  13378. default:
  13379. strcpy(fname, TxDefaultProfile_1_JSON );
  13380. break;
  13381. }
  13382. #endif
  13383. memset(fname, 0, sizeof fname);
  13384. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13385. TxDefaultProfileFileIsNull=TRUE;
  13386. if((access(fname,F_OK))!=-1)
  13387. {
  13388. fptr1 = fopen(fname, "r");
  13389. c = 0;
  13390. c = fgetc(fptr1);
  13391. //DEBUG_INFO("c:%d\n",c);
  13392. rewind(fptr1);
  13393. if(c == EOF)
  13394. {
  13395. DEBUG_INFO("\n End of file reached.");
  13396. TxDefaultProfileFileIsNull=TRUE;
  13397. fclose(fptr1);
  13398. }
  13399. else
  13400. {
  13401. TxDefaultProfileFileIsNull=FALSE;
  13402. while(fscanf(fptr1, "%s", word) != EOF)
  13403. {
  13404. if(strcmp(word, "chargingProfileId") == 0)
  13405. {
  13406. n_chargingProfile = n_chargingProfile + 1;
  13407. }
  13408. }
  13409. rewind(fptr1);
  13410. //search Charging Profile Element
  13411. int i = 0;
  13412. int j = 0;
  13413. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13414. {
  13415. #if 0
  13416. //***********connectorId****************/
  13417. c = 0;
  13418. loc = strstr(sLineWord, "connectorId");
  13419. memset(sstr ,0, sizeof(sstr) );
  13420. while (loc[strlen("connectorId")+2+c] != ',')
  13421. {
  13422. sstr[c] = loc[strlen("connectorId")+2+c];
  13423. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13424. c++;
  13425. }
  13426. sstr[c] = '\0';
  13427. tempconnectorIdInt = atoi(sstr);
  13428. #endif
  13429. //***********chargingProfileId**************/
  13430. c = 0;
  13431. loc = strstr(sLineWord, "chargingProfileId");
  13432. //DEBUG_INFO("loc=%s\n",loc);
  13433. memset(sstr ,0, sizeof(sstr) );
  13434. if(loc != NULL)
  13435. {
  13436. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13437. {
  13438. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13439. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13440. c++;
  13441. }
  13442. sstr[c] = '\0';
  13443. tempchargingProfileId = atoi(sstr);
  13444. }
  13445. else
  13446. {
  13447. tempchargingProfileId = 0;
  13448. }
  13449. //***********stackLevel**************/
  13450. c = 0;
  13451. loc = strstr(sLineWord, "stackLevel");
  13452. //DEBUG_INFO("loc=%s\n",loc);
  13453. memset(sstr ,0, sizeof(sstr) );
  13454. if(loc != NULL)
  13455. {
  13456. while (loc[2+strlen("stackLevel")+c] != '\"')
  13457. {
  13458. sstr[c] = loc[2+strlen("stackLevel")+c];
  13459. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13460. c++;
  13461. }
  13462. sstr[c] = '\0';
  13463. tempstackLevel = atoi(sstr);
  13464. }
  13465. else
  13466. {
  13467. tempstackLevel = 0;
  13468. }
  13469. //***********chargingProfilePurpose **************/
  13470. c = 0;
  13471. loc = strstr(sLineWord, "chargingProfilePurpose");
  13472. //DEBUG_INFO("loc=%s\n",loc);
  13473. memset(sstr ,0, sizeof(sstr) );
  13474. if(loc != NULL)
  13475. {
  13476. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13477. {
  13478. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13479. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13480. c++;
  13481. }
  13482. sstr[c] = '\0';
  13483. strcpy(tempchargingProfilePurposeStr,sstr);
  13484. }
  13485. else
  13486. {
  13487. strcpy(tempchargingProfilePurposeStr,"");
  13488. }
  13489. //***********chargingProfileKind **************/
  13490. c = 0;
  13491. loc = strstr(sLineWord, "chargingProfileKind");
  13492. //DEBUG_INFO("loc=%s\n",loc);
  13493. memset(sstr ,0, sizeof(sstr) );
  13494. if(loc != NULL)
  13495. {
  13496. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13497. {
  13498. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13499. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13500. c++;
  13501. }
  13502. sstr[c] = '\0';
  13503. strcpy(tempchargingProfileKindStr,sstr);
  13504. }
  13505. else
  13506. {
  13507. strcpy(tempchargingProfileKindStr,"");
  13508. }
  13509. //***********recurrencyKind **************/
  13510. c = 0;
  13511. loc = strstr(sLineWord, "recurrencyKind");
  13512. //DEBUG_INFO("loc=%s\n",loc);
  13513. memset(sstr ,0, sizeof(sstr) );
  13514. if(loc != NULL)
  13515. {
  13516. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13517. {
  13518. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13519. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13520. c++;
  13521. }
  13522. sstr[c] = '\0';
  13523. strcpy(temprecurrencyKindStr,sstr);
  13524. }
  13525. else
  13526. {
  13527. strcpy(temprecurrencyKindStr,"");
  13528. }
  13529. //***********validFrom**************/
  13530. c = 0;
  13531. loc = strstr(sLineWord, "validFrom");
  13532. if(loc != NULL)
  13533. {
  13534. memset(sstr ,0, sizeof(sstr) );
  13535. while (loc[3+strlen("validFrom")+c] != '\"')
  13536. {
  13537. sstr[c] = loc[3+strlen("validFrom")+c];
  13538. c++;
  13539. }
  13540. sstr[c] = '\0';
  13541. strcpy(tempvalidFromStr,sstr);
  13542. }
  13543. else
  13544. {
  13545. strcpy(tempvalidFromStr,"");
  13546. }
  13547. //***********validTo **************/
  13548. c = 0;
  13549. loc = strstr(sLineWord, "validTo");
  13550. if(loc != NULL)
  13551. {
  13552. memset(sstr ,0, sizeof(sstr) );
  13553. while (loc[3+strlen("validTo")+c] != '\"')
  13554. {
  13555. sstr[c] = loc[3+strlen("validTo")+c];
  13556. c++;
  13557. }
  13558. sstr[c] = '\0';
  13559. strcpy(tempvalidToStr,sstr);
  13560. }
  13561. else
  13562. {
  13563. strcpy(tempvalidToStr,"");
  13564. }
  13565. //***********duration**************/
  13566. c = 0;
  13567. loc = strstr(sLineWord, "duration");
  13568. if(loc != NULL)
  13569. {
  13570. memset(sstr ,0, sizeof(sstr) );
  13571. while (loc[2+strlen("duration")+c] != ',')
  13572. {
  13573. sstr[c] = loc[2+strlen("duration")+c];
  13574. c++;
  13575. }
  13576. sstr[c] = '\0';
  13577. tempdurationInt = atoi(sstr);
  13578. }
  13579. else
  13580. {
  13581. tempdurationInt = 0;
  13582. }
  13583. //**********startSchedule**********/
  13584. c = 0;
  13585. loc = strstr(sLineWord, "startSchedule");
  13586. memset(sstr ,0, sizeof(sstr) );
  13587. while (loc[3+strlen("startSchedule")+c] != '\"')
  13588. {
  13589. sstr[c] = loc[3+strlen("startSchedule")+c];
  13590. c++;
  13591. }
  13592. sstr[c] = '\0';
  13593. strcpy(tempstartScheduleStr, sstr);
  13594. strcpy(TxDefaultProfileScheduleStr, sstr);
  13595. //**********chargingRateUnit**********/
  13596. c = 0;
  13597. loc = strstr(sLineWord, "chargingRateUnit");
  13598. memset(sstr ,0, sizeof(sstr) );
  13599. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13600. {
  13601. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13602. c++;
  13603. }
  13604. sstr[c] = '\0';
  13605. strcpy(tempchargingRateUnitStr, sstr);
  13606. //**********minChargingRate*******/
  13607. c = 0;
  13608. loc = strstr(sLineWord, "minChargingRate");
  13609. if(loc != NULL)
  13610. {
  13611. memset(sstr ,0, sizeof(sstr) );
  13612. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13613. {
  13614. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13615. c++;
  13616. }
  13617. sstr[c] = '\0';
  13618. tempminChargingRateFloat = atof(sstr);
  13619. }
  13620. else
  13621. {
  13622. tempminChargingRateFloat = 0.0;
  13623. }
  13624. //
  13625. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13626. tp.tm_isdst = -1;
  13627. time_t utc = mktime(&tp);
  13628. time_t t = time(NULL);
  13629. diff_t = difftime(t, utc);
  13630. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13631. //parsing strings to words
  13632. i = 0;
  13633. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13634. loc = loc+3+strlen("chargingSchedulePeriod");
  13635. pch = strtok(loc ,"{");
  13636. while (pch != NULL)
  13637. {
  13638. strcpy(SchedulePeriodList[i], pch);
  13639. pch = strtok (NULL, "{");
  13640. i = i + 1;
  13641. }
  13642. n_SchedulePeriods = i;
  13643. for(int i=0;i<n_SchedulePeriods;i++)
  13644. {
  13645. //*************startPeriod****************/
  13646. c = 0;
  13647. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13648. memset(sstr ,0, sizeof(sstr) );
  13649. while (loc[strlen("startPeriod")+2+c] != ',')
  13650. {
  13651. sstr[c] = loc[strlen("startPeriod")+2+c];
  13652. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13653. c++;
  13654. }
  13655. sstr[c] = '\0';
  13656. tempStartPeriodInt = atoi(sstr);
  13657. //*************limit****************/
  13658. c = 0;
  13659. loc = strstr(SchedulePeriodList[i], "limit");
  13660. memset(sstr ,0, sizeof(sstr) );
  13661. while (loc[strlen("limit")+2+c] != ',')
  13662. {
  13663. sstr[c] = loc[strlen("limit")+2+c];
  13664. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13665. c++;
  13666. }
  13667. sstr[c] = '\0';
  13668. tempLimitInt = atof(sstr);
  13669. //*************numberPhases****************/
  13670. c = 0;
  13671. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13672. memset(sstr ,0, sizeof(sstr) );
  13673. while (loc[strlen("numberPhases")+2+c] != '}')
  13674. {
  13675. sstr[c] = loc[strlen("numberPhases")+2+c];
  13676. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13677. c++;
  13678. }
  13679. sstr[c] = '\0';
  13680. tempNumberPhasesInt = atoi(sstr);
  13681. if(j == 0)
  13682. {
  13683. TxDefaultProfile.Duration = tempdurationInt;
  13684. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13685. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13686. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13687. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13688. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13689. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13690. TxDefaultProfile_TEMP.TransactionId = 0;
  13691. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13692. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13693. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13694. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13695. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13696. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13697. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13698. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13699. }
  13700. else
  13701. {
  13702. //other stack level charging Profile
  13703. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13704. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13705. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13706. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13707. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13708. }
  13709. }
  13710. if(MinChargingRate < tempminChargingRateFloat)
  13711. {
  13712. MinChargingRate = tempminChargingRateFloat;
  13713. }
  13714. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13715. if(confirmPeriods < n_SchedulePeriods)
  13716. confirmPeriods = n_SchedulePeriods;
  13717. j = j + 1;
  13718. }
  13719. fclose(fptr1);
  13720. //Stacking Charging Profiles
  13721. for(int l=0; l <(j-1) ;l++)
  13722. {
  13723. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13724. {
  13725. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13726. {
  13727. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13728. {
  13729. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13730. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13731. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13732. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13733. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13734. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13735. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13736. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13737. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13738. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13739. }
  13740. else
  13741. {
  13742. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13743. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13744. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13745. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13746. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13747. }
  13748. }
  13749. }
  13750. }//end of Stacking Charging Profiles
  13751. }// end else
  13752. }// the end of ACCESS TxDefaultProfile
  13753. //****************************TxProfile************************************************/
  13754. #if 0
  13755. switch(gunindex + 1)
  13756. {
  13757. case 0:
  13758. break;
  13759. case 1:
  13760. strcpy(fname, TxProfile_1_JSON );
  13761. break;
  13762. case 2:
  13763. strcpy(fname, TxProfile_2_JSON );
  13764. break;
  13765. default:
  13766. strcpy(fname, TxProfile_1_JSON );
  13767. break;
  13768. }
  13769. #endif
  13770. memset(fname, 0, sizeof fname);
  13771. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  13772. TxProfileIsNull=TRUE;
  13773. if((access(fname,F_OK))!=-1)
  13774. {
  13775. fptr1 = fopen(fname, "r");
  13776. c = 0;
  13777. c = fgetc(fptr1);
  13778. //DEBUG_INFO("c:%d\n",c);
  13779. rewind(fptr1);
  13780. if(c == EOF)
  13781. {
  13782. DEBUG_INFO("\n End of file reached.");
  13783. TxProfileIsNull=TRUE;
  13784. fclose(fptr1);
  13785. }
  13786. else
  13787. {
  13788. TxProfileIsNull=FALSE;
  13789. while(fscanf(fptr1, "%s", word) != EOF)
  13790. {
  13791. if(strcmp(word, "chargingProfileId") == 0)
  13792. {
  13793. n_chargingProfile = n_chargingProfile + 1;
  13794. }
  13795. }
  13796. rewind(fptr1);
  13797. //search Charging Profile Element
  13798. int i= 0;
  13799. int j= 0;
  13800. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13801. #if 0
  13802. /***********connectorId****************/
  13803. c = 0;
  13804. loc = strstr(sLineWord, "connectorId");
  13805. memset(sstr ,0, sizeof(sstr) );
  13806. while (loc[strlen("connectorId")+2+c] != ',')
  13807. {
  13808. sstr[c] = loc[strlen("connectorId")+2+c];
  13809. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13810. c++;
  13811. }
  13812. sstr[c] = '\0';
  13813. tempconnectorIdInt = atoi(sstr);
  13814. #endif
  13815. //***********chargingProfileId**************/
  13816. c = 0;
  13817. loc = strstr(sLineWord, "chargingProfileId");
  13818. memset(sstr ,0, sizeof(sstr) );
  13819. if(loc != NULL)
  13820. {
  13821. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13822. {
  13823. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13824. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13825. c++;
  13826. }
  13827. sstr[c] = '\0';
  13828. tempchargingProfileId = atoi(sstr);
  13829. }
  13830. else
  13831. {
  13832. tempchargingProfileId = 0;
  13833. }
  13834. //***********transactionId **************/
  13835. c = 0;
  13836. loc = strstr(sLineWord, "transactionId");
  13837. //DEBUG_INFO("loc=%s\n",loc);
  13838. memset(sstr ,0, sizeof(sstr) );
  13839. if(loc != NULL)
  13840. {
  13841. while (loc[2+strlen("transactionId")+c] != '\"')
  13842. {
  13843. sstr[c] = loc[2+strlen("transactionId")+c];
  13844. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13845. c++;
  13846. }
  13847. sstr[c] = '\0';
  13848. temptransactionId = atoi(sstr);
  13849. }
  13850. else
  13851. {
  13852. temptransactionId = 0;
  13853. }
  13854. //***********stackLevel**************/
  13855. c = 0;
  13856. loc = strstr(sLineWord, "stackLevel");
  13857. //DEBUG_INFO("loc=%s\n",loc);
  13858. memset(sstr ,0, sizeof(sstr) );
  13859. if(loc != NULL)
  13860. {
  13861. while (loc[2+strlen("stackLevel")+c] != '\"')
  13862. {
  13863. sstr[c] = loc[2+strlen("stackLevel")+c];
  13864. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13865. c++;
  13866. }
  13867. sstr[c] = '\0';
  13868. tempstackLevel = atoi(sstr);
  13869. }
  13870. else
  13871. {
  13872. tempstackLevel = 0;
  13873. }
  13874. //***********chargingProfilePurpose **************/
  13875. c = 0;
  13876. loc = strstr(sLineWord, "chargingProfilePurpose");
  13877. //DEBUG_INFO("loc=%s\n",loc);
  13878. memset(sstr ,0, sizeof(sstr) );
  13879. if(loc != NULL)
  13880. {
  13881. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13882. {
  13883. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13884. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13885. c++;
  13886. }
  13887. sstr[c] = '\0';
  13888. strcpy(tempchargingProfilePurposeStr,sstr);
  13889. }
  13890. else
  13891. {
  13892. strcpy(tempchargingProfilePurposeStr,"");
  13893. }
  13894. //***********chargingProfileKind **************/
  13895. c = 0;
  13896. loc = strstr(sLineWord, "chargingProfileKind");
  13897. //DEBUG_INFO("loc=%s\n",loc);
  13898. memset(sstr ,0, sizeof(sstr) );
  13899. if(loc != NULL)
  13900. {
  13901. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13902. {
  13903. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13904. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13905. c++;
  13906. }
  13907. sstr[c] = '\0';
  13908. strcpy(tempchargingProfileKindStr,sstr);
  13909. }
  13910. else
  13911. {
  13912. strcpy(tempchargingProfileKindStr,"");
  13913. }
  13914. //***********recurrencyKind **************/
  13915. c = 0;
  13916. loc = strstr(sLineWord, "recurrencyKind");
  13917. //DEBUG_INFO("loc=%s\n",loc);
  13918. memset(sstr ,0, sizeof(sstr) );
  13919. if(loc != NULL)
  13920. {
  13921. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13922. {
  13923. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13924. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13925. c++;
  13926. }
  13927. sstr[c] = '\0';
  13928. strcpy(temprecurrencyKindStr,sstr);
  13929. }
  13930. else
  13931. {
  13932. strcpy(temprecurrencyKindStr,"");
  13933. }
  13934. //***********validFrom**************/
  13935. c = 0;
  13936. loc = strstr(sLineWord, "validFrom");
  13937. if(loc != NULL)
  13938. {
  13939. memset(sstr ,0, sizeof(sstr) );
  13940. while (loc[3+strlen("validFrom")+c] != '\"')
  13941. {
  13942. sstr[c] = loc[3+strlen("validFrom")+c];
  13943. c++;
  13944. }
  13945. sstr[c] = '\0';
  13946. strcpy(tempvalidFromStr,sstr);
  13947. }
  13948. else
  13949. {
  13950. strcpy(tempvalidFromStr,"");
  13951. }
  13952. //***********validTo**************/
  13953. c = 0;
  13954. loc = strstr(sLineWord, "validTo");
  13955. if(loc != NULL)
  13956. {
  13957. memset(sstr ,0, sizeof(sstr) );
  13958. while (loc[3+strlen("validTo")+c] != '\"')
  13959. {
  13960. sstr[c] = loc[3+strlen("validTo")+c];
  13961. c++;
  13962. }
  13963. sstr[c] = '\0';
  13964. strcpy(tempvalidToStr,sstr);
  13965. }
  13966. else
  13967. {
  13968. strcpy(tempvalidToStr,"");
  13969. }
  13970. //***********duration**************/
  13971. c = 0;
  13972. loc = strstr(sLineWord, "duration");
  13973. //DEBUG_INFO("loc=%s\n",loc);
  13974. memset(sstr ,0, sizeof(sstr) );
  13975. if(loc != NULL)
  13976. {
  13977. while (loc[2+strlen("duration")+c] != '\"')
  13978. {
  13979. sstr[c] = loc[2+strlen("duration")+c];
  13980. c++;
  13981. }
  13982. sstr[c] = '\0';
  13983. tempdurationInt = atoi(sstr);
  13984. }
  13985. else
  13986. {
  13987. tempdurationInt = 0;
  13988. }
  13989. //**********startSchedule**********/
  13990. c = 0;
  13991. loc = strstr(sLineWord, "startSchedule");
  13992. memset(sstr ,0, sizeof(sstr) );
  13993. while (loc[3+strlen("startSchedule")+c] != '\"')
  13994. {
  13995. sstr[c] = loc[3+strlen("startSchedule")+c];
  13996. c++;
  13997. }
  13998. sstr[c] = '\0';
  13999. strcpy(tempstartScheduleStr, sstr);
  14000. strcpy(TxProfileScheduleStr, sstr);
  14001. //**********chargingRateUnit**********/
  14002. c = 0;
  14003. loc = strstr(sLineWord, "chargingRateUnit");
  14004. memset(sstr ,0, sizeof(sstr) );
  14005. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14006. {
  14007. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14008. c++;
  14009. }
  14010. sstr[c] = '\0';
  14011. strcpy(tempchargingRateUnitStr, sstr);
  14012. //**********minChargingRate*******/
  14013. c = 0;
  14014. loc = strstr(sLineWord, "minChargingRate");
  14015. if(loc != NULL)
  14016. {
  14017. memset(sstr ,0, sizeof(sstr) );
  14018. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14019. {
  14020. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14021. c++;
  14022. }
  14023. sstr[c] = '\0';
  14024. tempminChargingRateFloat = atof(sstr);
  14025. }
  14026. else
  14027. {
  14028. tempminChargingRateFloat = 0.0;
  14029. }
  14030. //
  14031. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14032. tp.tm_isdst = -1;
  14033. time_t utc = mktime(&tp);
  14034. time_t t = time(NULL);
  14035. diff_t = difftime(t, utc);
  14036. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14037. //parsing strings to words
  14038. i = 0;
  14039. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14040. loc = loc+3+strlen("chargingSchedulePeriod");
  14041. pch = strtok(loc ,"{");
  14042. while (pch != NULL)
  14043. {
  14044. strcpy(SchedulePeriodList[i], pch);
  14045. pch = strtok (NULL, "{");
  14046. i = i + 1;
  14047. }
  14048. n_SchedulePeriods = i;
  14049. for(int i=0;i<n_SchedulePeriods;i++)
  14050. {
  14051. //*************startPeriod****************/
  14052. c = 0;
  14053. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14054. memset(sstr ,0, sizeof(sstr) );
  14055. while (loc[strlen("startPeriod")+2+c] != ',')
  14056. {
  14057. sstr[c] = loc[strlen("startPeriod")+2+c];
  14058. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14059. c++;
  14060. }
  14061. sstr[c] = '\0';
  14062. tempStartPeriodInt = atoi(sstr);
  14063. //*************limit****************/
  14064. c = 0;
  14065. loc = strstr(SchedulePeriodList[i], "limit");
  14066. memset(sstr ,0, sizeof(sstr) );
  14067. while (loc[strlen("limit")+2+c] != ',')
  14068. {
  14069. sstr[c] = loc[strlen("limit")+2+c];
  14070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14071. c++;
  14072. }
  14073. sstr[c] = '\0';
  14074. tempLimitInt = atof(sstr);
  14075. //*************numberPhases****************/
  14076. c = 0;
  14077. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14078. memset(sstr ,0, sizeof(sstr) );
  14079. while (loc[strlen("numberPhases")+2+c] != '}')
  14080. {
  14081. sstr[c] = loc[strlen("numberPhases")+2+c];
  14082. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14083. c++;
  14084. }
  14085. sstr[c] = '\0';
  14086. tempNumberPhasesInt = atoi(sstr);
  14087. //TxProfile.Duration = durationInt;
  14088. TxProfile.TotalPeriod = n_SchedulePeriods;
  14089. TxProfile.Period[i].Limit = tempLimitInt;
  14090. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14091. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14092. }
  14093. if(MinChargingRate < tempminChargingRateFloat)
  14094. {
  14095. MinChargingRate = tempminChargingRateFloat;
  14096. }
  14097. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14098. if(confirmPeriods < n_SchedulePeriods)
  14099. confirmPeriods = n_SchedulePeriods;
  14100. if(j == 0)
  14101. {
  14102. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14103. TxProfile_TEMP.StackLevel = tempstackLevel;
  14104. TxProfile_TEMP.TransactionId = 0;
  14105. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14106. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14107. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14108. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14109. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14110. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14111. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14112. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14113. }
  14114. }
  14115. fclose(fptr1);
  14116. }
  14117. }// the end of ACCESS TxProfile
  14118. //-----------------------------------------------CompositeSchedule--------------------------//
  14119. int period=0;
  14120. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14121. {
  14122. //TxProfile
  14123. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14124. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14125. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14126. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14127. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14128. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14129. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14130. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14131. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14132. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14133. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14134. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14135. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14136. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14137. {
  14138. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14139. {
  14140. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14141. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14142. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14143. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14144. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14145. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14146. period = period + 1;
  14147. }
  14148. else
  14149. {
  14150. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14151. {
  14152. }
  14153. else
  14154. {
  14155. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14156. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14157. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14158. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14159. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14160. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14161. period = period + 1;
  14162. }
  14163. }
  14164. }
  14165. struct tm tp;
  14166. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14167. tp.tm_isdst = -1;
  14168. time_t utc = mktime(&tp);
  14169. time_t t = time(NULL);
  14170. double diff_f = difftime(t, utc);
  14171. int diff_i;// = (int)diff_f;
  14172. int quotient; // = diff_i / 86400;//86400 seconds/day
  14173. if(diff_f >= 0)
  14174. {
  14175. diff_i = (int)diff_f;
  14176. quotient = diff_i / 86400;//86400 seconds/day
  14177. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14178. {
  14179. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  14180. {
  14181. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14182. {
  14183. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14184. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14185. }
  14186. else
  14187. {
  14188. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14189. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14190. }
  14191. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14192. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14193. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14194. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14195. period = period + 1;
  14196. }
  14197. }
  14198. }// end of if(diff_f >= 0)
  14199. }
  14200. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14201. {
  14202. //TxDefaultProfile
  14203. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14204. struct tm tp;
  14205. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14206. tp.tm_isdst = -1;
  14207. time_t utc = mktime(&tp);
  14208. time_t t = time(NULL);
  14209. double diff_f = difftime(t, utc);
  14210. int diff_i;// = (int)diff_f;
  14211. int quotient; // = diff_i / 86400;//86400 seconds/day
  14212. int remainder;
  14213. //---- Define StartSchedule----/
  14214. struct tm *gtime;
  14215. time_t now;
  14216. char buf[28];
  14217. //---Read the current system time---/
  14218. time(&now);
  14219. //---Convert the system time to GMT (now UTC)---/
  14220. gtime = gmtime(&now);
  14221. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14222. if(diff_f >= 0)
  14223. {
  14224. diff_i = (int)diff_f;
  14225. quotient = diff_i / 86400;//86400 seconds/day
  14226. remainder = diff_i % 86400;
  14227. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14228. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14229. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14230. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  14231. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14232. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14233. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14234. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14235. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14236. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14237. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14238. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14239. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14240. {
  14241. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14242. {
  14243. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14244. {
  14245. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14246. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14247. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14248. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14249. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14250. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14251. period = period + 1;
  14252. }
  14253. else
  14254. {
  14255. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14256. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14257. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14258. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14259. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14260. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14261. period = period + 1;
  14262. }
  14263. }
  14264. }
  14265. } // end of diff_f >= 0
  14266. }
  14267. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14268. {
  14269. //TxDefaultProfile
  14270. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14271. struct tm tp;
  14272. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14273. tp.tm_isdst = -1;
  14274. time_t utc = mktime(&tp);
  14275. time_t t = time(NULL);
  14276. double diff_f = difftime(t, utc);
  14277. int diff_i;// = (int)diff_f;
  14278. int quotient; // = diff_i / 86400;//86400 seconds/day
  14279. int remainder;
  14280. //---- Define StartSchedule----/
  14281. struct tm *gtime;
  14282. time_t now;
  14283. char buf[28];
  14284. //---Read the current system time---/
  14285. time(&now);
  14286. //---Convert the system time to GMT (now UTC)---/
  14287. gtime = gmtime(&now);
  14288. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14289. if(diff_f >= 0)
  14290. {
  14291. diff_i = (int)diff_f;
  14292. quotient = diff_i / 86400;//86400 seconds/day
  14293. remainder = diff_i % 86400;
  14294. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14295. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14296. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14297. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14298. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14299. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14300. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14301. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14302. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14303. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  14304. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14305. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14306. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14307. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14308. {
  14309. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14310. {
  14311. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14312. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14313. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14314. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14315. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14316. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14317. period = period + 1;
  14318. }
  14319. }
  14320. } //end of diff_f >= 0
  14321. }
  14322. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14323. {
  14324. //ChargePointMaxProfile
  14325. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14326. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14327. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14328. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14329. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14330. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14331. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14332. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14333. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14334. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14335. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14336. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14337. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14338. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  14339. {
  14340. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14341. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14342. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14343. period = period + 1;
  14344. }
  14345. }
  14346. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14347. {
  14348. //TxProfile Daily
  14349. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14350. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14351. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14352. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14353. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14354. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14355. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14356. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14357. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14358. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14359. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14360. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14361. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14362. for(int l=0; l< TxProfile.TotalPeriod; l++)
  14363. {
  14364. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  14365. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  14366. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  14367. }
  14368. }
  14369. confirmPeriods = period;
  14370. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14371. 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,"
  14372. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14373. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14374. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14375. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14376. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14377. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14378. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14379. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14380. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14381. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14383. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14384. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14385. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14386. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14387. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14388. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14389. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14390. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14391. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14394. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14395. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14396. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14397. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14398. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14399. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14400. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14401. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14402. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14403. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14404. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14405. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14406. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14407. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14408. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14409. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14410. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14411. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14412. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14413. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14414. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14415. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14416. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14417. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14418. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14419. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14420. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14421. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14422. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14423. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14424. }
  14425. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14426. {
  14427. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14428. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14429. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14430. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14431. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14432. }
  14433. int GetWebSocketPingInterval(void)
  14434. {
  14435. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14436. }
  14437. void LWS_Send(char * str)
  14438. {
  14439. //=====================================================
  14440. // Check InternetConn 0: disconnected, 1: connected
  14441. //====================================================
  14442. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14443. {
  14444. DEBUG_INFO("\n offline now !!!\n");
  14445. return;
  14446. }
  14447. pthread_mutex_lock(&lock);
  14448. memset(SendBuffer,0,SendBufLen);
  14449. sprintf((char *)SendBuffer, "%s", str);
  14450. pthread_mutex_unlock(&lock);
  14451. lws_callback_on_writable(wsi_client);
  14452. lws_service(context, 10000);//timeout_ms
  14453. }