MessageHandler.c 572 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "hashmap.h"
  21. #include "ShareMemory.h"
  22. #include "TransactionQueue.h"
  23. #include "define.h"
  24. #include "SystemLogMessage.h"
  25. //#include "config.h"
  26. #include <sys/socket.h>
  27. #include <netinet/in.h>
  28. #include <stdlib.h>
  29. /*for sendfile()*/
  30. #include <sys/sendfile.h>
  31. /*for O_RDONLY*/
  32. #include <fcntl.h>
  33. #include "sqlite3.h"
  34. #include <arpa/inet.h>
  35. //#define _GNU_SOURCE
  36. #include <time.h>
  37. #include "MessageHandler.h"
  38. #include <assert.h>
  39. #include <pthread.h>
  40. #include <mcheck.h>
  41. #define PASS 1
  42. #define FAIL -1
  43. #define FALSE 0
  44. #define TRUE 1 // Option 1
  45. //ChargePointMaxProfile
  46. #define ChargePointMaxProfile_JSON "../Storage/OCPP/ChargePointMaxProfile.json"
  47. //TxDefaultProfile
  48. #define TxDefaultProfile_0_JSON "../Storage/OCPP/TxDefaultProfile_0.json"
  49. #define TxDefaultProfile_1_JSON "../Storage/OCPP/TxDefaultProfile_1.json"
  50. #define TxDefaultProfile_2_JSON "../Storage/OCPP/TxDefaultProfile_2.json"
  51. //TxProfile
  52. #define TxProfile_1_JSON "../Storage/OCPP/TxProfile_1.json"
  53. #define TxProfile_2_JSON "../Storage/OCPP/TxProfile_2.json"
  54. #define ChargingProfile_0_JSON "../Storage/OCPP/chargingprofile_0.json"
  55. #define ChargingProfile_1_JSON "../Storage/OCPP/chargingprofile_1.json"
  56. #define ChargingProfile_2_JSON "../Storage/OCPP/chargingprofile_2.json"
  57. #define AuthorizationCache_JSON "../Storage/OCPP/AuthorizationCache.json"
  58. #define LocalAuthorizationList_JSON "../Storage/OCPP/LocalAuthorizationList.json"
  59. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  60. struct StatusCodeData *ShmStatusCodeData;
  61. struct PsuData *ShmPsuData ;
  62. struct OCPP16Data *ShmOCPP16Data;
  63. // define Macro
  64. #define SystemLogMessage
  65. // OCPP Message Type
  66. #define MESSAGE_TYPE_CALL 2
  67. #define MESSAGE_TYPE_CALLRESULT 3
  68. #define MESSAGE_TYPE_CALLERROR 4
  69. //
  70. #define server_cycle_Status 120
  71. #define MACROSTR(k) #k
  72. //ConfigurationMaxKeys
  73. #define GetConfigurationMaxKeysNUM 43
  74. //char guid[37];
  75. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  76. char queuedata[2600]={0};
  77. //===============================
  78. // Configuration: unknownkey
  79. //===============================
  80. static char unknownkey[10][20]={0};
  81. static int UnknownKeynum = 0;
  82. //===============================
  83. // Gun Total Numbers
  84. //===============================
  85. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  86. static int gunTotalNumber=0;
  87. //===============================
  88. // Local List Version
  89. //===============================
  90. static int localversion=0;
  91. static char idTagAuthorization[32]={0};
  92. //===============================
  93. // OCPP Path
  94. //===============================
  95. extern char OcppPath[160];
  96. extern char OcppProtocol[10];
  97. extern char OcppHost[50];
  98. extern char OcppTempPath[50];
  99. int OcppPort=0;
  100. //===============================
  101. // OCPP sign variable
  102. //===============================
  103. int server_sign = FALSE;
  104. int server_pending = FALSE;
  105. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  106. int BootNotificationInterval = 0;
  107. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  108. //===============================
  109. // OCPP auth variable
  110. //===============================
  111. int authenrequest = FALSE;
  112. int authorizeRetryTimes = 0; //number of Retry times
  113. //===============================
  114. // OCPP StartTransaction transactionId variables
  115. //===============================
  116. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  117. //===============================
  118. // OCPP other variables
  119. //===============================
  120. int isUpdateRequest = FALSE;
  121. static int HeartBeatWaitTime = 10;
  122. static int FirstHeartBeat = 0;
  123. static int FirmwareStatusNotificationStatus = 3; // Idle
  124. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  125. static char CurrentChargingProfileScheduleStr[30]={0};
  126. //========================================
  127. // OCPP status/previous related variables
  128. //========================================
  129. static int GunStatusInterval = 10;
  130. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  131. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  132. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  133. static int GbPreviousSystemStatus[GB_QUANTITY];
  134. static int AcPreviousSystemStatus[AC_QUANTITY];
  135. int TransactionMessageAttemptsValue = 0;
  136. int TransactionMessageRetryIntervalValue = 0;
  137. static struct OCPPAuthLocalElemet
  138. {
  139. int listVersionInt;
  140. char idTagstr[20];
  141. char parentIdTag[20];
  142. char expiryDate[30];
  143. char idTagstatus[16];
  144. }idTagQuery;
  145. //=============================================
  146. // OCPP HeartBeat Response Not Receive Counts
  147. //============================================
  148. static int HeartBeatWithNOResponse = 0;
  149. static int HeartBeatCount = 0;
  150. extern struct lws *wsi_client;
  151. extern struct lws_context *context;
  152. extern unsigned char SendBuffer[4096];
  153. extern int SendBufLen;
  154. extern char *random_uuid( char buf[37] );
  155. extern void split(char **arr, char *str, const char *del);
  156. extern pthread_mutex_t mutex1;
  157. extern struct Charger_Info Charger;
  158. extern sqlite3 *db;
  159. int TransactionMessageAttemptsGet(void);
  160. int TransactionMessageRetryIntervalGet(void);
  161. int GetOcppConnStatus(void);
  162. void SetOcppConnStatus(uint8_t status);
  163. int updateSetting(char *key, char *value);
  164. int setKeyValue(char *key, char *value);
  165. void OCPP_get_TableAuthlocalAllData(void);
  166. void processUnkownKey(void);
  167. struct StructOCPPMeterValue
  168. {
  169. unsigned char TimeStamp[28];
  170. struct StructSampledValue SampledValue[10];
  171. };
  172. struct ClientTime
  173. {
  174. unsigned int Heartbeat;
  175. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  176. unsigned int StartTransaction;
  177. unsigned int StopTransaction;
  178. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  179. }clientTime;
  180. typedef union
  181. {
  182. //Operations Initiated by Central System
  183. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  184. struct
  185. {
  186. //CsMsgValue[0]
  187. unsigned char StatusNotificationReq :1; //bit 0,
  188. unsigned char StatusNotificationConf :1; //bit 0,
  189. unsigned char :6; //bit 2~7
  190. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  191. }CpinitiateMsg;
  192. CpinitiateMsg cpinitateMsg;
  193. //==========================================
  194. // Init all Enumeration & Mapping String
  195. //==========================================
  196. /*ChargePointErrorCode*/
  197. typedef enum {
  198. ConnectorLockFailure,
  199. EVCommunicationError,
  200. GroundFailure,
  201. HighTemperature,
  202. InternalError,
  203. LocalListConflict,
  204. NoError,
  205. OtherError,
  206. OverCurrentFailure,
  207. OverVoltage,
  208. PowerMeterFailure,
  209. PowerSwitchFailure,
  210. ReaderFailure,
  211. ResetFailure,
  212. UnderVoltage,
  213. WeakSignal
  214. } ChargePointErrorCode;
  215. #if 0
  216. static char *ChargePointErrorCodeStr[] = {
  217. MACROSTR(ConnectorLockFailure),
  218. MACROSTR(EVCommunicationError),
  219. MACROSTR(GroundFailure),
  220. MACROSTR(HighTemperature),
  221. MACROSTR(InternalError),
  222. MACROSTR(LocalListConflict),
  223. MACROSTR(NoError),
  224. MACROSTR(OtherError),
  225. MACROSTR(OverCurrentFailure),
  226. MACROSTR(OverVoltage),
  227. MACROSTR(PowerMeterFailure),
  228. MACROSTR(PowerSwitchFailure),
  229. MACROSTR(ReaderFailure),
  230. MACROSTR(ResetFailure),
  231. MACROSTR(UnderVoltage),
  232. MACROSTR(WeakSignal)
  233. };
  234. #endif
  235. /*ChargePointStatus*/
  236. typedef enum {
  237. Available =0,
  238. Preparing,
  239. Charging,
  240. SuspendedEVSE,
  241. SuspendedEV,
  242. Finishing,
  243. Reserved,
  244. Unavailable,
  245. Faulted
  246. } ChargePointStatus;
  247. static char * ChargePointStatusStr[] = {
  248. MACROSTR(Available),
  249. MACROSTR(Preparing),
  250. MACROSTR(Charging),
  251. MACROSTR(SuspendedEVSE),
  252. MACROSTR(SuspendedEV),
  253. MACROSTR(Finishing),
  254. MACROSTR(Reserved),
  255. MACROSTR(Unavailable),
  256. MACROSTR(Faulted)
  257. };
  258. /*AvailabilityType*/
  259. typedef enum {
  260. RegistrationStatus_Accepted,
  261. RegistrationStatus_Pending,
  262. RegistrationStatus_Rejected
  263. } RegistrationStatus;
  264. static char *RegistrationStatusStr[] = {
  265. MACROSTR(Accepted),
  266. MACROSTR(Pending),
  267. MACROSTR(Rejected)
  268. };
  269. /*AvailabilityType*/
  270. typedef enum {
  271. Inoperative,
  272. Operative
  273. } AvailabilityType;
  274. static char *AvailabilityTypeStr[] = {
  275. MACROSTR(Inoperative),
  276. MACROSTR(Operative)
  277. };
  278. /*AvailabilityStatus*/
  279. typedef enum {
  280. Accepted,
  281. Rejected,
  282. Scheduled
  283. } AvailabilityStatus;
  284. static char *AvailabilityStatusStr[] = {
  285. MACROSTR(Accepted),
  286. MACROSTR(Rejected),
  287. MACROSTR(Scheduled)
  288. };
  289. /*ConfigurationStatus*/
  290. typedef enum {
  291. ConfigurationStatus_Accepted,
  292. ConfigurationStatus_Rejected,
  293. RebootRequired,
  294. NotSupported
  295. } ConfigurationStatus;
  296. static char *ConfigurationStatusStr[] = {
  297. MACROSTR(Accepted),
  298. MACROSTR(Rejected),
  299. MACROSTR(RebootRequired),
  300. MACROSTR(NotSupported)
  301. };
  302. /*ClearCacheStatus*/
  303. typedef enum {
  304. ClearCacheStatus_Accepted,
  305. ClearCacheStatus_Rejected
  306. } ClearCacheStatus;
  307. static char *ClearCacheStatusStr[] = {
  308. MACROSTR(Accepted),
  309. MACROSTR(Rejected)
  310. };
  311. /*ChargingProfilePurposeType*/
  312. typedef enum {
  313. ChargePointMaxProfile,
  314. TxDefaultProfile,
  315. TxProfile
  316. } ChargingProfilePurposeType;
  317. static char *ChargingProfilePurposeTypeStr[] = {
  318. MACROSTR(ChargePointMaxProfile),
  319. MACROSTR(TxDefaultProfile),
  320. MACROSTR(TxProfile)
  321. };
  322. /*ChargingProfileStatus*/
  323. typedef enum {
  324. ChargingProfileStatus_Accepted,
  325. ChargingProfileStatus_Rejected,
  326. ChargingProfileStatus_NotSupported
  327. } ChargingProfileStatus;
  328. static char *ChargingProfileStatusStr[] = {
  329. MACROSTR(Accepted),
  330. MACROSTR(Rejected),
  331. MACROSTR(NotSupported)
  332. };
  333. /*ClearChargingProfileStatus*/
  334. typedef enum {
  335. ClearChargingProfileStatus_Accepted,
  336. ClearChargingProfileStatus_Unknown
  337. } ClearChargingProfileStatus;
  338. static char *ClearChargingProfileStatusStr[] = {
  339. MACROSTR(Accepted),
  340. MACROSTR(Unknown)
  341. };
  342. /*GetCompositeScheduleStatus*/
  343. typedef enum {
  344. GetCompositeScheduleStatus_Accepted,
  345. GetCompositeScheduleStatus_Rejected
  346. } GetCompositeScheduleStatus;
  347. static char *GetCompositeScheduleStatusStr[] = {
  348. MACROSTR(Accepted),
  349. MACROSTR(Rejected)
  350. };
  351. /*ChargingRateUnitType*/
  352. typedef enum {
  353. ChargingRateUnitType_W,
  354. ChargingRateUnitType_A
  355. } ChargingRateUnitType;
  356. /*AuthorizationStatus*/
  357. typedef enum {
  358. AuthorizationStatus_Accepted ,
  359. AuthorizationStatus_Blocked ,
  360. AuthorizationStatus_Expired ,
  361. AuthorizationStatus_Invalid ,
  362. AuthorizationStatus_ConcurrentTx
  363. } AuthorizationStatus;
  364. /*UpdateType*/
  365. typedef enum {
  366. Differential ,
  367. Full
  368. } UpdateType;
  369. static char *UpdateTypeStr[] = {
  370. MACROSTR(Differential),
  371. MACROSTR(Full)
  372. };
  373. /*UpdateStatus*/
  374. typedef enum {
  375. UpdateStatus_Accepted ,
  376. UpdateStatus_Failed ,
  377. UpdateStatus_NotSupported ,
  378. UpdateStatus_VersionMismatch
  379. } UpdateStatus;
  380. static char *UpdateStatusStr[] = {
  381. MACROSTR(Accepted),
  382. MACROSTR(Failed),
  383. MACROSTR(NotSupported),
  384. MACROSTR(VersionMismatch)
  385. };
  386. /*RemoteStartStopStatus*/
  387. typedef enum {
  388. RemoteStartStopStatus_Accepted,
  389. RemoteStartStopStatus_Rejected
  390. } RemoteStartStopStatus;
  391. static char *RemoteStartStopStatusStr[] = {
  392. MACROSTR(Accepted),
  393. MACROSTR(Rejected)
  394. };
  395. /*ReservationStatus*/
  396. typedef enum {
  397. ReservationStatus_Accepted,
  398. ReservationStatus_Faulted,
  399. ReservationStatus_Occupied,
  400. ReservationStatus_Rejected,
  401. ReservationStatus_Unavailable
  402. } ReservationStatus;
  403. static char *ReservationStatusStr[] = {
  404. MACROSTR(Accepted),
  405. MACROSTR(Faulted),
  406. MACROSTR(Occupied),
  407. MACROSTR(Rejected),
  408. MACROSTR(Unavailable)
  409. };
  410. /*ResetType*/
  411. typedef enum {
  412. Hard,
  413. Soft
  414. } ResetType;
  415. static char *ResetTypeStr[] = {
  416. MACROSTR(Hard),
  417. MACROSTR(Soft)
  418. };
  419. /*ResetStatus*/
  420. typedef enum {
  421. ResetStatus_Accepted,
  422. ResetStatus_Rejected
  423. } ResetStatus;
  424. static char *ResetStatusStr[] = {
  425. MACROSTR(Accepted),
  426. MACROSTR(Rejected)
  427. };
  428. /*DiagnosticsStatus*/
  429. typedef enum {
  430. DiagnosticsStatus_Idle,
  431. DiagnosticsStatus_Uploaded,
  432. DiagnosticsStatus_UploadFailed,
  433. DiagnosticsStatus_Uploading
  434. } DiagnosticsStatus;
  435. static char * DiagnosticsStatusStr[] = {
  436. MACROSTR(Idle),
  437. MACROSTR(Uploaded),
  438. MACROSTR(UploadFailed),
  439. MACROSTR(Uploading)
  440. };
  441. /*FirmwareStatus*/
  442. typedef enum {
  443. FirmwareStatus_Downloaded,
  444. FirmwareStatus_DownloadFailed,
  445. FirmwareStatus_Downloading,
  446. FirmwareStatus_Idle,
  447. FirmwareStatus_InstallationFailed,
  448. FirmwareStatus_Installing,
  449. FirmwareStatus_Installed
  450. } FirmwareStatus;
  451. static char * FirmwareStatusStr[] = {
  452. MACROSTR(Downloaded),
  453. MACROSTR(DownloadFailed),
  454. MACROSTR(Downloading),
  455. MACROSTR(Idle),
  456. MACROSTR(InstallationFailed),
  457. MACROSTR(Installing),
  458. MACROSTR(Installed)
  459. };
  460. /*MessageTrigger*/
  461. typedef enum {
  462. BootNotification,
  463. DiagnosticsStatusNotification,
  464. FirmwareStatusNotification,
  465. Heartbeat,
  466. MeterValues,
  467. StatusNotification
  468. } MessageTrigger;
  469. static char * MessageTriggerStr[] = {
  470. MACROSTR(BootNotification),
  471. MACROSTR(DiagnosticsStatusNotification),
  472. MACROSTR(FirmwareStatusNotification),
  473. MACROSTR(Heartbeat),
  474. MACROSTR(MeterValues),
  475. MACROSTR(StatusNotification)
  476. };
  477. /*TriggerMessageStatus*/
  478. typedef enum {
  479. TriggerMessageStatus_Accepted ,
  480. TriggerMessageStatus_Rejected ,
  481. TriggerMessageStatus_NotImplemented
  482. } TriggerMessageStatus;
  483. static char * TriggerMessageStatusStr[] = {
  484. MACROSTR(Accepted),
  485. MACROSTR(Rejected),
  486. MACROSTR(NotImplemented)
  487. };
  488. /*UnlockStatus*/
  489. typedef enum {
  490. Unlocked,
  491. UnlockFailed,
  492. UnlockStatus_NotSupported
  493. } UnlockStatus;
  494. static char * UnlockStatusStr[] = {
  495. MACROSTR(Unlocked),
  496. MACROSTR(UnlockFailed),
  497. MACROSTR(NotSupported)
  498. };
  499. /*StopTransactionReason*/
  500. typedef enum {
  501. EmergencyStop,
  502. EVDisconnected,
  503. HardReset,
  504. Local,
  505. Other,
  506. PowerLoss,
  507. Reboot,
  508. Remote,
  509. SoftReset,
  510. UnlockCommand,
  511. DeAuthorized
  512. } StopTransactionReason;
  513. #if 0
  514. static char * StopTransactionReasonStr[] = {
  515. MACROSTR(EmergencyStop),
  516. MACROSTR(EVDisconnected),
  517. MACROSTR(HardReset),
  518. MACROSTR(Local),
  519. MACROSTR(Other),
  520. MACROSTR(PowerLoss),
  521. MACROSTR(Reboot),
  522. MACROSTR(Remote),
  523. MACROSTR(SoftReset),
  524. MACROSTR(UnlockCommand),
  525. MACROSTR(DeAuthorized)
  526. };
  527. #endif
  528. /*CancelReservationStatus*/
  529. typedef enum {
  530. CancelReservationStatus_Accepted,
  531. CancelReservationStatus_Rejected
  532. } CancelReservationStatus;
  533. static char * CancelReservationStatusStr[] = {
  534. MACROSTR(Accepted),
  535. MACROSTR(Rejected)
  536. };
  537. /*ReadingContext*/
  538. typedef enum {
  539. ReadingContext_Interruption_Begin,
  540. ReadingContext_Interruption_End,
  541. ReadingContext_Other,
  542. ReadingContext_Sample_Clock,
  543. ReadingContext_Sample_Periodic ,
  544. ReadingContext_Transaction_Begin ,
  545. ReadingContext_Transaction_End,
  546. ReadingContext_Trigger
  547. } ReadingContext;
  548. static char * ReadingContextStr[] = {
  549. MACROSTR(Interruption.Begin),
  550. MACROSTR(Interruption.End),
  551. MACROSTR(Other),
  552. MACROSTR(Sample.Clock),
  553. MACROSTR(Sample.Periodic),
  554. MACROSTR(Transaction.Begin),
  555. MACROSTR(Transaction.End),
  556. MACROSTR(Trigger)
  557. };
  558. /*ValueFormat*/
  559. typedef enum {
  560. Raw,
  561. SignedData
  562. } ValueFormat;
  563. static char * ValueFormatStr[] = {
  564. MACROSTR(Raw),
  565. MACROSTR(SignedData)
  566. };
  567. /*Measurand*/
  568. typedef enum {
  569. Current_Export ,
  570. Current_Import,
  571. Current_Offered,
  572. Energy_Active_Export_Register,
  573. Energy_Active_Import_Register,
  574. Energy_Reactive_Export_Register,
  575. Energy_Reactive_Import_Register,
  576. Energy_Active_Export_Interval,
  577. Energy_Active_Import_Interval,
  578. Energy_Reactive_Export_Interval,
  579. Energy_Reactive_Import_Interval,
  580. Frequency,
  581. Power_Active_Export ,
  582. Power_Active_Import,
  583. Power_Factor,
  584. Power_Offered,
  585. Power_Reactive_Export,
  586. Power_Reactive_Import,
  587. RPM,
  588. SoC,
  589. Temperature ,
  590. Voltage
  591. } Measurand;
  592. static char * MeasurandStr[] = {
  593. MACROSTR(Current.Export),
  594. MACROSTR(Current.Import),
  595. MACROSTR(Current.Offered),
  596. MACROSTR(Energy.Active.Export.Register),
  597. MACROSTR(Energy.Active.Import.Register),
  598. MACROSTR(Energy.Reactive.Export.Register),
  599. MACROSTR(Energy.Reactive.Import.Register),
  600. MACROSTR(Energy.Active.Export.Interval),
  601. MACROSTR(Energy.Active.Import.Interval),
  602. MACROSTR(Energy.Reactive.Export.Interval),
  603. MACROSTR(Energy.Reactive.Import.Interval),
  604. MACROSTR(Frequency),
  605. MACROSTR(Power.Active.Export),
  606. MACROSTR(Power.Active.Import),
  607. MACROSTR(Power.Factor),
  608. MACROSTR(Power.Offered),
  609. MACROSTR(Power.Reactive.ExportMACROSTR),
  610. MACROSTR(Power.Reactive.Import),
  611. MACROSTR(RPM),
  612. MACROSTR(SoC),
  613. MACROSTR(Temperature),
  614. MACROSTR(Voltage)
  615. };
  616. /*Location*/
  617. typedef enum {
  618. Location_Body,
  619. Location_Cable,
  620. Location_EV,
  621. Location_Inlet ,
  622. Location_Outlet
  623. } Location;
  624. static char * LocationStr[] = {
  625. MACROSTR(Body),
  626. MACROSTR(Cable),
  627. MACROSTR(EV),
  628. MACROSTR(Inlet),
  629. MACROSTR(Outlet)
  630. };
  631. /*Phase*/
  632. typedef enum {
  633. L1,
  634. L2,
  635. L3,
  636. N,
  637. L1_N,
  638. L2_N,
  639. L3_N,
  640. L1_L2,
  641. L2_L3,
  642. L3_L1
  643. } Phase;
  644. static char * PhaseStr[] = {
  645. MACROSTR(L1),
  646. MACROSTR(L2),
  647. MACROSTR(L3),
  648. MACROSTR(N),
  649. MACROSTR(L1-N),
  650. MACROSTR(L2-N),
  651. MACROSTR(L3-N),
  652. MACROSTR(L1-L2),
  653. MACROSTR(L2-L3),
  654. MACROSTR(L3-L1)
  655. };
  656. /*UnitOfMeasure*/
  657. typedef enum {
  658. UnitOfMeasure_Wh,
  659. UnitOfMeasure_kWh ,
  660. UnitOfMeasure_varh ,
  661. UnitOfMeasure_kvarh ,
  662. UnitOfMeasure_W ,
  663. UnitOfMeasure_kW ,
  664. UnitOfMeasure_VA ,
  665. UnitOfMeasure_kVA ,
  666. UnitOfMeasure_var ,
  667. UnitOfMeasure_kvar ,
  668. UnitOfMeasure_A ,
  669. UnitOfMeasure_V ,
  670. UnitOfMeasure_Celsius ,
  671. UnitOfMeasure_Fahrenheit ,
  672. UnitOfMeasure_K ,
  673. UnitOfMeasure_Percent
  674. } UnitOfMeasure;
  675. static char * UnitOfMeasureStr[] = {
  676. MACROSTR(Wh),
  677. MACROSTR(kWh),
  678. MACROSTR(varh),
  679. MACROSTR(kvarh),
  680. MACROSTR(W),
  681. MACROSTR(kW),
  682. MACROSTR(VA),
  683. MACROSTR(kVA),
  684. MACROSTR(var),
  685. MACROSTR(kvar),
  686. MACROSTR(A),
  687. MACROSTR(V),
  688. MACROSTR(Celsius),
  689. MACROSTR(Fahrenheit),
  690. MACROSTR(K),
  691. MACROSTR(Percent)
  692. };
  693. #if 0
  694. /*Configuration enum*/
  695. enum CoreProfile {
  696. AllowOfflineTxForUnknownId=0,
  697. AuthorizationCacheEnabled,
  698. AuthorizeRemoteTxRequests,
  699. BlinkRepeat,
  700. ClockAlignedDataInterval,
  701. ConnectionTimeOut,
  702. GetConfigurationMaxKeys,
  703. HeartbeatInterval,
  704. LightIntensity,
  705. LocalAuthorizeOffline,
  706. LocalPreAuthorize,
  707. MaxEnergyOnInvalidId,
  708. MeterValuesAlignedData,
  709. MeterValuesAlignedDataMaxLength,
  710. MeterValuesSampledData,
  711. MeterValuesSampledDataMaxLength,
  712. MeterValueSampleInterval,
  713. MinimumStatusDuration,
  714. NumberOfConnectors,
  715. ResetRetries,
  716. ConnectorPhaseRotation,
  717. ConnectorPhaseRotationMaxLength,
  718. StopTransactionOnEVSideDisconnect,
  719. StopTransactionOnInvalidId,
  720. StopTxnAlignedData,
  721. StopTxnAlignedDataMaxLength,
  722. StopTxnSampledData,
  723. StopTxnSampledDataMaxLength,
  724. SupportedFeatureProfiles,
  725. SupportedFeatureProfilesMaxLength,
  726. TransactionMessageAttempts,
  727. TransactionMessageRetryInterval,
  728. UnlockConnectorOnEVSideDisconnect,
  729. WebSocketPingInterval,
  730. _CoreProfile_CNT
  731. };
  732. #endif
  733. enum LocalAuthListManagementProfile{
  734. LocalAuthListEnabled=0,
  735. LocalAuthListMaxLength,
  736. SendLocalListMaxLength,
  737. _LocalAuthListManagementProfile_CNT
  738. };
  739. enum ReservationProfile{
  740. ReserveConnectorZeroSupported
  741. };
  742. enum SmartChargingProfile{
  743. ChargeProfileMaxStackLevel,
  744. ChargingScheduleAllowedChargingRateUnit,
  745. ChargingScheduleMaxPeriods,
  746. ConnectorSwitch3to1PhaseSupported,
  747. MaxChargingProfilesInstalled
  748. };
  749. enum ChargerSystemStatus{
  750. ChargerSystemStatus_Booting,
  751. ChargerSystemStatus_Idle,
  752. ChargerSystemStatus_Authorizing,
  753. ChargerSystemStatus_Preparing,
  754. ChargerSystemStatus_Charging,
  755. ChargerSystemStatus_Terminating,
  756. ChargerSystemStatus_Alarm,
  757. ChargerSystemStatus_Fault
  758. };
  759. enum GetConfigurationKey {
  760. GetConfiguration_AllowOfflineTxForUnknownId=0,
  761. GetConfiguration_AuthorizationCacheEnabled,
  762. GetConfiguration_AuthorizeRemoteTxRequests,
  763. GetConfiguration_BlinkRepeat,
  764. GetConfiguration_ClockAlignedDataInterval,
  765. GetConfiguration_ConnectionTimeOut,
  766. GetConfiguration_GetConfigurationMaxKeys,
  767. GetConfiguration_HeartbeatInterval,
  768. GetConfiguration_LightIntensity,
  769. GetConfiguration_LocalAuthorizeOffline,
  770. GetConfiguration_LocalPreAuthorize,
  771. GetConfiguration_MaxEnergyOnInvalidId,
  772. GetConfiguration_MeterValuesAlignedData,
  773. GetConfiguration_MeterValuesAlignedDataMaxLength,
  774. GetConfiguration_MeterValuesSampledData,
  775. GetConfiguration_MeterValuesSampledDataMaxLength,
  776. GetConfiguration_MeterValueSampleInterval,
  777. GetConfiguration_MinimumStatusDuration,
  778. GetConfiguration_NumberOfConnectors,
  779. GetConfiguration_ResetRetries,
  780. GetConfiguration_ConnectorPhaseRotation,
  781. GetConfiguration_ConnectorPhaseRotationMaxLength,
  782. GetConfiguration_StopTransactionOnEVSideDisconnect,
  783. GetConfiguration_StopTransactionOnInvalidId,
  784. GetConfiguration_StopTxnAlignedData,
  785. GetConfiguration_StopTxnAlignedDataMaxLength,
  786. GetConfiguration_StopTxnSampledData,
  787. GetConfiguration_StopTxnSampledDataMaxLength,
  788. GetConfiguration_SupportedFeatureProfiles,
  789. GetConfiguration_SupportedFeatureProfilesMaxLength,
  790. GetConfiguration_TransactionMessageAttempts,
  791. GetConfiguration_TransactionMessageRetryInterval,
  792. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  793. GetConfiguration_WebSocketPingInterval,
  794. GetConfiguration_LocalAuthListEnabled,
  795. GetConfiguration_LocalAuthListMaxLength,
  796. GetConfiguration_SendLocalListMaxLength,
  797. GetConfiguration_ReserveConnectorZeroSupported,
  798. GetConfiguration_ChargeProfileMaxStackLevel,
  799. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  800. GetConfiguration_ChargingScheduleMaxPeriods,
  801. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  802. GetConfiguration_MaxChargingProfilesInstalled,
  803. };
  804. //GetConfiguration Array
  805. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  806. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  807. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  808. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  809. //==========================================
  810. // Init all share memory
  811. //==========================================
  812. int InitShareMemory()
  813. {
  814. int result = PASS;
  815. int MeterSMId;
  816. //creat ShmSysConfigAndInfo
  817. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  818. {
  819. #ifdef SystemLogMessage
  820. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  821. #endif
  822. result = FAIL;
  823. }
  824. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  825. {
  826. #ifdef SystemLogMessage
  827. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  828. #endif
  829. result = FAIL;
  830. }
  831. else
  832. {}
  833. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  834. {
  835. #ifdef SystemLogMessage
  836. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  837. #endif
  838. result = FAIL;
  839. }
  840. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  841. {
  842. #ifdef SystemLogMessage
  843. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  844. #endif
  845. result = FAIL;
  846. }
  847. else
  848. {}
  849. //creat ShmPsuData
  850. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  851. {
  852. #ifdef SystemLogMessage
  853. DEBUG_ERROR("shmget ShmPsuData NG\n");
  854. #endif
  855. result = FAIL;
  856. }
  857. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  858. {
  859. #ifdef SystemLogMessage
  860. DEBUG_ERROR("shmat ShmPsuData NG\n");
  861. #endif
  862. result = FAIL;
  863. }
  864. else
  865. {}
  866. //creat ShmOCPP16Data
  867. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  868. {
  869. #ifdef SystemLogMessage
  870. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  871. #endif
  872. result = FAIL;
  873. }
  874. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  875. {
  876. #ifdef SystemLogMessage
  877. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  878. #endif
  879. result = FAIL;
  880. }
  881. else
  882. {}
  883. /****************************** For Initial Settings************************************************/
  884. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  885. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  886. {
  887. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  888. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  889. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  890. }
  891. // Charger PRE_SYS_MODE
  892. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  893. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  894. clientTime.Heartbeat=time((time_t*)NULL);
  895. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  896. {
  897. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  898. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  899. }
  900. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  901. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  902. // allocate Configuration memory address
  903. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  904. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  905. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  906. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  908. {
  909. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  910. DEBUG_INFO("DC ...\n");
  911. }
  912. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  913. {
  914. SystemInitial = AC_QUANTITY;
  915. DEBUG_INFO("AC ...\n");
  916. }
  917. //Status Setting
  918. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  919. {
  920. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  921. }
  922. for (int index = 0; index < CCS_QUANTITY; index++)
  923. {
  924. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  925. }
  926. for (int index = 0; index < GB_QUANTITY; index++)
  927. {
  928. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  929. }
  930. for (int index = 0; index < AC_QUANTITY; index++)
  931. {
  932. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  933. }
  934. return result;
  935. }
  936. int ProcessShareMemory()
  937. {
  938. if(InitShareMemory() == FAIL)
  939. {
  940. #ifdef SystemLogMessage
  941. DEBUG_ERROR("InitShareMemory NG\n");
  942. #endif
  943. if(ShmStatusCodeData!=NULL)
  944. {
  945. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  946. }
  947. sleep(5);
  948. return FAIL;
  949. }
  950. return PASS;
  951. }
  952. //---------------------------------------------
  953. // new:
  954. // enum SYSTEM_STATUS
  955. // {
  956. // SYS_MODE_BOOTING = 0,
  957. // SYS_MODE_IDLE = 1,
  958. // SYS_MODE_AUTHORIZING = 2,
  959. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  960. // SYS_MODE_REASSIGN = 4,
  961. // SYS_MODE_PREPARING = 5,
  962. // SYS_MODE_PREPARE_FOR_EV = 6,
  963. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  964. // SYS_MODE_CHARGING = 8,
  965. // SYS_MODE_TERMINATING = 9,
  966. // SYS_MODE_COMPLETE = 10,
  967. // SYS_MODE_ALARM = 11,
  968. // SYS_MODE_FAULT = 12,
  969. // SYS_MODE_RESERVATION = 13,
  970. // SYS_MODE_BOOKING = 14,
  971. // SYS_MODE_MAINTAIN = 15,
  972. // SYS_MODE_DEBUG = 16,
  973. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  974. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  975. // SYS_MODE_UPDATE = 19
  976. // };
  977. //
  978. //
  979. //-----------------------------------------
  980. void CheckSystemValue(void)
  981. {
  982. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  983. int IdleModeCnt = 0;
  984. char filenmae[100]={0};
  985. char str[100]={0};
  986. //===============================
  987. // send Heartbeat
  988. //===============================
  989. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  990. {
  991. printf("Heartbeat !!!\n");
  992. //parameter for test
  993. sendHeartbeatRequest(0);
  994. //==============================================
  995. // Reset Waiting Time
  996. //==============================================
  997. clientTime.Heartbeat=time((time_t*)NULL);
  998. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  999. }
  1000. //==============================================
  1001. // Update firmware request
  1002. //==============================================
  1003. if(isUpdateRequest == TRUE )
  1004. {
  1005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1006. {
  1007. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1008. {
  1009. //check SystemStatus
  1010. /*************************DC*******************************/
  1011. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1012. {
  1013. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1014. {
  1015. IdleModeCnt = IdleModeCnt + 1;
  1016. }
  1017. }
  1018. for (int index = 0; index < CCS_QUANTITY; index++)
  1019. {
  1020. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1021. {
  1022. IdleModeCnt = IdleModeCnt + 1;
  1023. }
  1024. }
  1025. for (int index = 0; index < GB_QUANTITY; index++)
  1026. {
  1027. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1028. {
  1029. IdleModeCnt = IdleModeCnt + 1;
  1030. }
  1031. }
  1032. }
  1033. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1034. {
  1035. isUpdateRequest = FALSE;
  1036. }
  1037. }
  1038. else
  1039. {
  1040. /*************************AC*******************************/
  1041. for (int index = 0; index < AC_QUANTITY; index++)
  1042. {
  1043. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1044. {
  1045. IdleModeCnt = IdleModeCnt + 1;
  1046. }
  1047. }
  1048. if(IdleModeCnt == AC_QUANTITY)
  1049. {
  1050. isUpdateRequest = FALSE;
  1051. }
  1052. }
  1053. }
  1054. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1055. {
  1056. //===============================
  1057. // CSU Trigger Reset Conf
  1058. //===============================
  1059. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1060. {
  1061. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1062. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1063. {
  1064. server_sign = FALSE;
  1065. }
  1066. }
  1067. //===============================
  1068. // CSU Trigger Authorize Request
  1069. //===============================
  1070. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1071. {
  1072. //if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1073. //{
  1074. sendAuthorizeRequest(0);
  1075. authorizeRetryTimes = authorizeRetryTimes + 1;
  1076. // authenrequest = TRUE
  1077. if(authorizeRetryTimes < 3)
  1078. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1079. //}
  1080. }
  1081. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1082. {
  1083. authorizeRetryTimes = 0;
  1084. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1085. server_sign = FALSE;
  1086. }
  1087. else if((server_sign == FALSE) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  1088. {
  1089. sendAuthorizeRequest(0);
  1090. }
  1091. //===============================
  1092. // CSU Trigger Smart Charging Profilw
  1093. //===============================
  1094. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1095. {
  1096. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1097. GetChargingProfileRequest(gun_index);
  1098. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1099. }
  1100. //==============================================
  1101. // Charger start transaction
  1102. //==============================================
  1103. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1104. {
  1105. sendStartTransactionRequest(gun_index);
  1106. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1107. clientTime.StartTransaction = time((time_t*)NULL);
  1108. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1109. }
  1110. //==============================================
  1111. // Charger stop transaction
  1112. //==============================================
  1113. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1114. {
  1115. sendStopTransactionRequest(gun_index);
  1116. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1117. clientTime.StopTransaction = time((time_t*)NULL);
  1118. }
  1119. //==============================================
  1120. // Charger status report
  1121. //==============================================
  1122. /* Check Mode Change */
  1123. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1124. {
  1125. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1126. {
  1127. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1128. {
  1129. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1130. {
  1131. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1132. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1133. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1134. statusModeChage[gun_index] = TRUE;
  1135. }
  1136. }
  1137. }
  1138. for (int index = 0; index < CCS_QUANTITY; index++)
  1139. {
  1140. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1141. {
  1142. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1143. {
  1144. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1145. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1146. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1147. statusModeChage[gun_index] = TRUE;
  1148. }
  1149. }
  1150. }
  1151. for (int index = 0; index < GB_QUANTITY; index++)
  1152. {
  1153. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1154. {
  1155. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1156. {
  1157. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1158. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1159. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1160. statusModeChage[gun_index] = TRUE;
  1161. }
  1162. }
  1163. }
  1164. }
  1165. else //AC
  1166. {
  1167. for (int index = 0; index < AC_QUANTITY; index++)
  1168. {
  1169. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1170. {
  1171. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1172. {
  1173. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1174. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1175. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1176. statusModeChage[gun_index] = TRUE;
  1177. }
  1178. }
  1179. }// END OF FOR
  1180. }// END OF ELSE
  1181. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1182. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1183. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1184. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1185. {
  1186. if(SystemInitial != 0)
  1187. SystemInitial = SystemInitial -1;
  1188. sendStatusNotificationRequest(gun_index);
  1189. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1190. statusModeChage[gun_index] = FALSE;
  1191. }
  1192. //==============================================
  1193. // Meter report
  1194. //==============================================
  1195. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1196. {
  1197. //check Transaction active
  1198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1199. {
  1200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1201. {
  1202. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1203. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1204. {
  1205. meterValueSend[gun_index] =1;
  1206. }
  1207. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1208. {
  1209. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1210. if((access(filenmae,F_OK))!=-1)
  1211. {
  1212. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1213. sprintf(str,"rm -f %s",filenmae);
  1214. system(str);
  1215. }
  1216. }
  1217. }// End for CHAdeMO
  1218. for (int index = 0; index < CCS_QUANTITY; index++)
  1219. {
  1220. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1221. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1222. {
  1223. meterValueSend[gun_index] =1;
  1224. }
  1225. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1226. {
  1227. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1228. if((access(filenmae,F_OK))!=-1)
  1229. {
  1230. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1231. sprintf(str,"rm -f %s",filenmae);
  1232. system(str);
  1233. }
  1234. }
  1235. } // End for CCS
  1236. for (int index = 0; index < GB_QUANTITY; index++)
  1237. {
  1238. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1239. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1240. {
  1241. meterValueSend[gun_index] =1;
  1242. }
  1243. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1244. {
  1245. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1246. if((access(filenmae,F_OK))!=-1)
  1247. {
  1248. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1249. sprintf(str,"rm -f %s",filenmae);
  1250. system(str);
  1251. }
  1252. }
  1253. }// End for GB
  1254. }
  1255. else
  1256. {
  1257. for (int index = 0; index < AC_QUANTITY; index++)
  1258. {
  1259. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1260. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1261. {
  1262. meterValueSend[gun_index] =1;
  1263. }
  1264. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1265. {
  1266. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1267. if((access(filenmae,F_OK))!=-1)
  1268. {
  1269. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1270. sprintf(str,"rm -f %s",filenmae);
  1271. system(str);
  1272. }
  1273. }
  1274. }//End for AC
  1275. }//END OF ELSE
  1276. // sleep(1);
  1277. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1278. if(meterValueSend[gun_index] == 1)
  1279. sendMeterValuesRequest(gun_index);
  1280. }
  1281. //==============================================
  1282. // Check Connector reserved
  1283. //==============================================
  1284. //===============================
  1285. // Check if Reserve is expired
  1286. //===============================
  1287. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1288. {
  1289. double diff_t;
  1290. struct tm tp;
  1291. // current time
  1292. time_t t = time(NULL);
  1293. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1294. tp.tm_isdst = -1;
  1295. time_t utc = mktime(&tp);
  1296. diff_t = difftime(utc, t);
  1297. if(diff_t <= 0)
  1298. {
  1299. DEBUG_INFO("reserve expired !!! \n");
  1300. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1301. }
  1302. }//END OF Check if Reserve is expired
  1303. //==========================================
  1304. // csu trigger FirmwareStatusNotificationReq
  1305. //==========================================
  1306. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1307. {
  1308. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1309. }
  1310. //==========================================
  1311. // csu trigger CancelReservationConf
  1312. //==========================================
  1313. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1314. {
  1315. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1316. }
  1317. //==========================================
  1318. // csu trigger ChangeAvailabilityConf
  1319. //==========================================
  1320. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1321. {
  1322. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1323. }
  1324. //==========================================
  1325. // csu trigger UnlockConnectorConf
  1326. //==========================================
  1327. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1328. {
  1329. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1330. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1331. }
  1332. //==========================================
  1333. // csu trigger ReserveNowConf
  1334. //==========================================
  1335. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1336. {
  1337. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1338. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1339. }
  1340. //==========================================
  1341. // csu trigger DataTransferReq
  1342. //==========================================
  1343. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1344. {
  1345. sendDataTransferRequest(gun_index);
  1346. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1347. }
  1348. }
  1349. }
  1350. //==========================================
  1351. // send request routine
  1352. //==========================================
  1353. int sendAuthorizeRequest(int gun_index)
  1354. {
  1355. mtrace();
  1356. int result = FAIL;
  1357. char message[100]={0};
  1358. char guid[37];
  1359. char tempdata[65]={0};
  1360. DEBUG_INFO("sendAuthorizeRequest \n");
  1361. //Local Authorize
  1362. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))
  1363. {
  1364. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1365. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1366. {
  1367. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1368. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1369. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1370. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1371. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1372. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1373. authorizeRetryTimes = 0;
  1374. return result;
  1375. }
  1376. else
  1377. {
  1378. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1379. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1380. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1381. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1382. result = PASS;
  1383. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1384. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1385. authorizeRetryTimes = 0;
  1386. return result;
  1387. }
  1388. }
  1389. //initailize struct Authorize
  1390. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1391. //get data from shared memory
  1392. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1393. random_uuid(guid);
  1394. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1395. LWS_Send(message);
  1396. sprintf(tempdata, "Authorize,%d", gun_index);
  1397. if(hashmap_operation(0, guid, tempdata) == 1)
  1398. {
  1399. result = PASS;
  1400. DEBUG_ERROR("Authorize mapItem pass\n");
  1401. }
  1402. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1403. return result;
  1404. }
  1405. int sendBootNotificationRequest(void)
  1406. {
  1407. mtrace();
  1408. int result = FAIL;
  1409. char message[500]={0}, payload[700]={0};
  1410. char guid[37]={0};
  1411. char tempdata[65]={0};
  1412. int IsGunCharging = FALSE;
  1413. //check Transaction active
  1414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1415. {
  1416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1417. {
  1418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1419. {
  1420. IsGunCharging = TRUE;
  1421. }
  1422. }
  1423. for (int index = 0; index < CCS_QUANTITY; index++)
  1424. {
  1425. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1426. {
  1427. IsGunCharging = TRUE;
  1428. }
  1429. }
  1430. for (int index = 0; index < GB_QUANTITY; index++)
  1431. {
  1432. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1433. {
  1434. IsGunCharging = TRUE;
  1435. }
  1436. }
  1437. }
  1438. else
  1439. {
  1440. for (int index = 0; index < AC_QUANTITY; index++)
  1441. {
  1442. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1443. {
  1444. IsGunCharging = TRUE;
  1445. }
  1446. }
  1447. }
  1448. if(IsGunCharging == TRUE)
  1449. {
  1450. server_sign = TRUE;
  1451. return result;
  1452. }
  1453. // Fill BootNotification fields
  1454. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1455. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1456. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1457. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1458. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1459. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1460. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1461. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1462. ShmOCPP16Data->ChargeBoxId
  1463. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1464. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1465. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1466. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1467. ,ShmOCPP16Data->BootNotification.CpIccid
  1468. ,ShmOCPP16Data->BootNotification.CpImsi
  1469. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1470. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1471. random_uuid(guid);
  1472. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1473. LWS_Send(message);
  1474. sprintf(tempdata, "BootNotification,0");
  1475. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1476. {
  1477. result = PASS;
  1478. }
  1479. memset(queuedata, 0, sizeof(queuedata));
  1480. strcpy(queuedata,message);
  1481. HeartBeatCount = 0;
  1482. return result;
  1483. }
  1484. int sendDataTransferRequest(int gun_index)
  1485. {
  1486. mtrace();
  1487. char message[1000]={0};
  1488. char guid[37]={0};
  1489. char tempdata[65]={0};
  1490. int result = FAIL;
  1491. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1492. random_uuid(guid);
  1493. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1494. MESSAGE_TYPE_CALL,
  1495. guid,
  1496. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1497. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1498. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1499. LWS_Send(message);
  1500. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1501. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1502. {
  1503. result = PASS;
  1504. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1505. }
  1506. return result;
  1507. }
  1508. int sendDiagnosticsStatusNotificationRequest(char *status)
  1509. {
  1510. mtrace();
  1511. int result = FAIL;
  1512. char message[110]={0};
  1513. char guid[37]={0};
  1514. char tempdata[65]={0};
  1515. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1516. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1517. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1518. random_uuid(guid);
  1519. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1520. LWS_Send(message);
  1521. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1522. if(hashmap_operation(0, guid, tempdata) == 1)
  1523. {
  1524. result = PASS;
  1525. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1526. }
  1527. //#ifdef SystemLogMessage
  1528. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1529. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1530. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1531. //#endif
  1532. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1533. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1534. //record status
  1535. if(strcmp(status,"Idle")==0)
  1536. {
  1537. DiagnosticsStatusNotificationStatus = 0;
  1538. }
  1539. else if(strcmp(status,"Uploaded")==0)
  1540. {
  1541. DiagnosticsStatusNotificationStatus = 1;
  1542. }
  1543. else if(strcmp(status,"UploadFailed")==0)
  1544. {
  1545. DiagnosticsStatusNotificationStatus = 2;
  1546. }
  1547. else if(strcmp(status,"Uploading")==0)
  1548. {
  1549. DiagnosticsStatusNotificationStatus = 3;
  1550. }
  1551. return result;
  1552. }
  1553. int sendFirmwareStatusNotificationRequest(char *status)
  1554. {
  1555. mtrace();
  1556. int result = FAIL;
  1557. char message[110]={0};
  1558. char guid[37]={0};
  1559. char tempdata[65]={0};
  1560. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1561. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1562. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1563. random_uuid(guid);
  1564. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1565. LWS_Send(message);
  1566. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1567. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1568. {
  1569. result = PASS;
  1570. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1571. }
  1572. //#ifdef SystemLogMessage
  1573. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1574. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1575. //#endif
  1576. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1577. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1578. //record status
  1579. if(strcmp(status,"Downloaded")==0)
  1580. {
  1581. FirmwareStatusNotificationStatus = 0;
  1582. }
  1583. else if(strcmp(status,"DownloadFailed")==0)
  1584. {
  1585. FirmwareStatusNotificationStatus = 1;
  1586. }
  1587. else if(strcmp(status,"Downloading")==0)
  1588. {
  1589. FirmwareStatusNotificationStatus = 2;
  1590. }
  1591. else if(strcmp(status,"Idle")==0)
  1592. {
  1593. FirmwareStatusNotificationStatus = 3;
  1594. }
  1595. else if(strcmp(status,"InstallationFailed")==0)
  1596. {
  1597. FirmwareStatusNotificationStatus = 4;
  1598. }
  1599. else if(strcmp(status,"Installing")==0)
  1600. {
  1601. FirmwareStatusNotificationStatus = 5;
  1602. }
  1603. else if(strcmp(status,"Installed")==0)
  1604. {
  1605. FirmwareStatusNotificationStatus = 6;
  1606. }
  1607. return result;
  1608. }
  1609. int sendHeartbeatRequest(int gun_index)
  1610. {
  1611. mtrace();
  1612. int result = FAIL;
  1613. char message[80]={0};
  1614. char guid[37]={0};
  1615. char tempdata[65]={0};
  1616. random_uuid(guid);
  1617. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1618. , MESSAGE_TYPE_CALL
  1619. , guid );
  1620. LWS_Send(message);
  1621. sprintf(tempdata, "Heartbeat,%d", 0);
  1622. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1623. {
  1624. result = PASS;
  1625. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1626. }
  1627. return result;
  1628. }
  1629. int sendStartTransactionRequest(int gun_index)
  1630. {
  1631. mtrace();
  1632. int result = FAIL;
  1633. char message[250]={0};
  1634. char guid[37]={0};
  1635. struct timeval tmnow;
  1636. struct tm *tm;
  1637. char buf[28];//, usec_buf[6];
  1638. char tempdata[65]={0};
  1639. DEBUG_INFO("sendStartTransactionRequest...");
  1640. gettimeofday(&tmnow, NULL);
  1641. time_t t;
  1642. t = time(NULL);
  1643. /*UTC time and date*/
  1644. tm = gmtime(&t);
  1645. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1646. #if 0 // remove temporally
  1647. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1648. strcat(buf,".");
  1649. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1650. strcat(buf,usec_buf);
  1651. #endif
  1652. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1653. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1654. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1656. {
  1657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1658. {
  1659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1660. {
  1661. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1662. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1663. }
  1664. }
  1665. for (int index = 0; index < CCS_QUANTITY; index++)
  1666. {
  1667. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1668. {
  1669. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1670. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1671. }
  1672. }
  1673. for (int index = 0; index < GB_QUANTITY; index++)
  1674. {
  1675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1676. {
  1677. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1678. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1679. }
  1680. }
  1681. }
  1682. else
  1683. {
  1684. for (int index = 0; index < AC_QUANTITY; index++)
  1685. {
  1686. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1687. {
  1688. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1689. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1690. }
  1691. }
  1692. }//END OF ELSE
  1693. random_uuid(guid);
  1694. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1695. , MESSAGE_TYPE_CALL
  1696. , guid
  1697. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1698. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1699. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1700. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1701. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1702. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1703. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1704. {
  1705. result = PASS;
  1706. }
  1707. strcpy(queuedata, message);
  1708. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1709. LWS_Send(message);
  1710. #if 0
  1711. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1712. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1713. {
  1714. result = PASS;
  1715. }
  1716. strcpy(queuedata, message);
  1717. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1718. #endif
  1719. //#ifdef SystemLogMessage
  1720. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1721. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1722. //#endif
  1723. return result;
  1724. }
  1725. int sendStatusNotificationRequest(int gun_index)
  1726. {
  1727. mtrace();
  1728. int result = FAIL;
  1729. char message[600]={0};
  1730. char guid[37];
  1731. int currentStatus = 0;
  1732. struct timeval tmnow;
  1733. struct tm *tm;
  1734. char buf[28];//, usec_buf[6];
  1735. char tempdata[65]={0};
  1736. gettimeofday(&tmnow, NULL);
  1737. time_t t;
  1738. t = time(NULL);
  1739. /*UTC time and date*/
  1740. tm = gmtime(&t);
  1741. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1742. #if 0 // remove temporally
  1743. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1744. strcat(buf,".");
  1745. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1746. strcat(buf,usec_buf);
  1747. #endif
  1748. printf("%s",buf);
  1749. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1750. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1751. // it's option
  1752. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1753. /*
  1754. enum _SYSTEM_STATUS
  1755. {
  1756. S_BOOTING = 0,
  1757. S_IDLE, = 1
  1758. S_AUTHORIZING, =2
  1759. S_REASSIGN_CHECK, =3
  1760. S_REASSIGN, =4
  1761. S_PRECHARGE, =5
  1762. S_PREPARING_FOR_EV, =6
  1763. S_PREPARING_FOR_EVSE, =7
  1764. S_CHARGING, =8
  1765. S_TERMINATING, =9
  1766. S_COMPLETE, =10
  1767. S_ALARM, =11
  1768. S_FAULT =12
  1769. }
  1770. */
  1771. //check Transaction active
  1772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1773. {
  1774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1775. {
  1776. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1777. {
  1778. currentStatus = 0; //OCPP Status: Available
  1779. }
  1780. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1781. {
  1782. currentStatus = 1; //OCPP Status: Preparing
  1783. }
  1784. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1785. {
  1786. currentStatus = 2; //OCPP Status: Charging
  1787. }
  1788. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1789. {
  1790. currentStatus = 5; //OCPP Status: Finishing
  1791. }
  1792. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1793. {
  1794. currentStatus = 4; //OCPP Status: SuspendedEV
  1795. }
  1796. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE) )) // ---> Unavailable
  1797. {
  1798. currentStatus = 7; //OCPP Status: Unavailable
  1799. }
  1800. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1801. {
  1802. currentStatus = 8; //OCPP Status: Faulted
  1803. }
  1804. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1805. {
  1806. currentStatus = 6; //OCPP Status: Reserved
  1807. }
  1808. }//end of for CHAdeMO_QUANTITY
  1809. for (int index = 0; index < CCS_QUANTITY; index++)
  1810. {
  1811. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1812. {
  1813. currentStatus = 0; //OCPP Status: Available
  1814. }
  1815. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1816. {
  1817. currentStatus = 1; //OCPP Status: Preparing
  1818. }
  1819. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1820. {
  1821. currentStatus = 2; //OCPP Status: Charging
  1822. }
  1823. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1824. {
  1825. currentStatus = 5; //OCPP Status: Finishing
  1826. }
  1827. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM ,S_TERMINATING ---> SuspendedEV
  1828. {
  1829. currentStatus = 4; //OCPP Status: SuspendedEV
  1830. }
  1831. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1832. {
  1833. currentStatus = 7; //OCPP Status : Unavailable
  1834. }
  1835. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1836. {
  1837. currentStatus = 8; //OCPP Status: Faulted
  1838. }
  1839. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1840. {
  1841. currentStatus = 6; //OCPP Status: Reserved
  1842. }
  1843. }
  1844. for (int index = 0; index < GB_QUANTITY; index++)
  1845. {
  1846. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1847. {
  1848. currentStatus = 0; //OCPP Status: Available
  1849. }
  1850. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1851. {
  1852. currentStatus = 1; //OCPP Status: Preparing
  1853. }
  1854. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1855. {
  1856. currentStatus = 2; //OCPP Status: Charging
  1857. }
  1858. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1859. {
  1860. currentStatus = 5; //OCPP Status: Finishing
  1861. }
  1862. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM , S_TERMINATING ---> SuspendedEV
  1863. {
  1864. currentStatus = 4; //OCPP Status: SuspendedEV
  1865. }
  1866. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1867. {
  1868. currentStatus = 7; //OCPP Status: Unavailable
  1869. }
  1870. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1871. {
  1872. currentStatus = 8; //OCPP Status: Faulted
  1873. }
  1874. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1875. {
  1876. currentStatus = 6; //OCPP Status: Reserved
  1877. }
  1878. }
  1879. }
  1880. else
  1881. {
  1882. for (int index = 0; index < AC_QUANTITY; index++)
  1883. {
  1884. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1885. {
  1886. currentStatus = 0; //OCPP Status: Available
  1887. }
  1888. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1889. {
  1890. currentStatus = 1; //OCPP Status: Preparing
  1891. }
  1892. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1893. {
  1894. currentStatus = 2; //OCPP Status: Charging
  1895. }
  1896. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1897. {
  1898. currentStatus = 5; //OCPP Status: Finishing
  1899. }
  1900. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1901. {
  1902. currentStatus = 4; //OCPP Status: SuspendedEV
  1903. }
  1904. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE))) // ---> Unavailable
  1905. {
  1906. currentStatus = 7; //OCPP Status: Unavailable
  1907. }
  1908. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1909. {
  1910. currentStatus = 8; //OCPP Status: Faulted
  1911. }
  1912. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1913. {
  1914. currentStatus = 6; //OCPP Status: Reserved
  1915. }
  1916. }//end of for AC_QUANTITY
  1917. }//END OF ELSE
  1918. //it's option
  1919. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1920. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1921. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1922. random_uuid(guid);
  1923. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1924. , MESSAGE_TYPE_CALL
  1925. , guid
  1926. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1927. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1928. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1929. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1930. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1931. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1932. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1933. LWS_Send(message);
  1934. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1935. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1936. {
  1937. //DEBUG_ERROR("statusNotification mapitem pass");
  1938. result = PASS;
  1939. }
  1940. return result;
  1941. }
  1942. int sendStopTransactionRequest(int gun_index)
  1943. {
  1944. mtrace();
  1945. int result = FAIL;
  1946. //char message[1500]={0};
  1947. char guid[37]={0};
  1948. char tempdata[65]={0};
  1949. //int idx_sample=0;
  1950. DEBUG_ERROR("sendStopTransactionRequest \n");
  1951. memset(queuedata, 0, sizeof(queuedata));
  1952. //ENERGY_ACTIVE_IMPORT_REGISTER
  1953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1954. {
  1955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1956. {
  1957. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1958. {
  1959. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1960. }
  1961. }// END OF CHAdeMO_QUANTITY
  1962. for (int index = 0; index < CCS_QUANTITY; index++)
  1963. {
  1964. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1965. {
  1966. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1967. }
  1968. }// END OF CCS_QUANTITY
  1969. for (int index = 0; index < GB_QUANTITY; index++)
  1970. {
  1971. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1972. {
  1973. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1974. }
  1975. }// END OF GB_QUANTITY
  1976. }
  1977. else
  1978. {
  1979. for (int index = 0; index < AC_QUANTITY; index++)
  1980. {
  1981. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1982. {
  1983. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1984. }
  1985. }// END OF AC_QUANTITY
  1986. }//END OF ELSE
  1987. //Stop Transaction Time
  1988. struct timeval tmnow;
  1989. struct tm *tm;
  1990. char buf[28];//, usec_buf[6];
  1991. gettimeofday(&tmnow, NULL);
  1992. time_t t;
  1993. t = time(NULL);
  1994. /*UTC time and date*/
  1995. tm = gmtime(&t);
  1996. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  1998. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  1999. random_uuid(guid);
  2000. /***********************************transactionData******************************************************/
  2001. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2003. //=================================
  2004. // Transaction_Begin
  2005. //=================================
  2006. // Energy.Active.Export.Interval
  2007. //idx_sample=0;
  2008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Export_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2013. {
  2014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2015. }
  2016. else
  2017. {
  2018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2019. }
  2020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2022. //=================================
  2023. // Transaction_End
  2024. //=================================
  2025. //Current.Export
  2026. //idx_sample=1;
  2027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2028. {
  2029. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2030. {
  2031. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2032. {
  2033. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2034. }
  2035. }
  2036. for (int index = 0; index < CCS_QUANTITY; index++)
  2037. {
  2038. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2039. {
  2040. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2041. }
  2042. }
  2043. for (int index = 0; index < GB_QUANTITY; index++)
  2044. {
  2045. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2046. {
  2047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2048. }
  2049. }
  2050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2051. }
  2052. else
  2053. {
  2054. for (int index = 0; index < AC_QUANTITY; index++)
  2055. {
  2056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2057. {
  2058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2059. }
  2060. }
  2061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2062. }// END FOR AC ELSE
  2063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2066. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2069. //Energy.Active.Export.Interval
  2070. //idx_sample=2;
  2071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2072. {
  2073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2074. {
  2075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2076. {
  2077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2078. }
  2079. }
  2080. for (int index = 0; index < CCS_QUANTITY; index++)
  2081. {
  2082. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2083. {
  2084. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2085. }
  2086. }
  2087. for (int index = 0; index < GB_QUANTITY; index++)
  2088. {
  2089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2090. {
  2091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2092. }
  2093. }
  2094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2095. }
  2096. else
  2097. {
  2098. for (int index = 0; index < AC_QUANTITY; index++)
  2099. {
  2100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2101. {
  2102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2103. }
  2104. }
  2105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2106. }// END FOR AC ELSE
  2107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2110. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2113. //Power.Active.Export
  2114. //idx_sample=3;
  2115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2116. {
  2117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2118. {
  2119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2120. {
  2121. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2122. }
  2123. }
  2124. for (int index = 0; index < CCS_QUANTITY; index++)
  2125. {
  2126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2127. {
  2128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2129. }
  2130. }
  2131. for (int index = 0; index < GB_QUANTITY; index++)
  2132. {
  2133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2134. {
  2135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2136. }
  2137. }
  2138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2139. }
  2140. else
  2141. {
  2142. for (int index = 0; index < AC_QUANTITY; index++)
  2143. {
  2144. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2145. {
  2146. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2147. }
  2148. }
  2149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2150. }// END FOR AC ELSE
  2151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2154. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2157. //Voltage
  2158. //idx_sample=4;
  2159. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2160. {
  2161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2162. {
  2163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2164. {
  2165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2166. }
  2167. }
  2168. for (int index = 0; index < CCS_QUANTITY; index++)
  2169. {
  2170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2171. {
  2172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2173. }
  2174. }
  2175. for (int index = 0; index < GB_QUANTITY; index++)
  2176. {
  2177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2178. {
  2179. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2180. }
  2181. }
  2182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2183. }
  2184. else
  2185. {
  2186. for (int index = 0; index < AC_QUANTITY; index++)
  2187. {
  2188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2189. {
  2190. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2191. }
  2192. }
  2193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2194. }// END FOR AC ELSE
  2195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2198. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2201. //SoC
  2202. //idx_sample=5;
  2203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2204. {
  2205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2206. {
  2207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2208. {
  2209. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2210. }
  2211. }
  2212. for (int index = 0; index < CCS_QUANTITY; index++)
  2213. {
  2214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2215. {
  2216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2217. }
  2218. }
  2219. for (int index = 0; index < GB_QUANTITY; index++)
  2220. {
  2221. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2222. {
  2223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2224. }
  2225. }
  2226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2232. } // END FOR DC CASE
  2233. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2234. {
  2235. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" } ] } ] } ]"
  2236. ,MESSAGE_TYPE_CALL
  2237. ,guid
  2238. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2239. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2240. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2241. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2242. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2243. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2244. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2245. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2246. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2247. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2248. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2249. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2250. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2251. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2252. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2253. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2254. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2255. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2256. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2257. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2258. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2259. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2260. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2261. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2262. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2263. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2264. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2265. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2266. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2267. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2268. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2269. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2270. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2271. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2272. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2273. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2274. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2275. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2276. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2277. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2278. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2279. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2280. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2281. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2282. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2283. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2284. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2285. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2286. );
  2287. }
  2288. else
  2289. {
  2290. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" } ] } ] } ]"
  2291. ,MESSAGE_TYPE_CALL
  2292. ,guid
  2293. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2294. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2295. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2296. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2297. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2298. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2299. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2304. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2334. );
  2335. }
  2336. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2337. if(hashmap_operation(0, guid, tempdata) == 1)
  2338. {
  2339. result = PASS;
  2340. DEBUG_INFO("StopTransaction mapitem pass\n");
  2341. }
  2342. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2343. LWS_Send(queuedata);
  2344. #if 0
  2345. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2346. if(hashmap_operation(0, guid, tempdata) == 1)
  2347. {
  2348. result = PASS;
  2349. DEBUG_INFO("StopTransaction mapitem pass\n");
  2350. }
  2351. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2352. #endif
  2353. //for test
  2354. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2355. return result;
  2356. }
  2357. int sendMeterValuesRequest(int gun_index)
  2358. {
  2359. mtrace();
  2360. int result = FAIL;
  2361. // char message[1500]={0};
  2362. char guid[37]={0};
  2363. //int idx_sample=0;
  2364. //int length = 0;
  2365. char tempdata[65]={0};
  2366. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2367. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2368. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2369. {
  2370. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2371. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2372. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2373. return result;
  2374. }
  2375. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2376. {
  2377. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2378. }
  2379. memset(queuedata, 0, sizeof(queuedata));
  2380. //set value
  2381. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2382. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2383. random_uuid(guid);
  2384. //UTC Date time
  2385. struct timeval tmnow;
  2386. struct tm *tm;
  2387. char buf[28];//, usec_buf[6];
  2388. gettimeofday(&tmnow, NULL);
  2389. time_t t;
  2390. t = time(NULL);
  2391. /*UTC time and date*/
  2392. tm = gmtime(&t);
  2393. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2395. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2396. //idx_sample=0;
  2397. //********************************(1)Current.Export************************************************/
  2398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2399. {
  2400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2401. {
  2402. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2403. {
  2404. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2405. }
  2406. }
  2407. for (int index = 0; index < CCS_QUANTITY; index++)
  2408. {
  2409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2410. {
  2411. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2412. }
  2413. }
  2414. for (int index = 0; index < GB_QUANTITY; index++)
  2415. {
  2416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2417. {
  2418. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2419. }
  2420. }
  2421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2422. }
  2423. else
  2424. {
  2425. for (int index = 0; index < AC_QUANTITY; index++)
  2426. {
  2427. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2428. {
  2429. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2430. }
  2431. }
  2432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2433. }// END FOR AC ELSE
  2434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2437. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2438. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2440. //idx_sample=1;
  2441. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2443. {
  2444. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2445. {
  2446. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2447. {
  2448. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2449. }
  2450. }
  2451. for (int index = 0; index < CCS_QUANTITY; index++)
  2452. {
  2453. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2454. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2455. {
  2456. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2457. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2458. }
  2459. }
  2460. for (int index = 0; index < GB_QUANTITY; index++)
  2461. {
  2462. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2463. {
  2464. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2465. }
  2466. }
  2467. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2468. }
  2469. else
  2470. {
  2471. for (int index = 0; index < AC_QUANTITY; index++)
  2472. {
  2473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2474. {
  2475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2476. }
  2477. }
  2478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2479. }//END FOR AC ELSE
  2480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2483. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2486. //idx_sample=2;
  2487. //********************************(4)Power.Active.Export************************************************/
  2488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2489. {
  2490. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2491. {
  2492. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2493. {
  2494. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2495. }
  2496. }
  2497. for (int index = 0; index < CCS_QUANTITY; index++)
  2498. {
  2499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2500. {
  2501. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2502. }
  2503. }
  2504. for (int index = 0; index < GB_QUANTITY; index++)
  2505. {
  2506. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2507. {
  2508. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2509. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2510. }
  2511. }
  2512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2513. }
  2514. else
  2515. {
  2516. for (int index = 0; index < AC_QUANTITY; index++)
  2517. {
  2518. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2519. {
  2520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2521. }
  2522. }
  2523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2524. }// END FOR AC ELSE
  2525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2527. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2528. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2529. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2531. //idx_sample=3;
  2532. //***********************************************(5)VOLTAGE******************************************************/
  2533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2534. {
  2535. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2536. {
  2537. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2538. {
  2539. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2540. }
  2541. }
  2542. for (int index = 0; index < CCS_QUANTITY; index++)
  2543. {
  2544. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2545. {
  2546. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2547. }
  2548. }
  2549. for (int index = 0; index < GB_QUANTITY; index++)
  2550. {
  2551. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2552. {
  2553. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2554. }
  2555. }
  2556. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2557. }
  2558. else
  2559. {
  2560. for (int index = 0; index < AC_QUANTITY; index++)
  2561. {
  2562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2563. {
  2564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2565. }
  2566. }
  2567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2568. }//END FOR AC ELSE
  2569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2570. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2572. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2576. {
  2577. //idx_sample=4;
  2578. //sampledValue = NULL;
  2579. //***********************************************(6)SOC******************************************************/
  2580. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2581. {
  2582. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2583. {
  2584. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2585. }
  2586. }
  2587. for (int index = 0; index < CCS_QUANTITY; index++)
  2588. {
  2589. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2590. {
  2591. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2592. }
  2593. }
  2594. for (int index = 0; index < GB_QUANTITY; index++)
  2595. {
  2596. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2597. {
  2598. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2599. }
  2600. }
  2601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2607. }
  2608. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2609. {
  2610. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2611. ,MESSAGE_TYPE_CALL
  2612. ,guid
  2613. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2614. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2615. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2616. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2617. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2618. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2619. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2620. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2621. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2622. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2623. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2624. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2651. );
  2652. }
  2653. else
  2654. {
  2655. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2656. ,MESSAGE_TYPE_CALL
  2657. ,guid
  2658. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2659. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2660. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2662. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2663. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2664. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2689. );
  2690. }
  2691. // Put request guid to hash map
  2692. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2693. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2694. {
  2695. result = PASS;
  2696. DEBUG_INFO("MeterValues mapitem pass\n");
  2697. }
  2698. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2699. LWS_Send(queuedata);
  2700. #if 0
  2701. // Put request guid to hash map
  2702. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2703. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2704. {
  2705. result = PASS;
  2706. DEBUG_INFO("MeterValues mapitem pass\n");
  2707. }
  2708. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2709. #endif
  2710. return result;
  2711. }
  2712. //==========================================
  2713. // send confirm routine
  2714. //==========================================
  2715. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2716. {
  2717. mtrace();
  2718. int result = FAIL;
  2719. char message[100]={0};
  2720. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2721. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2722. LWS_Send(message);
  2723. result = TRUE;
  2724. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2725. return result;
  2726. }
  2727. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2728. {
  2729. mtrace();
  2730. int result = FAIL;
  2731. char message[100]={0};
  2732. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2733. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2734. LWS_Send(message);
  2735. result = TRUE;
  2736. return result;
  2737. }
  2738. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2739. {
  2740. mtrace();
  2741. int result = FAIL;
  2742. char message[100]={0};
  2743. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2744. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2745. LWS_Send(message);
  2746. result = TRUE;
  2747. return result;
  2748. }
  2749. int sendClearCacheConfirmation(char *uuid,char *payload)
  2750. {
  2751. mtrace();
  2752. int result = FAIL;
  2753. char message[500]={0};
  2754. // int count = 0;
  2755. // int gun_index = 0;
  2756. // char guid[37];
  2757. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2758. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2759. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2760. LWS_Send(message);
  2761. return result;
  2762. }
  2763. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2764. {
  2765. mtrace();
  2766. int result = FAIL;
  2767. char message[500]={0};
  2768. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2769. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2770. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2771. LWS_Send(message);
  2772. return result;
  2773. }
  2774. int sendDataTransferConfirmation(char *uuid,char *payload)
  2775. {
  2776. mtrace();
  2777. char statusStr[20]={0};
  2778. char dataStr[10]={0};
  2779. char sstr[20]={0};
  2780. int c = 0;
  2781. char *loc;
  2782. int result = FAIL;
  2783. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2784. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2785. /**********************status**************************/
  2786. loc = strstr(payload, "status");
  2787. memset(sstr ,0, sizeof(sstr) );
  2788. c = 0;
  2789. while (loc[3+strlen("status")+c] != '\"')
  2790. {
  2791. sstr[c] = loc[3+strlen("status")+c];
  2792. c++;
  2793. }
  2794. sstr[c] = '\0';
  2795. strcpy(statusStr, sstr);
  2796. /**********************data**************************/
  2797. loc = strstr(payload, "data");
  2798. memset(sstr ,0, sizeof(sstr) );
  2799. c = 0;
  2800. while (loc[3+strlen("data")+c] != '\"')
  2801. {
  2802. sstr[c] = loc[3+strlen("data")+c];
  2803. c++;
  2804. }
  2805. sstr[c] = '\0';
  2806. strcpy(dataStr, sstr);
  2807. return result;
  2808. }
  2809. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2810. {
  2811. mtrace();
  2812. int result = FAIL;
  2813. char message[1000]={0};
  2814. double diff_f = 0.0;
  2815. int diff_i = 0;
  2816. int diffSeconds = 0;
  2817. struct tm tp;
  2818. int TimeZero = FALSE;
  2819. int CompositeScheduleIndex = 0;
  2820. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2821. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2822. {
  2823. TimeZero = TRUE;
  2824. }
  2825. else
  2826. {
  2827. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2828. }
  2829. if(TimeZero == FALSE)
  2830. {
  2831. tp.tm_isdst = -1;
  2832. time_t utc = mktime(&tp);
  2833. time_t t = time(NULL);
  2834. diff_f = difftime(t, utc);
  2835. diff_i = (int)diff_f;
  2836. diffSeconds = diff_i % 86400;//86400 seconds/day
  2837. }
  2838. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2839. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2840. #if 0 //remove temporally
  2841. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":6.0,\"numberPhases\":3},{\"startPeriod\":40,\"limit\":10.0,\"numberPhases\":3},{\"startPeriod\":100,\"limit\":8.0,\"numberPhases\":3}"
  2842. ,MESSAGE_TYPE_CALLRESULT
  2843. ,uuid
  2844. ,payload
  2845. ,connectorIdInt
  2846. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2847. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2848. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2849. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2850. #endif
  2851. if(nPeriod == 0)
  2852. {
  2853. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2854. ,MESSAGE_TYPE_CALLRESULT
  2855. ,uuid
  2856. ,payload
  2857. ,connectorIdInt
  2858. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2859. }
  2860. else
  2861. {
  2862. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2863. ,MESSAGE_TYPE_CALLRESULT
  2864. ,uuid
  2865. ,payload
  2866. ,connectorIdInt
  2867. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2868. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2869. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2870. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2871. int len = nPeriod;
  2872. //Last Period StartPriod is less than diffSeconds
  2873. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2874. {
  2875. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2876. , 0
  2877. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2878. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2879. }
  2880. else
  2881. {
  2882. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2883. {
  2884. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2885. {
  2886. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2887. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2888. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2889. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2890. }
  2891. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2892. {
  2893. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2894. , (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)) //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
  2895. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2896. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2897. }
  2898. }
  2899. }
  2900. sprintf(message + strlen(message), "]}}]");
  2901. }
  2902. LWS_Send(message);
  2903. result = TRUE;
  2904. return result;
  2905. }
  2906. int sendGetConfigurationConfirmation(char *uuid)
  2907. {
  2908. mtrace();
  2909. int result = FAIL;
  2910. int MaxKeySupported = 0;
  2911. int sentConfigurationNumber= 0;
  2912. int sentunConfigurationNumber= 0;
  2913. char message[4000]={0};
  2914. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2915. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2916. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2917. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  2918. ,MESSAGE_TYPE_CALLRESULT
  2919. ,uuid );
  2920. //configuration key
  2921. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2922. {
  2923. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2924. {
  2925. if (sentConfigurationNumber == 0)
  2926. {
  2927. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  2928. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2929. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2930. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2931. }
  2932. else
  2933. {
  2934. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2935. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2936. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2937. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2938. }
  2939. sentConfigurationNumber = sentConfigurationNumber + 1;
  2940. }
  2941. }
  2942. sprintf(message + strlen(message), "]");
  2943. if(UnknownKeynum != 0)
  2944. {
  2945. sprintf(message + strlen(message), ",\"unknownKey\":[");
  2946. //unkown key
  2947. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  2948. {
  2949. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  2950. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  2951. if(sentunConfigurationNumber == 0)
  2952. {
  2953. sprintf(message + strlen(message), "\"%s\""
  2954. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2955. }
  2956. else
  2957. {
  2958. sprintf(message + strlen(message), ",\"%s\""
  2959. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2960. }
  2961. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  2962. }
  2963. sprintf(message + strlen(message), "]");
  2964. }
  2965. sprintf(message + strlen(message), "} ]");
  2966. LWS_Send(message);
  2967. return result;
  2968. }
  2969. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  2970. {
  2971. mtrace();
  2972. int result = FAIL;
  2973. char message[400]={0};
  2974. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  2975. if(strcmp(payload,"")==0)
  2976. {
  2977. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  2978. }
  2979. else
  2980. {
  2981. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  2982. }
  2983. LWS_Send(message);
  2984. result = TRUE;
  2985. return result;
  2986. }
  2987. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  2988. {
  2989. mtrace();
  2990. int result = FAIL;
  2991. char message[80]={0};
  2992. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  2993. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  2994. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  2995. LWS_Send(message);
  2996. result = TRUE;
  2997. return result;
  2998. }
  2999. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3000. {
  3001. mtrace();
  3002. int result = FAIL;
  3003. char message[80]={0};
  3004. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3005. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3006. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3007. LWS_Send(message);
  3008. result = TRUE;
  3009. return result;
  3010. }
  3011. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3012. {
  3013. mtrace();
  3014. int result = FAIL;
  3015. char message[80]={0};
  3016. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3017. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3018. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3019. LWS_Send(message);
  3020. result = TRUE;
  3021. return result;
  3022. }
  3023. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3024. {
  3025. mtrace();
  3026. int result = FAIL;
  3027. char message[80]={0};
  3028. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3029. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3030. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3031. LWS_Send(message);
  3032. result = TRUE;
  3033. return result;
  3034. }
  3035. int sendResetConfirmation(char *uuid,char *payload)
  3036. {
  3037. mtrace();
  3038. int result = FAIL;
  3039. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3040. char message[80]={0};
  3041. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3042. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3043. LWS_Send(message);
  3044. result = TRUE;
  3045. return result;
  3046. }
  3047. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3048. {
  3049. mtrace();
  3050. int result = FAIL;
  3051. char message[500]={0};
  3052. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3053. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3054. LWS_Send(message);
  3055. result = TRUE;
  3056. return result;
  3057. }
  3058. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3059. {
  3060. mtrace();
  3061. int result = FAIL;
  3062. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3063. char message[80]={0};
  3064. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3065. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3066. LWS_Send(message);
  3067. result = TRUE;
  3068. return result;
  3069. }
  3070. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3071. {
  3072. mtrace();
  3073. int result = FAIL;
  3074. char message[80]={0};
  3075. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3076. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3077. LWS_Send(message);
  3078. result = TRUE;
  3079. return result;
  3080. }
  3081. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3082. {
  3083. mtrace();
  3084. int result = FAIL;
  3085. char message[80]={0};
  3086. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3087. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3088. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3089. LWS_Send(message);
  3090. result = TRUE;
  3091. return result;
  3092. }
  3093. int sendUpdateFirmwareConfirmation(char *uuid)
  3094. {
  3095. mtrace();
  3096. int result = FAIL;
  3097. char message[60]={0};
  3098. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3099. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3100. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3101. LWS_Send(message);
  3102. result = TRUE;
  3103. return result;
  3104. }
  3105. //==========================================
  3106. // send CallError routine
  3107. //==========================================
  3108. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3109. {
  3110. mtrace();
  3111. //int result = FAIL;
  3112. char message[220]={0};
  3113. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3114. #ifdef SystemLogMessage
  3115. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3116. uniqueId, action, errorCode, errorDescription);
  3117. #endif
  3118. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3119. LWS_Send(message);
  3120. //result = TRUE;
  3121. }
  3122. //==========================================
  3123. // Handle server request routine Start
  3124. //==========================================
  3125. #define GUN_NUM 1
  3126. int handleCancelReservationRequest(char *uuid, char *payload)
  3127. {
  3128. mtrace();
  3129. int result = FAIL;
  3130. int gunNO = 0;
  3131. int reservationIdInt =0;
  3132. char comfirmstr[20];
  3133. int c = 0;
  3134. char *loc;
  3135. char sstr[100]={0};
  3136. DEBUG_INFO("handle CancelReservationRequest\n");
  3137. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3138. c = 0;
  3139. loc = strstr(payload, "reservationId");
  3140. memset(sstr ,0, sizeof(sstr) );
  3141. while (loc[strlen("reservationId")+2+c] != '}')
  3142. {
  3143. sstr[c] = loc[strlen("reservationId")+2+c];
  3144. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3145. c++;
  3146. }
  3147. sstr[c] = '\0';
  3148. reservationIdInt = atoi(sstr);
  3149. memset(comfirmstr, 0, sizeof comfirmstr);
  3150. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3151. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3152. //check Transaction active
  3153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3154. {
  3155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3156. {
  3157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3158. {
  3159. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3160. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3161. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3162. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3163. goto end;
  3164. }
  3165. }
  3166. for (int index = 0; index < CCS_QUANTITY; index++)
  3167. {
  3168. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3169. {
  3170. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3171. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3172. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3173. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3174. goto end;
  3175. }
  3176. }
  3177. for (int index = 0; index < GB_QUANTITY; index++)
  3178. {
  3179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3180. {
  3181. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3182. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3183. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3184. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3185. goto end;
  3186. }
  3187. }
  3188. }
  3189. else
  3190. {
  3191. for (int index = 0; index < AC_QUANTITY; index++)
  3192. {
  3193. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3194. {
  3195. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3196. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3197. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3198. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3199. goto end;
  3200. }
  3201. }
  3202. }// END FOR AC ELSE
  3203. //The reservationId does NOT match the reservationId
  3204. sendCancelReservationConfirmation(uuid, comfirmstr);
  3205. end:
  3206. // Fill in ocpp packet uuid
  3207. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3208. return result;
  3209. }
  3210. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3211. {
  3212. mtrace();
  3213. int result = FAIL;
  3214. int gunIndex = 0;
  3215. char sstr[90]={0};
  3216. char typeStr[16]={0};
  3217. char comfirmstr[20];
  3218. int specificId = FALSE;
  3219. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3220. char *loc;
  3221. //int intervalInt = 0;
  3222. int c = 0;
  3223. /*** connectorId ****/
  3224. c = 0;
  3225. loc = strstr(payload, "connectorId");
  3226. memset(sstr ,0, sizeof(sstr) );
  3227. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3228. {
  3229. sstr[c] = loc[strlen("connectorId")+2+c];
  3230. c++;
  3231. }
  3232. sstr[c] = '\0';
  3233. gunIndex = atoi(sstr);
  3234. /***type ****/
  3235. loc = strstr(payload, "type");
  3236. memset(sstr ,0, sizeof(sstr) );
  3237. c = 0;
  3238. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3239. {
  3240. sstr[c] = loc[3+strlen("type")+c];
  3241. c++;
  3242. }
  3243. sstr[c] = '\0';
  3244. strcpy(typeStr, sstr);
  3245. if(gunIndex != 0)
  3246. {
  3247. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3248. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3249. }
  3250. else
  3251. {
  3252. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3253. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3254. }
  3255. memset(comfirmstr, 0, sizeof comfirmstr);
  3256. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3257. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3258. {
  3259. specificId = TRUE;
  3260. }
  3261. if(specificId == FALSE)
  3262. goto end;
  3263. if(gunIndex != 0)
  3264. {
  3265. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3266. }
  3267. else
  3268. {
  3269. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3270. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3271. }
  3272. /*
  3273. enum SYSTEM_STATUS
  3274. {
  3275. SYS_MODE_BOOTING = 0,
  3276. SYS_MODE_IDLE = 1,
  3277. SYS_MODE_AUTHORIZING = 2,
  3278. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3279. SYS_MODE_REASSIGN = 4,
  3280. SYS_MODE_PREPARING = 5,
  3281. SYS_MODE_PREPARE_FOR_EV = 6,
  3282. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3283. SYS_MODE_CHARGING = 8,
  3284. SYS_MODE_TERMINATING = 9,
  3285. SYS_MODE_COMPLETE = 10,
  3286. SYS_MODE_ALARM = 11,
  3287. SYS_MODE_FAULT = 12,
  3288. SYS_MODE_RESERVATION = 13,
  3289. SYS_MODE_BOOKING = 14,
  3290. SYS_MODE_MAINTAIN = 15,
  3291. SYS_MODE_DEBUG = 16,
  3292. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3293. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3294. SYS_MODE_UPDATE = 19
  3295. };
  3296. */
  3297. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3298. {
  3299. //check Transaction active
  3300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3301. {
  3302. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3303. {
  3304. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3305. {
  3306. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3307. {
  3308. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3309. }
  3310. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3311. {
  3312. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3313. }
  3314. else
  3315. {
  3316. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3317. }
  3318. goto end;
  3319. }
  3320. }//END FOR CHAdeMO_QUANTITY
  3321. for (int index = 0; index < CCS_QUANTITY; index++)
  3322. {
  3323. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3324. {
  3325. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3326. {
  3327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3328. }
  3329. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3330. {
  3331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3332. }
  3333. else
  3334. {
  3335. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3336. }
  3337. goto end;
  3338. }
  3339. }//END FOR CCS_QUANTITY
  3340. for (int index = 0; index < GB_QUANTITY; index++)
  3341. {
  3342. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3343. {
  3344. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3345. {
  3346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3347. }
  3348. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3349. {
  3350. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3351. }
  3352. else
  3353. {
  3354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3355. }
  3356. goto end;
  3357. }
  3358. }// END FOR GB_QUANTITY
  3359. }
  3360. else
  3361. {
  3362. for (int index = 0; index < AC_QUANTITY; index++)
  3363. {
  3364. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3365. {
  3366. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3367. {
  3368. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3369. }
  3370. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3371. {
  3372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3373. }
  3374. else
  3375. {
  3376. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3377. }
  3378. goto end;
  3379. }
  3380. }//END FOR AC_QUANTITY
  3381. }// END FOR AC ELSE
  3382. }//END FOR AvailabilityTypeStr[Inoperative]
  3383. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3384. {
  3385. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3386. //check Transaction active
  3387. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3388. {
  3389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3390. {
  3391. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3392. {
  3393. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3394. goto end;
  3395. }
  3396. }//END FOR CHAdeMO_QUANTITY
  3397. for (int index = 0; index < CCS_QUANTITY; index++)
  3398. {
  3399. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3400. {
  3401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3402. goto end;
  3403. }
  3404. }//END FOR CCS_QUANTITY
  3405. for (int index = 0; index < GB_QUANTITY; index++)
  3406. {
  3407. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3408. {
  3409. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3410. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3411. goto end;
  3412. }
  3413. }// END FOR GB_QUANTITY
  3414. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3415. }
  3416. else
  3417. {
  3418. for (int index = 0; index < AC_QUANTITY; index++)
  3419. {
  3420. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3421. {
  3422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3423. goto end;
  3424. }
  3425. }//END FOR CHAdeMO_QUANTITY
  3426. }//END FOR AC ELSE
  3427. }//END FOR AvailabilityTypeStr[Operative]
  3428. end:
  3429. if(gunIndex != 0)
  3430. {
  3431. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3432. }
  3433. else
  3434. {
  3435. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3436. }
  3437. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3438. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3439. return result;
  3440. }
  3441. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3442. {
  3443. mtrace();
  3444. int result = FAIL;
  3445. char sstr[100]={0};
  3446. char keystr[40]={0};
  3447. char valuestr[100]={0};
  3448. char *loc;
  3449. int c = 0;
  3450. char comfirmstr[20]={0};
  3451. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3452. /***key ****/
  3453. loc = strstr(payload, "key");
  3454. memset(sstr ,0, sizeof(sstr) );
  3455. c = 0;
  3456. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3457. {
  3458. sstr[c] = loc[3+strlen("key")+c];
  3459. c++;
  3460. }
  3461. sstr[c] = '\0';
  3462. strcpy(keystr, sstr);
  3463. //DEBUG_INFO( "keystr=%s\n",keystr);
  3464. /***value ****/
  3465. loc = strstr(payload, "value");
  3466. memset(sstr ,0, sizeof(sstr) );
  3467. c = 0;
  3468. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3469. {
  3470. sstr[c] = loc[3+strlen("value")+c];
  3471. c++;
  3472. }
  3473. sstr[c] = '\0';
  3474. strcpy(valuestr, sstr);
  3475. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3476. if((uuid==NULL) || (payload ==NULL) )
  3477. {
  3478. #ifdef Debug
  3479. DEBUG_INFO("payload is null\n");
  3480. #endif
  3481. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3482. }
  3483. else
  3484. {
  3485. int status = setKeyValue(keystr, valuestr);
  3486. switch(status)
  3487. {
  3488. case ConfigurationStatus_Accepted:
  3489. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3490. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3491. StoreConfigurationTable();
  3492. break;
  3493. case ConfigurationStatus_Rejected:
  3494. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3495. break;
  3496. case RebootRequired:
  3497. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3498. StoreConfigurationTable();
  3499. break;
  3500. case NotSupported:
  3501. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3502. break;
  3503. default:
  3504. break;
  3505. }
  3506. }
  3507. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3508. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3509. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3510. return result;
  3511. }
  3512. int handleClearCacheRequest(char *uuid, char *payload)
  3513. {
  3514. mtrace();
  3515. int result = FAIL;
  3516. char comfirmstr[20];
  3517. int fd;
  3518. char rmFileCmd[100]={0};
  3519. struct stat stats;
  3520. DEBUG_INFO("handle ClearCacheRequest\n");
  3521. stat("../Storage/OCPP", &stats);
  3522. // Check for directory existence
  3523. if (S_ISDIR(stats.st_mode) == 1)
  3524. {
  3525. //DEBUG_ERROR("\n OCPP directory exist \n");
  3526. }
  3527. else
  3528. {
  3529. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3530. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3531. system(rmFileCmd);
  3532. }
  3533. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3534. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3535. {
  3536. DEBUG_INFO("AuthorizationCache file exist.\n");
  3537. }
  3538. else
  3539. {
  3540. DEBUG_INFO("AuthorizationCache file not exist\n");
  3541. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3542. if(log == NULL)
  3543. {
  3544. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3545. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3546. goto end;
  3547. }
  3548. else
  3549. {
  3550. fclose(log);
  3551. }
  3552. }
  3553. fd = open(AuthorizationCache_JSON,O_RDWR);
  3554. if(fd < 0)
  3555. {
  3556. DEBUG_INFO("open AuthorizationCache file failed\n");
  3557. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3558. }
  3559. else
  3560. {
  3561. DEBUG_INFO("open AuthorizationCache file successful\n");
  3562. //* 清空? 件 */
  3563. ftruncate(fd,0);
  3564. //* ? 新设置? 件? 移??*/
  3565. lseek(fd,0,SEEK_SET);
  3566. close(fd);
  3567. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3568. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3569. }
  3570. end:
  3571. sendClearCacheConfirmation(uuid, comfirmstr);
  3572. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3573. return result;
  3574. }
  3575. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3576. {
  3577. mtrace();
  3578. int result = FAIL;
  3579. int resultRename;
  3580. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3581. char chargingProfilePurposeStr[26]={0};
  3582. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3583. char tempchargingProfilePurposeStr[26]={0};
  3584. char sstr[160]={0};//sstr[200]={ 0 };
  3585. char str[100]={0};
  3586. int c = 0;
  3587. //int i = 0;
  3588. //char * pch;
  3589. char *loc;
  3590. char fname[200];
  3591. char comfirmstr[20]={0};
  3592. char word[1000]={0};
  3593. int clearflag = FALSE;
  3594. int chargingProfileIdIsNULL = FALSE;
  3595. int connectorIsNULL = FALSE;
  3596. int chargingProfilePurposeIsNULL = FALSE;
  3597. int stackLevelIsNULL = FALSE;
  3598. FILE *fptr1, *fptr2;
  3599. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3600. int n_chargingProfile=0;
  3601. char sLineWord[1060]={0};
  3602. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3603. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3604. //***id ****/
  3605. c = 0;
  3606. loc = strstr(payload, "id");
  3607. memset(sstr ,0, sizeof(sstr) );
  3608. if(loc == NULL)
  3609. {
  3610. chargingProfileIdIsNULL = TRUE;
  3611. }
  3612. else
  3613. {
  3614. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3615. {
  3616. sstr[c] = loc[strlen("id")+2+c];
  3617. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3618. c++;
  3619. }
  3620. sstr[c] = '\0';
  3621. chargingProfileIdInt = atoi(sstr);
  3622. }
  3623. //***connectorId ****/
  3624. c=0;
  3625. loc = strstr(payload, "connectorId");
  3626. memset(sstr ,0, sizeof(sstr) );
  3627. if(loc == NULL)
  3628. {
  3629. connectorIsNULL = TRUE;
  3630. }
  3631. else
  3632. {
  3633. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3634. {
  3635. sstr[c] = loc[strlen("connectorId")+2+c];
  3636. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3637. c++;
  3638. }
  3639. sstr[c] = '\0';
  3640. connectorIdInt = atoi(sstr);
  3641. }
  3642. //***chargingProfilePurpose ****/
  3643. loc = strstr(payload, "chargingProfilePurpose");
  3644. memset(sstr ,0, sizeof(sstr) );
  3645. c = 0;
  3646. if(loc == NULL)
  3647. {
  3648. chargingProfilePurposeIsNULL = TRUE;
  3649. }
  3650. else
  3651. {
  3652. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3653. {
  3654. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3655. c++;
  3656. }
  3657. sstr[c] = '\0';
  3658. strcpy(chargingProfilePurposeStr, sstr);
  3659. }
  3660. //***stackLevel ****/
  3661. c=0;
  3662. loc = strstr(payload, "stackLevel");
  3663. memset(sstr ,0, sizeof(sstr) );
  3664. if(loc == NULL)
  3665. {
  3666. stackLevelIsNULL = TRUE;
  3667. }
  3668. else
  3669. {
  3670. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3671. {
  3672. sstr[c] = loc[strlen("stackLevel")+2+c];
  3673. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3674. c++;
  3675. }
  3676. sstr[c] = '\0';
  3677. stackLevelInt = atoi(sstr);
  3678. }
  3679. if(connectorIsNULL == FALSE)
  3680. {
  3681. switch(connectorIdInt)
  3682. {
  3683. case 0:
  3684. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3685. {
  3686. strcpy(fname, ChargePointMaxProfile_JSON);
  3687. }
  3688. // else
  3689. // {
  3690. // strcpy(fname, TxDefaultProfile_0_JSON);
  3691. // }
  3692. break;
  3693. case 1:
  3694. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3695. {
  3696. strcpy(fname, TxDefaultProfile_1_JSON);
  3697. }
  3698. // else
  3699. // {
  3700. // strcpy(fname, TxProfile_1_JSON);
  3701. // }
  3702. break;
  3703. case 2:
  3704. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3705. {
  3706. strcpy(fname, TxDefaultProfile_2_JSON);
  3707. }
  3708. // else
  3709. // {
  3710. // strcpy(fname, TxProfile_2_JSON);
  3711. // }
  3712. break;
  3713. default:
  3714. strcpy(fname, ChargePointMaxProfile_JSON );
  3715. break;
  3716. }
  3717. }
  3718. else
  3719. {
  3720. strcpy(fname, ChargePointMaxProfile_JSON );
  3721. }
  3722. fptr1 = fopen(fname, "r");
  3723. if (!fptr1)
  3724. {
  3725. //file not exist
  3726. DEBUG_INFO("Unable to open the input file!!\n");
  3727. fptr1 = fopen(fname, "w+");
  3728. }
  3729. fclose(fptr1);
  3730. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3731. {
  3732. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3733. goto end;
  3734. }
  3735. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3736. {
  3737. //clear the whole contents of a file in C
  3738. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3739. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3740. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3741. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3742. fclose(fopen(TxProfile_1_JSON, "w"));
  3743. fclose(fopen(TxProfile_2_JSON, "w"));
  3744. #if 0
  3745. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3746. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3747. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3748. #endif
  3749. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3750. }
  3751. else
  3752. {
  3753. fptr1 = fopen(fname, "r");
  3754. fptr2 = fopen(temp, "w+");
  3755. while(fscanf(fptr1, "%s", word) != EOF)
  3756. {
  3757. //DEBUG_INFO("word=%s\n",word);
  3758. if(strcmp(word, "chargingProfileId") == 0)
  3759. {
  3760. n_chargingProfile = n_chargingProfile + 1;
  3761. DEBUG_INFO("chargingProfileId Found\n");
  3762. }
  3763. }
  3764. rewind(fptr1);
  3765. //search Charging Profile Element
  3766. //int i= 0;
  3767. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3768. {
  3769. //*************************tempconnectorIdInt*********************************/
  3770. loc = strstr(sLineWord, "connectorId");
  3771. c = 0;
  3772. memset(sstr ,0, sizeof(sstr) );
  3773. while (loc[strlen("connectorId")+2+c] != ',')
  3774. {
  3775. sstr[c] = loc[strlen("connectorId")+2+c];
  3776. c++;
  3777. }
  3778. sstr[c] = '\0';
  3779. tempconnectorIdInt = atoi(sstr);
  3780. //chargingProfileId
  3781. c = 0;
  3782. loc = strstr(sLineWord, "chargingProfileId");
  3783. memset(sstr ,0, sizeof(sstr) );
  3784. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3785. {
  3786. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3787. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3788. c++;
  3789. }
  3790. sstr[c] = '\0';
  3791. tempchargingProfileIdInt = atoi(sstr);
  3792. //stackLevel
  3793. c = 0;
  3794. loc = strstr(sLineWord, "stackLevel");
  3795. memset(sstr ,0, sizeof(sstr) );
  3796. while (loc[strlen("stackLevel")+2+c] != ',')
  3797. {
  3798. sstr[c] = loc[strlen("stackLevel")+2+c];
  3799. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3800. c++;
  3801. }
  3802. sstr[c] = '\0';
  3803. tempstackLevelInt = atoi(sstr);
  3804. c = 0;
  3805. loc = strstr(sLineWord, "chargingProfilePurpose");
  3806. memset(sstr ,0, sizeof(sstr) );
  3807. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3808. {
  3809. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3810. c++;
  3811. }
  3812. sstr[c] = '\0';
  3813. strcpy(tempchargingProfilePurposeStr, sstr);
  3814. if(chargingProfileIdIsNULL == FALSE)
  3815. {
  3816. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3817. {
  3818. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3819. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3820. clearflag = TRUE;
  3821. continue;
  3822. }
  3823. else
  3824. {
  3825. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3826. //json_object_array_add(newHeatMap, jsonitem);
  3827. fprintf(fptr2, sLineWord);//writing data into file
  3828. }
  3829. }
  3830. else
  3831. {
  3832. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3833. {
  3834. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3835. {
  3836. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3837. clearflag = TRUE;
  3838. continue;
  3839. }
  3840. }
  3841. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3842. {
  3843. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3844. {
  3845. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3846. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3847. {
  3848. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3849. clearflag = TRUE;
  3850. continue;
  3851. }
  3852. }
  3853. }
  3854. else
  3855. {
  3856. //json_object_array_add(newHeatMap, jsonitem);
  3857. fprintf(fptr2, sLineWord);//writing data into file
  3858. }
  3859. }
  3860. memset(sLineWord, 0, sizeof sLineWord);
  3861. }
  3862. if(clearflag == FALSE)
  3863. {
  3864. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3865. goto end;
  3866. }
  3867. fclose(fptr1);
  3868. fclose(fptr2);
  3869. sprintf(str,"rm -f %s",fname);
  3870. system(str);
  3871. resultRename = rename(temp, fname);
  3872. if(resultRename == 0)
  3873. {
  3874. DEBUG_INFO("File ChargingProfile renamed successfully");
  3875. }
  3876. else
  3877. {
  3878. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  3879. }
  3880. }
  3881. end:
  3882. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3883. return result;
  3884. }
  3885. int handleDataTransferRequest(char *uuid, char *payload)
  3886. {
  3887. mtrace();
  3888. int result = FAIL;
  3889. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  3890. char tempvendorId[255]={0};
  3891. char tempmessageId[50]={0};
  3892. char tempdata[50]={0};
  3893. char sstr[160]={0};//sstr[200]={ 0 };
  3894. char message[80]={0};
  3895. int c = 0;
  3896. char *loc;
  3897. DEBUG_INFO("handle DataTransferRequest\n");
  3898. if((uuid != NULL) && (payload != NULL))
  3899. {
  3900. //===============================
  3901. // vendorId
  3902. //===============================
  3903. c = 0;
  3904. loc = strstr(payload, "vendorId");
  3905. while (loc[strlen("vendorId")+3+c] != '\"')
  3906. {
  3907. sstr[c] = loc[strlen("vendorId")+3+c];
  3908. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3909. c++;
  3910. }
  3911. sstr[c] = '\0';
  3912. strcpy(tempvendorId,sstr);
  3913. //===============================
  3914. // messageId
  3915. //===============================
  3916. memset(sstr ,0, sizeof(sstr) );
  3917. c = 0;
  3918. loc = strstr(payload, "messageId");
  3919. while (loc[strlen("messageId")+3+c] != '\"')
  3920. {
  3921. sstr[c] = loc[strlen("messageId")+3+c];
  3922. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3923. c++;
  3924. }
  3925. sstr[c] = '\0';
  3926. strcpy(tempmessageId,sstr);
  3927. //===============================
  3928. // data
  3929. //===============================
  3930. memset(sstr ,0, sizeof(sstr) );
  3931. c = 0;
  3932. loc = strstr(payload, "data");
  3933. printf("loc=%s\n",loc);
  3934. while (loc[strlen("data")+3+c] != '\"')
  3935. {
  3936. sstr[c] = loc[strlen("data")+3+c];
  3937. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3938. c++;
  3939. }
  3940. sstr[c] = '\0';
  3941. strcpy(tempdata,sstr);
  3942. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  3943. }
  3944. else
  3945. {
  3946. char guid[37]={0};
  3947. random_uuid(guid);
  3948. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  3949. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  3950. }
  3951. LWS_Send(message);
  3952. return result;
  3953. }
  3954. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  3955. {
  3956. mtrace();
  3957. int result = FAIL;
  3958. int connectorIdInt, durationInt;
  3959. char chargingRateUnitStr[4]={0};
  3960. //int tempconnectorIdInt,
  3961. int tempdurationInt;
  3962. float tempminChargingRateFloat = 0.0;
  3963. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  3964. int tempStartPeriodInt=0;
  3965. float tempLimitInt=0.0;//0.1;
  3966. int tempNumberPhasesInt=0;
  3967. char fname[200];
  3968. char comfirmstr[20];
  3969. //float totallimit =0.0;
  3970. float MinChargingRate =0.0;
  3971. //double diff_t;
  3972. //struct tm tp;
  3973. FILE *fptr1;
  3974. int c = 0;
  3975. //int i = 0;
  3976. char * pch;
  3977. char *loc;
  3978. char sstr[200]={ 0 };
  3979. int n_chargingProfile = 0;
  3980. int n_SchedulePeriods = 0;
  3981. char SchedulePeriodList[10][200]={0};
  3982. char sLineWord[800]={0};
  3983. //int n_periods = 0;
  3984. char word[1000]={0};
  3985. int confirmPeriods = 0;
  3986. struct StructProfile ChargePointMaxProfile;
  3987. struct StructProfile TxDefaultProfile;
  3988. struct StructProfile TxProfile;
  3989. struct StructProfile TxDefaultProfiletemp[2]={0};
  3990. int TxDefaultProfileFileIsNull=FALSE;
  3991. int ChargePointMaxProfileIsNull=FALSE;
  3992. int TxProfileIsNull=FALSE;
  3993. int CompositeSceduleIndex = 0;
  3994. char ChargePointMaxProfileScheduleStr[30]={0};
  3995. char TxDefaultProfileScheduleStr[30]={0};
  3996. char TxProfileScheduleStr[30]={0};
  3997. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  3998. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  3999. memset(&TxProfile,0,sizeof(struct StructProfile));
  4000. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4001. c=0;
  4002. loc = strstr(payload, "connectorId");
  4003. memset(sstr ,0, sizeof(sstr) );
  4004. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4005. {
  4006. sstr[c] = loc[strlen("connectorId")+2+c];
  4007. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4008. c++;
  4009. }
  4010. sstr[c] = '\0';
  4011. connectorIdInt = atoi(sstr);
  4012. c=0;
  4013. loc = strstr(payload, "duration");
  4014. memset(sstr ,0, sizeof(sstr) );
  4015. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4016. {
  4017. sstr[c] = loc[strlen("duration")+2+c];
  4018. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4019. c++;
  4020. }
  4021. sstr[c] = '\0';
  4022. durationInt = atoi(sstr);
  4023. c = 0;
  4024. loc = strstr(payload, "chargingRateUnit");
  4025. memset(sstr ,0, sizeof(sstr) );
  4026. if(loc == NULL)
  4027. {
  4028. }
  4029. else
  4030. {
  4031. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4032. {
  4033. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4034. c++;
  4035. }
  4036. sstr[c] = '\0';
  4037. strcpy(chargingRateUnitStr, sstr);
  4038. }
  4039. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4040. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4041. if(connectorIdInt==0) // connectorId is 0
  4042. {
  4043. //******************************ChargePointMaxProfile*****************************************************/
  4044. strcpy(fname, ChargePointMaxProfile_JSON );
  4045. char word[30]={0};
  4046. char sLineWord[1060]={0};
  4047. int n_chargingProfile=0;
  4048. ChargePointMaxProfileIsNull=TRUE;
  4049. if((access(fname,F_OK))!=-1)
  4050. {
  4051. fptr1 = fopen(fname, "r");
  4052. int c;
  4053. c = fgetc(fptr1);
  4054. //DEBUG_INFO("c:%d\n",c);
  4055. rewind(fptr1);
  4056. if(c == EOF)
  4057. {
  4058. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4059. ChargePointMaxProfileIsNull=TRUE;
  4060. fclose(fptr1);
  4061. }
  4062. else
  4063. {
  4064. ChargePointMaxProfileIsNull=FALSE;
  4065. while(fscanf(fptr1, "%s", word) != EOF)
  4066. {
  4067. if(strcmp(word, "chargingProfileId") == 0)
  4068. {
  4069. n_chargingProfile = n_chargingProfile + 1;
  4070. printf("Found\n");
  4071. }
  4072. }
  4073. rewind(fptr1);
  4074. //search Charging Profile Element
  4075. int i= 0;
  4076. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4077. #if 0
  4078. /***********connectorId****************/
  4079. c = 0;
  4080. loc = strstr(sLineWord, "connectorId");
  4081. // printf("loc=%s\n",loc);
  4082. memset(sstr ,0, sizeof(sstr) );
  4083. while (loc[strlen("connectorId")+2+c] != ',')
  4084. {
  4085. sstr[c] = loc[strlen("connectorId")+2+c];
  4086. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4087. c++;
  4088. }
  4089. sstr[c] = '\0';
  4090. tempconnectorIdInt = atoi(sstr);
  4091. #endif
  4092. //***********validFrom**************/
  4093. c = 0;
  4094. loc = strstr(sLineWord, "validFrom");
  4095. //DEBUG_INFO("loc=%s\n",loc);
  4096. memset(sstr ,0, sizeof(sstr) );
  4097. if(loc != NULL)
  4098. {
  4099. while (loc[3+strlen("validFrom")+c] != '\"')
  4100. {
  4101. sstr[c] = loc[3+strlen("validFrom")+c];
  4102. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4103. c++;
  4104. }
  4105. sstr[c] = '\0';
  4106. DEBUG_INFO("validFrom=%s\n",sstr);
  4107. strcpy(tempvalidFromStr,sstr);
  4108. }
  4109. else
  4110. {
  4111. strcpy(tempvalidFromStr,"");
  4112. }
  4113. //**********startSchedule**********/
  4114. c = 0;
  4115. loc = strstr(sLineWord, "startSchedule");
  4116. //DEBUG_INFO("loc=%s\n",loc);
  4117. memset(sstr ,0, sizeof(sstr) );
  4118. while (loc[3+strlen("startSchedule")+c] != '\"')
  4119. {
  4120. sstr[c] = loc[3+strlen("startSchedule")+c];
  4121. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4122. c++;
  4123. }
  4124. sstr[c] = '\0';
  4125. strcpy(tempstartScheduleStr, sstr);
  4126. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4127. //**********chargingRateUnit**********/
  4128. c = 0;
  4129. loc = strstr(sLineWord, "chargingRateUnit");
  4130. memset(sstr ,0, sizeof(sstr) );
  4131. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4132. {
  4133. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4134. c++;
  4135. }
  4136. sstr[c] = '\0';
  4137. strcpy(tempchargingRateUnitStr, sstr);
  4138. //**********minChargingRate*******/
  4139. c = 0;
  4140. loc = strstr(sLineWord, "minChargingRate");
  4141. //printf("loc=%s\n",loc);
  4142. if(loc != NULL)
  4143. {
  4144. memset(sstr ,0, sizeof(sstr) );
  4145. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4146. {
  4147. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4148. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4149. c++;
  4150. }
  4151. sstr[c] = '\0';
  4152. tempminChargingRateFloat = atof(sstr);
  4153. }
  4154. else
  4155. {
  4156. tempminChargingRateFloat = 0.0;
  4157. }
  4158. //
  4159. #if 0
  4160. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4161. tp.tm_isdst = -1;
  4162. time_t utc = mktime(&tp);
  4163. // current time
  4164. time_t t = time(NULL);
  4165. #endif
  4166. //diff_t = difftime(t, utc);
  4167. //parsing strings to words
  4168. i = 0;
  4169. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4170. loc = loc+3+strlen("chargingSchedulePeriod");
  4171. pch = strtok(loc ,"{");
  4172. while (pch != NULL)
  4173. {
  4174. strcpy(SchedulePeriodList[i], pch);
  4175. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4176. //printf ("%s\n",pch);
  4177. pch = strtok (NULL, "{");
  4178. i = i + 1;
  4179. }
  4180. n_SchedulePeriods = i;
  4181. for(int i=0;i<n_SchedulePeriods;i++)
  4182. {
  4183. //*************startPeriod****************/
  4184. c = 0;
  4185. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4186. memset(sstr ,0, sizeof(sstr) );
  4187. while (loc[strlen("startPeriod")+2+c] != ',')
  4188. {
  4189. sstr[c] = loc[strlen("startPeriod")+2+c];
  4190. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4191. c++;
  4192. }
  4193. sstr[c] = '\0';
  4194. tempStartPeriodInt = atoi(sstr);
  4195. //*************limit****************/
  4196. c = 0;
  4197. loc = strstr(SchedulePeriodList[i], "limit");
  4198. memset(sstr ,0, sizeof(sstr) );
  4199. while (loc[strlen("limit")+2+c] != ',')
  4200. {
  4201. sstr[c] = loc[strlen("limit")+2+c];
  4202. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4203. c++;
  4204. }
  4205. sstr[c] = '\0';
  4206. tempLimitInt = atof(sstr);
  4207. //*************numberPhases****************/
  4208. c = 0;
  4209. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4210. memset(sstr ,0, sizeof(sstr) );
  4211. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4212. {
  4213. sstr[c] = loc[strlen("numberPhases")+2+c];
  4214. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4215. c++;
  4216. }
  4217. sstr[c] = '\0';
  4218. tempNumberPhasesInt = atoi(sstr);
  4219. ChargePointMaxProfile.Duration = durationInt;
  4220. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4221. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4222. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4223. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4224. }
  4225. if(MinChargingRate < tempminChargingRateFloat)
  4226. MinChargingRate = tempminChargingRateFloat;
  4227. }
  4228. }// End of file ChargingProfile
  4229. } //THE END OF ACCESS ChargePointMaxProfile
  4230. //******************************TxDefaultProfile***********************************************/
  4231. strcpy(fname, TxDefaultProfile_0_JSON);
  4232. memset(word, 0, 30);
  4233. memset(sLineWord, 0, 1060);
  4234. //char word[30]={0};
  4235. //char sLineWord[1060]={0};
  4236. n_chargingProfile=0;
  4237. TxDefaultProfileFileIsNull=TRUE;
  4238. if((access(fname,F_OK))!=-1)
  4239. {
  4240. fptr1 = fopen(fname, "r");
  4241. c = 0;
  4242. c = fgetc(fptr1);
  4243. //DEBUG_INFO("c:%d\n",c);
  4244. rewind(fptr1);
  4245. if(c == EOF)
  4246. {
  4247. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4248. TxDefaultProfileFileIsNull=TRUE;
  4249. fclose(fptr1);
  4250. }
  4251. else
  4252. {
  4253. TxDefaultProfileFileIsNull=FALSE;
  4254. while(fscanf(fptr1, "%s", word) != EOF)
  4255. {
  4256. if(strcmp(word, "chargingProfileId") == 0)
  4257. {
  4258. n_chargingProfile = n_chargingProfile + 1;
  4259. printf("Found\n");
  4260. }
  4261. }
  4262. rewind(fptr1);
  4263. //search Charging Profile Element
  4264. int i= 0;
  4265. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4266. #if 0
  4267. /***********connectorId****************/
  4268. c = 0;
  4269. loc = strstr(sLineWord, "connectorId");
  4270. // printf("loc=%s\n",loc);
  4271. memset(sstr ,0, sizeof(sstr) );
  4272. while (loc[strlen("connectorId")+2+c] != ',')
  4273. {
  4274. sstr[c] = loc[strlen("connectorId")+2+c];
  4275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4276. c++;
  4277. }
  4278. sstr[c] = '\0';
  4279. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4280. tempconnectorIdInt = atoi(sstr);
  4281. #endif
  4282. //***********validFrom**************/
  4283. c = 0;
  4284. loc = strstr(sLineWord, "validFrom");
  4285. //DEBUG_INFO("loc=%s\n",loc);
  4286. memset(sstr ,0, sizeof(sstr) );
  4287. if(loc != NULL)
  4288. {
  4289. while (loc[3+strlen("validFrom")+c] != '\"')
  4290. {
  4291. sstr[c] = loc[3+strlen("validFrom")+c];
  4292. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4293. c++;
  4294. }
  4295. sstr[c] = '\0';
  4296. DEBUG_INFO("validFrom=%s\n",sstr);
  4297. strcpy(tempvalidFromStr,sstr);
  4298. }
  4299. else
  4300. {
  4301. strcpy(tempvalidFromStr,"");
  4302. }
  4303. //**********startSchedule**********/
  4304. c = 0;
  4305. loc = strstr(sLineWord, "startSchedule");
  4306. //DEBUG_INFO("loc=%s\n",loc);
  4307. memset(sstr ,0, sizeof(sstr) );
  4308. while (loc[3+strlen("startSchedule")+c] != '\"')
  4309. {
  4310. sstr[c] = loc[3+strlen("startSchedule")+c];
  4311. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4312. c++;
  4313. }
  4314. sstr[c] = '\0';
  4315. strcpy(tempstartScheduleStr, sstr);
  4316. strcpy(TxDefaultProfileScheduleStr, sstr);
  4317. DEBUG_INFO(" debug 3-1\n");
  4318. //**********chargingRateUnit**********/
  4319. c = 0;
  4320. loc = strstr(sLineWord, "chargingRateUnit");
  4321. memset(sstr ,0, sizeof(sstr) );
  4322. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4323. {
  4324. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4325. c++;
  4326. }
  4327. sstr[c] = '\0';
  4328. strcpy(tempchargingRateUnitStr, sstr);
  4329. //**********minChargingRate*******/
  4330. c = 0;
  4331. loc = strstr(sLineWord, "minChargingRate");
  4332. //printf("loc=%s\n",loc);
  4333. if(loc != NULL)
  4334. {
  4335. memset(sstr ,0, sizeof(sstr) );
  4336. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4337. {
  4338. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4339. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4340. c++;
  4341. }
  4342. sstr[c] = '\0';
  4343. tempminChargingRateFloat = atof(sstr);
  4344. }
  4345. else
  4346. {
  4347. tempminChargingRateFloat = 0.0;
  4348. }
  4349. #if 0
  4350. //
  4351. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4352. tp.tm_isdst = -1;
  4353. time_t utc = mktime(&tp);
  4354. // current time
  4355. time_t t = time(NULL);
  4356. //diff_t = difftime(t, utc);
  4357. #endif
  4358. //parsing strings to words
  4359. i = 0;
  4360. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4361. loc = loc+3+strlen("chargingSchedulePeriod");
  4362. pch = strtok(loc ,"{");
  4363. while (pch != NULL)
  4364. {
  4365. strcpy(SchedulePeriodList[i], pch);
  4366. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4367. //printf ("%s\n",pch);
  4368. pch = strtok (NULL, "{");
  4369. i = i + 1;
  4370. }
  4371. n_SchedulePeriods = i;
  4372. for(int i=0;i<n_SchedulePeriods;i++)
  4373. {
  4374. //*************startPeriod****************/
  4375. c = 0;
  4376. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4377. memset(sstr ,0, sizeof(sstr) );
  4378. while (loc[strlen("startPeriod")+2+c] != ',')
  4379. {
  4380. sstr[c] = loc[strlen("startPeriod")+2+c];
  4381. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4382. c++;
  4383. }
  4384. sstr[c] = '\0';
  4385. tempStartPeriodInt = atoi(sstr);
  4386. //*************limit****************/
  4387. c = 0;
  4388. loc = strstr(SchedulePeriodList[i], "limit");
  4389. memset(sstr ,0, sizeof(sstr) );
  4390. while (loc[strlen("limit")+2+c] != ',')
  4391. {
  4392. sstr[c] = loc[strlen("limit")+2+c];
  4393. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4394. c++;
  4395. }
  4396. sstr[c] = '\0';
  4397. tempLimitInt = atof(sstr);
  4398. //*************numberPhases****************/
  4399. c = 0;
  4400. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4401. memset(sstr ,0, sizeof(sstr) );
  4402. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4403. {
  4404. sstr[c] = loc[strlen("numberPhases")+2+c];
  4405. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4406. c++;
  4407. }
  4408. sstr[c] = '\0';
  4409. tempNumberPhasesInt = atoi(sstr);
  4410. TxDefaultProfile.Duration = durationInt;
  4411. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4412. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4413. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4414. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4415. }
  4416. if(MinChargingRate < tempminChargingRateFloat)
  4417. MinChargingRate = tempminChargingRateFloat;
  4418. }
  4419. }
  4420. }// the end of ACCESS TxDefaultProfile
  4421. // Composite Schedule
  4422. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4423. {
  4424. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4425. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4426. {
  4427. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4428. {
  4429. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4430. }
  4431. else
  4432. {
  4433. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4434. }
  4435. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4436. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4437. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4438. }
  4439. }
  4440. //* Define temporary variables */
  4441. struct tm *gtime;
  4442. time_t now;
  4443. char buf[28];
  4444. /* Read the current system time */
  4445. time(&now);
  4446. /* Convert the system time to GMT (now UTC) */
  4447. gtime = gmtime(&now);
  4448. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4449. // make .conf
  4450. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4451. //MaxChargingProfilesInstalled is 10
  4452. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4453. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4454. //nPeriod = 1;
  4455. if(chargingRateUnitStr[0] != 0)
  4456. {
  4457. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4458. }
  4459. else
  4460. {
  4461. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4462. }
  4463. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4464. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4465. confirmPeriods = 1;
  4466. }
  4467. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4468. {
  4469. //*****************************ChargePointMaxProfile******************************************/
  4470. strcpy(fname, ChargePointMaxProfile_JSON);
  4471. ChargePointMaxProfileIsNull=TRUE;
  4472. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4473. {
  4474. fptr1 = fopen(fname, "r");
  4475. int c;
  4476. c = fgetc(fptr1);
  4477. //DEBUG_INFO("c:%d\n",c);
  4478. rewind(fptr1);
  4479. if(c == EOF)
  4480. {
  4481. DEBUG_INFO("\n End of file reached.");
  4482. ChargePointMaxProfileIsNull=TRUE;
  4483. fclose(fptr1);
  4484. }
  4485. else
  4486. {
  4487. ChargePointMaxProfileIsNull=FALSE;
  4488. while(fscanf(fptr1, "%s", word) != EOF)
  4489. {
  4490. if(strcmp(word, "chargingProfileId") == 0)
  4491. {
  4492. n_chargingProfile = n_chargingProfile + 1;
  4493. }
  4494. }
  4495. rewind(fptr1);
  4496. //search Charging Profile Element
  4497. int i = 0;
  4498. int j = 0;
  4499. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4500. #if 0
  4501. /***********connectorId****************/
  4502. c = 0;
  4503. loc = strstr(sLineWord, "connectorId");
  4504. memset(sstr ,0, sizeof(sstr) );
  4505. while (loc[strlen("connectorId")+2+c] != ',')
  4506. {
  4507. sstr[c] = loc[strlen("connectorId")+2+c];
  4508. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4509. c++;
  4510. }
  4511. sstr[c] = '\0';
  4512. tempconnectorIdInt = atoi(sstr);
  4513. #endif
  4514. //***********validFrom**************/
  4515. c = 0;
  4516. loc = strstr(sLineWord, "validFrom");
  4517. if(loc != NULL)
  4518. {
  4519. memset(sstr ,0, sizeof(sstr) );
  4520. while (loc[3+strlen("validFrom")+c] != '\"')
  4521. {
  4522. sstr[c] = loc[3+strlen("validFrom")+c];
  4523. c++;
  4524. }
  4525. sstr[c] = '\0';
  4526. strcpy(tempvalidFromStr,sstr);
  4527. }
  4528. else
  4529. {
  4530. strcpy(tempvalidFromStr,"");
  4531. }
  4532. //***********validFrom**************/
  4533. c = 0;
  4534. loc = strstr(sLineWord, "duration");
  4535. if(loc != NULL)
  4536. {
  4537. memset(sstr ,0, sizeof(sstr) );
  4538. while (loc[2+strlen("duration")+c] != ',')
  4539. {
  4540. sstr[c] = loc[2+strlen("duration")+c];
  4541. c++;
  4542. }
  4543. sstr[c] = '\0';
  4544. tempdurationInt = atoi(sstr);
  4545. }
  4546. else
  4547. {
  4548. tempdurationInt = 0;
  4549. }
  4550. //**********startSchedule**********/
  4551. c = 0;
  4552. loc = strstr(sLineWord, "startSchedule");
  4553. memset(sstr ,0, sizeof(sstr) );
  4554. while (loc[3+strlen("startSchedule")+c] != '\"')
  4555. {
  4556. sstr[c] = loc[3+strlen("startSchedule")+c];
  4557. c++;
  4558. }
  4559. sstr[c] = '\0';
  4560. strcpy(tempstartScheduleStr, sstr);
  4561. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4562. //**********chargingRateUnit**********/
  4563. c = 0;
  4564. loc = strstr(sLineWord, "chargingRateUnit");
  4565. memset(sstr ,0, sizeof(sstr) );
  4566. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4567. {
  4568. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4569. c++;
  4570. }
  4571. sstr[c] = '\0';
  4572. strcpy(tempchargingRateUnitStr, sstr);
  4573. //**********minChargingRate*******/
  4574. c = 0;
  4575. loc = strstr(sLineWord, "minChargingRate");
  4576. if(loc != NULL)
  4577. {
  4578. memset(sstr ,0, sizeof(sstr) );
  4579. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4580. {
  4581. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4582. c++;
  4583. }
  4584. sstr[c] = '\0';
  4585. tempminChargingRateFloat = atof(sstr);
  4586. }
  4587. else
  4588. {
  4589. tempminChargingRateFloat = 0.0;
  4590. }
  4591. #if 0
  4592. //
  4593. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4594. tp.tm_isdst = -1;
  4595. time_t utc = mktime(&tp);
  4596. time_t t = time(NULL);
  4597. //diff_t = difftime(t, utc);
  4598. #endif
  4599. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4600. //DEBUG_INFO(" debug 5 -1\n");
  4601. //parsing strings to words
  4602. i = 0;
  4603. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4604. loc = loc+3+strlen("chargingSchedulePeriod");
  4605. pch = strtok(loc ,"{");
  4606. while (pch != NULL)
  4607. {
  4608. strcpy(SchedulePeriodList[i], pch);
  4609. pch = strtok (NULL, "{");
  4610. i = i + 1;
  4611. }
  4612. n_SchedulePeriods = i;
  4613. for(int i=0;i<n_SchedulePeriods;i++)
  4614. {
  4615. //*************startPeriod****************/
  4616. c = 0;
  4617. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4618. memset(sstr ,0, sizeof(sstr) );
  4619. while (loc[strlen("startPeriod")+2+c] != ',')
  4620. {
  4621. sstr[c] = loc[strlen("startPeriod")+2+c];
  4622. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4623. c++;
  4624. }
  4625. sstr[c] = '\0';
  4626. tempStartPeriodInt = atoi(sstr);
  4627. //*************limit****************/
  4628. c = 0;
  4629. loc = strstr(SchedulePeriodList[i], "limit");
  4630. memset(sstr ,0, sizeof(sstr) );
  4631. while (loc[strlen("limit")+2+c] != ',')
  4632. {
  4633. sstr[c] = loc[strlen("limit")+2+c];
  4634. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4635. c++;
  4636. }
  4637. sstr[c] = '\0';
  4638. tempLimitInt = atof(sstr);
  4639. //*************numberPhases****************/
  4640. c = 0;
  4641. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4642. memset(sstr ,0, sizeof(sstr) );
  4643. while (loc[strlen("numberPhases")+2+c] != '}')
  4644. {
  4645. sstr[c] = loc[strlen("numberPhases")+2+c];
  4646. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4647. c++;
  4648. }
  4649. sstr[c] = '\0';
  4650. tempNumberPhasesInt = atoi(sstr);
  4651. if(j == 0)
  4652. {
  4653. ChargePointMaxProfile.Duration = tempdurationInt;
  4654. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4655. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4656. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4657. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4658. }
  4659. }
  4660. if(MinChargingRate < tempminChargingRateFloat)
  4661. {
  4662. MinChargingRate = tempminChargingRateFloat;
  4663. }
  4664. if(confirmPeriods < n_SchedulePeriods)
  4665. {
  4666. confirmPeriods = n_SchedulePeriods;
  4667. }
  4668. j = j + 1;
  4669. }
  4670. fclose(fptr1);
  4671. }
  4672. }// the end of access file ChargePointMaxProfile
  4673. //****************************TxDefaultProfile************************************************/
  4674. switch(connectorIdInt)
  4675. {
  4676. case 0:
  4677. break;
  4678. case 1:
  4679. strcpy(fname, TxDefaultProfile_1_JSON );
  4680. break;
  4681. case 2:
  4682. strcpy(fname, TxDefaultProfile_2_JSON );
  4683. break;
  4684. default:
  4685. strcpy(fname, TxDefaultProfile_1_JSON );
  4686. break;
  4687. }
  4688. TxDefaultProfileFileIsNull=TRUE;
  4689. if((access(fname,F_OK))!=-1)
  4690. {
  4691. fptr1 = fopen(fname, "r");
  4692. c = 0;
  4693. c = fgetc(fptr1);
  4694. //DEBUG_INFO("c:%d\n",c);
  4695. rewind(fptr1);
  4696. if(c == EOF)
  4697. {
  4698. DEBUG_INFO("\n End of file reached.");
  4699. TxDefaultProfileFileIsNull=TRUE;
  4700. fclose(fptr1);
  4701. }
  4702. else
  4703. {
  4704. TxDefaultProfileFileIsNull=FALSE;
  4705. while(fscanf(fptr1, "%s", word) != EOF)
  4706. {
  4707. if(strcmp(word, "chargingProfileId") == 0)
  4708. {
  4709. n_chargingProfile = n_chargingProfile + 1;
  4710. }
  4711. }
  4712. rewind(fptr1);
  4713. //search Charging Profile Element
  4714. int i = 0;
  4715. int j = 0;
  4716. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4717. //DEBUG_INFO(" 1-1\n");
  4718. #if 0
  4719. /***********connectorId****************/
  4720. c = 0;
  4721. loc = strstr(sLineWord, "connectorId");
  4722. memset(sstr ,0, sizeof(sstr) );
  4723. while (loc[strlen("connectorId")+2+c] != ',')
  4724. {
  4725. sstr[c] = loc[strlen("connectorId")+2+c];
  4726. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4727. c++;
  4728. }
  4729. sstr[c] = '\0';
  4730. tempconnectorIdInt = atoi(sstr);
  4731. #endif
  4732. //***********validFrom**************/
  4733. c = 0;
  4734. loc = strstr(sLineWord, "validFrom");
  4735. if(loc != NULL)
  4736. {
  4737. memset(sstr ,0, sizeof(sstr) );
  4738. while (loc[3+strlen("validFrom")+c] != '\"')
  4739. {
  4740. sstr[c] = loc[3+strlen("validFrom")+c];
  4741. c++;
  4742. }
  4743. sstr[c] = '\0';
  4744. strcpy(tempvalidFromStr,sstr);
  4745. }
  4746. else
  4747. {
  4748. strcpy(tempvalidFromStr,"");
  4749. }
  4750. //***********validFrom**************/
  4751. c = 0;
  4752. loc = strstr(sLineWord, "duration");
  4753. if(loc != NULL)
  4754. {
  4755. memset(sstr ,0, sizeof(sstr) );
  4756. while (loc[2+strlen("duration")+c] != ',')
  4757. {
  4758. sstr[c] = loc[2+strlen("duration")+c];
  4759. c++;
  4760. }
  4761. sstr[c] = '\0';
  4762. tempdurationInt = atoi(sstr);
  4763. }
  4764. else
  4765. {
  4766. tempdurationInt = 0;
  4767. }
  4768. //**********startSchedule**********/
  4769. c = 0;
  4770. loc = strstr(sLineWord, "startSchedule");
  4771. memset(sstr ,0, sizeof(sstr) );
  4772. while (loc[3+strlen("startSchedule")+c] != '\"')
  4773. {
  4774. sstr[c] = loc[3+strlen("startSchedule")+c];
  4775. c++;
  4776. }
  4777. sstr[c] = '\0';
  4778. strcpy(tempstartScheduleStr, sstr);
  4779. strcpy(TxDefaultProfileScheduleStr, sstr);
  4780. //**********chargingRateUnit**********/
  4781. c = 0;
  4782. loc = strstr(sLineWord, "chargingRateUnit");
  4783. memset(sstr ,0, sizeof(sstr) );
  4784. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4785. {
  4786. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4787. c++;
  4788. }
  4789. sstr[c] = '\0';
  4790. strcpy(tempchargingRateUnitStr, sstr);
  4791. //**********minChargingRate*******/
  4792. c = 0;
  4793. loc = strstr(sLineWord, "minChargingRate");
  4794. if(loc != NULL)
  4795. {
  4796. memset(sstr ,0, sizeof(sstr) );
  4797. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4798. {
  4799. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4800. c++;
  4801. }
  4802. sstr[c] = '\0';
  4803. tempminChargingRateFloat = atof(sstr);
  4804. }
  4805. else
  4806. {
  4807. tempminChargingRateFloat = 0.0;
  4808. }
  4809. #if 0
  4810. //
  4811. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4812. tp.tm_isdst = -1;
  4813. time_t utc = mktime(&tp);
  4814. time_t t = time(NULL);
  4815. //diff_t = difftime(t, utc);
  4816. #endif
  4817. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4818. //parsing strings to words
  4819. i = 0;
  4820. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4821. loc = loc+3+strlen("chargingSchedulePeriod");
  4822. pch = strtok(loc ,"{");
  4823. while (pch != NULL)
  4824. {
  4825. strcpy(SchedulePeriodList[i], pch);
  4826. pch = strtok (NULL, "{");
  4827. i = i + 1;
  4828. }
  4829. n_SchedulePeriods = i;
  4830. for(int i=0;i<n_SchedulePeriods;i++)
  4831. {
  4832. //*************startPeriod****************/
  4833. c = 0;
  4834. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4835. memset(sstr ,0, sizeof(sstr) );
  4836. while (loc[strlen("startPeriod")+2+c] != ',')
  4837. {
  4838. sstr[c] = loc[strlen("startPeriod")+2+c];
  4839. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4840. c++;
  4841. }
  4842. sstr[c] = '\0';
  4843. tempStartPeriodInt = atoi(sstr);
  4844. //*************limit****************/
  4845. c = 0;
  4846. loc = strstr(SchedulePeriodList[i], "limit");
  4847. memset(sstr ,0, sizeof(sstr) );
  4848. while (loc[strlen("limit")+2+c] != ',')
  4849. {
  4850. sstr[c] = loc[strlen("limit")+2+c];
  4851. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4852. c++;
  4853. }
  4854. sstr[c] = '\0';
  4855. tempLimitInt = atof(sstr);
  4856. //*************numberPhases****************/
  4857. c = 0;
  4858. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4859. memset(sstr ,0, sizeof(sstr) );
  4860. while (loc[strlen("numberPhases")+2+c] != '}')
  4861. {
  4862. sstr[c] = loc[strlen("numberPhases")+2+c];
  4863. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4864. c++;
  4865. }
  4866. sstr[c] = '\0';
  4867. tempNumberPhasesInt = atoi(sstr);
  4868. if(j == 0)
  4869. {
  4870. TxDefaultProfile.Duration = tempdurationInt;
  4871. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4872. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4873. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4874. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4875. }
  4876. else
  4877. {
  4878. //other stack level charging Profile
  4879. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  4880. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  4881. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  4882. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  4883. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  4884. }
  4885. }
  4886. if(MinChargingRate < tempminChargingRateFloat)
  4887. MinChargingRate = tempminChargingRateFloat;
  4888. if(confirmPeriods < n_SchedulePeriods)
  4889. confirmPeriods = n_SchedulePeriods;
  4890. j = j + 1;
  4891. //DEBUG_INFO(" 1-2\n");
  4892. }
  4893. fclose(fptr1);
  4894. //Stacking Charging Profiles
  4895. for(int l=0; l <(j-1) ;l++)
  4896. {
  4897. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  4898. {
  4899. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  4900. {
  4901. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  4902. {
  4903. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  4904. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  4905. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  4906. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4907. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4908. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4909. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4910. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4911. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4912. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4913. }
  4914. else
  4915. {
  4916. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4917. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4918. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4919. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4920. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4921. }
  4922. }
  4923. }
  4924. }
  4925. //end of Stacking Charging Profiles
  4926. }
  4927. }// the end of ACCESS TxDefaultProfile
  4928. //****************************TxProfile************************************************/
  4929. switch(connectorIdInt)
  4930. {
  4931. case 0:
  4932. break;
  4933. case 1:
  4934. strcpy(fname, TxProfile_1_JSON );
  4935. break;
  4936. case 2:
  4937. strcpy(fname, TxProfile_2_JSON );
  4938. break;
  4939. default:
  4940. strcpy(fname, TxProfile_1_JSON );
  4941. break;
  4942. }
  4943. TxProfileIsNull=TRUE;
  4944. if((access(fname,F_OK))!=-1)
  4945. {
  4946. fptr1 = fopen(fname, "r");
  4947. c = 0;
  4948. c = fgetc(fptr1);
  4949. //DEBUG_INFO("c:%d\n",c);
  4950. rewind(fptr1);
  4951. if(c == EOF)
  4952. {
  4953. DEBUG_INFO("\n End of file reached.");
  4954. TxProfileIsNull=TRUE;
  4955. fclose(fptr1);
  4956. }
  4957. else
  4958. {
  4959. TxProfileIsNull=FALSE;
  4960. while(fscanf(fptr1, "%s", word) != EOF)
  4961. {
  4962. if(strcmp(word, "chargingProfileId") == 0)
  4963. {
  4964. n_chargingProfile = n_chargingProfile + 1;
  4965. }
  4966. }
  4967. rewind(fptr1);
  4968. //search Charging Profile Element
  4969. int i= 0;
  4970. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4971. #if 0
  4972. /***********connectorId****************/
  4973. c = 0;
  4974. loc = strstr(sLineWord, "connectorId");
  4975. memset(sstr ,0, sizeof(sstr) );
  4976. while (loc[strlen("connectorId")+2+c] != ',')
  4977. {
  4978. sstr[c] = loc[strlen("connectorId")+2+c];
  4979. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4980. c++;
  4981. }
  4982. sstr[c] = '\0';
  4983. tempconnectorIdInt = atoi(sstr);
  4984. #endif
  4985. //***********validFrom**************/
  4986. c = 0;
  4987. loc = strstr(sLineWord, "validFrom");
  4988. if(loc != NULL)
  4989. {
  4990. memset(sstr ,0, sizeof(sstr) );
  4991. while (loc[3+strlen("validFrom")+c] != '\"')
  4992. {
  4993. sstr[c] = loc[3+strlen("validFrom")+c];
  4994. c++;
  4995. }
  4996. sstr[c] = '\0';
  4997. strcpy(tempvalidFromStr,sstr);
  4998. }
  4999. else
  5000. {
  5001. strcpy(tempvalidFromStr,"");
  5002. }
  5003. //**********startSchedule**********/
  5004. c = 0;
  5005. loc = strstr(sLineWord, "startSchedule");
  5006. memset(sstr ,0, sizeof(sstr) );
  5007. while (loc[3+strlen("startSchedule")+c] != '\"')
  5008. {
  5009. sstr[c] = loc[3+strlen("startSchedule")+c];
  5010. c++;
  5011. }
  5012. sstr[c] = '\0';
  5013. strcpy(tempstartScheduleStr, sstr);
  5014. strcpy(TxProfileScheduleStr, sstr);
  5015. //**********chargingRateUnit**********/
  5016. c = 0;
  5017. loc = strstr(sLineWord, "chargingRateUnit");
  5018. memset(sstr ,0, sizeof(sstr) );
  5019. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5020. {
  5021. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5022. c++;
  5023. }
  5024. sstr[c] = '\0';
  5025. strcpy(tempchargingRateUnitStr, sstr);
  5026. //**********minChargingRate*******/
  5027. c = 0;
  5028. loc = strstr(sLineWord, "minChargingRate");
  5029. if(loc != NULL)
  5030. {
  5031. memset(sstr ,0, sizeof(sstr) );
  5032. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5033. {
  5034. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5035. c++;
  5036. }
  5037. sstr[c] = '\0';
  5038. tempminChargingRateFloat = atof(sstr);
  5039. }
  5040. else
  5041. {
  5042. tempminChargingRateFloat = 0.0;
  5043. }
  5044. #if 0
  5045. //
  5046. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5047. tp.tm_isdst = -1;
  5048. time_t utc = mktime(&tp);
  5049. time_t t = time(NULL);
  5050. //diff_t = difftime(t, utc);
  5051. #endif
  5052. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5053. //parsing strings to words
  5054. i = 0;
  5055. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5056. loc = loc+3+strlen("chargingSchedulePeriod");
  5057. pch = strtok(loc ,"{");
  5058. while (pch != NULL)
  5059. {
  5060. strcpy(SchedulePeriodList[i], pch);
  5061. pch = strtok (NULL, "{");
  5062. i = i + 1;
  5063. }
  5064. n_SchedulePeriods = i;
  5065. for(int i=0;i<n_SchedulePeriods;i++)
  5066. {
  5067. //*************startPeriod****************/
  5068. c = 0;
  5069. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5070. memset(sstr ,0, sizeof(sstr) );
  5071. while (loc[strlen("startPeriod")+2+c] != ',')
  5072. {
  5073. sstr[c] = loc[strlen("startPeriod")+2+c];
  5074. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5075. c++;
  5076. }
  5077. sstr[c] = '\0';
  5078. tempStartPeriodInt = atoi(sstr);
  5079. //*************limit****************/
  5080. c = 0;
  5081. loc = strstr(SchedulePeriodList[i], "limit");
  5082. memset(sstr ,0, sizeof(sstr) );
  5083. while (loc[strlen("limit")+2+c] != ',')
  5084. {
  5085. sstr[c] = loc[strlen("limit")+2+c];
  5086. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5087. c++;
  5088. }
  5089. sstr[c] = '\0';
  5090. tempLimitInt = atof(sstr);
  5091. //*************numberPhases****************/
  5092. c = 0;
  5093. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5094. memset(sstr ,0, sizeof(sstr) );
  5095. while (loc[strlen("numberPhases")+2+c] != '}')
  5096. {
  5097. sstr[c] = loc[strlen("numberPhases")+2+c];
  5098. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5099. c++;
  5100. }
  5101. sstr[c] = '\0';
  5102. tempNumberPhasesInt = atoi(sstr);
  5103. TxProfile.Duration = durationInt;
  5104. TxProfile.TotalPeriod = n_SchedulePeriods;
  5105. TxProfile.Period[i].Limit = tempLimitInt;
  5106. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5107. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5108. }
  5109. if(MinChargingRate < tempminChargingRateFloat)
  5110. MinChargingRate = tempminChargingRateFloat;
  5111. if(confirmPeriods < n_SchedulePeriods)
  5112. confirmPeriods = n_SchedulePeriods;
  5113. }
  5114. fclose(fptr1);
  5115. }
  5116. }// the end of ACCESS TxProfile
  5117. //CompositeSchedule
  5118. int period=0;
  5119. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5120. {
  5121. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5122. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5123. {
  5124. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5125. {
  5126. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5127. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5128. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5129. period = period + 1;
  5130. }
  5131. else
  5132. {
  5133. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5134. {
  5135. }
  5136. else
  5137. {
  5138. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5139. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5140. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5141. period = period + 1;
  5142. }
  5143. }
  5144. }
  5145. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5146. {
  5147. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5148. {
  5149. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5150. {
  5151. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5152. }
  5153. else
  5154. {
  5155. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5156. }
  5157. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5158. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5159. period = period + 1;
  5160. }
  5161. }
  5162. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5163. {
  5164. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5165. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5166. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5167. period = period + 1;
  5168. }
  5169. }
  5170. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5171. {
  5172. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5173. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5174. {
  5175. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5176. {
  5177. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5178. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5179. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5180. period = period + 1;
  5181. }
  5182. else
  5183. {
  5184. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5185. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5186. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5187. period = period + 1;
  5188. }
  5189. }
  5190. }
  5191. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5192. {
  5193. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5194. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5195. {
  5196. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5197. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5198. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5199. period = period + 1;
  5200. }
  5201. }
  5202. confirmPeriods = period;
  5203. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5204. //* Define temporary variables */
  5205. struct tm *gtime;
  5206. time_t now;
  5207. char buf[28];
  5208. //* Read the current system time */
  5209. time(&now);
  5210. //* Convert the system time to GMT (now UTC) */
  5211. gtime = gmtime(&now);
  5212. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5213. // make .conf
  5214. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5215. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5216. //DEBUG_INFO(" debug 11\n");
  5217. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5218. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5219. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5220. }
  5221. else
  5222. {
  5223. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5224. }
  5225. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5226. return result;
  5227. }
  5228. int handleGetConfigurationRequest(char *uuid, char *payload)
  5229. {
  5230. mtrace();
  5231. int result = FAIL;
  5232. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5233. //struct json_object *jsonitem;
  5234. int MaxKeySupported = 0;
  5235. int n_keys = 0;
  5236. char requestKey[43][50]={0};
  5237. char search[]="[";
  5238. char sstr[500]={ 0 };
  5239. //int pos;
  5240. int l, c = 0;
  5241. int i = 0;
  5242. char *delim = "\",\"";
  5243. char * pch;
  5244. char *loc = strstr(payload, search);
  5245. //********************* Parsing String ***********************************/
  5246. if(loc == NULL) {
  5247. DEBUG_INFO("no key match in Configuration \n");
  5248. }
  5249. else {
  5250. //pos = loc - payload;
  5251. l = strlen(loc)-4;
  5252. while (c < l)
  5253. {
  5254. sstr[c] = loc[c+2];
  5255. c++;
  5256. }
  5257. sstr[c] = '\0';
  5258. //parsing strings to words
  5259. pch = strtok(sstr,delim);
  5260. if(pch == NULL)
  5261. {
  5262. strcpy(requestKey[0], sstr);
  5263. }
  5264. else
  5265. {
  5266. while (pch != NULL)
  5267. {
  5268. strcpy(requestKey[i], pch);
  5269. pch = strtok (NULL, delim);
  5270. i = i + 1;
  5271. }
  5272. n_keys = i;
  5273. }
  5274. }
  5275. UnknownKeynum = 0;
  5276. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5277. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5278. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5279. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5280. if(n_keys != 0)
  5281. {
  5282. for(int i=0;i<n_keys;i++)
  5283. {
  5284. getKeyValue(requestKey[i]);
  5285. //json_object_put(jsonitem);
  5286. }
  5287. }
  5288. else
  5289. {
  5290. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5291. getKeyValue("");
  5292. }
  5293. processUnkownKey();
  5294. sendGetConfigurationConfirmation(uuid);
  5295. return result;
  5296. }
  5297. static char fnamePlusPath[100]={0};
  5298. static char fnamePWithNoPath[60]={0};
  5299. void checkUploadLog(void)
  5300. {
  5301. FILE *fp;
  5302. /* Open the command for reading. */
  5303. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5304. if (fp == NULL) {
  5305. printf("Failed to run command\n" );
  5306. exit(1);
  5307. }
  5308. int ftppathlen = 0;
  5309. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5310. int i = 0;
  5311. /* Read the output a line at a time - output it. */
  5312. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5313. if(i==0)
  5314. {
  5315. ftppathlen = strlen(fnamePlusPath);
  5316. printf("%s\n", fnamePlusPath);
  5317. fnamePlusPath[ftppathlen]='\0';
  5318. break;
  5319. }
  5320. i= i+1;
  5321. }
  5322. /* close */
  5323. pclose(fp);
  5324. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5325. {
  5326. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5327. {
  5328. fnamePlusPath[k]='\0';
  5329. }
  5330. }
  5331. i=1;
  5332. //char fname[60]={0};
  5333. while(i < ftppathlen)
  5334. {
  5335. int len=ftppathlen-i;
  5336. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5337. {
  5338. printf("compare '/' all right\n");
  5339. break;
  5340. }
  5341. i=i+1;
  5342. }
  5343. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5344. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5345. fnamePWithNoPath[i+1] = '\0';
  5346. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5347. {
  5348. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5349. {
  5350. fnamePWithNoPath[j]='\0';
  5351. }
  5352. }
  5353. FILE* fp1 = fopen(fnamePlusPath, "r");
  5354. if (fp1)
  5355. {
  5356. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5357. // file exists
  5358. fclose(fp1);
  5359. }
  5360. else
  5361. {
  5362. // file doesn't exist
  5363. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5364. }
  5365. }
  5366. static char GetDiagnosticspayloadData[300]={0};
  5367. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5368. {
  5369. mtrace();
  5370. int result = FAIL;
  5371. pthread_t t; // pthread 變數
  5372. system("exec /root/logPackTools 'log' 6");
  5373. #if 0
  5374. //char buffer [128];
  5375. time (&rawtime);
  5376. //printf("%ld\n", rawtime);
  5377. timeinfo = localtime (&rawtime);
  5378. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5379. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5380. if((access(fnamePlusPath,F_OK))!=-1)
  5381. {
  5382. DEBUG_INFO("fnamePlusPath exist.\n");
  5383. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5384. }
  5385. else
  5386. {
  5387. DEBUG_INFO("fnamePlusPath not exist!\n");
  5388. }
  5389. #endif
  5390. checkUploadLog();
  5391. memset(GetDiagnosticspayloadData, 0, 300);
  5392. strcpy(GetDiagnosticspayloadData, payload);
  5393. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5394. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5395. return result;
  5396. }
  5397. void* GetDiagnosticsProcess(void* data)
  5398. {
  5399. pthread_detach(pthread_self());
  5400. mtrace();
  5401. int retriesInt=0, retryIntervalInt=0;
  5402. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5403. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5404. char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
  5405. int port=0;
  5406. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5407. int c = 0;
  5408. char *loc;
  5409. int isSuccess = FALSE;
  5410. char ftpbuf[200]={0};
  5411. //char temp[100]={0};
  5412. char * pch;
  5413. // [2,"137d88c7-a403-4ead-bb2d-fc6ec90531c1","GetDiagnostics",{"location":"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/","retries":0,"retryInterval":0,"startTime":"0001-01-01T00:00:00.000Z","stopTime":"0001-01-01T00:00:00.000Z"}]
  5414. char str[300]={ 0 };
  5415. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5416. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5417. DEBUG_INFO("GetDiagnosticsProcess\n");
  5418. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5419. //****************location*******************/
  5420. c = 0;
  5421. memset(sstr ,0, sizeof(sstr) );
  5422. loc = strstr(str, "location");
  5423. while (loc[3+strlen("location")+c] != '\"')
  5424. {
  5425. sstr[c] = loc[3+strlen("location")+c];
  5426. c++;
  5427. }
  5428. sstr[c] = '\0';
  5429. strcpy(locationstr,sstr);
  5430. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5431. if(strcmp(locationstr,"")==0)
  5432. {
  5433. DEBUG_INFO("location is <Empty>!\n");
  5434. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5435. goto end;
  5436. }
  5437. //****************retries*******************/
  5438. c = 0;
  5439. loc = strstr(str, "retries");
  5440. if(loc == NULL)
  5441. {
  5442. retriesIsNULL = TRUE;
  5443. }
  5444. else
  5445. {
  5446. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5447. {
  5448. sstr[c] = loc[strlen("retries")+2+c];
  5449. c++;
  5450. }
  5451. sstr[c] = '\0';
  5452. retriesInt = atoi(sstr);
  5453. }
  5454. if(retriesIsNULL == TRUE)
  5455. {
  5456. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5457. }
  5458. //****************retryInterval*******************/
  5459. c = 0;
  5460. loc = strstr(str, "retryInterval");
  5461. if(loc == NULL)
  5462. {
  5463. retryIntervalIsNULL = TRUE;
  5464. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5465. }
  5466. else
  5467. {
  5468. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5469. {
  5470. sstr[c] = loc[strlen("retryInterval")+2+c];
  5471. c++;
  5472. }
  5473. sstr[c] = '\0';
  5474. retryIntervalInt = atoi(sstr);
  5475. }
  5476. //****************startTime*******************/
  5477. c = 0;
  5478. memset(sstr ,0, sizeof(sstr) );
  5479. loc = strstr(str, "startTime");
  5480. if(loc == NULL)
  5481. {
  5482. startTimeIsNULL = TRUE;
  5483. }
  5484. else
  5485. {
  5486. while (loc[3+strlen("startTime")+c] != '\"')
  5487. {
  5488. sstr[c] = loc[3+strlen("startTime")+c];
  5489. c++;
  5490. }
  5491. sstr[c] = '\0';
  5492. strcpy(startTimestr,sstr);
  5493. }
  5494. //****************stopTime*******************/
  5495. c = 0;
  5496. memset(sstr ,0, sizeof(sstr) );
  5497. loc = strstr(str, "stopTime");
  5498. if(loc == NULL)
  5499. {
  5500. stopTimeIsNULL = TRUE;
  5501. }
  5502. else
  5503. {
  5504. while (loc[3+strlen("stopTime")+c] != '\"')
  5505. {
  5506. sstr[c] = loc[3+strlen("stopTime")+c];
  5507. c++;
  5508. }
  5509. sstr[c] = '\0';
  5510. strcpy(stopTimestr,sstr);
  5511. }
  5512. memset(protocol, 0, sizeof(protocol));
  5513. memset(user, 0, sizeof(user) );
  5514. memset(password, 0, sizeof(password));
  5515. memset(host, 0, sizeof(host));
  5516. memset(path, 0, sizeof(path));
  5517. memset(ftppath, 0, sizeof(ftppath));
  5518. memset(host1, 0, sizeof(host1));
  5519. memset(path1, 0, sizeof(path1));
  5520. /*location: ftp://user:password@host:port/path*/
  5521. #if 0
  5522. time_t rawtime;
  5523. struct tm * timeinfo;
  5524. //char buffer [128];
  5525. time (&rawtime);
  5526. //printf("%ld\n", rawtime);
  5527. timeinfo = localtime (&rawtime);
  5528. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5529. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5530. #endif
  5531. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5532. if((access(fnamePlusPath,F_OK))!=-1)
  5533. {
  5534. DEBUG_INFO("fnamePlusPath exist.\n");
  5535. }
  5536. else
  5537. {
  5538. DEBUG_INFO("fnamePlusPath not exist!\n");
  5539. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5540. goto end;
  5541. }
  5542. pch=strchr(locationstr,'@');
  5543. if(pch==NULL)
  5544. {
  5545. sscanf(locationstr,
  5546. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5547. protocol, host, &port, path);
  5548. strcpy(user,"anonymous");
  5549. strcpy(password,"");
  5550. }
  5551. else
  5552. {
  5553. //DEBUG_INFO("pch=%s\n", pch);
  5554. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5555. protocol, user, password, host, &port, path);
  5556. }
  5557. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5558. {
  5559. DEBUG_INFO("protocol is not ftp/http ! \n");
  5560. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5561. goto end;
  5562. }
  5563. if(strncmp(locationstr,"http", 4) == 0)
  5564. {
  5565. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  5566. sprintf(ftppath,"/%s", path);
  5567. do{
  5568. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5569. sleep(retryIntervalInt);
  5570. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5571. if(!isSuccess)
  5572. {
  5573. DEBUG_INFO("Diagnostics fail.\n");
  5574. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5575. }
  5576. else
  5577. {
  5578. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5579. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5580. }
  5581. }
  5582. else
  5583. {
  5584. sscanf(host,"%[^/]%s",host1, path1);
  5585. sprintf(ftppath,"%s", path1);
  5586. int ftppathlen=strlen(ftppath);
  5587. int i=1;
  5588. char filenametemp[50];
  5589. while(i < ftppathlen)
  5590. {
  5591. int len=ftppathlen-i;
  5592. if(ftppath[len]== 47) // '/' ascll code: 47
  5593. {
  5594. DEBUG_INFO("find '/' all right\n");
  5595. break;
  5596. }
  5597. i=i+1;
  5598. }
  5599. memset(filenametemp, 0, sizeof(filenametemp));
  5600. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5601. filenametemp[i+1] = 0;
  5602. memset(ftpbuf, 0, sizeof(ftpbuf));
  5603. if(port == 0)
  5604. port = 21;
  5605. do{
  5606. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  5607. sleep(retryIntervalInt);
  5608. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5609. if(!isSuccess)
  5610. {
  5611. DEBUG_INFO("Diagnostics fail.\n");
  5612. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5613. }
  5614. else
  5615. {
  5616. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5617. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5618. }
  5619. }
  5620. end:
  5621. DiagnosticsStatusNotificationStatus = 0; //Idle
  5622. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5623. }
  5624. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5625. {
  5626. mtrace();
  5627. int result = FAIL;
  5628. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5629. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5630. {
  5631. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5632. localversion = -1;
  5633. }
  5634. else
  5635. {
  5636. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5637. OCPP_getListVerion();
  5638. }
  5639. //from db.OCPP_getListVerion
  5640. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5641. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5642. sendGetLocalListVersionConfirmation(uuid,"");
  5643. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5644. return result;
  5645. }
  5646. int handleRemoteStartRequest(char *uuid, char *payload)
  5647. {
  5648. mtrace();
  5649. int result = FAIL;
  5650. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5651. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5652. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5653. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5654. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5655. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5656. int chargingSchedulePeriodCount = 0;
  5657. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5658. int c = 0;
  5659. char *loc;
  5660. char comfirmstr[20]={0};
  5661. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5662. if(server_pending == TRUE)
  5663. {
  5664. return 0;
  5665. }
  5666. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5667. //**********connectorId****************/
  5668. c = 0;
  5669. memset(sstr ,0, sizeof(sstr) );
  5670. loc = strstr(payload, "connectorId");
  5671. if(loc == NULL)
  5672. {
  5673. connectorIdIsNULL = TRUE;
  5674. }
  5675. else
  5676. {
  5677. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5678. {
  5679. sstr[c] = loc[strlen("connectorId")+2+c];
  5680. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5681. c++;
  5682. }
  5683. sstr[c] = '\0';
  5684. connectorIdInt = atoi(sstr);
  5685. }
  5686. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  5687. {
  5688. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5689. goto end;
  5690. }
  5691. //****************idTag*******************/
  5692. c = 0;
  5693. memset(sstr ,0, sizeof(sstr) );
  5694. loc = strstr(payload, "idTag");
  5695. while (loc[3+strlen("idTag")+c] != '\"')
  5696. {
  5697. sstr[c] = loc[3+strlen("idTag")+c];
  5698. c++;
  5699. }
  5700. sstr[c] = '\0';
  5701. strcpy(idTagstr,sstr);
  5702. //****************chargingProfile*******************/
  5703. c = 0;
  5704. memset(sstr ,0, sizeof(sstr) );
  5705. loc = strstr(payload, "chargingProfile");
  5706. if(loc == NULL)
  5707. {
  5708. chargingProfileIsNULL = TRUE;
  5709. }
  5710. else
  5711. {
  5712. //****************chargingProfileId*******************/
  5713. c=0;
  5714. loc = strstr(payload, "chargingProfileId");
  5715. memset(sstr ,0, sizeof(sstr) );
  5716. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5717. {
  5718. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5719. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5720. c++;
  5721. }
  5722. sstr[c] = '\0';
  5723. chargingProfileIdInt = atoi(sstr);
  5724. //****************transactionId*******************/
  5725. loc = strstr(payload, "transactionId");
  5726. if(loc == NULL)
  5727. {
  5728. transactionIdIsNULL = TRUE;
  5729. }
  5730. else
  5731. {
  5732. c=0;
  5733. memset(sstr ,0, sizeof(sstr) );
  5734. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5735. {
  5736. sstr[c] = loc[strlen("transactionId")+2+c];
  5737. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5738. c++;
  5739. }
  5740. sstr[c] = '\0';
  5741. transactionIdInt = atoi(sstr);
  5742. }
  5743. //****************stackLevel*******************/
  5744. c=0;
  5745. loc = strstr(payload, "stackLevel");
  5746. memset(sstr ,0, sizeof(sstr) );
  5747. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5748. {
  5749. sstr[c] = loc[strlen("stackLevel")+2+c];
  5750. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5751. c++;
  5752. }
  5753. sstr[c] = '\0';
  5754. stackLevelInt = atoi(sstr);
  5755. //****************chargingProfilePurpose*******************/
  5756. c = 0;
  5757. memset(sstr ,0, sizeof(sstr) );
  5758. loc = strstr(payload, "chargingProfilePurpose");
  5759. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5760. {
  5761. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5762. c++;
  5763. }
  5764. sstr[c] = '\0';
  5765. strcpy(chargingProfilePurposestr,sstr);
  5766. //****************chargingProfileKind*******************/
  5767. c = 0;
  5768. memset(sstr ,0, sizeof(sstr) );
  5769. loc = strstr(payload, "chargingProfileKind");
  5770. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5771. {
  5772. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5773. c++;
  5774. }
  5775. sstr[c] = '\0';
  5776. strcpy(chargingProfileKindstr,sstr);
  5777. //****************recurrencyKind*******************/
  5778. loc = strstr(payload, "recurrencyKind");
  5779. if(loc == NULL)
  5780. {
  5781. recurrencyKindIsNULL = TRUE;
  5782. }
  5783. else
  5784. {
  5785. c = 0;
  5786. memset(sstr ,0, sizeof(sstr) );
  5787. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5788. {
  5789. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5790. c++;
  5791. }
  5792. sstr[c] = '\0';
  5793. strcpy(recurrencyKindstr,sstr);
  5794. }
  5795. //****************validFrom*******************/
  5796. loc = strstr(payload, "validFrom");
  5797. if(loc == NULL)
  5798. {
  5799. validFromIsNULL = TRUE;
  5800. }
  5801. else
  5802. {
  5803. c = 0;
  5804. memset(sstr ,0, sizeof(sstr) );
  5805. while (loc[3+strlen("validFrom")+c] != '\"')
  5806. {
  5807. sstr[c] = loc[3+strlen("validFrom")+c];
  5808. c++;
  5809. }
  5810. sstr[c] = '\0';
  5811. strcpy(validFromstr,sstr);
  5812. }
  5813. //****************validTo*******************/
  5814. loc = strstr(payload, "validTo");
  5815. if(loc == NULL)
  5816. {
  5817. validToIsNULL = TRUE;
  5818. }
  5819. else
  5820. {
  5821. c = 0;
  5822. memset(sstr ,0, sizeof(sstr) );
  5823. while (loc[3+strlen("validTo")+c] != '\"')
  5824. {
  5825. sstr[c] = loc[3+strlen("validTo")+c];
  5826. c++;
  5827. }
  5828. sstr[c] = '\0';
  5829. strcpy(validTostr,sstr);
  5830. }
  5831. //****************chargingSchedule*******************/
  5832. loc = strstr(payload, "chargingSchedule");
  5833. if(loc != NULL)
  5834. {
  5835. //****************duration*******************/
  5836. loc = strstr(payload, "duration");
  5837. if(loc == NULL)
  5838. {
  5839. durationIsNULL = TRUE;
  5840. }
  5841. else
  5842. {
  5843. c=0;
  5844. memset(sstr ,0, sizeof(sstr) );
  5845. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5846. {
  5847. sstr[c] = loc[strlen("duration")+2+c];
  5848. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5849. c++;
  5850. }
  5851. sstr[c] = '\0';
  5852. durationInt = atoi(sstr);
  5853. }
  5854. //****************startSchedule******************/
  5855. loc = strstr(payload, "startSchedule");
  5856. if(loc == NULL)
  5857. {
  5858. startScheduleIsNULL = TRUE;
  5859. }
  5860. else
  5861. {
  5862. c = 0;
  5863. memset(sstr ,0, sizeof(sstr) );
  5864. while (loc[3+strlen("startSchedule")+c] != '\"')
  5865. {
  5866. sstr[c] = loc[3+strlen("startSchedule")+c];
  5867. c++;
  5868. }
  5869. sstr[c] = '\0';
  5870. strcpy(startSchedulestr,sstr);
  5871. }
  5872. //****************chargingRateUnit*******************/
  5873. c = 0;
  5874. memset(sstr ,0, sizeof(sstr) );
  5875. loc = strstr(payload, "chargingRateUnit");
  5876. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5877. {
  5878. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5879. c++;
  5880. }
  5881. sstr[c] = '\0';
  5882. strcpy(chargingRateUnitstr,sstr);
  5883. //****************minChargingRate*******************/
  5884. loc = strstr(payload, "minChargingRate");
  5885. if(loc == NULL)
  5886. {
  5887. minChargingRateIsNULL = TRUE;
  5888. }
  5889. else
  5890. {
  5891. c=0;
  5892. memset(sstr ,0, sizeof(sstr) );
  5893. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5894. {
  5895. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5896. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5897. c++;
  5898. }
  5899. sstr[c] = '\0';
  5900. minChargingRateflaot = atof(sstr);
  5901. }
  5902. //****************chargingSchedulePeriod count*******************/
  5903. int what_len = strlen("startPeriod");
  5904. char *where = payload;
  5905. while ((where = strstr(where, "startPeriod"))) {
  5906. where += what_len;
  5907. chargingSchedulePeriodCount++;
  5908. }
  5909. where = payload;
  5910. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5911. {
  5912. //****************startPeriod*******************/
  5913. c=0;
  5914. loc = strstr(where, "startPeriod");
  5915. memset(sstr ,0, sizeof(sstr) );
  5916. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5917. {
  5918. sstr[c] = loc[strlen("startPeriod")+2+c];
  5919. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5920. c++;
  5921. }
  5922. sstr[c] = '\0';
  5923. startPeriodInt[periodNums] = atoi(sstr);
  5924. //****************limit*******************/
  5925. c=0;
  5926. loc = strstr(where, "limit");
  5927. memset(sstr ,0, sizeof(sstr) );
  5928. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5929. {
  5930. sstr[c] = loc[strlen("limit")+2+c];
  5931. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5932. c++;
  5933. }
  5934. sstr[c] = '\0';
  5935. limitflaot[periodNums] = atof(sstr);
  5936. //****************numberPhases*******************/
  5937. loc = strstr(where, "numberPhases");
  5938. if(loc == NULL)
  5939. {
  5940. numberPhasesIsNULL = TRUE;
  5941. }
  5942. else
  5943. {
  5944. c=0;
  5945. memset(sstr ,0, sizeof(sstr) );
  5946. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  5947. {
  5948. sstr[c] = loc[strlen("numberPhases")+2+c];
  5949. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5950. c++;
  5951. }
  5952. sstr[c] = '\0';
  5953. numberPhasesInt[periodNums] = atoi(sstr);
  5954. }
  5955. where = loc;
  5956. }
  5957. }
  5958. }
  5959. /*
  5960. enum _SYSTEM_STATUS
  5961. {
  5962. S_BOOTING = 0,
  5963. S_IDLE, = 1
  5964. S_AUTHORIZING, =2
  5965. S_REASSIGN_CHECK, =3
  5966. S_REASSIGN, =4
  5967. S_PRECHARGE, =5
  5968. S_PREPARING_FOR_EV, =6
  5969. S_PREPARING_FOR_EVSE, =7
  5970. S_CHARGING, =8
  5971. S_TERMINATING, =9
  5972. S_COMPLETE, =10
  5973. S_ALARM, =11
  5974. S_FAULT =12
  5975. }
  5976. */
  5977. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  5978. {
  5979. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  5980. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  5981. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  5982. //check Transaction active
  5983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5984. {
  5985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5986. {
  5987. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  5988. {
  5989. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  5990. {
  5991. //Reserved
  5992. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  5993. }
  5994. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  5995. {
  5996. //Reserved
  5997. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  5998. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5999. goto end;
  6000. }
  6001. else
  6002. {
  6003. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6004. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6005. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6006. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6007. {
  6008. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6009. goto end;
  6010. }
  6011. }//END FOR ELSE
  6012. }
  6013. }// END FOR CHAdeMO_QUANTITY
  6014. for (int index = 0; index < CCS_QUANTITY; index++)
  6015. {
  6016. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6017. {
  6018. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6019. {
  6020. //Reserved
  6021. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6022. }
  6023. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6024. {
  6025. //Reserved
  6026. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6027. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6028. goto end;
  6029. }
  6030. else
  6031. {
  6032. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6033. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6034. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6035. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6036. {
  6037. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6038. goto end;
  6039. }
  6040. }// END FOR ELSE
  6041. }
  6042. }// END FOR CCS_QUANTITY
  6043. for (int index = 0; index < GB_QUANTITY; index++)
  6044. {
  6045. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6046. {
  6047. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6048. {
  6049. //Reserved
  6050. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6051. }
  6052. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6053. {
  6054. //Reserved
  6055. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6056. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6057. goto end;
  6058. }
  6059. else
  6060. {
  6061. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6062. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6063. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6064. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6065. {
  6066. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6067. goto end;
  6068. }
  6069. }// END FOR ELSE
  6070. }
  6071. } // END FOR GB_QUANTITY
  6072. }
  6073. else
  6074. {
  6075. for (int index = 0; index < AC_QUANTITY; index++)
  6076. {
  6077. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6078. {
  6079. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6080. {
  6081. //Reserved
  6082. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6083. }
  6084. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6085. {
  6086. //Reserved
  6087. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6088. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6089. goto end;
  6090. }
  6091. else
  6092. {
  6093. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6094. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6095. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6096. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6097. {
  6098. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6099. goto end;
  6100. }
  6101. }//END FOR ELSE
  6102. }
  6103. }// END FOR AC_QUANTITY
  6104. }
  6105. if(chargingProfileIsNULL == FALSE)
  6106. {
  6107. //ChargingProfile
  6108. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6109. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6110. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6111. if(recurrencyKindIsNULL == FALSE) //OPTION
  6112. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6113. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6114. if(transactionIdIsNULL == FALSE) // OPTION
  6115. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6116. if(validFromIsNULL == FALSE) // OPTION
  6117. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6118. if(validToIsNULL == FALSE) //OPTION
  6119. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6120. //ChargingSchedule
  6121. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6122. if(durationIsNULL == FALSE) //OPTION
  6123. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6124. if(minChargingRateIsNULL == FALSE) //OPTION
  6125. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6126. if(startScheduleIsNULL == FALSE) //OPTION
  6127. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6128. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6129. {
  6130. //ChargingSchedulePeriod
  6131. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6132. if(numberPhasesIsNULL == FALSE)
  6133. {
  6134. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6135. }
  6136. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6137. }
  6138. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6139. {
  6140. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6141. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6142. //memset idTag
  6143. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6144. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6145. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6146. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6147. }
  6148. else
  6149. {
  6150. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6151. }
  6152. }
  6153. else
  6154. {
  6155. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6156. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6157. //memset idTag
  6158. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6159. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6160. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6161. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6162. }
  6163. }
  6164. else
  6165. {
  6166. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6167. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6168. }
  6169. end:
  6170. if(connectorIdIsNULL == FALSE)
  6171. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6172. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6173. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6174. //OCPP send RemoteStartConfirmation by first.
  6175. sendRemoteStartConfirmation(uuid, comfirmstr);
  6176. return result;
  6177. }
  6178. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6179. {
  6180. mtrace();
  6181. int result = FAIL;
  6182. int match = FALSE;
  6183. int GunNO = 0;
  6184. int transactionIdInt=0;
  6185. int transactionIdIsNULL= FALSE;
  6186. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6187. int c = 0;
  6188. char *loc;
  6189. char comfirmstr[20];
  6190. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6191. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6192. if(server_pending == TRUE)
  6193. {
  6194. return 0;
  6195. }
  6196. c=0;
  6197. loc = strstr(payload, "transactionId");
  6198. if(loc == NULL)
  6199. {
  6200. transactionIdIsNULL= TRUE;
  6201. }
  6202. else
  6203. {
  6204. memset(sstr ,0, sizeof(sstr) );
  6205. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6206. {
  6207. sstr[c] = loc[strlen("transactionId")+2+c];
  6208. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6209. c++;
  6210. }
  6211. sstr[c] = '\0';
  6212. transactionIdInt = atoi(sstr);
  6213. }
  6214. if(transactionIdIsNULL == FALSE)
  6215. {
  6216. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6217. {
  6218. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6219. {
  6220. //check Transaction active
  6221. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6222. {
  6223. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6224. {
  6225. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6226. {
  6227. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6228. {
  6229. match = TRUE;
  6230. GunNO = gun_index;
  6231. }
  6232. }
  6233. }// END FOR CHAdeMO_QUANTITY
  6234. for (int index = 0; index < CCS_QUANTITY; index++)
  6235. {
  6236. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6237. {
  6238. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6239. {
  6240. match = TRUE;
  6241. GunNO = gun_index;
  6242. }
  6243. }
  6244. }// END FOR CCS_QUANTITY
  6245. for (int index = 0; index < GB_QUANTITY; index++)
  6246. {
  6247. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6248. {
  6249. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6250. {
  6251. match = TRUE;
  6252. GunNO = gun_index;
  6253. }
  6254. }
  6255. }// END FOR GB_QUANTITY
  6256. }
  6257. else
  6258. {
  6259. for (int index = 0; index < AC_QUANTITY; index++)
  6260. {
  6261. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6262. {
  6263. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6264. {
  6265. match = TRUE;
  6266. GunNO = gun_index;
  6267. }
  6268. }
  6269. }// END FOR CHAdeMO_QUANTITY
  6270. }// END FOR AC ELSE
  6271. }// CHECK IF ResponseTransactionId == transactionIdInt
  6272. }//END FOR
  6273. if( match == TRUE)
  6274. {
  6275. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6276. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6277. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6278. }
  6279. else
  6280. {
  6281. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6282. }
  6283. }
  6284. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6285. return result;
  6286. }
  6287. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6288. {
  6289. mtrace();
  6290. int result = FAIL;
  6291. int connectorIdInt=0, reservationIdInt=0;
  6292. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6293. char comfirmstr[20]={0};
  6294. char sstr[180]={ 0 };
  6295. int c = 0;
  6296. char *loc;
  6297. //char *ptr;
  6298. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6299. //***(1)connectorId ****/
  6300. c=0;
  6301. loc = strstr(payload, "connectorId");
  6302. memset(sstr ,0, sizeof(sstr) );
  6303. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6304. {
  6305. sstr[c] = loc[strlen("connectorId")+2+c];
  6306. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6307. c++;
  6308. }
  6309. sstr[c] = '\0';
  6310. connectorIdInt = atoi(sstr);
  6311. //***(2)expiryDate ****/
  6312. loc = strstr(payload, "expiryDate");
  6313. memset(sstr ,0, sizeof(sstr) );
  6314. c = 0;
  6315. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6316. {
  6317. sstr[c] = loc[3+strlen("expiryDate")+c];
  6318. c++;
  6319. }
  6320. sstr[c] = '\0';
  6321. strcpy(expiryDatestr, sstr);
  6322. //***(3)idTag ****/
  6323. loc = strstr(payload, "idTag");
  6324. memset(sstr ,0, sizeof(sstr) );
  6325. c = 0;
  6326. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6327. {
  6328. sstr[c] = loc[3+strlen("idTag")+c];
  6329. c++;
  6330. }
  6331. sstr[c] = '\0';
  6332. strcpy(idTagstr, sstr);
  6333. //***(4)parentIdTag ****/
  6334. loc = strstr(payload, "parentIdTag");
  6335. memset(sstr ,0, sizeof(sstr) );
  6336. c = 0;
  6337. if(loc == NULL)
  6338. {
  6339. strcpy(parentIdTagstr, "");
  6340. }
  6341. else
  6342. {
  6343. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6344. {
  6345. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6346. c++;
  6347. }
  6348. sstr[c] = '\0';
  6349. strcpy(parentIdTagstr, sstr);
  6350. }
  6351. //***(5)reservationId ****/
  6352. c=0;
  6353. loc = strstr(payload, "reservationId");
  6354. memset(sstr ,0, sizeof(sstr) );
  6355. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6356. {
  6357. sstr[c] = loc[strlen("reservationId")+2+c];
  6358. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6359. c++;
  6360. }
  6361. sstr[c] = '\0';
  6362. reservationIdInt = atoi(sstr);
  6363. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6364. /*
  6365. enum SYSTEM_STATUS
  6366. {
  6367. SYS_MODE_BOOTING = 0,
  6368. SYS_MODE_IDLE = 1,
  6369. SYS_MODE_AUTHORIZING = 2,
  6370. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6371. SYS_MODE_REASSIGN = 4,
  6372. SYS_MODE_PREPARING = 5,
  6373. SYS_MODE_PREPARE_FOR_EV = 6,
  6374. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6375. SYS_MODE_CHARGING = 8,
  6376. SYS_MODE_TERMINATING = 9,
  6377. SYS_MODE_COMPLETE = 10,
  6378. SYS_MODE_ALARM = 11,
  6379. SYS_MODE_FAULT = 12,
  6380. SYS_MODE_RESERVATION = 13,
  6381. SYS_MODE_BOOKING = 14,
  6382. SYS_MODE_MAINTAIN = 15,
  6383. SYS_MODE_DEBUG = 16,
  6384. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6385. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6386. SYS_MODE_UPDATE = 19
  6387. };
  6388. */
  6389. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6390. {
  6391. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6392. goto end;
  6393. }
  6394. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6395. {
  6396. //check Transaction active
  6397. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6398. {
  6399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6400. {
  6401. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6402. {
  6403. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6404. {
  6405. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6406. {
  6407. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6408. {
  6409. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6410. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6411. }
  6412. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6413. {
  6414. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6415. }
  6416. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6417. {
  6418. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6419. }
  6420. else
  6421. {
  6422. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6423. }
  6424. }
  6425. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6426. {
  6427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6428. }
  6429. }
  6430. else
  6431. {
  6432. //replace reservation
  6433. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6434. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6435. }
  6436. }
  6437. } // END FOR CHAdeMO_QUANTITY
  6438. for (int index = 0; index < CCS_QUANTITY; index++)
  6439. {
  6440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6441. {
  6442. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6443. {
  6444. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6445. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6446. {
  6447. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6448. {
  6449. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6450. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6451. }
  6452. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6453. {
  6454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6455. }
  6456. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6457. {
  6458. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6459. }
  6460. else
  6461. {
  6462. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6463. }
  6464. }
  6465. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6466. {
  6467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6468. }
  6469. }
  6470. else
  6471. {
  6472. //replace reservation
  6473. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6475. }
  6476. }
  6477. } // END FOR CCS_QUANTITY
  6478. for (int index = 0; index < GB_QUANTITY; index++)
  6479. {
  6480. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6481. {
  6482. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6483. {
  6484. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6485. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6486. {
  6487. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6488. {
  6489. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6491. }
  6492. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6493. {
  6494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6495. }
  6496. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6497. {
  6498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6499. }
  6500. else
  6501. {
  6502. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6503. }
  6504. }
  6505. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6506. {
  6507. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6508. }
  6509. }
  6510. else
  6511. {
  6512. //replace reservation
  6513. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6514. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6515. }
  6516. }
  6517. }// END FOR GB_QUANTITY
  6518. }
  6519. else
  6520. {
  6521. for (int index = 0; index < AC_QUANTITY; index++)
  6522. {
  6523. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6524. {
  6525. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6526. {
  6527. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6528. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6529. {
  6530. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6531. {
  6532. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6533. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6534. }
  6535. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6536. {
  6537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6538. }
  6539. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6540. {
  6541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6542. }
  6543. else
  6544. {
  6545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6546. }
  6547. }
  6548. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6549. {
  6550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6551. }
  6552. }
  6553. else
  6554. {
  6555. //replace reservation
  6556. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6557. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6558. }
  6559. }
  6560. } // END FOR AC_QUANTITY
  6561. }//END FOR AC ELSE
  6562. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6563. }
  6564. else if(connectorIdInt == 0)
  6565. {
  6566. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6567. {
  6568. //check Transaction active
  6569. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6570. {
  6571. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6572. {
  6573. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6574. {
  6575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6576. goto end;
  6577. }
  6578. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6579. {
  6580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6581. goto end;
  6582. }
  6583. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6584. {
  6585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6586. goto end;
  6587. }
  6588. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6589. {
  6590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6591. goto end;
  6592. }
  6593. }
  6594. }// END FOR CHAdeMO_QUANTITY
  6595. for (int index = 0; index < CCS_QUANTITY; index++)
  6596. {
  6597. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6598. {
  6599. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6600. {
  6601. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6602. }
  6603. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6604. {
  6605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6606. }
  6607. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6608. {
  6609. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6610. }
  6611. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6612. {
  6613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6614. }
  6615. }
  6616. } // END FOR CCS_QUANTITY
  6617. for (int index = 0; index < GB_QUANTITY; index++)
  6618. {
  6619. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6620. {
  6621. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6622. {
  6623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6624. }
  6625. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6626. {
  6627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6628. }
  6629. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6630. {
  6631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6632. }
  6633. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6634. {
  6635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6636. }
  6637. }
  6638. } // END FOR GB_QUANTITY
  6639. }
  6640. else
  6641. {
  6642. for (int index = 0; index < AC_QUANTITY; index++)
  6643. {
  6644. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6645. {
  6646. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6647. {
  6648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6649. goto end;
  6650. }
  6651. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6652. {
  6653. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6654. goto end;
  6655. }
  6656. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6657. {
  6658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6659. goto end;
  6660. }
  6661. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6662. {
  6663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6664. goto end;
  6665. }
  6666. }
  6667. }// END FOR AC_QUANTITY
  6668. }
  6669. //The connectorId is 0
  6670. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6672. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6673. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6674. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6675. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6676. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6677. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6678. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6679. result = TRUE;
  6680. return result;
  6681. }
  6682. else
  6683. {
  6684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6685. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6686. }
  6687. if(strcmp(comfirmstr,"Accepted") == 0)
  6688. {
  6689. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6690. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6691. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6692. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6693. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6694. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6695. result = TRUE;
  6696. return result;
  6697. }
  6698. end:
  6699. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6700. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6701. return result;
  6702. }
  6703. int handleResetRequest(char *uuid, char *payload)
  6704. {
  6705. mtrace();
  6706. int result = FAIL;
  6707. char sstr[10]={0};
  6708. char typestr[10]={0};
  6709. char comfirmstr[20]={0};
  6710. int c = 0;
  6711. char *loc;
  6712. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6713. DEBUG_INFO("handleResetRequest ...\n");
  6714. loc = strstr(payload, "type");
  6715. memset(sstr ,0, sizeof(sstr) );
  6716. c = 0;
  6717. while (loc[3+strlen("type")+c] != '\"')
  6718. {
  6719. sstr[c] = loc[3+strlen("type")+c];
  6720. c++;
  6721. }
  6722. sstr[c] = '\0';
  6723. strcpy(typestr,sstr);
  6724. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6725. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6726. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6727. {
  6728. //check Transaction active
  6729. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6730. {
  6731. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6732. {
  6733. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6734. {
  6735. //0: unplug, 1: Plug-in
  6736. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6737. }
  6738. }
  6739. for (int index = 0; index < CCS_QUANTITY; index++)
  6740. {
  6741. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6742. {
  6743. //0: unplug, 1: Plug-in
  6744. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6745. }
  6746. }
  6747. for (int index = 0; index < GB_QUANTITY; index++)
  6748. {
  6749. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6750. {
  6751. //0: unplug, 1: Plug-in
  6752. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6753. }
  6754. }
  6755. }
  6756. else
  6757. {
  6758. for (int index = 0; index < AC_QUANTITY; index++)
  6759. {
  6760. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6761. {
  6762. //0: unplug, 1: Plug-in
  6763. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6764. }
  6765. }
  6766. }// END FOR AC ELSE
  6767. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6768. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6769. result = TRUE;
  6770. return result;
  6771. }
  6772. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6773. {
  6774. //check Transaction active
  6775. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6776. {
  6777. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6778. {
  6779. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6780. {
  6781. //0: unplug, 1: Plug-in
  6782. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6783. }
  6784. }
  6785. for (int index = 0; index < CCS_QUANTITY; index++)
  6786. {
  6787. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6788. {
  6789. //0: unplug, 1: Plug-in
  6790. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6791. }
  6792. }
  6793. for (int index = 0; index < GB_QUANTITY; index++)
  6794. {
  6795. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6796. {
  6797. //0: unplug, 1: Plug-in
  6798. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6799. }
  6800. }
  6801. }
  6802. else
  6803. {
  6804. for (int index = 0; index < AC_QUANTITY; index++)
  6805. {
  6806. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6807. {
  6808. //0: unplug, 1: Plug-in
  6809. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6810. }
  6811. }
  6812. }// END FOR AC ELSE
  6813. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6814. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6815. result = TRUE;
  6816. return result;
  6817. }
  6818. else
  6819. {
  6820. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6821. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6822. goto errorend;
  6823. }
  6824. errorend:
  6825. sendResetConfirmation(uuid, comfirmstr);
  6826. return result;
  6827. }
  6828. int handleSendLocalListRequest(char *uuid, char *payload)
  6829. {
  6830. mtrace();
  6831. int result = FAIL;
  6832. int listVersionInt;
  6833. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6834. char listsearch[]="listVersion";
  6835. char updateTypesearch[]="updateType";
  6836. char localAuthorizationListsearch[]="localAuthorizationList";
  6837. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6838. char CardList[500][160]={0};
  6839. char updateTypestr[15]={0};
  6840. char idTagstr[20]={0};
  6841. char parentIdTag[20]={0};
  6842. char expiryDate[30]={0};
  6843. char idTagstatus[16]={0};
  6844. int c = 0;
  6845. int i = 0;
  6846. char *delim1 = "}";
  6847. char * pch;
  6848. char *loc;
  6849. //char *ptr;
  6850. char comfirmstr[20];
  6851. //int n_localAuthorizations = 0;
  6852. int checkState_Faulted = FALSE;
  6853. DEBUG_INFO("handleSendLocalListRequest\n");
  6854. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6855. {
  6856. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6857. goto end;
  6858. }
  6859. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6860. {
  6861. //check Charge Point state
  6862. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6863. {
  6864. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6865. {
  6866. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6867. }
  6868. }
  6869. for (int index = 0; index < CCS_QUANTITY; index++)
  6870. {
  6871. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6872. {
  6873. checkState_Faulted = TRUE; //OCPP Status
  6874. }
  6875. }
  6876. for (int index = 0; index < GB_QUANTITY; index++)
  6877. {
  6878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6879. {
  6880. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6881. }
  6882. }
  6883. }
  6884. else
  6885. {
  6886. //check Charge Point state
  6887. for (int index = 0; index < AC_QUANTITY; index++)
  6888. {
  6889. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6890. {
  6891. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6892. }
  6893. }
  6894. }// END FOR AC ELSE
  6895. if(checkState_Faulted == TRUE)
  6896. {
  6897. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6898. goto end;
  6899. }
  6900. //listVersion
  6901. c = 0;
  6902. loc = strstr(payload, listsearch);
  6903. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  6904. {
  6905. sstr[c] = loc[strlen("listVersion")+2+c];
  6906. c++;
  6907. }
  6908. sstr[c] = '\0';
  6909. listVersionInt = atoi(sstr);
  6910. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6911. //updateType
  6912. loc = strstr(payload, updateTypesearch);
  6913. c = 0;
  6914. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6915. {
  6916. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6917. c++;
  6918. }
  6919. sstr[c] = '\0';
  6920. strcpy(updateTypestr, sstr);
  6921. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6922. //localAuthorizationList
  6923. memset(sstr ,0, sizeof(sstr) );
  6924. loc = strstr(payload, localAuthorizationListsearch);
  6925. if(loc != NULL) // localAuthorizationList is not NULL
  6926. {
  6927. //Check UpdateType
  6928. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6929. {
  6930. //Local list full update
  6931. printf("Local list full update.\n");
  6932. OCPP_cleanLocalList();
  6933. }
  6934. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6935. {
  6936. //Local list different update
  6937. printf("Local list different update.\n");
  6938. OCPP_getListVerion();
  6939. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6940. {
  6941. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6942. goto end;
  6943. }
  6944. }
  6945. else
  6946. {
  6947. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6948. goto end;
  6949. }
  6950. c = 0;
  6951. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6952. {
  6953. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6954. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6955. c++;
  6956. }
  6957. sstr[c] = '\0';
  6958. //DEBUG_INFO("sstr=%s\n", sstr);
  6959. //parsing strings to words
  6960. i = 0;
  6961. pch = strtok(sstr,delim1);
  6962. while (pch != NULL)
  6963. {
  6964. strcpy(CardList[i], pch);
  6965. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  6966. pch = strtok (NULL, delim1);
  6967. i = i + 1;
  6968. }
  6969. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  6970. //local Authorizations List Numbers
  6971. //n_localAuthorizations = i;
  6972. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6973. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  6974. c= 0;
  6975. while(c < i)
  6976. {
  6977. //Search "IdToken"
  6978. memset(sstr ,0, sizeof(sstr) );
  6979. loc = strstr(CardList[c], "idTag");
  6980. int j = 0;
  6981. while (loc[3+strlen("idTag")+j] != '\"')
  6982. {
  6983. sstr[j] = loc[3+strlen("idTag")+j];
  6984. //printf("i=%d sstr=%c\n",c, sstr[j]);
  6985. j++;
  6986. }
  6987. sstr[j] = '\0';
  6988. strcpy(idTagstr, sstr);
  6989. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  6990. //Search "expiryDate"
  6991. memset(sstr ,0, sizeof(sstr) );
  6992. loc = strstr(CardList[c], "expiryDate");
  6993. j = 0;
  6994. if(loc != NULL)
  6995. {
  6996. while (loc[3+strlen("expiryDate")+j] != '\"')
  6997. {
  6998. sstr[j] = loc[3+strlen("expiryDate")+j];
  6999. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7000. j++;
  7001. }
  7002. sstr[j] = '\0';
  7003. strcpy(expiryDate, sstr);
  7004. }
  7005. else
  7006. {
  7007. strcpy(expiryDate, "");
  7008. }
  7009. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7010. //Search "parentIdTag"
  7011. memset(sstr ,0, sizeof(sstr) );
  7012. loc = strstr(CardList[c], "parentIdTag");
  7013. j = 0;
  7014. if(loc != NULL)
  7015. {
  7016. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7017. {
  7018. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7019. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7020. j++;
  7021. }
  7022. sstr[j] = '\0';
  7023. strcpy(parentIdTag, sstr);
  7024. }
  7025. else
  7026. {
  7027. strcpy(parentIdTag, "");
  7028. }
  7029. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7030. //Search "status"
  7031. memset(sstr ,0, sizeof(sstr) );
  7032. loc = strstr(CardList[c], "status");
  7033. j = 0;
  7034. while (loc[3+strlen("status")+j] != '\"')
  7035. {
  7036. sstr[j] = loc[3+strlen("status")+j];
  7037. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7038. j++;
  7039. }
  7040. sstr[j] = '\0';
  7041. strcpy(idTagstatus, sstr);
  7042. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7043. OCPP_getIdTag(idTagstr);
  7044. //OCPP_getIdTag("test"); For Test
  7045. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7046. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7047. {
  7048. //Local list full update
  7049. DEBUG_INFO("Local list full update.\n");
  7050. // update list
  7051. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7052. OCPP_get_TableAuthlocalAllData();
  7053. }
  7054. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7055. {
  7056. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7057. {
  7058. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7059. }
  7060. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7061. {
  7062. OCPP_deleteIdTag(idTagstr);
  7063. }
  7064. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7065. {
  7066. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7067. }
  7068. }
  7069. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7070. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7071. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7072. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7073. c++;
  7074. }
  7075. }
  7076. else
  7077. {
  7078. //Check UpdateType
  7079. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7080. {
  7081. //Local list full update
  7082. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7083. OCPP_cleanLocalList();
  7084. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7085. goto end;
  7086. }
  7087. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7088. {
  7089. //Local list different update
  7090. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7091. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7092. goto end;
  7093. }
  7094. }
  7095. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7096. end:
  7097. sendSendLocalListConfirmation(uuid, comfirmstr);
  7098. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7099. return result;
  7100. }
  7101. #define MAX 200
  7102. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7103. {
  7104. mtrace();
  7105. int result = FAIL;
  7106. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7107. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7108. char chargingProfilePurposeStr[30]={0};
  7109. char chargingProfileKindStr[16]={0};
  7110. char recurrencyKindStr[10]={0};
  7111. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7112. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7113. int chargingSchedulePeriodCount = 0;
  7114. //int updateflag = FALSE;
  7115. char comfirmstr[20]={0};
  7116. int meet= FALSE;
  7117. char sstr[10]={0};
  7118. int c = 0;
  7119. char *loc;
  7120. FILE *fptr1;//, *fptr2;
  7121. //int lno=0;//, linectr = 0;
  7122. //int modifyflag = FALSE;
  7123. char filename[MAX]={0};
  7124. char tempfile[] = "../Storage/OCPP/temp.json";
  7125. //int resultRename=0;
  7126. char rmFileCmd[50]={0};
  7127. char tempchargingProfilePurposeStr[30]={0};
  7128. //[2,"d65bcbca-0b07-49c1-b679-e6c6ff9f5627","SetChargingProfile",{"connectorId":0,"csChargingProfiles":{"chargingProfileId":1,"transactionId":0,"stackLevel":0,"chargingProfilePurpose":"TxDefaultProfile","chargingProfileKind":"Absolute","recurrencyKind":"Daily","validFrom":"2019-07-01T02:39:55.000Z","validTo":"2019-07-04T02:39:55.000Z","chargingSchedule":{"duration":86400,"startSchedule":"2019-07-01T02:39:55.000Z","chargingRateUnit":"A","chargingSchedulePeriod":[{"startPeriod":0,"limit":20.0,"numberPhases":3},{"startPeriod":300,"limit":10.0,"numberPhases":3},{"startPeriod":600,"limit":20.0,"numberPhases":3},{"startPeriod":1200,"limit":10.0,"numberPhases":3},{"startPeriod":1800,"limit":20.0,"numberPhases":3},{"startPeriod":2400,"limit":10.0,"numberPhases":3},{"startPeriod":3000,"limit":20.0,"numberPhases":3}],"minChargingRate":20.1}}}]
  7129. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7130. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7131. //*********************connectorId***************************/
  7132. loc = strstr(payload, "connectorId");
  7133. c = 0;
  7134. memset(sstr ,0, sizeof(sstr) );
  7135. while (loc[strlen("connectorId")+2+c] != ',')
  7136. {
  7137. sstr[c] = loc[strlen("connectorId")+2+c];
  7138. c++;
  7139. }
  7140. sstr[c] = '\0';
  7141. connectorIdInt = atoi(sstr);
  7142. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7143. {
  7144. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7145. }
  7146. else
  7147. {
  7148. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7149. }
  7150. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7151. //*********************chargingProfileId***************************/
  7152. loc = strstr(payload, "chargingProfileId");
  7153. c = 0;
  7154. memset(sstr ,0, sizeof(sstr) );
  7155. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7156. {
  7157. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7158. c++;
  7159. }
  7160. sstr[c] = '\0';
  7161. chargingProfileIdInt = atoi(sstr);
  7162. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7163. {
  7164. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7165. }
  7166. else
  7167. {
  7168. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7169. }
  7170. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7171. //*********************transactionId***************************/
  7172. loc = strstr(payload, "transactionId");
  7173. if(loc != NULL)
  7174. {
  7175. c = 0;
  7176. memset(sstr ,0, sizeof(sstr) );
  7177. while (loc[strlen("transactionId")+2+c] != ',')
  7178. {
  7179. sstr[c] = loc[strlen("transactionId")+2+c];
  7180. c++;
  7181. }
  7182. sstr[c] = '\0';
  7183. transactionIdInt = atoi(sstr);
  7184. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7185. {
  7186. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7187. }
  7188. else
  7189. {
  7190. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7191. }
  7192. }
  7193. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7194. //*********************stackLevel***************************/
  7195. loc = strstr(payload, "stackLevel");
  7196. c = 0;
  7197. memset(sstr ,0, sizeof(sstr) );
  7198. while (loc[strlen("stackLevel")+2+c] != ',')
  7199. {
  7200. sstr[c] = loc[strlen("stackLevel")+2+c];
  7201. c++;
  7202. }
  7203. sstr[c] = '\0';
  7204. stackLevelInt = atoi(sstr);
  7205. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7206. {
  7207. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7208. }
  7209. else
  7210. {
  7211. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7212. }
  7213. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7214. //*********************chargingProfilePurpose***************************/
  7215. loc = strstr(payload, "chargingProfilePurpose");
  7216. c = 0;
  7217. memset(sstr ,0, sizeof(sstr) );
  7218. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7219. {
  7220. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7221. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7222. c++;
  7223. }
  7224. sstr[c] = '\0';
  7225. strcpy(chargingProfilePurposeStr,sstr);
  7226. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7227. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7228. {
  7229. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7230. }
  7231. else
  7232. {
  7233. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7234. }
  7235. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7236. //*********************chargingProfileKind***************************/
  7237. loc = strstr(payload, "chargingProfileKind");
  7238. c = 0;
  7239. memset(sstr ,0, sizeof(sstr) );
  7240. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7241. {
  7242. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7243. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7244. c++;
  7245. }
  7246. sstr[c] = '\0';
  7247. strcpy(chargingProfileKindStr,sstr);
  7248. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7249. {
  7250. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7251. }
  7252. else
  7253. {
  7254. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7255. }
  7256. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7257. //*********************recurrencyKind***************************/
  7258. loc = strstr(payload, "recurrencyKind");
  7259. if(loc != NULL)
  7260. {
  7261. c = 0;
  7262. memset(sstr ,0, sizeof(sstr) );
  7263. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7264. {
  7265. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7266. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7267. c++;
  7268. }
  7269. sstr[c] = '\0';
  7270. strcpy(recurrencyKindStr,sstr);
  7271. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7272. {
  7273. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7274. }
  7275. else
  7276. {
  7277. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7278. }
  7279. }
  7280. else
  7281. {
  7282. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7283. {
  7284. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7285. }
  7286. else
  7287. {
  7288. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7289. }
  7290. }
  7291. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7292. //*********************validFrom***************************/
  7293. loc = strstr(payload, "validFrom");
  7294. if(loc != NULL)
  7295. {
  7296. c = 0;
  7297. memset(sstr ,0, sizeof(sstr) );
  7298. while (loc[3+strlen("validFrom")+c] != '\"')
  7299. {
  7300. sstr[c] = loc[3+strlen("validFrom")+c];
  7301. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7302. c++;
  7303. }
  7304. sstr[c] = '\0';
  7305. strcpy(validFromStr,sstr);
  7306. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7307. {
  7308. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7309. }
  7310. else
  7311. {
  7312. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7313. }
  7314. }
  7315. else
  7316. {
  7317. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7318. {
  7319. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7320. }
  7321. else
  7322. {
  7323. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7324. }
  7325. }
  7326. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7327. //*********************validTo***************************/
  7328. loc = strstr(payload, "validTo");
  7329. if(loc != NULL)
  7330. {
  7331. c = 0;
  7332. memset(sstr ,0, sizeof(sstr) );
  7333. while (loc[3+strlen("validTo")+c] != '\"')
  7334. {
  7335. sstr[c] = loc[3+strlen("validTo")+c];
  7336. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7337. c++;
  7338. }
  7339. sstr[c] = '\0';
  7340. strcpy(validToStr,sstr);
  7341. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7342. {
  7343. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7344. }
  7345. else
  7346. {
  7347. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7348. }
  7349. }
  7350. else
  7351. {
  7352. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7353. {
  7354. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7355. }
  7356. else
  7357. {
  7358. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7359. }
  7360. }
  7361. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7362. //*********************duration***************************/
  7363. loc = strstr(payload, "duration");
  7364. if(loc != NULL)
  7365. {
  7366. c = 0;
  7367. memset(sstr ,0, sizeof(sstr) );
  7368. while (loc[strlen("duration")+2+c] != ',')
  7369. {
  7370. sstr[c] = loc[strlen("duration")+2+c];
  7371. c++;
  7372. }
  7373. sstr[c] = '\0';
  7374. durationInt = atoi(sstr);
  7375. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7376. {
  7377. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7378. }
  7379. else
  7380. {
  7381. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7382. }
  7383. }
  7384. else
  7385. {
  7386. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7387. {
  7388. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7389. }
  7390. else
  7391. {
  7392. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7393. }
  7394. }
  7395. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7396. //*********************startSchedule***************************/
  7397. loc = strstr(payload, "startSchedule");
  7398. if(loc != NULL)
  7399. {
  7400. c = 0;
  7401. memset(sstr ,0, sizeof(sstr) );
  7402. while (loc[3+strlen("startSchedule")+c] != '\"')
  7403. {
  7404. sstr[c] = loc[3+strlen("startSchedule")+c];
  7405. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7406. c++;
  7407. }
  7408. sstr[c] = '\0';
  7409. strcpy(startScheduleStr,sstr);
  7410. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7411. {
  7412. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7413. }
  7414. else
  7415. {
  7416. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7417. }
  7418. }
  7419. else
  7420. {
  7421. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7422. {
  7423. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7424. }
  7425. else
  7426. {
  7427. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7428. }
  7429. }
  7430. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7431. //*********************chargingRateUnit***************************/
  7432. loc = strstr(payload, "chargingRateUnit");
  7433. if(loc != NULL)
  7434. {
  7435. c = 0;
  7436. memset(sstr ,0, sizeof(sstr) );
  7437. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7438. {
  7439. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7440. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7441. c++;
  7442. }
  7443. sstr[c] = '\0';
  7444. strcpy(chargingRateUnitStr,sstr);
  7445. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7446. {
  7447. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7448. }
  7449. else
  7450. {
  7451. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7452. }
  7453. }
  7454. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7455. //****************chargingSchedulePeriod count start*******************/
  7456. int what_len = strlen("startPeriod");
  7457. char tempChargingProfile[1000]={0};
  7458. strcpy(tempChargingProfile,(const char*)payload);
  7459. char *where = tempChargingProfile;
  7460. if (what_len)
  7461. {
  7462. while ((where = strstr(where, "startPeriod"))) {
  7463. where += what_len;
  7464. chargingSchedulePeriodCount++;
  7465. }
  7466. }
  7467. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7468. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7469. //where = payload;
  7470. int templength = 0;
  7471. //int searchstart = 0;
  7472. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7473. {
  7474. //****************startPeriod*******************/
  7475. c=0;
  7476. loc = strstr(tempChargingProfile + templength, "startPeriod");
  7477. memset(sstr ,0, sizeof(sstr) );
  7478. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7479. {
  7480. sstr[c] = loc[strlen("startPeriod")+2+c];
  7481. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7482. c++;
  7483. }
  7484. sstr[c] = '\0';
  7485. startPeriodInt[periodNums] = atoi(sstr);
  7486. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7487. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7488. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7489. {
  7490. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7491. }
  7492. else
  7493. {
  7494. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7495. }
  7496. templength = strlen("startPeriod")+2+c;
  7497. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7498. //****************limit*******************/
  7499. c=0;
  7500. loc = strstr(tempChargingProfile + templength, "limit");
  7501. memset(sstr ,0, sizeof(sstr) );
  7502. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7503. {
  7504. sstr[c] = loc[strlen("limit")+2+c];
  7505. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7506. c++;
  7507. }
  7508. sstr[c] = '\0';
  7509. limitflaot[periodNums] = atof(sstr);
  7510. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7511. {
  7512. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7513. }
  7514. else
  7515. {
  7516. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7517. }
  7518. templength = templength + strlen("limit")+2+c;
  7519. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7520. //****************numberPhases*******************/
  7521. loc = strstr(tempChargingProfile + templength, "numberPhases");
  7522. if(loc != NULL)
  7523. {
  7524. c=0;
  7525. memset(sstr ,0, sizeof(sstr) );
  7526. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7527. {
  7528. sstr[c] = loc[strlen("numberPhases")+2+c];
  7529. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7530. c++;
  7531. }
  7532. sstr[c] = '\0';
  7533. numberPhasesInt[periodNums] = atoi(sstr);
  7534. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7535. {
  7536. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7537. }
  7538. else
  7539. {
  7540. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7541. }
  7542. templength = templength + strlen("numberPhases")+2+c;
  7543. }
  7544. //where = loc;
  7545. }
  7546. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7547. //****************chargingSchedulePeriod count end*******************/
  7548. //*********************minChargingRate***************************/
  7549. loc = strstr(payload, "minChargingRate");
  7550. if(loc != NULL)
  7551. {
  7552. c = 0;
  7553. memset(sstr ,0, sizeof(sstr) );
  7554. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7555. {
  7556. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7557. c++;
  7558. }
  7559. sstr[c] = '\0';
  7560. minChargingRateFloat = atof(sstr);
  7561. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7562. {
  7563. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7564. }
  7565. else
  7566. {
  7567. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7568. }
  7569. }
  7570. else
  7571. {
  7572. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7573. {
  7574. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7575. }
  7576. else
  7577. {
  7578. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7579. }
  7580. }
  7581. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7582. {
  7583. //printf("set chargingProfile 1-2\n");
  7584. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7585. if(connectorIdInt != 0)
  7586. {
  7587. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7588. goto end;
  7589. }
  7590. strcpy(filename, ChargePointMaxProfile_JSON );
  7591. fptr1 = fopen(filename, "r");
  7592. if (!fptr1)
  7593. {
  7594. //file not exist
  7595. DEBUG_INFO("Unable to open the input file!!\n");
  7596. fptr1 = fopen(filename, "w+");
  7597. }
  7598. fclose(fptr1);
  7599. }
  7600. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7601. {
  7602. //printf("set chargingProfile 1-3\n");
  7603. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7604. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7605. {
  7606. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7607. goto end;
  7608. }
  7609. switch(connectorIdInt)
  7610. {
  7611. case 0:
  7612. strcpy(filename, TxDefaultProfile_0_JSON );
  7613. break;
  7614. case 1:
  7615. strcpy(filename, TxDefaultProfile_1_JSON );
  7616. break;
  7617. case 2:
  7618. strcpy(filename, TxDefaultProfile_2_JSON );
  7619. break;
  7620. default:
  7621. strcpy(filename, TxDefaultProfile_0_JSON );
  7622. break;
  7623. }
  7624. fptr1 = fopen(filename, "r");
  7625. if (!fptr1)
  7626. {
  7627. //file not exist
  7628. //DEBUG_INFO("Unable to open the input file!!\n");
  7629. fptr1 = fopen(filename, "w+");
  7630. }
  7631. fclose(fptr1);
  7632. }
  7633. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7634. {
  7635. //printf("set chargingProfile 1-4\n");
  7636. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7637. //check Transaction active
  7638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7639. {
  7640. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7641. {
  7642. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7643. {
  7644. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7645. {
  7646. meet = TRUE;
  7647. break;
  7648. }
  7649. }
  7650. }
  7651. }
  7652. for (int index = 0; index < CCS_QUANTITY; index++)
  7653. {
  7654. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7655. {
  7656. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7657. {
  7658. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7659. {
  7660. meet = TRUE;
  7661. break;
  7662. }
  7663. }
  7664. }
  7665. }
  7666. for (int index = 0; index < GB_QUANTITY; index++)
  7667. {
  7668. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7669. {
  7670. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7671. {
  7672. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7673. {
  7674. meet = TRUE;
  7675. break;
  7676. }
  7677. }
  7678. }
  7679. }
  7680. if(meet == FALSE)
  7681. {
  7682. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7683. goto end;
  7684. }
  7685. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7686. {
  7687. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7688. goto end;
  7689. }
  7690. switch(connectorIdInt)
  7691. {
  7692. case 0:
  7693. break;
  7694. case 1:
  7695. strcpy(filename, TxProfile_1_JSON);
  7696. break;
  7697. case 2:
  7698. strcpy(filename, TxProfile_2_JSON);
  7699. break;
  7700. default:
  7701. strcpy(filename, TxProfile_1_JSON);
  7702. break;
  7703. }
  7704. fptr1 = fopen(filename, "r");
  7705. if (!fptr1)
  7706. {
  7707. //file not exist
  7708. DEBUG_INFO("Unable to open the input file!!\n");
  7709. fptr1 = fopen(filename, "w+");
  7710. }
  7711. fclose(fptr1);
  7712. }
  7713. //**********************************Write to File********************************************************/
  7714. FILE *infile;
  7715. FILE *outfile;
  7716. // open file for writing
  7717. infile = fopen (filename, "r");
  7718. outfile = fopen (tempfile, "w");
  7719. int d =0;
  7720. d = fgetc(infile);
  7721. //DEBUG_INFO("d:%d\n",d);
  7722. rewind(infile);
  7723. //*检测到文件结束标识返回1,否则返回0。*/
  7724. if(d == EOF)
  7725. {
  7726. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7727. fprintf(outfile,"%s\n",payload);
  7728. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7729. fclose(infile);
  7730. fclose(outfile);
  7731. sprintf(rmFileCmd,"rm -f %s",filename);
  7732. system(rmFileCmd);
  7733. rename(tempfile, filename);
  7734. #if 0
  7735. resultRename = rename(tempfile, filename);
  7736. if(resultRename == 0)
  7737. {
  7738. DEBUG_INFO("File chargingProfile renamed successfully");
  7739. }
  7740. else
  7741. {
  7742. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7743. }
  7744. #endif
  7745. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7746. //system(rmFileCmd);
  7747. }
  7748. else
  7749. {
  7750. char buf[1000]={0};
  7751. int ChargingProfileAdded = FALSE;
  7752. while (fgets(buf, sizeof(buf), infile) != NULL)
  7753. {
  7754. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7755. //*************************tempconnectorIdInt*********************************/
  7756. loc = strstr(buf, "connectorId");
  7757. c = 0;
  7758. memset(sstr ,0, sizeof(sstr) );
  7759. while (loc[strlen("connectorId")+2+c] != ',')
  7760. {
  7761. sstr[c] = loc[strlen("connectorId")+2+c];
  7762. c++;
  7763. }
  7764. sstr[c] = '\0';
  7765. tempconnectorIdInt = atoi(sstr);
  7766. //*************************tempchargingProfileIdInt*********************************/
  7767. loc = strstr(buf, "chargingProfileId");
  7768. c = 0;
  7769. memset(sstr ,0, sizeof(sstr) );
  7770. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7771. {
  7772. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7773. c++;
  7774. }
  7775. sstr[c] = '\0';
  7776. tempchargingProfileIdInt = atoi(sstr);
  7777. //*************************tempstackLevelInt*********************************/
  7778. loc = strstr(buf, "stackLevel");
  7779. c = 0;
  7780. memset(sstr ,0, sizeof(sstr) );
  7781. while (loc[strlen("stackLevel")+2+c] != ',')
  7782. {
  7783. sstr[c] = loc[strlen("stackLevel")+2+c];
  7784. c++;
  7785. }
  7786. sstr[c] = '\0';
  7787. tempstackLevelInt = atoi(sstr);
  7788. //*************************tempchargingProfilePurposeStr*********************************/
  7789. loc = strstr(payload, "chargingProfilePurpose");
  7790. c = 0;
  7791. memset(sstr ,0, sizeof(sstr) );
  7792. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7793. {
  7794. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7795. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7796. c++;
  7797. }
  7798. sstr[c] = '\0';
  7799. strcpy(tempchargingProfilePurposeStr,sstr);
  7800. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7801. {
  7802. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7803. {
  7804. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7805. if(ChargingProfileAdded == FALSE)
  7806. {
  7807. fprintf(outfile,"%s\n",payload);
  7808. ChargingProfileAdded = TRUE;
  7809. }
  7810. }
  7811. else
  7812. {
  7813. if(tempstackLevelInt < stackLevelInt)
  7814. {
  7815. if(ChargingProfileAdded == FALSE)
  7816. {
  7817. fprintf(outfile,"%s\n",payload);
  7818. ChargingProfileAdded = TRUE;
  7819. fprintf(outfile,"%s\n",buf);
  7820. }
  7821. else
  7822. {
  7823. fprintf(outfile,"%s\n",buf);
  7824. }
  7825. }
  7826. else
  7827. {
  7828. if(ChargingProfileAdded == FALSE)
  7829. {
  7830. fprintf(outfile,"%s\n",buf);
  7831. fprintf(outfile,"%s\n",payload);
  7832. ChargingProfileAdded = TRUE;
  7833. }
  7834. else
  7835. {
  7836. fprintf(outfile,"%s\n",buf);
  7837. }
  7838. }
  7839. }
  7840. }
  7841. else
  7842. {
  7843. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7844. {
  7845. if(ChargingProfileAdded == FALSE)
  7846. {
  7847. fprintf(outfile,"%s\n",payload);
  7848. ChargingProfileAdded = TRUE;
  7849. fprintf(outfile,"%s\n",buf);
  7850. }
  7851. else
  7852. {
  7853. fprintf(outfile,"%s\n",buf);
  7854. }
  7855. }
  7856. else if(tempstackLevelInt < stackLevelInt)
  7857. {
  7858. if(ChargingProfileAdded == FALSE)
  7859. {
  7860. fprintf(outfile,"%s\n",payload);
  7861. ChargingProfileAdded = TRUE;
  7862. fprintf(outfile,"%s\n",buf);
  7863. }
  7864. else
  7865. {
  7866. fprintf(outfile,"%s\n",buf);
  7867. }
  7868. }
  7869. else
  7870. {
  7871. if(ChargingProfileAdded == FALSE)
  7872. {
  7873. fprintf(outfile,"%s\n",buf);
  7874. fprintf(outfile,"%s\n",payload);
  7875. ChargingProfileAdded = TRUE;
  7876. }
  7877. else
  7878. {
  7879. fprintf(outfile,"%s\n",buf);
  7880. }
  7881. }
  7882. }
  7883. } // end of while loop
  7884. fclose(infile);
  7885. fclose(outfile);
  7886. sprintf(rmFileCmd,"rm -f %s",filename);
  7887. system(rmFileCmd);
  7888. rename(tempfile, filename);
  7889. #if 0
  7890. resultRename = rename(tempfile, filename);
  7891. if(resultRename == 0)
  7892. {
  7893. DEBUG_INFO("File chargingProfile renamed successfully");
  7894. }
  7895. else
  7896. {
  7897. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7898. }
  7899. #endif
  7900. result = TRUE;
  7901. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7902. }
  7903. end:
  7904. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7905. return result;
  7906. return result;
  7907. }
  7908. int handleTriggerMessageRequest(char *uuid, char *payload)
  7909. {
  7910. mtrace();
  7911. int result = FAIL;
  7912. int connectorIdIsNULL = FALSE;
  7913. int connectorIdInt =0;
  7914. char sstr[40]={0};
  7915. char requestedMessagestr[40]={0};
  7916. char comfirmstr[20]={0};
  7917. int c = 0;
  7918. char *loc;
  7919. DEBUG_INFO("handleTriggerMessageRequest\n");
  7920. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7921. c = 0;
  7922. loc = strstr(payload, "requestedMessage");
  7923. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7924. {
  7925. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7926. c++;
  7927. }
  7928. sstr[c] = '\0';
  7929. strcpy(requestedMessagestr, sstr);
  7930. c = 0;
  7931. loc = strstr(payload, "connectorId");
  7932. if(loc == NULL)
  7933. {
  7934. connectorIdIsNULL = TRUE;
  7935. }
  7936. else
  7937. {
  7938. memset(sstr ,0, sizeof(sstr) );
  7939. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7940. {
  7941. sstr[c] = loc[strlen("connectorId")+2+c];
  7942. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7943. c++;
  7944. }
  7945. sstr[c] = '\0';
  7946. connectorIdInt = atoi(sstr);
  7947. }
  7948. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7949. {
  7950. //connectorIdInt = json_object_get_int(connectorId);
  7951. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7952. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7953. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7954. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7955. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7956. }
  7957. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7958. {
  7959. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7960. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7961. return TRUE;
  7962. }
  7963. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7964. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7965. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7966. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7967. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7968. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7969. {
  7970. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7971. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7972. return TRUE;
  7973. }
  7974. else
  7975. {
  7976. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7977. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7978. }
  7979. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7980. {
  7981. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  7982. {
  7983. FirmwareStatusNotificationStatus = 3;
  7984. }
  7985. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7986. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7987. }
  7988. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7989. {
  7990. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7991. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7992. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7993. }
  7994. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7995. {
  7996. sendBootNotificationRequest();
  7997. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7998. }
  7999. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8000. {
  8001. sendHeartbeatRequest(connectorIdInt);
  8002. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8003. }
  8004. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8005. {
  8006. if(connectorIdIsNULL == FALSE)
  8007. {
  8008. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8009. {
  8010. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8011. sendMeterValuesRequest(connectorIdInt -1);
  8012. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8013. }
  8014. }
  8015. else
  8016. {
  8017. for(int idx=0;idx< gunTotalNumber;idx++)
  8018. {
  8019. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8020. sendMeterValuesRequest(idx);
  8021. }
  8022. }
  8023. }
  8024. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8025. {
  8026. if(connectorIdIsNULL == FALSE)
  8027. {
  8028. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8029. {
  8030. sendStatusNotificationRequest(connectorIdInt -1);
  8031. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8032. }
  8033. }
  8034. else
  8035. {
  8036. for(int idx=0;idx< gunTotalNumber;idx++)
  8037. sendStatusNotificationRequest(idx);
  8038. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8039. }
  8040. }
  8041. return result;
  8042. }
  8043. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8044. {
  8045. mtrace();
  8046. int result = FAIL;
  8047. char sstr[6]={0};
  8048. int connectorIdInt =0;
  8049. char comfirmstr[20]={0};
  8050. int c = 0;
  8051. char *loc;
  8052. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8053. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8054. c = 0;
  8055. loc = strstr(payload, "connectorId");
  8056. memset(sstr ,0, sizeof(sstr) );
  8057. while (loc[strlen("connectorId")+2+c] != '}')
  8058. {
  8059. sstr[c] = loc[strlen("connectorId")+2+c];
  8060. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8061. c++;
  8062. }
  8063. sstr[c] = '\0';
  8064. connectorIdInt = atoi(sstr);
  8065. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8066. if(gunTotalNumber == 0)
  8067. {
  8068. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8069. goto end;
  8070. }
  8071. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8072. {
  8073. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8074. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8075. goto end;
  8076. }
  8077. else
  8078. {
  8079. //check Transaction active
  8080. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8081. {
  8082. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8083. {
  8084. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8085. {
  8086. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8087. }
  8088. }
  8089. for (int index = 0; index < CCS_QUANTITY; index++)
  8090. {
  8091. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8092. {
  8093. //stop Transaction
  8094. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8095. }
  8096. }
  8097. for (int index = 0; index < GB_QUANTITY; index++)
  8098. {
  8099. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8100. {
  8101. //stop Transaction
  8102. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8103. }
  8104. }
  8105. }
  8106. else
  8107. {
  8108. for (int index = 0; index < AC_QUANTITY; index++)
  8109. {
  8110. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8111. {
  8112. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8113. }
  8114. }
  8115. }// END FOR AC ELSE
  8116. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8117. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8118. result = TRUE;
  8119. return result;
  8120. }
  8121. end:
  8122. //json_object_put(obj); --- remove temporally
  8123. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8124. return result;
  8125. }
  8126. static char UpdateFirmwarepayloadData[300]={0};
  8127. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8128. {
  8129. mtrace();
  8130. int result = FAIL;
  8131. pthread_t t;
  8132. sendUpdateFirmwareConfirmation(uuid);
  8133. memset(UpdateFirmwarepayloadData, 0, 300);
  8134. strcpy(UpdateFirmwarepayloadData, payload);
  8135. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8136. ////pthread_join(t, NULL); //
  8137. //pthread_detach(t);
  8138. //sendUpdateFirmwareConfirmation(uuid);
  8139. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8140. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8141. return result;
  8142. }
  8143. void *UpdateFirmwareProcess(void *data)
  8144. {
  8145. pthread_detach(pthread_self());
  8146. mtrace();
  8147. int retriesInt =0, retryIntervalInt=0;
  8148. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8149. int port=0;
  8150. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8151. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8152. //char comfirmstr[20];
  8153. int isSuccess = 0;
  8154. char ftpbuf[200];
  8155. char temp[100];
  8156. char * pch;
  8157. int retriesISNULL=FALSE;
  8158. int retryInterval=FALSE;
  8159. int c = 0;
  8160. //int i = 0;
  8161. char *loc;
  8162. char sstr[300]={ 0 };
  8163. char str[300]={ 0 };
  8164. //char *str = (char*) data; // ? ?輸入資 ?
  8165. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8166. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8167. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8168. //***************location **************/
  8169. loc = strstr(str, "location");
  8170. memset(sstr ,0, sizeof(sstr) );
  8171. c = 0;
  8172. while (loc[3+strlen("location")+c] != '\"')
  8173. {
  8174. sstr[c] = loc[3+strlen("location")+c];
  8175. c++;
  8176. }
  8177. sstr[c] = '\0';
  8178. strcpy(locationstr, sstr);
  8179. //***************retries**************/
  8180. c = 0;
  8181. loc = strstr(str, "retries");
  8182. if(loc == NULL)
  8183. {
  8184. retriesISNULL=TRUE;
  8185. }
  8186. else
  8187. {
  8188. memset(sstr ,0, sizeof(sstr) );
  8189. while (loc[strlen("retries")+2+c] != ',')
  8190. {
  8191. sstr[c] = loc[strlen("retries")+2+c];
  8192. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8193. c++;
  8194. }
  8195. sstr[c] = '\0';
  8196. }
  8197. if(retriesISNULL == FALSE)
  8198. {
  8199. retriesInt = atoi(sstr);
  8200. }
  8201. //***************retrieveDate **************/
  8202. loc = strstr(str, "retrieveDate");
  8203. memset(sstr ,0, sizeof(sstr) );
  8204. c = 0;
  8205. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8206. {
  8207. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8208. c++;
  8209. }
  8210. sstr[c] = '\0';
  8211. strcpy(retrieveDatestr, sstr);
  8212. //***************retryInterval **************/
  8213. c = 0;
  8214. loc = strstr(str, "retryInterval");
  8215. memset(sstr ,0, sizeof(sstr) );
  8216. if(loc == NULL)
  8217. {
  8218. retryInterval=TRUE;
  8219. }
  8220. else
  8221. {
  8222. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8223. {
  8224. sstr[c] = loc[strlen("retryInterval")+2+c];
  8225. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8226. c++;
  8227. }
  8228. sstr[c] = '\0';
  8229. }
  8230. if(retryInterval==FALSE)
  8231. {
  8232. retryIntervalInt = atoi(sstr);
  8233. }
  8234. memset(ftppath, 0, sizeof(ftppath));
  8235. memset(path, 0, sizeof(path));
  8236. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8237. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8238. if(strncmp(locationstr,"http", 4) == 0)
  8239. {
  8240. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8241. protocol, host, path);
  8242. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8243. // protocol, user, password, host, path);
  8244. sprintf(ftppath,"/%s", path);
  8245. //DEBUG_INFO("protocol =%s\n",protocol);
  8246. //DEBUG_INFO("host =%s\n",host);
  8247. //DEBUG_INFO("path =%s\n",path);
  8248. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8249. int ftppathlen=strlen(ftppath);
  8250. int i=1;
  8251. char filenametemp[50];
  8252. while(i < ftppathlen)
  8253. {
  8254. int len=ftppathlen-i;
  8255. if(ftppath[len]== 47) // '/' ascll code: 47
  8256. {
  8257. DEBUG_INFO("compare '/' all right\n");
  8258. break;
  8259. }
  8260. i=i+1;
  8261. }
  8262. memset(filenametemp, 0, sizeof(filenametemp));
  8263. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8264. filenametemp[i+1] = 0;
  8265. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8266. do{
  8267. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8268. sleep(retryIntervalInt);
  8269. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8270. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8271. if(!isSuccess)
  8272. {
  8273. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8274. }
  8275. else
  8276. {
  8277. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8278. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8279. isUpdateRequest = TRUE;
  8280. }
  8281. }
  8282. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8283. {
  8284. memset(ftpbuf, 0, sizeof(ftpbuf));
  8285. memset(temp, 0, sizeof(temp));
  8286. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8287. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8288. int ftppathlen=strlen(ftpbuf);
  8289. int i=1;
  8290. char filenametemp[50];
  8291. while(i < ftppathlen)
  8292. {
  8293. int len=ftppathlen-i;
  8294. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8295. {
  8296. DEBUG_INFO(" compare '/' all right\n");
  8297. break;
  8298. }
  8299. i=i+1;
  8300. }
  8301. memset(filenametemp, 0, sizeof(filenametemp));
  8302. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8303. filenametemp[i+1] = 0;
  8304. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8305. pch=strchr(temp,'@');
  8306. if(pch==NULL)
  8307. {
  8308. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8309. protocol, host, &port, path);
  8310. strcpy(user,"anonymous");
  8311. strcpy(password,"");
  8312. }
  8313. else
  8314. {
  8315. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8316. protocol, user, password, host, &port, path);
  8317. }
  8318. sscanf(host,"%[^/]%s",host1, path1);
  8319. sprintf(ftppath,"%s", path1);
  8320. //DEBUG_INFO("protocol =%s\n",protocol);
  8321. //DEBUG_INFO("user =%s\n",user);
  8322. //DEBUG_INFO("password =%s\n",password);
  8323. //DEBUG_INFO("host1 =%s\n",host1);
  8324. //DEBUG_INFO("port =%d\n",port);
  8325. //DEBUG_INFO("path1 =%s\n",path1);
  8326. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8327. //ftpFile(host, user, password, port, ftppath, fname);
  8328. //download firmware pthred
  8329. if(port == 0)
  8330. {
  8331. port = 21;
  8332. }
  8333. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8334. do{
  8335. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8336. sleep(retryIntervalInt);
  8337. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8338. if(!isSuccess)
  8339. {
  8340. //BulldogUtil.sleepMs(interval*1000);
  8341. DEBUG_INFO("Update firmware request and download file fail.\n");
  8342. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8343. }
  8344. else
  8345. {
  8346. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8347. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8348. isUpdateRequest = TRUE;
  8349. }
  8350. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8351. }
  8352. else
  8353. {
  8354. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8355. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8356. }
  8357. pthread_exit(NULL);
  8358. }
  8359. //==========================================
  8360. // Handle server response routine
  8361. //==========================================
  8362. void handleAuthorizeResponse(char *payload, int gun_index)
  8363. {
  8364. mtrace();
  8365. char expiryDatestr[30]={0};
  8366. char parentIdTagstr[20]={0};
  8367. char statusstr[20]={0};
  8368. char expiryDatestrtemp[30]={0};
  8369. char parentIdTagstrtemp[20]={0};
  8370. char IdTagstrtemp[20]={0};
  8371. char statusstrtemp[20]={0};
  8372. int expiryDateISNULL=FALSE;
  8373. int parentIdTagISNULL=FALSE;
  8374. char sstr[160]={ 0 };
  8375. char* filename = AuthorizationCache_JSON;
  8376. char tempfile[] = "../Storage/OCPP/temp.json";
  8377. int c = 0;
  8378. char *loc;
  8379. int resultRename=0;
  8380. int responseIdTagInfoAsZero= 0;
  8381. char rmFileCmd[50]={0};
  8382. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8383. //***********expiryDate*************/
  8384. loc = strstr(payload, "expiryDate");
  8385. memset(sstr ,0, sizeof(sstr) );
  8386. c = 0;
  8387. if(loc == NULL)
  8388. {
  8389. expiryDateISNULL = TRUE;
  8390. }
  8391. else
  8392. {
  8393. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8394. {
  8395. sstr[c] = loc[3+strlen("expiryDate")+c];
  8396. c++;
  8397. }
  8398. sstr[c] = '\0';
  8399. strcpy(expiryDatestr, sstr);
  8400. }
  8401. //***********parentIdTag*************/
  8402. loc = strstr(payload, "parentIdTag");
  8403. memset(sstr ,0, sizeof(sstr) );
  8404. c = 0;
  8405. if(loc == NULL)
  8406. {
  8407. parentIdTagISNULL = TRUE;
  8408. }
  8409. else
  8410. {
  8411. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8412. {
  8413. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8414. c++;
  8415. }
  8416. sstr[c] = '\0';
  8417. strcpy(parentIdTagstr, sstr);
  8418. }
  8419. //***********status*************/
  8420. loc = strstr(payload, "status");
  8421. memset(sstr ,0, sizeof(sstr) );
  8422. c = 0;
  8423. while (loc[3+strlen("status")+c] != '\"')
  8424. {
  8425. sstr[c] = loc[3+strlen("status")+c];
  8426. c++;
  8427. }
  8428. sstr[c] = '\0';
  8429. strcpy(statusstr, sstr);
  8430. if(expiryDateISNULL == FALSE)
  8431. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8432. if(parentIdTagISNULL == FALSE)
  8433. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8434. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8435. //Update idTag information to authorization cache if supproted
  8436. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8437. {
  8438. if((access(filename,F_OK))!=-1)
  8439. {
  8440. printf("AuthorizationCache exist.\n");
  8441. }
  8442. else
  8443. {
  8444. printf("AuthorizationCache not exist\n");
  8445. FILE *log = fopen(filename, "w+");
  8446. if(log == NULL)
  8447. {
  8448. printf("log is NULL\n");
  8449. goto out;
  8450. }
  8451. else
  8452. {
  8453. fclose(log);
  8454. }
  8455. }
  8456. FILE *infile;
  8457. FILE *outfile;
  8458. // open file for writing
  8459. infile = fopen (filename, "r");
  8460. outfile = fopen (tempfile, "w");
  8461. //*检测到文件结束标识返回1,否则返回0。*/
  8462. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8463. int c;
  8464. c = fgetc(infile);
  8465. //DEBUG_INFO("c:%d\n",c);
  8466. rewind(infile);
  8467. if(c == EOF)
  8468. {
  8469. DEBUG_INFO("Orignal File is NULL\n");
  8470. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8471. {
  8472. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8473. }
  8474. else
  8475. {
  8476. strcpy(expiryDatestrtemp, "");
  8477. }
  8478. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8479. {
  8480. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8481. }
  8482. else
  8483. {
  8484. //write Authorize IdTag
  8485. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8486. }
  8487. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8488. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8489. fclose(infile);
  8490. fclose(outfile);
  8491. sprintf(rmFileCmd,"rm -f %s",filename);
  8492. system(rmFileCmd);
  8493. resultRename = rename(tempfile, filename);
  8494. if(resultRename == 0)
  8495. {
  8496. printf("File renamed successfully");
  8497. }
  8498. else
  8499. {
  8500. printf("Error: unable to rename the file");
  8501. }
  8502. }
  8503. else
  8504. {
  8505. char buf[160]={0};
  8506. while (fgets(buf, sizeof(buf), infile) != NULL)
  8507. {
  8508. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8509. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8510. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8511. memset(statusstr, 0, sizeof(statusstrtemp));
  8512. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8513. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8514. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8515. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8516. //------------------IdTag-----------------------
  8517. loc = strstr(buf, "idTag");
  8518. memset(sstr ,0, sizeof(sstr) );
  8519. c = 0;
  8520. while (loc[3+strlen("idTag")+c] != '\"')
  8521. {
  8522. sstr[c] = loc[3+strlen("idTag")+c];
  8523. c++;
  8524. }
  8525. sstr[c] = '\0';
  8526. strcpy(IdTagstrtemp,sstr);
  8527. //*********************expiryDate***************/
  8528. loc = strstr(buf, "expiryDate");
  8529. memset(sstr ,0, sizeof(sstr) );
  8530. c = 0;
  8531. while (loc[3+strlen("expiryDate")+c] != '\"')
  8532. {
  8533. sstr[c] = loc[3+strlen("expiryDate")+c];
  8534. c++;
  8535. }
  8536. sstr[c] = '\0';
  8537. strcpy(expiryDatestr,sstr);
  8538. //*********************parentIdTag***************/
  8539. loc = strstr(buf, "parentIdTag");
  8540. memset(sstr ,0, sizeof(sstr) );
  8541. c = 0;
  8542. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8543. {
  8544. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8545. c++;
  8546. }
  8547. sstr[c] = '\0';
  8548. strcpy(parentIdTagstr,sstr);
  8549. //*********************status***************/
  8550. loc = strstr(buf, "status");
  8551. memset(sstr ,0, sizeof(sstr) );
  8552. c = 0;
  8553. while (loc[3+strlen("status")+c] != '\"')
  8554. {
  8555. sstr[c] = loc[3+strlen("status")+c];
  8556. c++;
  8557. }
  8558. sstr[c] = '\0';
  8559. strcpy(statusstr,sstr);
  8560. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8561. {
  8562. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8563. responseIdTagInfoAsZero = 1;
  8564. }
  8565. else
  8566. {
  8567. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8568. }
  8569. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8570. {
  8571. //modify item
  8572. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8573. {
  8574. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8575. }
  8576. else
  8577. {
  8578. strcpy(expiryDatestrtemp, "");
  8579. }
  8580. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8581. {
  8582. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8583. }
  8584. else
  8585. {
  8586. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8587. }
  8588. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8589. }
  8590. else
  8591. {
  8592. //wrie original item
  8593. strcpy(expiryDatestrtemp, expiryDatestr);
  8594. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8595. strcpy(statusstrtemp, statusstr);
  8596. }
  8597. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8598. }
  8599. fclose(infile);
  8600. fclose(outfile);
  8601. sprintf(rmFileCmd,"rm -f %s",filename);
  8602. system(rmFileCmd);
  8603. resultRename = rename(tempfile, filename);
  8604. if(resultRename == 0)
  8605. {
  8606. DEBUG_INFO("File renamed successfully");
  8607. }
  8608. else
  8609. {
  8610. DEBUG_INFO("Error: unable to rename the file");
  8611. }
  8612. }
  8613. }
  8614. out:
  8615. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8616. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8617. authorizeRetryTimes = 0;
  8618. }
  8619. void handleBootNotificationResponse(char *payload, int gun_index)
  8620. {
  8621. mtrace();
  8622. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8623. char statusStr[12]={0};
  8624. char currentTimeStr[30]={0};
  8625. char *loc;
  8626. int intervalInt = 0;
  8627. int c = 0;
  8628. //double diff_t;
  8629. struct tm tp;
  8630. char buf[28]={0};
  8631. char timebuf[50]={0};
  8632. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8633. //*** interval ****/
  8634. c = 0;
  8635. loc = strstr(payload, "interval");
  8636. //printf("loc=%s\n",loc);
  8637. memset(sstr ,0, sizeof(sstr) );
  8638. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8639. {
  8640. sstr[c] = loc[strlen("interval")+2+c];
  8641. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8642. c++;
  8643. }
  8644. sstr[c] = '\0';
  8645. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8646. intervalInt = atoi(sstr);
  8647. //***status ****/
  8648. loc = strstr(payload, "status");
  8649. memset(sstr ,0, sizeof(sstr) );
  8650. c = 0;
  8651. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8652. {
  8653. sstr[c] = loc[3+strlen("status")+c];
  8654. c++;
  8655. }
  8656. sstr[c] = '\0';
  8657. strcpy(statusStr, sstr);
  8658. //***currentTime ****/
  8659. loc = strstr(payload, "currentTime");
  8660. //printf("loc=%s\n",loc);
  8661. memset(sstr ,0, sizeof(sstr) );
  8662. c = 0;
  8663. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8664. {
  8665. sstr[c] = loc[3+strlen("currentTime")+c];
  8666. c++;
  8667. }
  8668. sstr[c] = '\0';
  8669. strcpy(currentTimeStr, sstr);
  8670. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8671. HeartBeatWaitTime = BootNotificationInterval;
  8672. clientTime.Heartbeat=time((time_t*)NULL);
  8673. //write back to ShmOCPP16Data->BootNotification
  8674. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8675. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8676. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8677. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8678. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8679. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8680. {
  8681. server_sign = TRUE;
  8682. server_pending =FALSE;
  8683. }
  8684. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8685. {
  8686. server_pending = TRUE;
  8687. }
  8688. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8689. tp.tm_isdst = -1;
  8690. //time_t utc = mktime(&tp);
  8691. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8692. memset(timebuf, 0, sizeof timebuf);
  8693. sprintf(timebuf,"date -s '%s'",buf);
  8694. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8695. system(timebuf);
  8696. //==============================================
  8697. // RTC sync
  8698. //==============================================
  8699. system("/sbin/hwclock -w --systohc");
  8700. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8701. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8702. }
  8703. void handleDataTransferResponse(char *payload, int gun_index)
  8704. {
  8705. char sstr[160]={0};//sstr[200]={ 0 };
  8706. int c = 0;
  8707. char *loc;
  8708. DEBUG_INFO("handleDataTransferResponse ...\n");
  8709. loc = strstr(payload, "status");
  8710. printf("loc=%s\n",loc);
  8711. c = 0;
  8712. while (loc[3+strlen("status")+c] != '\"')
  8713. {
  8714. sstr[c] = loc[3+strlen("status")+c];
  8715. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8716. c++;
  8717. }
  8718. sstr[c] = '\0';
  8719. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8720. }
  8721. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8722. {
  8723. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8724. //struct json_object *obj;
  8725. // obj = json_tokener_parse(payload);
  8726. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8727. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8728. //No fields are defined.
  8729. }
  8730. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8731. {
  8732. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8733. //struct json_object *obj;
  8734. // obj = json_tokener_parse(payload);
  8735. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8736. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8737. //No fields are defined.
  8738. }
  8739. void handleHeartbeatResponse(char *payload, int gun_index)
  8740. {
  8741. mtrace();
  8742. //double diff_t;
  8743. struct tm tp;
  8744. char buf[28]={0};
  8745. char timebuf[50]={0};
  8746. char sstr[30]={ 0 };
  8747. int c = 0;
  8748. char *loc;
  8749. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8750. if((HeartBeatCount%360) == 0)
  8751. {
  8752. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8753. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8754. }
  8755. HeartBeatCount = HeartBeatCount + 1;
  8756. c = 0;
  8757. loc = strstr(payload, "currentTime");
  8758. memset(sstr ,0, sizeof(sstr) );
  8759. while (loc[3+strlen("currentTime")+c] != '\"')
  8760. {
  8761. sstr[c] = loc[3+strlen("currentTime")+c];
  8762. c++;
  8763. }
  8764. sstr[c] = '\0';
  8765. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8766. // #ifdef SystemLogMessage
  8767. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8768. // #endif
  8769. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8770. tp.tm_isdst = -1;
  8771. //time_t utc = mktime(&tp);
  8772. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8773. memset(timebuf, 0, sizeof timebuf);
  8774. sprintf(timebuf,"date -s '%s'",buf);
  8775. system(timebuf);
  8776. //==============================================
  8777. // RTC sync
  8778. //==============================================
  8779. system("/sbin/hwclock -w --systohc");
  8780. if(FirstHeartBeat == 0)
  8781. {
  8782. FirstHeartBeat = 1;
  8783. }
  8784. HeartBeatWithNOResponse = 0;
  8785. }
  8786. void handleMeterValuesResponse(char *payload, int gun_index)
  8787. {
  8788. mtrace();
  8789. //struct json_object *obj;
  8790. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8791. //No fields are defined.
  8792. }
  8793. void handleStartTransactionResponse(char *payload, int gun_index)
  8794. {
  8795. mtrace();
  8796. char sstr[28]={ 0 };
  8797. int c = 0;
  8798. char *loc;
  8799. int transactionIdInt = 0;
  8800. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8801. DEBUG_INFO("handleStartTransactionResponse\n");
  8802. //****************expiryDate********************/
  8803. loc = strstr(payload, "expiryDate");
  8804. if(loc == NULL)
  8805. {
  8806. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8807. }
  8808. else
  8809. {
  8810. c = 0;
  8811. memset(sstr ,0, sizeof(sstr) );
  8812. while (loc[3+strlen("expiryDate")+c] != '\"')
  8813. {
  8814. sstr[c] = loc[3+strlen("expiryDate")+c];
  8815. c++;
  8816. }
  8817. sstr[c] = '\0';
  8818. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8819. }
  8820. //****************parentIdTag********************/
  8821. loc = strstr(payload, "parentIdTag");
  8822. if(loc == NULL)
  8823. {
  8824. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8825. }
  8826. else
  8827. {
  8828. c = 0;
  8829. memset(sstr ,0, sizeof(sstr) );
  8830. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8831. {
  8832. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8833. c++;
  8834. }
  8835. sstr[c] = '\0';
  8836. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8837. }
  8838. //****************status********************/
  8839. loc = strstr(payload, "status");
  8840. if(loc == NULL)
  8841. {
  8842. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8843. }
  8844. else
  8845. {
  8846. c = 0;
  8847. memset(sstr ,0, sizeof(sstr) );
  8848. while (loc[3+strlen("status")+c] != '\"')
  8849. {
  8850. sstr[c] = loc[3+strlen("status")+c];
  8851. c++;
  8852. }
  8853. sstr[c] = '\0';
  8854. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8855. }
  8856. //****************transactionId********************/
  8857. c=0;
  8858. loc = strstr(payload, "transactionId");
  8859. memset(sstr ,0, sizeof(sstr) );
  8860. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8861. {
  8862. sstr[c] = loc[strlen("transactionId")+2+c];
  8863. c++;
  8864. }
  8865. sstr[c] = '\0';
  8866. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8867. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8868. TransactionId[gun_index] = transactionIdInt;
  8869. DEBUG_INFO("gun_index: %d\n", gun_index);
  8870. DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  8871. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8872. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8873. #ifdef SystemLogMessage
  8874. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8875. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8876. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8877. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8878. #endif
  8879. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8880. {
  8881. //add Charging Record
  8882. SettingChargingRecord(gun_index, transactionIdInt);
  8883. }
  8884. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8885. }
  8886. void handleStatusNotificationResponse(char *payload, int gun_index)
  8887. {
  8888. mtrace();
  8889. printf("handleStatusNotificationResponse\n");
  8890. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8891. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8892. }
  8893. void handleStopTransactionnResponse(char *payload, int gun_index)
  8894. {
  8895. mtrace();
  8896. char sstr[30]={ 0 };
  8897. int c = 0;
  8898. char *loc;
  8899. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8900. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8901. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8902. loc = strstr(payload, "idTagInfo");
  8903. //***********************idTagInfo************************/
  8904. if(loc != NULL)
  8905. {
  8906. //***********************expiryDate************************/
  8907. loc = strstr(payload, "expiryDate");
  8908. if(loc != NULL)
  8909. {
  8910. memset(sstr ,0, sizeof(sstr) );
  8911. c = 0;
  8912. while (loc[3+strlen("expiryDate")+c] != '\"')
  8913. {
  8914. sstr[c] = loc[3+strlen("expiryDate")+c];
  8915. c++;
  8916. }
  8917. sstr[c] = '\0';
  8918. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8919. }
  8920. //***********************parentIdTag************************/
  8921. loc = strstr(payload, "parentIdTag");
  8922. if(loc != NULL)
  8923. {
  8924. memset(sstr ,0, sizeof(sstr) );
  8925. c = 0;
  8926. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8927. {
  8928. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8929. c++;
  8930. }
  8931. sstr[c] = '\0';
  8932. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8933. }
  8934. //***********************status************************/
  8935. loc = strstr(payload, "status");
  8936. memset(sstr ,0, sizeof(sstr) );
  8937. c = 0;
  8938. while (loc[3+strlen("status")+c] != '\"')
  8939. {
  8940. sstr[c] = loc[3+strlen("status")+c];
  8941. c++;
  8942. }
  8943. sstr[c] = '\0';
  8944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8945. }
  8946. #ifdef SystemLogMessage
  8947. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8948. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8949. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8950. #endif
  8951. }
  8952. //==========================================
  8953. // Handle Error routine
  8954. //==========================================
  8955. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8956. {
  8957. mtrace();
  8958. #ifdef SystemLogMessage
  8959. DEBUG_INFO("errorCode: %s\n", errorCode);
  8960. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8961. DEBUG_INFO("errorDetails: %s\n", payload);
  8962. #endif
  8963. }
  8964. //===============================================
  8965. // Common routine
  8966. //===============================================
  8967. int initialConfigurationTable(void)
  8968. {
  8969. FILE *fp;
  8970. FILE *outfile;
  8971. char str[200]={0};
  8972. char sstr[100]={0};
  8973. int c = 0;
  8974. char *loc;
  8975. printf("initialConfigurationTable \n");
  8976. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8977. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  8978. {
  8979. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  8980. if(outfile == NULL) {
  8981. DEBUG_INFO("Error opening file");
  8982. return FALSE;
  8983. }
  8984. /*Core Profile*/
  8985. //AllowOfflineTxForUnknownId
  8986. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8987. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  8991. //AuthorizationCacheEnabled
  8992. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  8996. //AuthorizeRemoteTxRequests
  8997. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "TRUE");
  9001. //BlinkRepeat
  9002. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9006. //ClockAlignedDataInterval
  9007. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9011. //ConnectionTimeOut
  9012. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9016. //GetConfigurationMaxKeys
  9017. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9021. // HeartbeatInterval
  9022. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9026. // LightIntensity
  9027. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9031. // LocalAuthorizeOffline
  9032. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9036. // LocalPreAuthorize
  9037. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9041. // MaxEnergyOnInvalidId
  9042. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9045. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9047. // MeterValuesAlignedData
  9048. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9052. // MeterValuesAlignedDataMaxLength
  9053. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9057. // MeterValuesSampledData
  9058. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9062. // MeterValuesSampledDataMaxLength
  9063. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9067. // MeterValueSampleInterval
  9068. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9072. // MinimumStatusDuration
  9073. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9077. // NumberOfConnectors
  9078. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9080. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9081. {
  9082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9083. }
  9084. else
  9085. {
  9086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9087. }
  9088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9089. // ResetRetries
  9090. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9094. // ConnectorPhaseRotation
  9095. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9099. // ConnectorPhaseRotationMaxLength
  9100. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9104. // StopTransactionOnEVSideDisconnect
  9105. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9109. // StopTransactionOnInvalidId
  9110. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9114. // StopTxnAlignedData
  9115. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9119. // StopTxnAlignedDataMaxLength
  9120. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9124. // StopTxnSampledData
  9125. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9129. // StopTxnSampledDataMaxLength
  9130. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9132. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9133. {
  9134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9135. }
  9136. else
  9137. {
  9138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9139. }
  9140. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9142. // SupportedFeatureProfiles
  9143. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9147. // SupportedFeatureProfilesMaxLength
  9148. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9152. // TransactionMessageAttempts
  9153. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9156. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9158. // TransactionMessageRetryInterval
  9159. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9162. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9164. // UnlockConnectorOnEVSideDisconnect
  9165. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9169. // WebSocketPingInterval
  9170. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9174. //* Local Auth List Management Profile*/
  9175. #if 0
  9176. //For OCTT Test Case
  9177. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9180. #endif
  9181. #if 1
  9182. //LocalAuthListEnabled
  9183. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9187. #endif
  9188. //LocalAuthListMaxLength
  9189. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9193. //SendLocalListMaxLength
  9194. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9198. //ReserveConnectorZeroSupported
  9199. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9203. //* Smart Charging Profile */
  9204. //ChargeProfileMaxStackLevel
  9205. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9209. // ChargingScheduleAllowedChargingRateUnit
  9210. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9214. // ChargingScheduleMaxPeriods
  9215. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9219. // ConnectorSwitch3to1PhaseSupported
  9220. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9224. // MaxChargingProfilesInstalled
  9225. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9229. fclose(outfile);
  9230. }
  9231. else
  9232. {
  9233. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9234. char keystr[60]={0};
  9235. char readonlystr[10]={0};
  9236. char valuestr[100]={0};
  9237. fp = fopen("../Storage/OCPP/OCPPConfiguration" , "r");
  9238. if(fp == NULL) {
  9239. DEBUG_INFO("Error opening file");
  9240. return FALSE;
  9241. }
  9242. while( fgets (str, sizeof(str), fp)!=NULL )
  9243. {
  9244. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9245. //*************************key*********************************/
  9246. loc = strstr(str, "key");
  9247. c = 0;
  9248. memset(sstr ,0, sizeof(sstr) );
  9249. while (loc[strlen("key")+3+c] != '\"')
  9250. {
  9251. sstr[c] = loc[strlen("key")+3+c];
  9252. c++;
  9253. }
  9254. sstr[c] = '\0';
  9255. strcpy(keystr,sstr);
  9256. //*************************readonly*********************************/
  9257. loc = strstr(str, "readonly");
  9258. c = 0;
  9259. memset(sstr ,0, sizeof(sstr) );
  9260. while (loc[strlen("readonly")+2+c] != ',')
  9261. {
  9262. sstr[c] = loc[strlen("readonly")+2+c];
  9263. c++;
  9264. }
  9265. sstr[c] = '\0';
  9266. strcpy(readonlystr,sstr);
  9267. //*************************value*********************************/
  9268. loc = strstr(str, "value");
  9269. c = 0;
  9270. memset(sstr ,0, sizeof(sstr) );
  9271. while (loc[strlen("value")+3+c] != '\"')
  9272. {
  9273. sstr[c] = loc[strlen("value")+3+c];
  9274. c++;
  9275. }
  9276. sstr[c] = '\0';
  9277. strcpy(valuestr,sstr);
  9278. // DEBUG_INFO("keystr=%s\n",keystr);
  9279. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9280. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9281. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9282. {
  9283. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9284. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9286. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9287. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9288. }
  9289. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9290. {
  9291. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9292. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9294. }
  9295. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9296. {
  9297. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9299. }
  9300. if(strcmp(keystr, "BlinkRepeat") == 0)
  9301. {
  9302. //Charger.BlinkRepeat = Integer.parseInt(value);
  9303. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9305. }
  9306. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9307. {
  9308. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9310. }
  9311. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9312. {
  9313. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9315. }
  9316. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9317. {
  9318. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9320. }
  9321. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9322. {
  9323. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9325. HeartBeatWaitTime = atoi(valuestr);
  9326. }
  9327. if(strcmp(keystr, "LightIntensity") == 0)
  9328. {
  9329. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9330. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9331. }
  9332. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9333. {
  9334. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9336. }
  9337. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9338. {
  9339. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9341. }
  9342. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9343. {
  9344. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9346. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9347. }
  9348. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9349. {
  9350. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9352. }
  9353. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9354. {
  9355. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9357. }
  9358. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9359. {
  9360. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9362. }
  9363. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9364. {
  9365. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9367. }
  9368. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9369. {
  9370. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9372. }
  9373. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9374. {
  9375. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9377. }
  9378. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9379. {
  9380. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9382. }
  9383. if(strcmp(keystr, "ResetRetries") == 0)
  9384. {
  9385. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9387. }
  9388. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9389. {
  9390. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9392. }
  9393. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9394. {
  9395. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9397. }
  9398. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  9399. {
  9400. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  9402. }
  9403. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  9404. {
  9405. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  9407. }
  9408. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  9409. {
  9410. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  9412. }
  9413. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  9414. {
  9415. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9417. }
  9418. if(strcmp(keystr, "StopTxnSampledData") == 0)
  9419. {
  9420. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  9422. }
  9423. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  9424. {
  9425. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9427. }
  9428. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  9429. {
  9430. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  9432. }
  9433. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  9434. {
  9435. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  9437. }
  9438. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  9439. {
  9440. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  9442. TransactionMessageAttemptsValue = atoi(valuestr);
  9443. }
  9444. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  9445. {
  9446. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  9448. TransactionMessageRetryIntervalValue = atoi(valuestr);
  9449. }
  9450. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  9451. {
  9452. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  9454. }
  9455. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  9456. {
  9457. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  9459. }
  9460. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  9461. {
  9462. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  9464. }
  9465. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  9466. {
  9467. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  9469. }
  9470. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  9471. {
  9472. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  9474. }
  9475. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  9476. {
  9477. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  9479. }
  9480. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  9481. {
  9482. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  9484. }
  9485. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  9486. {
  9487. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  9489. }
  9490. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  9491. {
  9492. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  9494. }
  9495. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  9496. {
  9497. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  9499. }
  9500. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  9501. {
  9502. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  9504. }
  9505. }
  9506. fclose(fp);
  9507. }
  9508. return 0;
  9509. }
  9510. void StoreConfigurationTable(void)
  9511. {
  9512. FILE *outfile;
  9513. outfile = fopen("../Storage/OCPP/OCPPConfiguration" , "w+");
  9514. if(outfile == NULL)
  9515. {
  9516. DEBUG_INFO("Error opening file");
  9517. return ;
  9518. }
  9519. /*Core Profile*/
  9520. //AllowOfflineTxForUnknownId
  9521. /*
  9522. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9523. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9526. */
  9527. //DEBUG_INFO("data=%s\n",data);
  9528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9529. //AuthorizationCacheEnabled
  9530. /*
  9531. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9534. */
  9535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9536. //AuthorizeRemoteTxRequests
  9537. /*
  9538. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9541. */
  9542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9543. //BlinkRepeat
  9544. /*
  9545. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9548. */
  9549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9550. //ClockAlignedDataInterval
  9551. /*
  9552. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9555. */
  9556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9557. //ConnectionTimeOut
  9558. /*
  9559. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9562. */
  9563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9564. //GetConfigurationMaxKeys
  9565. /*
  9566. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9569. */
  9570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9571. // HeartbeatInterval
  9572. /*
  9573. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9576. */
  9577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9578. // LightIntensity
  9579. /*
  9580. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9583. */
  9584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9585. // LocalAuthorizeOffline
  9586. /*
  9587. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9590. */
  9591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9592. // LocalPreAuthorize
  9593. /*
  9594. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9597. */
  9598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9599. // MaxEnergyOnInvalidId
  9600. /*
  9601. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9604. */
  9605. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9607. // MeterValuesAlignedData
  9608. /*
  9609. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9612. */
  9613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9614. // MeterValuesAlignedDataMaxLength
  9615. /*
  9616. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9619. */
  9620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9621. // MeterValuesSampledData
  9622. /*
  9623. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9626. */
  9627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9628. // MeterValuesSampledDataMaxLength
  9629. /*
  9630. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9633. */
  9634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9635. // MeterValueSampleInterval
  9636. /*
  9637. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9640. */
  9641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9642. // MinimumStatusDuration
  9643. /*
  9644. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9647. */
  9648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9649. // NumberOfConnectors
  9650. /*
  9651. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9653. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9654. {
  9655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9656. }
  9657. else
  9658. {
  9659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9660. }
  9661. */
  9662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9663. // ResetRetries
  9664. /*
  9665. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9668. */
  9669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9670. // ConnectorPhaseRotation
  9671. /*
  9672. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9675. */
  9676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9677. // ConnectorPhaseRotationMaxLength
  9678. /*
  9679. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9682. */
  9683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9684. // StopTransactionOnEVSideDisconnect
  9685. /*
  9686. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9689. */
  9690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9691. // StopTransactionOnInvalidId
  9692. /*
  9693. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9696. */
  9697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9698. // StopTxnAlignedData
  9699. /*
  9700. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9703. */
  9704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9705. // StopTxnAlignedDataMaxLength
  9706. /*
  9707. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9710. */
  9711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9712. // StopTxnSampledData
  9713. /*
  9714. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9717. */
  9718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9719. // StopTxnSampledDataMaxLength
  9720. /*
  9721. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9724. */
  9725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9726. // SupportedFeatureProfiles
  9727. /*
  9728. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9731. */
  9732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  9733. // SupportedFeatureProfilesMaxLength
  9734. /*
  9735. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9738. */
  9739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  9740. // TransactionMessageAttempts
  9741. /*
  9742. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9745. */
  9746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9747. // TransactionMessageRetryInterval
  9748. /*
  9749. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9752. */
  9753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9754. // UnlockConnectorOnEVSideDisconnect
  9755. /*
  9756. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9759. */
  9760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  9761. // WebSocketPingInterval
  9762. /*
  9763. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9766. */
  9767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  9768. //* Local Auth List Management Profile*/
  9769. //LocalAuthListEnabled
  9770. /*
  9771. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9774. */
  9775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9776. //LocalAuthListMaxLength
  9777. /*
  9778. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9781. */
  9782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  9783. //SendLocalListMaxLength
  9784. /*
  9785. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9788. */
  9789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  9790. //ReserveConnectorZeroSupported
  9791. /*
  9792. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9795. */
  9796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9797. //* Smart Charging Profile */
  9798. //ChargeProfileMaxStackLevel
  9799. /*
  9800. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9803. */
  9804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9805. // ChargingScheduleAllowedChargingRateUnit
  9806. /*
  9807. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9810. */
  9811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9812. // ChargingScheduleMaxPeriods
  9813. /*
  9814. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9817. */
  9818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9819. // ConnectorSwitch3to1PhaseSupported
  9820. /*
  9821. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9824. */
  9825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9826. // MaxChargingProfilesInstalled
  9827. /*
  9828. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9831. */
  9832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9833. fclose(outfile);
  9834. }
  9835. void getKeyValue(char *keyReq)
  9836. {
  9837. int isEmpty = FALSE;
  9838. int isKnowKey = FALSE;
  9839. //int unKnowIndex = 0;
  9840. DEBUG_INFO("getKeyValue \n");
  9841. DEBUG_INFO("keyReq=%s \n",keyReq);
  9842. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9843. isEmpty = TRUE;
  9844. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9845. {
  9846. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  9847. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9850. {
  9851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9852. }
  9853. else
  9854. {
  9855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9856. }
  9857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9858. isKnowKey = TRUE;
  9859. }
  9860. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9861. {
  9862. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9865. {
  9866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9867. }
  9868. else
  9869. {
  9870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9871. }
  9872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9873. isKnowKey = TRUE;
  9874. }
  9875. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9876. {
  9877. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9880. {
  9881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9882. }
  9883. else
  9884. {
  9885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9886. }
  9887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9888. isKnowKey = TRUE;
  9889. }
  9890. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9891. {
  9892. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9895. {
  9896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9897. }
  9898. else
  9899. {
  9900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9901. }
  9902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9903. isKnowKey = TRUE;
  9904. }
  9905. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9906. {
  9907. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9910. {
  9911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9912. }
  9913. else
  9914. {
  9915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9916. }
  9917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9918. isKnowKey = TRUE;
  9919. }
  9920. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9921. {
  9922. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9925. {
  9926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9927. }
  9928. else
  9929. {
  9930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9931. }
  9932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9933. isKnowKey = TRUE;
  9934. }
  9935. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9936. {
  9937. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9940. {
  9941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9942. }
  9943. else
  9944. {
  9945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9946. }
  9947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9948. isKnowKey = TRUE;
  9949. }
  9950. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9951. {
  9952. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9955. {
  9956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9957. }
  9958. else
  9959. {
  9960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9961. }
  9962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9963. isKnowKey = TRUE;
  9964. }
  9965. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9966. {
  9967. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9970. {
  9971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9972. }
  9973. else
  9974. {
  9975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9976. }
  9977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9978. isKnowKey = TRUE;
  9979. }
  9980. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9981. {
  9982. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9985. {
  9986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9987. }
  9988. else
  9989. {
  9990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9991. }
  9992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9993. isKnowKey = TRUE;
  9994. }
  9995. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9996. {
  9997. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10000. {
  10001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10002. }
  10003. else
  10004. {
  10005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10006. }
  10007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10008. isKnowKey = TRUE;
  10009. }
  10010. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10011. {
  10012. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10015. {
  10016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10017. }
  10018. else
  10019. {
  10020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10021. }
  10022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10023. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10024. isKnowKey = TRUE;
  10025. }
  10026. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10027. {
  10028. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10030. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10031. {
  10032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10033. }
  10034. else
  10035. {
  10036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10037. }
  10038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10039. isKnowKey = TRUE;
  10040. }
  10041. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10042. {
  10043. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10046. {
  10047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10048. }
  10049. else
  10050. {
  10051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10052. }
  10053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10054. isKnowKey = TRUE;
  10055. }
  10056. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10057. {
  10058. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10061. {
  10062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10063. }
  10064. else
  10065. {
  10066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10067. }
  10068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10069. isKnowKey = TRUE;
  10070. }
  10071. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10072. {
  10073. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10076. {
  10077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10078. }
  10079. else
  10080. {
  10081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10082. }
  10083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10084. isKnowKey = TRUE;
  10085. }
  10086. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10087. {
  10088. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10091. {
  10092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10093. }
  10094. else
  10095. {
  10096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10097. }
  10098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10099. isKnowKey = TRUE;
  10100. }
  10101. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10102. {
  10103. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10106. {
  10107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10108. }
  10109. else
  10110. {
  10111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10112. }
  10113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10114. isKnowKey = TRUE;
  10115. }
  10116. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10117. {
  10118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10121. {
  10122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10123. }
  10124. else
  10125. {
  10126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10127. }
  10128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10129. isKnowKey = TRUE;
  10130. }
  10131. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10132. {
  10133. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10136. {
  10137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10138. }
  10139. else
  10140. {
  10141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10142. }
  10143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10144. isKnowKey = TRUE;
  10145. }
  10146. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10147. {
  10148. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10151. {
  10152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10153. }
  10154. else
  10155. {
  10156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10157. }
  10158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10159. isKnowKey = TRUE;
  10160. }
  10161. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10162. {
  10163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10166. {
  10167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10168. }
  10169. else
  10170. {
  10171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10172. }
  10173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10174. isKnowKey = TRUE;
  10175. }
  10176. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10177. {
  10178. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10181. {
  10182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10183. }
  10184. else
  10185. {
  10186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10187. }
  10188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10189. isKnowKey = TRUE;
  10190. }
  10191. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10192. {
  10193. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10196. {
  10197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10198. }
  10199. else
  10200. {
  10201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10202. }
  10203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10204. isKnowKey = TRUE;
  10205. }
  10206. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10207. {
  10208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10211. {
  10212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10213. }
  10214. else
  10215. {
  10216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10217. }
  10218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10219. isKnowKey = TRUE;
  10220. }
  10221. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10222. {
  10223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10226. {
  10227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10228. }
  10229. else
  10230. {
  10231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10232. }
  10233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10234. isKnowKey = TRUE;
  10235. }
  10236. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10237. {
  10238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10241. {
  10242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10243. }
  10244. else
  10245. {
  10246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10247. }
  10248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10249. isKnowKey = TRUE;
  10250. }
  10251. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10252. {
  10253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10256. {
  10257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10258. }
  10259. else
  10260. {
  10261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10262. }
  10263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10264. isKnowKey = TRUE;
  10265. }
  10266. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10267. {
  10268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10271. {
  10272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10273. }
  10274. else
  10275. {
  10276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10277. }
  10278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10279. isKnowKey = TRUE;
  10280. }
  10281. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10282. {
  10283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10286. {
  10287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10288. }
  10289. else
  10290. {
  10291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10292. }
  10293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10294. isKnowKey = TRUE;
  10295. }
  10296. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10297. {
  10298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10301. {
  10302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10303. }
  10304. else
  10305. {
  10306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10307. }
  10308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10309. isKnowKey = TRUE;
  10310. }
  10311. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10312. {
  10313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10316. {
  10317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10318. }
  10319. else
  10320. {
  10321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10322. }
  10323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10324. isKnowKey = TRUE;
  10325. }
  10326. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10327. {
  10328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10331. {
  10332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10333. }
  10334. else
  10335. {
  10336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10337. }
  10338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10339. isKnowKey = TRUE;
  10340. }
  10341. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10342. {
  10343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10346. {
  10347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10348. }
  10349. else
  10350. {
  10351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10352. }
  10353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10354. isKnowKey = TRUE;
  10355. }
  10356. #if 0
  10357. //For OCTT Test Case
  10358. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10359. {
  10360. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10362. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10363. {
  10364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10365. }
  10366. else
  10367. {
  10368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10369. }
  10370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10371. isKnowKey = TRUE;
  10372. }
  10373. #endif
  10374. #if 1
  10375. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10376. {
  10377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10379. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10380. {
  10381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10382. }
  10383. else
  10384. {
  10385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10386. }
  10387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10388. isKnowKey = TRUE;
  10389. }
  10390. #endif
  10391. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10392. {
  10393. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10395. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10396. {
  10397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10398. }
  10399. else
  10400. {
  10401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10402. }
  10403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  10404. isKnowKey = TRUE;
  10405. }
  10406. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  10407. {
  10408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  10409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  10410. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  10411. {
  10412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10413. }
  10414. else
  10415. {
  10416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10417. }
  10418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  10419. isKnowKey = TRUE;
  10420. }
  10421. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  10422. {
  10423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  10424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  10425. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  10426. {
  10427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  10428. }
  10429. else
  10430. {
  10431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  10432. }
  10433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10434. isKnowKey = TRUE;
  10435. }
  10436. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  10437. {
  10438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  10439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  10440. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  10441. {
  10442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  10443. }
  10444. else
  10445. {
  10446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  10447. }
  10448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10449. isKnowKey = TRUE;
  10450. }
  10451. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  10452. {
  10453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  10454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  10455. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  10456. {
  10457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  10458. }
  10459. else
  10460. {
  10461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  10462. }
  10463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10464. isKnowKey = TRUE;
  10465. }
  10466. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  10467. {
  10468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  10469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  10470. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  10471. {
  10472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  10473. }
  10474. else
  10475. {
  10476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  10477. }
  10478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10479. isKnowKey = TRUE;
  10480. }
  10481. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  10482. {
  10483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  10484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  10485. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  10486. {
  10487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  10488. }
  10489. else
  10490. {
  10491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  10492. }
  10493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10494. isKnowKey = TRUE;
  10495. }
  10496. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  10497. {
  10498. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  10499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  10500. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  10501. {
  10502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  10503. }
  10504. else
  10505. {
  10506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  10507. }
  10508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10509. isKnowKey = TRUE;
  10510. }
  10511. //=========================================================
  10512. if(!isEmpty && !isKnowKey)
  10513. {
  10514. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  10515. strcpy(unknownkey[UnknownKeynum], keyReq);
  10516. UnknownKeynum = UnknownKeynum + 1;
  10517. }
  10518. }
  10519. void processUnkownKey(void)
  10520. {
  10521. DEBUG_INFO("processUnkownKey\n");
  10522. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  10523. for(int index=0; index < UnknownKeynum; index++)
  10524. {
  10525. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  10526. {
  10527. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  10528. }
  10529. }
  10530. }
  10531. int setKeyValue(char *key, char *value)
  10532. {
  10533. int isSuccess = NotSupported;
  10534. int check_ascii=0;
  10535. char str[10]={0};
  10536. #ifdef Debug
  10537. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  10538. #endif
  10539. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  10540. {
  10541. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10543. {
  10544. strcpy(str, (const char*)value);
  10545. for(int i = 0; str[i]; i++){
  10546. str[i] = tolower(str[i]);
  10547. }
  10548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10549. isSuccess = ConfigurationStatus_Accepted;
  10550. }
  10551. else
  10552. {
  10553. isSuccess = ConfigurationStatus_Rejected;
  10554. }
  10555. }
  10556. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  10557. {
  10558. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10560. {
  10561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  10562. isSuccess = ConfigurationStatus_Accepted;
  10563. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  10564. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  10565. }
  10566. else
  10567. {
  10568. isSuccess = ConfigurationStatus_Rejected;
  10569. }
  10570. }
  10571. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  10572. {
  10573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10574. {
  10575. strcpy(str, (const char*)value);
  10576. for(int i = 0; str[i]; i++)
  10577. {
  10578. str[i] = tolower(str[i]);
  10579. }
  10580. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  10581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10582. isSuccess = ConfigurationStatus_Accepted;
  10583. }
  10584. else
  10585. {
  10586. isSuccess = ConfigurationStatus_Rejected;
  10587. }
  10588. }
  10589. if(strcmp(key, "BlinkRepeat") == 0)
  10590. {
  10591. //Charger.BlinkRepeat = Integer.parseInt(value);
  10592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10593. {
  10594. check_ascii = value[0];
  10595. if( (check_ascii < 48) || (check_ascii > 57) )
  10596. {
  10597. isSuccess = ConfigurationStatus_Rejected;
  10598. }
  10599. else
  10600. {
  10601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  10602. isSuccess = ConfigurationStatus_Accepted;
  10603. }
  10604. }
  10605. else
  10606. {
  10607. isSuccess = ConfigurationStatus_Rejected;
  10608. }
  10609. }
  10610. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  10611. {
  10612. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10613. {
  10614. check_ascii = value[0];
  10615. if( (check_ascii < 48) || (check_ascii > 57) )
  10616. {
  10617. isSuccess = ConfigurationStatus_Rejected;
  10618. }
  10619. else
  10620. {
  10621. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  10622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  10623. isSuccess = ConfigurationStatus_Accepted;
  10624. }
  10625. }
  10626. else
  10627. {
  10628. isSuccess = ConfigurationStatus_Rejected;
  10629. }
  10630. }
  10631. if(strcmp(key, "ConnectionTimeOut") == 0 )
  10632. {
  10633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10634. {
  10635. check_ascii = value[0];
  10636. if( (check_ascii < 48) || (check_ascii > 57) )
  10637. {
  10638. isSuccess = ConfigurationStatus_Rejected;
  10639. }
  10640. else
  10641. {
  10642. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  10643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  10644. isSuccess = ConfigurationStatus_Accepted;
  10645. }
  10646. }
  10647. else
  10648. {
  10649. isSuccess = ConfigurationStatus_Rejected;
  10650. }
  10651. }
  10652. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  10653. {
  10654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10655. {
  10656. check_ascii = value[0];
  10657. if( (check_ascii < 48) || (check_ascii > 57) )
  10658. {
  10659. isSuccess = ConfigurationStatus_Rejected;
  10660. }
  10661. else
  10662. {
  10663. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  10665. isSuccess = ConfigurationStatus_Accepted;
  10666. }
  10667. }
  10668. else
  10669. {
  10670. isSuccess = ConfigurationStatus_Rejected;
  10671. }
  10672. }
  10673. if(strcmp(key, "HeartbeatInterval") == 0)
  10674. {
  10675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10676. {
  10677. check_ascii = value[0];
  10678. if( (check_ascii < 48) || (check_ascii > 57) )
  10679. {
  10680. isSuccess = ConfigurationStatus_Rejected;
  10681. }
  10682. else
  10683. {
  10684. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  10686. HeartBeatWaitTime = atoi(value);
  10687. isSuccess = ConfigurationStatus_Accepted;
  10688. }
  10689. }
  10690. else
  10691. {
  10692. isSuccess = ConfigurationStatus_Rejected;
  10693. }
  10694. }
  10695. if(strcmp(key, "LightIntensity") == 0)
  10696. {
  10697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10698. {
  10699. check_ascii = value[0];
  10700. if( (check_ascii < 48) || (check_ascii > 57) )
  10701. {
  10702. isSuccess = ConfigurationStatus_Rejected;
  10703. }
  10704. else
  10705. {
  10706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10707. isSuccess = ConfigurationStatus_Accepted;
  10708. }
  10709. }
  10710. else
  10711. {
  10712. isSuccess = ConfigurationStatus_Rejected;
  10713. }
  10714. }
  10715. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10716. {
  10717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10718. {
  10719. strcpy(str, (const char*)value);
  10720. for(int i = 0; str[i]; i++)
  10721. {
  10722. str[i] = tolower(str[i]);
  10723. }
  10724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10725. isSuccess = ConfigurationStatus_Accepted;
  10726. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10727. }
  10728. else
  10729. {
  10730. isSuccess = ConfigurationStatus_Rejected;
  10731. }
  10732. }
  10733. if(strcmp(key, "LocalPreAuthorize") == 0)
  10734. {
  10735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10736. {
  10737. strcpy(str, (const char*)value);
  10738. for(int i = 0; str[i]; i++)
  10739. {
  10740. str[i] = tolower(str[i]);
  10741. }
  10742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10743. isSuccess = ConfigurationStatus_Accepted;
  10744. }
  10745. else
  10746. {
  10747. isSuccess = ConfigurationStatus_Rejected;
  10748. }
  10749. }
  10750. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10751. {
  10752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10753. {
  10754. check_ascii = value[0];
  10755. if( (check_ascii < 48) || (check_ascii > 57) )
  10756. {
  10757. isSuccess = ConfigurationStatus_Rejected;
  10758. }
  10759. else
  10760. {
  10761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10762. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  10763. isSuccess = ConfigurationStatus_Accepted;
  10764. }
  10765. }
  10766. else
  10767. {
  10768. isSuccess = ConfigurationStatus_Rejected;
  10769. }
  10770. }
  10771. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10772. {
  10773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10774. {
  10775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10776. isSuccess = ConfigurationStatus_Accepted;
  10777. }
  10778. else
  10779. {
  10780. isSuccess = ConfigurationStatus_Rejected;
  10781. }
  10782. }
  10783. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  10784. {
  10785. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10786. {
  10787. check_ascii = value[0];
  10788. if( (check_ascii < 48) || (check_ascii > 57) )
  10789. {
  10790. isSuccess = ConfigurationStatus_Rejected;
  10791. }
  10792. else
  10793. {
  10794. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  10796. isSuccess = ConfigurationStatus_Accepted;
  10797. }
  10798. }
  10799. else
  10800. {
  10801. isSuccess = ConfigurationStatus_Rejected;
  10802. }
  10803. }
  10804. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10805. {
  10806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10807. {
  10808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10809. isSuccess = ConfigurationStatus_Accepted;
  10810. }
  10811. else
  10812. {
  10813. isSuccess = ConfigurationStatus_Rejected;
  10814. }
  10815. }
  10816. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  10817. {
  10818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10819. {
  10820. check_ascii = value[0];
  10821. if( (check_ascii < 48) || (check_ascii > 57) )
  10822. {
  10823. isSuccess = ConfigurationStatus_Rejected;
  10824. }
  10825. else
  10826. {
  10827. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  10829. isSuccess = ConfigurationStatus_Accepted;
  10830. }
  10831. }
  10832. else
  10833. {
  10834. isSuccess = ConfigurationStatus_Rejected;
  10835. }
  10836. }
  10837. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10838. {
  10839. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10840. {
  10841. check_ascii = value[0];
  10842. if( (check_ascii < 48) || (check_ascii > 57) )
  10843. {
  10844. isSuccess = ConfigurationStatus_Rejected;
  10845. }
  10846. else
  10847. {
  10848. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10850. isSuccess = ConfigurationStatus_Accepted;
  10851. }
  10852. }
  10853. else
  10854. {
  10855. isSuccess = ConfigurationStatus_Rejected;
  10856. }
  10857. }
  10858. if(strcmp(key, "MinimumStatusDuration") == 0)
  10859. {
  10860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10861. {
  10862. check_ascii = value[0];
  10863. if( (check_ascii < 48) || (check_ascii > 57) )
  10864. {
  10865. isSuccess = ConfigurationStatus_Rejected;
  10866. }
  10867. else
  10868. {
  10869. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10871. isSuccess = ConfigurationStatus_Accepted;
  10872. }
  10873. }
  10874. else
  10875. {
  10876. isSuccess = ConfigurationStatus_Rejected;
  10877. }
  10878. }
  10879. if(strcmp(key, "NumberOfConnectors") == 0)
  10880. {
  10881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10882. {
  10883. check_ascii = value[0];
  10884. if( (check_ascii < 48) || (check_ascii > 57) )
  10885. {
  10886. isSuccess = ConfigurationStatus_Rejected;
  10887. }
  10888. else
  10889. {
  10890. //Charger.ResetRetries = Integer.parseInt(value);
  10891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  10892. isSuccess = ConfigurationStatus_Accepted;
  10893. }
  10894. }
  10895. else
  10896. {
  10897. isSuccess = ConfigurationStatus_Rejected;
  10898. }
  10899. }
  10900. if(strcmp(key, "ResetRetries") == 0)
  10901. {
  10902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10903. {
  10904. check_ascii = value[0];
  10905. if( (check_ascii < 48) || (check_ascii > 57) )
  10906. {
  10907. isSuccess = ConfigurationStatus_Rejected;
  10908. }
  10909. else
  10910. {
  10911. //Charger.ResetRetries = Integer.parseInt(value);
  10912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10913. isSuccess = ConfigurationStatus_Accepted;
  10914. }
  10915. }
  10916. else
  10917. {
  10918. isSuccess = ConfigurationStatus_Rejected;
  10919. }
  10920. }
  10921. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10922. {
  10923. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10924. {
  10925. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10926. isSuccess = ConfigurationStatus_Accepted;
  10927. }
  10928. else
  10929. {
  10930. isSuccess = ConfigurationStatus_Rejected;
  10931. }
  10932. }
  10933. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  10934. {
  10935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10936. {
  10937. check_ascii = value[0];
  10938. if( (check_ascii < 48) || (check_ascii > 57) )
  10939. {
  10940. isSuccess = ConfigurationStatus_Rejected;
  10941. }
  10942. else
  10943. {
  10944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  10945. isSuccess = ConfigurationStatus_Accepted;
  10946. }
  10947. }
  10948. else
  10949. {
  10950. isSuccess = ConfigurationStatus_Rejected;
  10951. }
  10952. }
  10953. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10954. {
  10955. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10956. {
  10957. strcpy(str, (const char*)value);
  10958. for(int i = 0; str[i]; i++)
  10959. {
  10960. str[i] = tolower(str[i]);
  10961. }
  10962. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10964. isSuccess = ConfigurationStatus_Accepted;
  10965. }
  10966. else
  10967. {
  10968. isSuccess = ConfigurationStatus_Rejected;
  10969. }
  10970. }
  10971. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10972. {
  10973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10974. {
  10975. strcpy(str, (const char*)value);
  10976. for(int i = 0; str[i]; i++)
  10977. {
  10978. str[i] = tolower(str[i]);
  10979. }
  10980. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10982. isSuccess = ConfigurationStatus_Accepted;
  10983. }
  10984. else
  10985. {
  10986. isSuccess = ConfigurationStatus_Rejected;
  10987. }
  10988. }
  10989. if(strcmp(key, "StopTxnAlignedData") == 0)
  10990. {
  10991. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10992. {
  10993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10994. isSuccess = ConfigurationStatus_Accepted;
  10995. }
  10996. else
  10997. {
  10998. isSuccess = ConfigurationStatus_Rejected;
  10999. }
  11000. }
  11001. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11002. {
  11003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11004. {
  11005. check_ascii = value[0];
  11006. if( (check_ascii < 48) || (check_ascii > 57) )
  11007. {
  11008. isSuccess = ConfigurationStatus_Rejected;
  11009. }
  11010. else
  11011. {
  11012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11013. isSuccess = ConfigurationStatus_Accepted;
  11014. }
  11015. }
  11016. else
  11017. {
  11018. isSuccess = ConfigurationStatus_Rejected;
  11019. }
  11020. }
  11021. if(strcmp(key, "StopTxnSampledData") == 0)
  11022. {
  11023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11024. {
  11025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11026. isSuccess = ConfigurationStatus_Accepted;
  11027. }
  11028. else
  11029. {
  11030. isSuccess = ConfigurationStatus_Rejected;
  11031. }
  11032. }
  11033. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11034. {
  11035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11036. {
  11037. check_ascii = value[0];
  11038. if( (check_ascii < 48) || (check_ascii > 57) )
  11039. {
  11040. isSuccess = ConfigurationStatus_Rejected;
  11041. }
  11042. else
  11043. {
  11044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11045. isSuccess = ConfigurationStatus_Accepted;
  11046. }
  11047. }
  11048. else
  11049. {
  11050. isSuccess = ConfigurationStatus_Rejected;
  11051. }
  11052. }
  11053. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11054. {
  11055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11056. {
  11057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11058. isSuccess = ConfigurationStatus_Accepted;
  11059. }
  11060. else
  11061. {
  11062. isSuccess = ConfigurationStatus_Rejected;
  11063. }
  11064. }
  11065. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11066. {
  11067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11068. {
  11069. check_ascii = value[0];
  11070. if( (check_ascii < 48) || (check_ascii > 57) )
  11071. {
  11072. isSuccess = ConfigurationStatus_Rejected;
  11073. }
  11074. else
  11075. {
  11076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11077. isSuccess = ConfigurationStatus_Accepted;
  11078. }
  11079. }
  11080. else
  11081. {
  11082. isSuccess = ConfigurationStatus_Rejected;
  11083. }
  11084. }
  11085. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11086. {
  11087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11088. {
  11089. check_ascii = value[0];
  11090. if( (check_ascii < 48) || (check_ascii > 57) )
  11091. {
  11092. isSuccess = ConfigurationStatus_Rejected;
  11093. }
  11094. else
  11095. {
  11096. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11098. TransactionMessageAttemptsValue = atoi(value);
  11099. isSuccess = ConfigurationStatus_Accepted;
  11100. }
  11101. }
  11102. else
  11103. {
  11104. isSuccess = ConfigurationStatus_Rejected;
  11105. }
  11106. }
  11107. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11108. {
  11109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11110. {
  11111. check_ascii = value[0];
  11112. if( (check_ascii < 48) || (check_ascii > 57) )
  11113. {
  11114. isSuccess = ConfigurationStatus_Rejected;
  11115. }
  11116. else
  11117. {
  11118. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11120. TransactionMessageRetryIntervalValue = atoi(value);
  11121. isSuccess = ConfigurationStatus_Accepted;
  11122. }
  11123. }
  11124. else
  11125. {
  11126. isSuccess = ConfigurationStatus_Rejected;
  11127. }
  11128. }
  11129. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11130. {
  11131. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11132. {
  11133. strcpy(str, (const char*)value);
  11134. for(int i = 0; str[i]; i++)
  11135. {
  11136. str[i] = tolower(str[i]);
  11137. }
  11138. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11140. isSuccess = ConfigurationStatus_Accepted;
  11141. }
  11142. else
  11143. {
  11144. isSuccess = ConfigurationStatus_Rejected;
  11145. }
  11146. }
  11147. if(strcmp(key, "WebSocketPingInterval") == 0)
  11148. {
  11149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11150. {
  11151. check_ascii = value[0];
  11152. if( (check_ascii < 48) || (check_ascii > 57) )
  11153. {
  11154. isSuccess = ConfigurationStatus_Rejected;
  11155. }
  11156. else
  11157. {
  11158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11159. isSuccess = ConfigurationStatus_Accepted;
  11160. }
  11161. }
  11162. else
  11163. {
  11164. isSuccess = ConfigurationStatus_Rejected;
  11165. }
  11166. }
  11167. #if 0
  11168. //For OCPP Test Case
  11169. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11170. {
  11171. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11172. {
  11173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11174. isSuccess = ConfigurationStatus_Accepted;
  11175. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11176. }
  11177. else
  11178. {
  11179. isSuccess = ConfigurationStatus_Rejected;
  11180. }
  11181. }
  11182. #endif
  11183. #if 1
  11184. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11185. {
  11186. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11187. {
  11188. strcpy(str, (const char*)value);
  11189. for(int i = 0; str[i]; i++)
  11190. {
  11191. str[i] = tolower(str[i]);
  11192. }
  11193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11194. isSuccess = ConfigurationStatus_Accepted;
  11195. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11196. }
  11197. else
  11198. {
  11199. isSuccess = ConfigurationStatus_Rejected;
  11200. }
  11201. }
  11202. #endif
  11203. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11204. {
  11205. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11206. {
  11207. check_ascii = value[0];
  11208. if( (check_ascii < 48) || (check_ascii > 57) )
  11209. {
  11210. isSuccess = ConfigurationStatus_Rejected;
  11211. }
  11212. else
  11213. {
  11214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11215. isSuccess = ConfigurationStatus_Accepted;
  11216. }
  11217. }
  11218. else
  11219. {
  11220. isSuccess = ConfigurationStatus_Rejected;
  11221. }
  11222. }
  11223. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11224. {
  11225. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11226. {
  11227. check_ascii = value[0];
  11228. if( (check_ascii < 48) || (check_ascii > 57) )
  11229. {
  11230. isSuccess = ConfigurationStatus_Rejected;
  11231. }
  11232. else
  11233. {
  11234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11235. isSuccess = ConfigurationStatus_Accepted;
  11236. }
  11237. }
  11238. else
  11239. {
  11240. isSuccess = ConfigurationStatus_Rejected;
  11241. }
  11242. }
  11243. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11244. {
  11245. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11246. {
  11247. strcpy(str, (const char*)value);
  11248. for(int i = 0; str[i]; i++)
  11249. {
  11250. str[i] = tolower(str[i]);
  11251. }
  11252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11253. isSuccess = ConfigurationStatus_Accepted;
  11254. }
  11255. else
  11256. {
  11257. isSuccess = ConfigurationStatus_Rejected;
  11258. }
  11259. }
  11260. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11261. {
  11262. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11263. {
  11264. check_ascii = value[0];
  11265. if( (check_ascii < 48) || (check_ascii > 57) )
  11266. {
  11267. isSuccess = ConfigurationStatus_Rejected;
  11268. }
  11269. else
  11270. {
  11271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11272. isSuccess = ConfigurationStatus_Accepted;
  11273. }
  11274. }
  11275. else
  11276. {
  11277. isSuccess = ConfigurationStatus_Rejected;
  11278. }
  11279. }
  11280. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11281. {
  11282. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11283. {
  11284. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11285. isSuccess = ConfigurationStatus_Accepted;
  11286. }
  11287. else
  11288. {
  11289. isSuccess = ConfigurationStatus_Rejected;
  11290. }
  11291. }
  11292. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11293. {
  11294. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11295. {
  11296. check_ascii = value[0];
  11297. if( (check_ascii < 48) || (check_ascii > 57) )
  11298. {
  11299. isSuccess = ConfigurationStatus_Rejected;
  11300. }
  11301. else
  11302. {
  11303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11304. isSuccess = ConfigurationStatus_Accepted;
  11305. }
  11306. }
  11307. else
  11308. {
  11309. isSuccess = ConfigurationStatus_Rejected;
  11310. }
  11311. }
  11312. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11313. {
  11314. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11315. {
  11316. strcpy(str, (const char*)value);
  11317. for(int i = 0; str[i]; i++)
  11318. {
  11319. str[i] = tolower(str[i]);
  11320. }
  11321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11322. isSuccess = ConfigurationStatus_Accepted;
  11323. }
  11324. else
  11325. {
  11326. isSuccess = ConfigurationStatus_Rejected;
  11327. }
  11328. }
  11329. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11330. {
  11331. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11332. {
  11333. check_ascii = value[0];
  11334. if( (check_ascii < 48) || (check_ascii > 57) )
  11335. {
  11336. isSuccess = ConfigurationStatus_Rejected;
  11337. }
  11338. else
  11339. {
  11340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11341. isSuccess = ConfigurationStatus_Accepted;
  11342. }
  11343. }
  11344. else
  11345. {
  11346. isSuccess = ConfigurationStatus_Rejected;
  11347. }
  11348. }
  11349. return isSuccess;
  11350. }
  11351. int updateSetting(char *key, char *value)
  11352. {
  11353. mtrace();
  11354. int isSuccess = FALSE;
  11355. char string[1000]={0}, buffer[1000]={0};
  11356. char strtemp[50]={0};
  11357. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11358. int pos, c = 0;
  11359. char *loc;
  11360. int pos1=0;
  11361. FILE *f = fopen("/var/www/settings1", "r");
  11362. if(f == NULL)
  11363. {
  11364. #ifdef Debug
  11365. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11366. #endif
  11367. return isSuccess;
  11368. }
  11369. fseek(f, 0, SEEK_END);
  11370. long fsize = ftell(f);
  11371. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11372. fread(string, 1, fsize, f);
  11373. fclose(f);
  11374. string[fsize] = 0;
  11375. loc = strstr(string, key);
  11376. if(loc != NULL)
  11377. {
  11378. DEBUG_INFO("key exist!\n");
  11379. pos = loc - string-1;
  11380. f = fopen("/var/www/settings1", "w");
  11381. strncpy(buffer, string, pos);
  11382. fprintf(f, "%s", buffer);
  11383. memset(sstr ,0, sizeof(sstr) );
  11384. c = 0;
  11385. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11386. {
  11387. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11388. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11389. c++;
  11390. }
  11391. sstr[c] = '\0';
  11392. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11393. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11394. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11395. memset(buffer ,0, sizeof(buffer) );
  11396. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11397. //printf("buffer=%s",buffer);
  11398. fprintf(f, "%s", buffer);
  11399. fclose(f);
  11400. }
  11401. else
  11402. {
  11403. printf("key not exist!\n");
  11404. f = fopen("/var/www/settings1", "w+");
  11405. fputs(string, f);
  11406. fseek(f, -1, SEEK_CUR);
  11407. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  11408. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  11409. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  11410. fclose(f);
  11411. }
  11412. isSuccess = TRUE;
  11413. return isSuccess;
  11414. }
  11415. int TransactionMessageAttemptsGet(void)
  11416. {
  11417. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11418. }
  11419. int FirstHeartBeatResponse(void)
  11420. {
  11421. return FirstHeartBeat;
  11422. }
  11423. int TransactionMessageRetryIntervalGet(void)
  11424. {
  11425. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11426. }
  11427. #define SA struct sockaddr
  11428. #define MAXBUF 1024
  11429. //static int m_socket_data;
  11430. //static int sockfd;
  11431. int ReadHttpStatus(int sock){
  11432. //char c;
  11433. char buff[1024]="",*ptr=buff+1;
  11434. int bytes_received, status;
  11435. DEBUG_INFO("Begin Response ..\n");
  11436. while((bytes_received = recv(sock, ptr, 1, 0))){
  11437. if(bytes_received==-1){
  11438. perror("ReadHttpStatus");
  11439. exit(1);
  11440. }
  11441. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  11442. ptr++;
  11443. }
  11444. *ptr=0;
  11445. ptr=buff+1;
  11446. sscanf(ptr,"%*s %d ", &status);
  11447. DEBUG_INFO("%s\n",ptr);
  11448. DEBUG_INFO("status=%d\n",status);
  11449. DEBUG_INFO("End Response ..\n");
  11450. return (bytes_received>0)?status:0;
  11451. }
  11452. //the only filed that it parsed is 'Content-Length'
  11453. int ParseHeader(int sock){
  11454. //char c;
  11455. char buff[1024]="",*ptr=buff+4;
  11456. int bytes_received;
  11457. DEBUG_INFO("Begin HEADER ..\n");
  11458. while((bytes_received = recv(sock, ptr, 1, 0))){
  11459. if(bytes_received==-1){
  11460. perror("Parse Header");
  11461. exit(1);
  11462. }
  11463. if(
  11464. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  11465. (ptr[-1]=='\r') && (*ptr=='\n' )
  11466. ) break;
  11467. ptr++;
  11468. }
  11469. *ptr=0;
  11470. ptr=buff+4;
  11471. //printf("%s",ptr);
  11472. if(bytes_received){
  11473. ptr=strstr(ptr,"Content-Length:");
  11474. if(ptr){
  11475. sscanf(ptr,"%*s %d",&bytes_received);
  11476. }else
  11477. bytes_received=-1; //unknown size
  11478. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  11479. }
  11480. DEBUG_INFO("End HEADER ..\n");
  11481. return bytes_received ;
  11482. }
  11483. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  11484. {
  11485. char rmFileCmd[100]={0};
  11486. char FilePath[100]={0};
  11487. char ftpbuf[200];
  11488. int systemresult;
  11489. //DEBUG_INFO("filename=%s\n",filename);
  11490. //DEBUG_INFO("url=%s\n",url);
  11491. sprintf(FilePath,"../mnt/%s",filename);
  11492. if((access(FilePath,F_OK))!=-1)
  11493. {
  11494. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11495. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11496. system(rmFileCmd);
  11497. }
  11498. memset(ftpbuf, 0, sizeof(ftpbuf));
  11499. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11500. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11501. systemresult = system(ftpbuf);
  11502. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11503. if(systemresult != 0)
  11504. {
  11505. DEBUG_INFO("http DownLoad error!\n");
  11506. return FALSE;
  11507. }
  11508. return TRUE;
  11509. }
  11510. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  11511. {
  11512. char rmFileCmd[100]={0};
  11513. char FilePath[100]={0};
  11514. char ftpbuf[200];
  11515. int systemresult;
  11516. //char temp[100];
  11517. #if 0
  11518. struct hostent* server;
  11519. char *IPbuffer;
  11520. server = gethostbyname(location);
  11521. // To convert an Internet network
  11522. // address into ASCII string
  11523. IPbuffer = inet_ntoa(*((struct in_addr*)
  11524. server->h_addr_list[0]));
  11525. #endif
  11526. sprintf(FilePath,"../mnt/%s",filename);
  11527. if((access(FilePath,F_OK))!=-1)
  11528. {
  11529. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11530. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11531. system(rmFileCmd);
  11532. }
  11533. memset(ftpbuf, 0, sizeof(ftpbuf));
  11534. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11535. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  11536. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11537. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11538. systemresult = system(ftpbuf);
  11539. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11540. if(systemresult != 0)
  11541. {
  11542. printf("wget error!\n");
  11543. return FALSE;
  11544. }
  11545. return TRUE;
  11546. }
  11547. int httpUploadFile(char *location, char *path, char *filename,char *url)
  11548. {
  11549. char rmFileCmd[100]={0};
  11550. char FilePath[100]={0};
  11551. char ftpbuf[200];
  11552. char filenametemp[60]={0};
  11553. int systemresult;
  11554. //DEBUG_INFO("filename=%s\n",filename);
  11555. //DEBUG_INFO("url=%s\n",url);
  11556. sprintf(FilePath,"%s","../mnt/upload_file.txt");
  11557. if((access(FilePath,F_OK))!=-1)
  11558. {
  11559. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11560. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11561. system(rmFileCmd);
  11562. }
  11563. FILE *fp = fopen("../mnt/upload_file.txt", "w+");
  11564. if(fp == NULL)
  11565. {
  11566. DEBUG_INFO("log is NULL\n");
  11567. return FALSE;
  11568. }
  11569. else
  11570. {
  11571. fprintf(fp, "%s\n", url);
  11572. sscanf(filename, "%*2[.]%s", filenametemp);
  11573. fprintf(fp, "%s\n", filenametemp);
  11574. fclose(fp);
  11575. }
  11576. memset(ftpbuf, 0, sizeof(ftpbuf));
  11577. sprintf(ftpbuf, "%s","../bin/php-cgi /var/www/ocpp_upload.php");
  11578. systemresult = system(ftpbuf);
  11579. DEBUG_INFO("systemresult=%d\n",systemresult);
  11580. if(systemresult != 0)
  11581. {
  11582. DEBUG_INFO("http upload error!\n");
  11583. return FALSE;
  11584. }
  11585. return TRUE;
  11586. }
  11587. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  11588. {
  11589. struct hostent* server;
  11590. char *IPbuffer;
  11591. char ftpbuf[200];
  11592. int systemresult;
  11593. // To retrieve host information
  11594. server = gethostbyname(location);
  11595. // To convert an Internet network
  11596. // address into ASCII string
  11597. IPbuffer = inet_ntoa(*((struct in_addr*)
  11598. server->h_addr_list[0]));
  11599. memset(ftpbuf, 0, sizeof(ftpbuf));
  11600. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  11601. /* format : ftpput -u username -p passwd IP target source*/
  11602. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  11603. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11604. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11605. systemresult = system(ftpbuf);
  11606. DEBUG_INFO("systemresult=%d\n",systemresult);
  11607. if(systemresult != 0)
  11608. {
  11609. DEBUG_INFO("ftpput error!\n");
  11610. return FALSE;
  11611. }
  11612. return TRUE;
  11613. }
  11614. int SettingChargingRecord(int target, int transactionId)
  11615. {
  11616. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11617. {
  11618. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11619. {
  11620. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11621. {
  11622. addBuff(target, transactionId, 0);
  11623. return TRUE;
  11624. }
  11625. }
  11626. for (int index = 0; index < CCS_QUANTITY; index++)
  11627. {
  11628. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11629. {
  11630. addBuff(target, transactionId, 0);
  11631. return TRUE;
  11632. }
  11633. }
  11634. for (int index = 0; index < GB_QUANTITY; index++)
  11635. {
  11636. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11637. {
  11638. addBuff(target, transactionId, 0);
  11639. return TRUE;
  11640. }
  11641. }
  11642. }
  11643. else
  11644. {
  11645. for (int index = 0; index < AC_QUANTITY; index++)
  11646. {
  11647. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11648. {
  11649. addBuff(target, transactionId, 0);
  11650. return TRUE;
  11651. }
  11652. }
  11653. }
  11654. return FALSE;
  11655. }
  11656. int addBuff(int gun_idx, int user_id, int cmd_sn)
  11657. {
  11658. int isSuccess = FALSE;
  11659. //char *query = NULL;
  11660. sqlite3_stmt *stmt;
  11661. int rc; // return code
  11662. char str[20];
  11663. sprintf(str,"%d",user_id);
  11664. 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 */
  11665. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  11666. rc = sqlite3_step(stmt); /* 3 */
  11667. if (rc != SQLITE_DONE) {
  11668. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  11669. goto out;
  11670. }
  11671. sqlite3_finalize(stmt);
  11672. // free(query);
  11673. out:
  11674. //----------------------
  11675. // close SQLite database
  11676. //----------------------
  11677. sqlite3_close(db);
  11678. printf("database closed.\n");
  11679. return isSuccess;
  11680. }
  11681. /**
  11682. * Place the contents of the specified file into a memory buffer
  11683. *
  11684. * @param[in] filename The path and name of the file to read
  11685. * @param[out] filebuffer A pointer to the contents in memory
  11686. * @return status 0 success, 1 on failure
  11687. */
  11688. int get_file_contents(const char* filename, char** outbuffer) {
  11689. FILE* file = NULL;
  11690. long filesize;
  11691. const int blocksize = 1;
  11692. size_t readsize;
  11693. char* filebuffer;
  11694. // Open the file
  11695. file = fopen(filename, "r");
  11696. if (NULL == file)
  11697. {
  11698. printf("'%s' not opened\n", filename);
  11699. exit(EXIT_FAILURE);
  11700. }
  11701. // Determine the file size
  11702. fseek(file, 0, SEEK_END);
  11703. filesize = ftell(file);
  11704. rewind (file);
  11705. // Allocate memory for the file contents
  11706. filebuffer = (char*) malloc(sizeof(char) * filesize);
  11707. *outbuffer = filebuffer;
  11708. if (filebuffer == NULL)
  11709. {
  11710. fputs ("malloc out-of-memory", stderr);
  11711. exit(EXIT_FAILURE);
  11712. }
  11713. // Read in the file
  11714. readsize = fread(filebuffer, blocksize, filesize, file);
  11715. if (readsize != filesize)
  11716. {
  11717. fputs ("didn't read file completely",stderr);
  11718. exit(EXIT_FAILURE);
  11719. }
  11720. // Clean exit
  11721. fclose(file);
  11722. return EXIT_SUCCESS;
  11723. }
  11724. static int selectSqlCount = 0;
  11725. static int callback(void *data, int argc, char **argv, char **azColName){
  11726. int i;
  11727. printf("%s: ", (const char*)data);
  11728. selectSqlCount = argc;
  11729. for(i = 0; i<argc; i++){
  11730. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  11731. }
  11732. printf("\n");
  11733. return 0;
  11734. }
  11735. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  11736. //int i;
  11737. //printf("%s:\n", (const char*)data);
  11738. localversion = argv[5] ? atoi(argv[5]) : 0;
  11739. printf("localversion=%d\n", localversion);
  11740. return 0;
  11741. }
  11742. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  11743. //int i;
  11744. //printf("%s:\n", (const char*)data);
  11745. //idTag
  11746. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  11747. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  11748. //parentIdTag
  11749. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  11750. //expir_date
  11751. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  11752. //status
  11753. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  11754. //version
  11755. idTagQuery.listVersionInt = atoi(argv[5]);
  11756. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  11757. return 0;
  11758. }
  11759. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  11760. int i;
  11761. //printf("%s:\n", (const char*)data);
  11762. #if 1
  11763. for(i=0; i<argc; i++){
  11764. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  11765. }
  11766. //printf("");
  11767. #endif
  11768. // localversion = argv[5] ? atoi(argv[5]) : 0;
  11769. // printf("localversion=%d\n", localversion);
  11770. return 0;
  11771. }
  11772. /** sqlite3_exec的回调。
  11773. *
  11774. * 向控制台打印查询的结果。
  11775. *
  11776. * @param in data 传递给回调函数的数据。
  11777. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  11778. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  11779. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  11780. * @return 状态码。
  11781. */
  11782. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  11783. {
  11784. for (int i = 0; i < n_columns; i++)
  11785. {
  11786. DEBUG_INFO("%s/t", col_values[i]);
  11787. }
  11788. DEBUG_INFO("/n");
  11789. return 0;
  11790. }
  11791. void OCPP_getListVerion()
  11792. {
  11793. int rc = 0;
  11794. // const char* data = "Callback function called";
  11795. char sql[100];
  11796. char zErrMsg[100];
  11797. memset(sql, 0, 100);
  11798. memset(zErrMsg, 0, 100);
  11799. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  11800. /* Execute SQL statement */
  11801. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  11802. DEBUG_INFO("rc=%d\n",rc);
  11803. if( rc != SQLITE_OK ){
  11804. DEBUG_INFO("SQL error: %s", zErrMsg);
  11805. //sqlite3_free(zErrMsg);
  11806. }else{
  11807. DEBUG_INFO("Operation done successfully");
  11808. }
  11809. }
  11810. void OCPP_getIdTag(char *idTag)
  11811. {
  11812. int rc = 0;
  11813. // const char* data = "Callback function called";
  11814. char sql[100];
  11815. char zErrMsg[100];
  11816. memset(sql, 0, 100);
  11817. memset(zErrMsg, 0, 100);
  11818. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  11819. memset(&idTagQuery, 0, sizeof(idTagQuery));
  11820. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11821. /* Execute SQL statement */
  11822. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  11823. if( rc != SQLITE_OK ){
  11824. DEBUG_INFO("SQL error: %s", zErrMsg);
  11825. //sqlite3_free(zErrMsg);
  11826. }else{
  11827. printf("Operation done successfully");
  11828. }
  11829. //return ver;
  11830. }
  11831. void OCPP_get_TableAuthlocalAllData(void)
  11832. {
  11833. int rc = 0;
  11834. // const char* data = "Callback function called";
  11835. char sql[100];
  11836. char zErrMsg[100];
  11837. memset(sql, 0, 100);
  11838. memset(zErrMsg, 0, 100);
  11839. sprintf(sql,"select * from ocpp_auth_local ");
  11840. /* Execute SQL statement */
  11841. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  11842. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  11843. if( rc != SQLITE_OK ){
  11844. DEBUG_INFO("SQL error: %s", zErrMsg);
  11845. //sqlite3_free(zErrMsg);
  11846. }else{
  11847. DEBUG_INFO("Operation done successfully");
  11848. }
  11849. //return ver;
  11850. }
  11851. int OCPP_cleanLocalList()
  11852. {
  11853. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  11854. char *errMsg = 0;
  11855. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  11856. if (SQLITE_OK != rc)
  11857. {
  11858. DEBUG_INFO("%s\n",errMsg);
  11859. return FALSE;
  11860. }
  11861. else
  11862. {
  11863. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  11864. }
  11865. return TRUE;
  11866. }
  11867. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11868. {
  11869. int isSuccess = FALSE;
  11870. int ret = 0;
  11871. //const char* data = "Callback function called";
  11872. char sql[200];
  11873. char zErrMsg[100];
  11874. memset(sql, 0, 200);
  11875. memset(zErrMsg, 0, 100);
  11876. 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);
  11877. //* Execute SQL statement */
  11878. //zErrMsg = 0;
  11879. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  11880. if( ret != SQLITE_OK ){
  11881. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  11882. // free(zErrMsg);
  11883. // free(sql);
  11884. return isSuccess;
  11885. }
  11886. DEBUG_INFO("successfully Insert records created\n");
  11887. isSuccess = TRUE;
  11888. return isSuccess;
  11889. }
  11890. void OCPP_deleteIdTag(char *idTag)
  11891. {
  11892. //int ver = 0;
  11893. //int isSuccess = FALSE;
  11894. int rc = 0;
  11895. char sql[100];
  11896. char zErrMsg[100];
  11897. memset(sql, 0, 100);
  11898. memset(zErrMsg, 0, 100);
  11899. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  11900. //* Execute SQL statement */
  11901. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  11902. if( rc != SQLITE_OK ){
  11903. DEBUG_INFO("SQL error: %s", zErrMsg);
  11904. //sqlite3_free(zErrMsg);
  11905. }else{
  11906. DEBUG_INFO("Operation done successfully");
  11907. }
  11908. }
  11909. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11910. {
  11911. int isSuccess = FALSE;
  11912. int ret = 0;
  11913. const char* data = "Callback function called";
  11914. char sql[200];
  11915. char zErrMsg[100];
  11916. memset(sql, 0, 200);
  11917. memset(zErrMsg, 0, 100);
  11918. //* selectFromTable */
  11919. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  11920. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11921. //* Execute SQL statement */
  11922. selectSqlCount = 0;
  11923. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11924. if( ret != SQLITE_OK ){
  11925. printf("Error SQL: %s\n", zErrMsg);
  11926. }
  11927. printf("successfully select operation done\n");
  11928. memset(sql, 0, 200);
  11929. memset(zErrMsg, 0, 100);
  11930. if(selectSqlCount == 0)
  11931. {
  11932. //Insert
  11933. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  11934. 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);
  11935. DEBUG_INFO("sql:%s\n", sql);
  11936. //* Execute SQL statement */
  11937. //zErrMsg = 0;
  11938. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  11939. if( ret != SQLITE_OK ){
  11940. printf("SQL error: %s\n", zErrMsg);
  11941. return isSuccess;
  11942. }
  11943. DEBUG_INFO("successfully Insert records created\n");
  11944. isSuccess = TRUE;
  11945. }
  11946. else
  11947. {
  11948. //Update
  11949. //* Create merged SQL statement */
  11950. 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);
  11951. /* Execute SQL statement */
  11952. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11953. if( ret != SQLITE_OK ){
  11954. printf("SQL error: %s\n", zErrMsg);
  11955. //sqlite3_free(zErrMsg);
  11956. //sqlite3_free(sql);
  11957. return isSuccess;
  11958. }
  11959. DEBUG_INFO("Successfully operation done \n");
  11960. isSuccess = TRUE;
  11961. }
  11962. return isSuccess;
  11963. }
  11964. int GetOcppServerURL()
  11965. {
  11966. int result = FALSE;
  11967. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  11968. memset(OcppHost, 0, sizeof(OcppHost));
  11969. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  11970. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  11971. {
  11972. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  11973. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  11974. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11975. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  11976. result = TRUE;
  11977. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  11978. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  11979. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  11980. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  11981. goto End;
  11982. }
  11983. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  11984. {
  11985. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  11986. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  11987. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11988. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  11989. result = TRUE;
  11990. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  11991. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  11992. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  11993. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  11994. goto End;
  11995. }
  11996. else
  11997. {
  11998. strcpy(OcppHost,"");
  11999. }
  12000. End:
  12001. return result;
  12002. }
  12003. int GetOcppPath()
  12004. {
  12005. int result = FALSE;
  12006. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12007. {
  12008. if(OcppTempPath == NULL)
  12009. {
  12010. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12011. }
  12012. else
  12013. {
  12014. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12015. }
  12016. result = TRUE;
  12017. goto End;
  12018. }
  12019. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12020. {
  12021. if(OcppTempPath == NULL)
  12022. {
  12023. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12024. }
  12025. else
  12026. {
  12027. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12028. }
  12029. result = TRUE;
  12030. goto End;
  12031. }
  12032. else
  12033. {
  12034. strcpy(OcppPath,"");
  12035. }
  12036. End:
  12037. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12038. return result;
  12039. }
  12040. int GetOcppPort()
  12041. {
  12042. return OcppPort;
  12043. }
  12044. int GetOcppConnStatus(void)
  12045. {
  12046. return ShmOCPP16Data->OcppConnStatus;
  12047. }
  12048. void SetOcppConnStatus(uint8_t status)
  12049. {
  12050. ShmOCPP16Data->OcppConnStatus = status;
  12051. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12052. if(status == FALSE)
  12053. {
  12054. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12055. {
  12056. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12057. }
  12058. else
  12059. {
  12060. SystemInitial = AC_QUANTITY;
  12061. }
  12062. }
  12063. }
  12064. int GetHeartBeatWithNOResponse(void)
  12065. {
  12066. return HeartBeatWithNOResponse;
  12067. }
  12068. void SetHeartBeatWithNOResponse(void)
  12069. {
  12070. HeartBeatWithNOResponse = 0;
  12071. }
  12072. int GetTransactionId(int gunindex)
  12073. {
  12074. return TransactionId[gunindex];
  12075. }
  12076. void SetTransactionIdZero(int gunindex)
  12077. {
  12078. TransactionId[gunindex] = 0;
  12079. }
  12080. int InternetDisconnect(void)
  12081. {
  12082. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12083. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12084. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12085. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12086. }
  12087. void GetChargingProfileRequest(int gunindex)
  12088. {
  12089. mtrace();
  12090. //int connectorIdInt, durationInt;
  12091. //char chargingRateUnitStr[4]={0};
  12092. int tempdurationInt = 0;
  12093. int tempchargingProfileId = 0;
  12094. int tempstackLevel = 0;
  12095. int temptransactionId = 0;
  12096. float tempminChargingRateFloat = 0.0;
  12097. char tempchargingProfilePurposeStr[24]={0};
  12098. char tempchargingProfileKindStr[12]={0};
  12099. char temprecurrencyKindStr[8]={0};
  12100. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12101. char tempvalidToStr[28]={0};
  12102. int tempStartPeriodInt = 0;
  12103. float tempLimitInt = 0.0;//0.1;
  12104. int tempNumberPhasesInt=0;
  12105. char fname[200];
  12106. //char comfirmstr[20];
  12107. float MinChargingRate =0.0;
  12108. double diff_t;
  12109. struct tm tp;
  12110. FILE *fptr1;//, *fptr2;
  12111. int c = 0;
  12112. char * pch;
  12113. char *loc;
  12114. char sstr[200]={ 0 };
  12115. int n_chargingProfile = 0;
  12116. int n_SchedulePeriods = 0;
  12117. char SchedulePeriodList[10][200]={0};
  12118. char sLineWord[800]={0};
  12119. char word[1000]={0};
  12120. int confirmPeriods = 0;
  12121. struct StructProfile ChargePointMaxProfile;
  12122. struct StructProfile TxDefaultProfile;
  12123. struct StructProfile TxProfile;
  12124. struct StructProfile TxDefaultProfiletemp[2]={0};
  12125. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12126. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12127. struct StructChargingProfile TxProfile_TEMP={0};
  12128. int TxDefaultProfileFileIsNull=FALSE;
  12129. int ChargePointMaxProfileIsNull=FALSE;
  12130. int TxProfileIsNull=FALSE;
  12131. // int CompositeSceduleIndex = 0;
  12132. char ChargePointMaxProfileScheduleStr[30]={0};
  12133. char TxDefaultProfileScheduleStr[30]={0};
  12134. char TxProfileScheduleStr[30]={0};
  12135. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12136. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12137. memset(&TxProfile,0,sizeof(struct StructProfile));
  12138. DEBUG_INFO("GetChargingProfileRequest\n");
  12139. //*****************************ChargePointMaxProfile******************************************/
  12140. strcpy(fname, ChargePointMaxProfile_JSON);
  12141. ChargePointMaxProfileIsNull=TRUE;
  12142. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12143. {
  12144. fptr1 = fopen(fname, "r");
  12145. int c;
  12146. c = fgetc(fptr1);
  12147. //DEBUG_INFO("c:%d\n",c);
  12148. rewind(fptr1);
  12149. if(c == EOF)
  12150. {
  12151. DEBUG_INFO("\n End of file reached.");
  12152. ChargePointMaxProfileIsNull=TRUE;
  12153. fclose(fptr1);
  12154. }
  12155. else
  12156. {
  12157. ChargePointMaxProfileIsNull=FALSE;
  12158. while(fscanf(fptr1, "%s", word) != EOF)
  12159. {
  12160. if(strcmp(word, "chargingProfileId") == 0)
  12161. {
  12162. n_chargingProfile = n_chargingProfile + 1;
  12163. }
  12164. }
  12165. rewind(fptr1);
  12166. //search Charging Profile Element
  12167. int i = 0;
  12168. int j = 0;
  12169. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12170. //***********chargingProfileId**************/
  12171. c = 0;
  12172. loc = strstr(sLineWord, "chargingProfileId");
  12173. //DEBUG_INFO("loc=%s\n",loc);
  12174. memset(sstr ,0, sizeof(sstr) );
  12175. if(loc != NULL)
  12176. {
  12177. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12178. {
  12179. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12180. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12181. c++;
  12182. }
  12183. sstr[c] = '\0';
  12184. tempchargingProfileId = atoi(sstr);
  12185. }
  12186. else
  12187. {
  12188. tempchargingProfileId = 0;
  12189. }
  12190. //***********stackLevel**************/
  12191. c = 0;
  12192. loc = strstr(sLineWord, "stackLevel");
  12193. //DEBUG_INFO("loc=%s\n",loc);
  12194. memset(sstr ,0, sizeof(sstr) );
  12195. if(loc != NULL)
  12196. {
  12197. while (loc[2+strlen("stackLevel")+c] != '\"')
  12198. {
  12199. sstr[c] = loc[2+strlen("stackLevel")+c];
  12200. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12201. c++;
  12202. }
  12203. sstr[c] = '\0';
  12204. tempstackLevel = atoi(sstr);
  12205. }
  12206. else
  12207. {
  12208. tempstackLevel = 0;
  12209. }
  12210. //***********chargingProfilePurpose **************/
  12211. c = 0;
  12212. loc = strstr(sLineWord, "chargingProfilePurpose");
  12213. //DEBUG_INFO("loc=%s\n",loc);
  12214. memset(sstr ,0, sizeof(sstr) );
  12215. if(loc != NULL)
  12216. {
  12217. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12218. {
  12219. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12220. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12221. c++;
  12222. }
  12223. sstr[c] = '\0';
  12224. strcpy(tempchargingProfilePurposeStr,sstr);
  12225. }
  12226. else
  12227. {
  12228. strcpy(tempchargingProfilePurposeStr,"");
  12229. }
  12230. //***********chargingProfileKind **************/
  12231. c = 0;
  12232. loc = strstr(sLineWord, "chargingProfileKind");
  12233. //DEBUG_INFO("loc=%s\n",loc);
  12234. memset(sstr ,0, sizeof(sstr) );
  12235. if(loc != NULL)
  12236. {
  12237. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12238. {
  12239. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12240. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12241. c++;
  12242. }
  12243. sstr[c] = '\0';
  12244. strcpy(tempchargingProfileKindStr,sstr);
  12245. }
  12246. else
  12247. {
  12248. strcpy(tempchargingProfileKindStr,"");
  12249. }
  12250. //***********recurrencyKind **************/
  12251. c = 0;
  12252. loc = strstr(sLineWord, "recurrencyKind");
  12253. //DEBUG_INFO("loc=%s\n",loc);
  12254. memset(sstr ,0, sizeof(sstr) );
  12255. if(loc != NULL)
  12256. {
  12257. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12258. {
  12259. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12260. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12261. c++;
  12262. }
  12263. sstr[c] = '\0';
  12264. strcpy(temprecurrencyKindStr,sstr);
  12265. }
  12266. else
  12267. {
  12268. strcpy(temprecurrencyKindStr,"");
  12269. }
  12270. //***********validFrom**************/
  12271. c = 0;
  12272. loc = strstr(sLineWord, "validFrom");
  12273. //DEBUG_INFO("loc=%s\n",loc);
  12274. memset(sstr ,0, sizeof(sstr) );
  12275. if(loc != NULL)
  12276. {
  12277. while (loc[3+strlen("validFrom")+c] != '\"')
  12278. {
  12279. sstr[c] = loc[3+strlen("validFrom")+c];
  12280. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12281. c++;
  12282. }
  12283. sstr[c] = '\0';
  12284. strcpy(tempvalidFromStr,sstr);
  12285. }
  12286. else
  12287. {
  12288. strcpy(tempvalidFromStr,"");
  12289. }
  12290. //***********validTo **************/
  12291. c = 0;
  12292. loc = strstr(sLineWord, "validTo");
  12293. //DEBUG_INFO("loc=%s\n",loc);
  12294. memset(sstr ,0, sizeof(sstr) );
  12295. if(loc != NULL)
  12296. {
  12297. while (loc[3+strlen("validTo")+c] != '\"')
  12298. {
  12299. sstr[c] = loc[3+strlen("validTo")+c];
  12300. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12301. c++;
  12302. }
  12303. sstr[c] = '\0';
  12304. strcpy(tempvalidToStr,sstr);
  12305. }
  12306. else
  12307. {
  12308. strcpy(tempvalidToStr,"");
  12309. }
  12310. //***********validFrom**************/
  12311. c = 0;
  12312. loc = strstr(sLineWord, "validFrom");
  12313. if(loc != NULL)
  12314. {
  12315. memset(sstr ,0, sizeof(sstr) );
  12316. while (loc[3+strlen("validFrom")+c] != '\"')
  12317. {
  12318. sstr[c] = loc[3+strlen("validFrom")+c];
  12319. c++;
  12320. }
  12321. sstr[c] = '\0';
  12322. strcpy(tempvalidFromStr,sstr);
  12323. }
  12324. else
  12325. {
  12326. strcpy(tempvalidFromStr,"");
  12327. }
  12328. //***********duration**************/
  12329. c = 0;
  12330. loc = strstr(sLineWord, "duration");
  12331. if(loc != NULL)
  12332. {
  12333. memset(sstr ,0, sizeof(sstr) );
  12334. while (loc[2+strlen("duration")+c] != ',')
  12335. {
  12336. sstr[c] = loc[2+strlen("duration")+c];
  12337. c++;
  12338. }
  12339. sstr[c] = '\0';
  12340. tempdurationInt = atoi(sstr);
  12341. }
  12342. else
  12343. {
  12344. tempdurationInt = 0;
  12345. }
  12346. //**********startSchedule**********/
  12347. c = 0;
  12348. loc = strstr(sLineWord, "startSchedule");
  12349. memset(sstr ,0, sizeof(sstr) );
  12350. while (loc[3+strlen("startSchedule")+c] != '\"')
  12351. {
  12352. sstr[c] = loc[3+strlen("startSchedule")+c];
  12353. c++;
  12354. }
  12355. sstr[c] = '\0';
  12356. strcpy(tempstartScheduleStr, sstr);
  12357. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  12358. //**********chargingRateUnit**********/
  12359. c = 0;
  12360. loc = strstr(sLineWord, "chargingRateUnit");
  12361. memset(sstr ,0, sizeof(sstr) );
  12362. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12363. {
  12364. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12365. c++;
  12366. }
  12367. sstr[c] = '\0';
  12368. strcpy(tempchargingRateUnitStr, sstr);
  12369. //**********minChargingRate*******/
  12370. c = 0;
  12371. loc = strstr(sLineWord, "minChargingRate");
  12372. if(loc != NULL)
  12373. {
  12374. memset(sstr ,0, sizeof(sstr) );
  12375. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12376. {
  12377. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12378. c++;
  12379. }
  12380. sstr[c] = '\0';
  12381. tempminChargingRateFloat = atof(sstr);
  12382. }
  12383. else
  12384. {
  12385. tempminChargingRateFloat = 0.0;
  12386. }
  12387. //
  12388. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12389. tp.tm_isdst = -1;
  12390. time_t utc = mktime(&tp);
  12391. time_t t = time(NULL);
  12392. diff_t = difftime(t, utc);
  12393. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12394. //parsing strings to words
  12395. i = 0;
  12396. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12397. loc = loc+3+strlen("chargingSchedulePeriod");
  12398. pch = strtok(loc ,"{");
  12399. while (pch != NULL)
  12400. {
  12401. strcpy(SchedulePeriodList[i], pch);
  12402. pch = strtok (NULL, "{");
  12403. i = i + 1;
  12404. }
  12405. n_SchedulePeriods = i;
  12406. for(int i=0;i<n_SchedulePeriods;i++)
  12407. {
  12408. //*************startPeriod****************/
  12409. c = 0;
  12410. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12411. memset(sstr ,0, sizeof(sstr) );
  12412. while (loc[strlen("startPeriod")+2+c] != ',')
  12413. {
  12414. sstr[c] = loc[strlen("startPeriod")+2+c];
  12415. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12416. c++;
  12417. }
  12418. sstr[c] = '\0';
  12419. tempStartPeriodInt = atoi(sstr);
  12420. //*************limit****************/
  12421. c = 0;
  12422. loc = strstr(SchedulePeriodList[i], "limit");
  12423. memset(sstr ,0, sizeof(sstr) );
  12424. while (loc[strlen("limit")+2+c] != ',')
  12425. {
  12426. sstr[c] = loc[strlen("limit")+2+c];
  12427. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12428. c++;
  12429. }
  12430. sstr[c] = '\0';
  12431. tempLimitInt = atof(sstr);
  12432. //*************numberPhases****************/
  12433. c = 0;
  12434. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12435. memset(sstr ,0, sizeof(sstr) );
  12436. while (loc[strlen("numberPhases")+2+c] != '}')
  12437. {
  12438. sstr[c] = loc[strlen("numberPhases")+2+c];
  12439. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12440. c++;
  12441. }
  12442. sstr[c] = '\0';
  12443. tempNumberPhasesInt = atoi(sstr);
  12444. if(j == 0)
  12445. {
  12446. ChargePointMaxProfile.Duration = tempdurationInt;
  12447. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  12448. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  12449. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12450. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12451. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12452. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  12453. ChargePointMaxProfile_TEMP.TransactionId = 0;
  12454. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12455. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12456. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12457. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12458. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12459. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12460. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12461. }
  12462. }
  12463. if(MinChargingRate < tempminChargingRateFloat)
  12464. {
  12465. MinChargingRate = tempminChargingRateFloat;
  12466. }
  12467. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12468. if(confirmPeriods < n_SchedulePeriods)
  12469. {
  12470. confirmPeriods = n_SchedulePeriods;
  12471. }
  12472. j = j + 1;
  12473. }
  12474. fclose(fptr1);
  12475. }
  12476. }// the end of access file ChargePointMaxProfile
  12477. //****************************TxDefaultProfile************************************************/
  12478. switch(gunindex + 1)
  12479. {
  12480. case 0:
  12481. break;
  12482. case 1:
  12483. strcpy(fname, TxDefaultProfile_1_JSON );
  12484. break;
  12485. case 2:
  12486. strcpy(fname, TxDefaultProfile_2_JSON );
  12487. break;
  12488. default:
  12489. strcpy(fname, TxDefaultProfile_1_JSON );
  12490. break;
  12491. }
  12492. TxDefaultProfileFileIsNull=TRUE;
  12493. if((access(fname,F_OK))!=-1)
  12494. {
  12495. fptr1 = fopen(fname, "r");
  12496. c = 0;
  12497. c = fgetc(fptr1);
  12498. //DEBUG_INFO("c:%d\n",c);
  12499. rewind(fptr1);
  12500. if(c == EOF)
  12501. {
  12502. DEBUG_INFO("\n End of file reached.");
  12503. TxDefaultProfileFileIsNull=TRUE;
  12504. fclose(fptr1);
  12505. }
  12506. else
  12507. {
  12508. TxDefaultProfileFileIsNull=FALSE;
  12509. while(fscanf(fptr1, "%s", word) != EOF)
  12510. {
  12511. if(strcmp(word, "chargingProfileId") == 0)
  12512. {
  12513. n_chargingProfile = n_chargingProfile + 1;
  12514. }
  12515. }
  12516. rewind(fptr1);
  12517. //search Charging Profile Element
  12518. int i = 0;
  12519. int j = 0;
  12520. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12521. #if 0
  12522. /***********connectorId****************/
  12523. c = 0;
  12524. loc = strstr(sLineWord, "connectorId");
  12525. memset(sstr ,0, sizeof(sstr) );
  12526. while (loc[strlen("connectorId")+2+c] != ',')
  12527. {
  12528. sstr[c] = loc[strlen("connectorId")+2+c];
  12529. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12530. c++;
  12531. }
  12532. sstr[c] = '\0';
  12533. tempconnectorIdInt = atoi(sstr);
  12534. #endif
  12535. //***********chargingProfileId**************/
  12536. c = 0;
  12537. loc = strstr(sLineWord, "chargingProfileId");
  12538. //DEBUG_INFO("loc=%s\n",loc);
  12539. memset(sstr ,0, sizeof(sstr) );
  12540. if(loc != NULL)
  12541. {
  12542. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12543. {
  12544. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12545. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12546. c++;
  12547. }
  12548. sstr[c] = '\0';
  12549. tempchargingProfileId = atoi(sstr);
  12550. }
  12551. else
  12552. {
  12553. tempchargingProfileId = 0;
  12554. }
  12555. //***********stackLevel**************/
  12556. c = 0;
  12557. loc = strstr(sLineWord, "stackLevel");
  12558. //DEBUG_INFO("loc=%s\n",loc);
  12559. memset(sstr ,0, sizeof(sstr) );
  12560. if(loc != NULL)
  12561. {
  12562. while (loc[2+strlen("stackLevel")+c] != '\"')
  12563. {
  12564. sstr[c] = loc[2+strlen("stackLevel")+c];
  12565. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12566. c++;
  12567. }
  12568. sstr[c] = '\0';
  12569. tempstackLevel = atoi(sstr);
  12570. }
  12571. else
  12572. {
  12573. tempstackLevel = 0;
  12574. }
  12575. //***********chargingProfilePurpose **************/
  12576. c = 0;
  12577. loc = strstr(sLineWord, "chargingProfilePurpose");
  12578. //DEBUG_INFO("loc=%s\n",loc);
  12579. memset(sstr ,0, sizeof(sstr) );
  12580. if(loc != NULL)
  12581. {
  12582. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12583. {
  12584. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12585. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12586. c++;
  12587. }
  12588. sstr[c] = '\0';
  12589. strcpy(tempchargingProfilePurposeStr,sstr);
  12590. }
  12591. else
  12592. {
  12593. strcpy(tempchargingProfilePurposeStr,"");
  12594. }
  12595. //***********chargingProfileKind **************/
  12596. c = 0;
  12597. loc = strstr(sLineWord, "chargingProfileKind");
  12598. //DEBUG_INFO("loc=%s\n",loc);
  12599. memset(sstr ,0, sizeof(sstr) );
  12600. if(loc != NULL)
  12601. {
  12602. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12603. {
  12604. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12605. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12606. c++;
  12607. }
  12608. sstr[c] = '\0';
  12609. strcpy(tempchargingProfileKindStr,sstr);
  12610. }
  12611. else
  12612. {
  12613. strcpy(tempchargingProfileKindStr,"");
  12614. }
  12615. //***********recurrencyKind **************/
  12616. c = 0;
  12617. loc = strstr(sLineWord, "recurrencyKind");
  12618. //DEBUG_INFO("loc=%s\n",loc);
  12619. memset(sstr ,0, sizeof(sstr) );
  12620. if(loc != NULL)
  12621. {
  12622. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12623. {
  12624. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12625. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12626. c++;
  12627. }
  12628. sstr[c] = '\0';
  12629. strcpy(temprecurrencyKindStr,sstr);
  12630. }
  12631. else
  12632. {
  12633. strcpy(temprecurrencyKindStr,"");
  12634. }
  12635. //***********validFrom**************/
  12636. c = 0;
  12637. loc = strstr(sLineWord, "validFrom");
  12638. if(loc != NULL)
  12639. {
  12640. memset(sstr ,0, sizeof(sstr) );
  12641. while (loc[3+strlen("validFrom")+c] != '\"')
  12642. {
  12643. sstr[c] = loc[3+strlen("validFrom")+c];
  12644. c++;
  12645. }
  12646. sstr[c] = '\0';
  12647. strcpy(tempvalidFromStr,sstr);
  12648. }
  12649. else
  12650. {
  12651. strcpy(tempvalidFromStr,"");
  12652. }
  12653. //***********validFrom**************/
  12654. c = 0;
  12655. loc = strstr(sLineWord, "duration");
  12656. if(loc != NULL)
  12657. {
  12658. memset(sstr ,0, sizeof(sstr) );
  12659. while (loc[2+strlen("duration")+c] != ',')
  12660. {
  12661. sstr[c] = loc[2+strlen("duration")+c];
  12662. c++;
  12663. }
  12664. sstr[c] = '\0';
  12665. tempdurationInt = atoi(sstr);
  12666. }
  12667. else
  12668. {
  12669. tempdurationInt = 0;
  12670. }
  12671. //**********startSchedule**********/
  12672. c = 0;
  12673. loc = strstr(sLineWord, "startSchedule");
  12674. memset(sstr ,0, sizeof(sstr) );
  12675. while (loc[3+strlen("startSchedule")+c] != '\"')
  12676. {
  12677. sstr[c] = loc[3+strlen("startSchedule")+c];
  12678. c++;
  12679. }
  12680. sstr[c] = '\0';
  12681. strcpy(tempstartScheduleStr, sstr);
  12682. strcpy(TxDefaultProfileScheduleStr, sstr);
  12683. //**********chargingRateUnit**********/
  12684. c = 0;
  12685. loc = strstr(sLineWord, "chargingRateUnit");
  12686. memset(sstr ,0, sizeof(sstr) );
  12687. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12688. {
  12689. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12690. c++;
  12691. }
  12692. sstr[c] = '\0';
  12693. strcpy(tempchargingRateUnitStr, sstr);
  12694. //**********minChargingRate*******/
  12695. c = 0;
  12696. loc = strstr(sLineWord, "minChargingRate");
  12697. if(loc != NULL)
  12698. {
  12699. memset(sstr ,0, sizeof(sstr) );
  12700. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12701. {
  12702. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12703. c++;
  12704. }
  12705. sstr[c] = '\0';
  12706. tempminChargingRateFloat = atof(sstr);
  12707. }
  12708. else
  12709. {
  12710. tempminChargingRateFloat = 0.0;
  12711. }
  12712. //
  12713. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12714. tp.tm_isdst = -1;
  12715. time_t utc = mktime(&tp);
  12716. time_t t = time(NULL);
  12717. diff_t = difftime(t, utc);
  12718. printf("diff between startScheduleStr and now =%f\n",diff_t);
  12719. //parsing strings to words
  12720. i = 0;
  12721. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12722. loc = loc+3+strlen("chargingSchedulePeriod");
  12723. pch = strtok(loc ,"{");
  12724. while (pch != NULL)
  12725. {
  12726. strcpy(SchedulePeriodList[i], pch);
  12727. pch = strtok (NULL, "{");
  12728. i = i + 1;
  12729. }
  12730. n_SchedulePeriods = i;
  12731. for(int i=0;i<n_SchedulePeriods;i++)
  12732. {
  12733. //*************startPeriod****************/
  12734. c = 0;
  12735. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12736. memset(sstr ,0, sizeof(sstr) );
  12737. while (loc[strlen("startPeriod")+2+c] != ',')
  12738. {
  12739. sstr[c] = loc[strlen("startPeriod")+2+c];
  12740. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12741. c++;
  12742. }
  12743. sstr[c] = '\0';
  12744. tempStartPeriodInt = atoi(sstr);
  12745. //*************limit****************/
  12746. c = 0;
  12747. loc = strstr(SchedulePeriodList[i], "limit");
  12748. memset(sstr ,0, sizeof(sstr) );
  12749. while (loc[strlen("limit")+2+c] != ',')
  12750. {
  12751. sstr[c] = loc[strlen("limit")+2+c];
  12752. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12753. c++;
  12754. }
  12755. sstr[c] = '\0';
  12756. tempLimitInt = atof(sstr);
  12757. //*************numberPhases****************/
  12758. c = 0;
  12759. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12760. memset(sstr ,0, sizeof(sstr) );
  12761. while (loc[strlen("numberPhases")+2+c] != '}')
  12762. {
  12763. sstr[c] = loc[strlen("numberPhases")+2+c];
  12764. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12765. c++;
  12766. }
  12767. sstr[c] = '\0';
  12768. tempNumberPhasesInt = atoi(sstr);
  12769. if(j == 0)
  12770. {
  12771. TxDefaultProfile.Duration = tempdurationInt;
  12772. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  12773. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  12774. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12775. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12776. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12777. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  12778. TxDefaultProfile_TEMP.TransactionId = 0;
  12779. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  12780. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12781. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12782. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12783. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12784. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12785. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12786. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12787. }
  12788. else
  12789. {
  12790. //other stack level charging Profile
  12791. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  12792. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  12793. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  12794. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  12795. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  12796. }
  12797. }
  12798. if(MinChargingRate < tempminChargingRateFloat)
  12799. {
  12800. MinChargingRate = tempminChargingRateFloat;
  12801. }
  12802. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12803. if(confirmPeriods < n_SchedulePeriods)
  12804. confirmPeriods = n_SchedulePeriods;
  12805. j = j + 1;
  12806. }
  12807. fclose(fptr1);
  12808. //Stacking Charging Profiles
  12809. for(int l=0; l <(j-1) ;l++)
  12810. {
  12811. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  12812. {
  12813. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  12814. {
  12815. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  12816. {
  12817. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  12818. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  12819. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  12820. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12821. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12822. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12823. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12824. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12825. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12826. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12827. }
  12828. else
  12829. {
  12830. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12831. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12832. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12833. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12834. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12835. }
  12836. }
  12837. }
  12838. }
  12839. //end of Stacking Charging Profiles
  12840. }
  12841. }// the end of ACCESS TxDefaultProfile
  12842. //****************************TxProfile************************************************/
  12843. switch(gunindex + 1)
  12844. {
  12845. case 0:
  12846. break;
  12847. case 1:
  12848. strcpy(fname, TxProfile_1_JSON );
  12849. break;
  12850. case 2:
  12851. strcpy(fname, TxProfile_2_JSON );
  12852. break;
  12853. default:
  12854. strcpy(fname, TxProfile_1_JSON );
  12855. break;
  12856. }
  12857. TxProfileIsNull=TRUE;
  12858. if((access(fname,F_OK))!=-1)
  12859. {
  12860. fptr1 = fopen(fname, "r");
  12861. c = 0;
  12862. c = fgetc(fptr1);
  12863. //DEBUG_INFO("c:%d\n",c);
  12864. rewind(fptr1);
  12865. if(c == EOF)
  12866. {
  12867. DEBUG_INFO("\n End of file reached.");
  12868. TxProfileIsNull=TRUE;
  12869. fclose(fptr1);
  12870. }
  12871. else
  12872. {
  12873. TxProfileIsNull=FALSE;
  12874. while(fscanf(fptr1, "%s", word) != EOF)
  12875. {
  12876. if(strcmp(word, "chargingProfileId") == 0)
  12877. {
  12878. n_chargingProfile = n_chargingProfile + 1;
  12879. }
  12880. }
  12881. rewind(fptr1);
  12882. //search Charging Profile Element
  12883. int i= 0;
  12884. int j= 0;
  12885. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12886. #if 0
  12887. /***********connectorId****************/
  12888. c = 0;
  12889. loc = strstr(sLineWord, "connectorId");
  12890. memset(sstr ,0, sizeof(sstr) );
  12891. while (loc[strlen("connectorId")+2+c] != ',')
  12892. {
  12893. sstr[c] = loc[strlen("connectorId")+2+c];
  12894. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12895. c++;
  12896. }
  12897. sstr[c] = '\0';
  12898. tempconnectorIdInt = atoi(sstr);
  12899. #endif
  12900. //***********chargingProfileId**************/
  12901. c = 0;
  12902. loc = strstr(sLineWord, "chargingProfileId");
  12903. memset(sstr ,0, sizeof(sstr) );
  12904. if(loc != NULL)
  12905. {
  12906. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12907. {
  12908. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12909. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12910. c++;
  12911. }
  12912. sstr[c] = '\0';
  12913. tempchargingProfileId = atoi(sstr);
  12914. }
  12915. else
  12916. {
  12917. tempchargingProfileId = 0;
  12918. }
  12919. //***********transactionId **************/
  12920. c = 0;
  12921. loc = strstr(sLineWord, "transactionId");
  12922. //DEBUG_INFO("loc=%s\n",loc);
  12923. memset(sstr ,0, sizeof(sstr) );
  12924. if(loc != NULL)
  12925. {
  12926. while (loc[2+strlen("transactionId")+c] != '\"')
  12927. {
  12928. sstr[c] = loc[2+strlen("transactionId")+c];
  12929. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12930. c++;
  12931. }
  12932. sstr[c] = '\0';
  12933. temptransactionId = atoi(sstr);
  12934. }
  12935. else
  12936. {
  12937. temptransactionId = 0;
  12938. }
  12939. //***********stackLevel**************/
  12940. c = 0;
  12941. loc = strstr(sLineWord, "stackLevel");
  12942. //DEBUG_INFO("loc=%s\n",loc);
  12943. memset(sstr ,0, sizeof(sstr) );
  12944. if(loc != NULL)
  12945. {
  12946. while (loc[2+strlen("stackLevel")+c] != '\"')
  12947. {
  12948. sstr[c] = loc[2+strlen("stackLevel")+c];
  12949. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12950. c++;
  12951. }
  12952. sstr[c] = '\0';
  12953. tempstackLevel = atoi(sstr);
  12954. }
  12955. else
  12956. {
  12957. tempstackLevel = 0;
  12958. }
  12959. //***********chargingProfilePurpose **************/
  12960. c = 0;
  12961. loc = strstr(sLineWord, "chargingProfilePurpose");
  12962. //DEBUG_INFO("loc=%s\n",loc);
  12963. memset(sstr ,0, sizeof(sstr) );
  12964. if(loc != NULL)
  12965. {
  12966. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12967. {
  12968. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12969. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12970. c++;
  12971. }
  12972. sstr[c] = '\0';
  12973. strcpy(tempchargingProfilePurposeStr,sstr);
  12974. }
  12975. else
  12976. {
  12977. strcpy(tempchargingProfilePurposeStr,"");
  12978. }
  12979. //***********chargingProfileKind **************/
  12980. c = 0;
  12981. loc = strstr(sLineWord, "chargingProfileKind");
  12982. //DEBUG_INFO("loc=%s\n",loc);
  12983. memset(sstr ,0, sizeof(sstr) );
  12984. if(loc != NULL)
  12985. {
  12986. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12987. {
  12988. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12989. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12990. c++;
  12991. }
  12992. sstr[c] = '\0';
  12993. strcpy(tempchargingProfileKindStr,sstr);
  12994. }
  12995. else
  12996. {
  12997. strcpy(tempchargingProfileKindStr,"");
  12998. }
  12999. //***********recurrencyKind **************/
  13000. c = 0;
  13001. loc = strstr(sLineWord, "recurrencyKind");
  13002. //DEBUG_INFO("loc=%s\n",loc);
  13003. memset(sstr ,0, sizeof(sstr) );
  13004. if(loc != NULL)
  13005. {
  13006. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13007. {
  13008. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13009. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13010. c++;
  13011. }
  13012. sstr[c] = '\0';
  13013. strcpy(temprecurrencyKindStr,sstr);
  13014. }
  13015. else
  13016. {
  13017. strcpy(temprecurrencyKindStr,"");
  13018. }
  13019. //***********validFrom**************/
  13020. c = 0;
  13021. loc = strstr(sLineWord, "validFrom");
  13022. if(loc != NULL)
  13023. {
  13024. memset(sstr ,0, sizeof(sstr) );
  13025. while (loc[3+strlen("validFrom")+c] != '\"')
  13026. {
  13027. sstr[c] = loc[3+strlen("validFrom")+c];
  13028. c++;
  13029. }
  13030. sstr[c] = '\0';
  13031. strcpy(tempvalidFromStr,sstr);
  13032. }
  13033. else
  13034. {
  13035. strcpy(tempvalidFromStr,"");
  13036. }
  13037. //***********duration**************/
  13038. c = 0;
  13039. loc = strstr(sLineWord, "duration");
  13040. //DEBUG_INFO("loc=%s\n",loc);
  13041. memset(sstr ,0, sizeof(sstr) );
  13042. if(loc != NULL)
  13043. {
  13044. while (loc[2+strlen("duration")+c] != '\"')
  13045. {
  13046. sstr[c] = loc[2+strlen("duration")+c];
  13047. c++;
  13048. }
  13049. sstr[c] = '\0';
  13050. tempdurationInt = atoi(sstr);
  13051. }
  13052. else
  13053. {
  13054. tempdurationInt = 0;
  13055. }
  13056. //**********startSchedule**********/
  13057. c = 0;
  13058. loc = strstr(sLineWord, "startSchedule");
  13059. memset(sstr ,0, sizeof(sstr) );
  13060. while (loc[3+strlen("startSchedule")+c] != '\"')
  13061. {
  13062. sstr[c] = loc[3+strlen("startSchedule")+c];
  13063. c++;
  13064. }
  13065. sstr[c] = '\0';
  13066. strcpy(tempstartScheduleStr, sstr);
  13067. strcpy(TxProfileScheduleStr, sstr);
  13068. //**********chargingRateUnit**********/
  13069. c = 0;
  13070. loc = strstr(sLineWord, "chargingRateUnit");
  13071. memset(sstr ,0, sizeof(sstr) );
  13072. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13073. {
  13074. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13075. c++;
  13076. }
  13077. sstr[c] = '\0';
  13078. strcpy(tempchargingRateUnitStr, sstr);
  13079. //**********minChargingRate*******/
  13080. c = 0;
  13081. loc = strstr(sLineWord, "minChargingRate");
  13082. if(loc != NULL)
  13083. {
  13084. memset(sstr ,0, sizeof(sstr) );
  13085. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13086. {
  13087. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13088. c++;
  13089. }
  13090. sstr[c] = '\0';
  13091. tempminChargingRateFloat = atof(sstr);
  13092. }
  13093. else
  13094. {
  13095. tempminChargingRateFloat = 0.0;
  13096. }
  13097. //
  13098. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13099. tp.tm_isdst = -1;
  13100. time_t utc = mktime(&tp);
  13101. time_t t = time(NULL);
  13102. diff_t = difftime(t, utc);
  13103. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13104. //parsing strings to words
  13105. i = 0;
  13106. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13107. loc = loc+3+strlen("chargingSchedulePeriod");
  13108. pch = strtok(loc ,"{");
  13109. while (pch != NULL)
  13110. {
  13111. strcpy(SchedulePeriodList[i], pch);
  13112. pch = strtok (NULL, "{");
  13113. i = i + 1;
  13114. }
  13115. n_SchedulePeriods = i;
  13116. for(int i=0;i<n_SchedulePeriods;i++)
  13117. {
  13118. //*************startPeriod****************/
  13119. c = 0;
  13120. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13121. memset(sstr ,0, sizeof(sstr) );
  13122. while (loc[strlen("startPeriod")+2+c] != ',')
  13123. {
  13124. sstr[c] = loc[strlen("startPeriod")+2+c];
  13125. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13126. c++;
  13127. }
  13128. sstr[c] = '\0';
  13129. tempStartPeriodInt = atoi(sstr);
  13130. //*************limit****************/
  13131. c = 0;
  13132. loc = strstr(SchedulePeriodList[i], "limit");
  13133. memset(sstr ,0, sizeof(sstr) );
  13134. while (loc[strlen("limit")+2+c] != ',')
  13135. {
  13136. sstr[c] = loc[strlen("limit")+2+c];
  13137. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13138. c++;
  13139. }
  13140. sstr[c] = '\0';
  13141. tempLimitInt = atof(sstr);
  13142. //*************numberPhases****************/
  13143. c = 0;
  13144. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13145. memset(sstr ,0, sizeof(sstr) );
  13146. while (loc[strlen("numberPhases")+2+c] != '}')
  13147. {
  13148. sstr[c] = loc[strlen("numberPhases")+2+c];
  13149. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13150. c++;
  13151. }
  13152. sstr[c] = '\0';
  13153. tempNumberPhasesInt = atoi(sstr);
  13154. //TxProfile.Duration = durationInt;
  13155. TxProfile.TotalPeriod = n_SchedulePeriods;
  13156. TxProfile.Period[i].Limit = tempLimitInt;
  13157. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13158. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13159. }
  13160. if(MinChargingRate < tempminChargingRateFloat)
  13161. {
  13162. MinChargingRate = tempminChargingRateFloat;
  13163. }
  13164. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13165. if(confirmPeriods < n_SchedulePeriods)
  13166. confirmPeriods = n_SchedulePeriods;
  13167. if(j == 0)
  13168. {
  13169. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13170. TxProfile_TEMP.StackLevel = tempstackLevel;
  13171. TxProfile_TEMP.TransactionId = 0;
  13172. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13173. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13174. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13175. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13176. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13177. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13178. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13179. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13180. }
  13181. }
  13182. fclose(fptr1);
  13183. }
  13184. }// the end of ACCESS TxProfile
  13185. //CompositeSchedule
  13186. int period=0;
  13187. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13188. {
  13189. //TxProfile
  13190. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13191. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13192. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13193. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13194. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13195. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13196. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13197. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13198. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13199. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13200. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13201. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13202. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13203. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13204. {
  13205. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13206. {
  13207. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13208. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13209. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13210. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13211. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13212. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13213. period = period + 1;
  13214. }
  13215. else
  13216. {
  13217. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13218. {
  13219. }
  13220. else
  13221. {
  13222. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13223. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13224. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13225. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13226. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13227. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13228. period = period + 1;
  13229. }
  13230. }
  13231. }
  13232. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13233. {
  13234. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  13235. {
  13236. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13237. {
  13238. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13239. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13240. }
  13241. else
  13242. {
  13243. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13244. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13245. }
  13246. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13247. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13248. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13249. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13250. period = period + 1;
  13251. }
  13252. }
  13253. }
  13254. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13255. {
  13256. //TxDefaultProfile
  13257. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13258. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13259. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13260. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13261. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  13262. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13263. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13264. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13265. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13266. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13267. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13268. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13269. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13270. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13271. {
  13272. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13273. {
  13274. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13275. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13276. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13277. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13278. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13279. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13280. period = period + 1;
  13281. }
  13282. else
  13283. {
  13284. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13285. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13286. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13287. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13288. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13289. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13290. period = period + 1;
  13291. }
  13292. }
  13293. }
  13294. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  13295. {
  13296. //TxDefaultProfile
  13297. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13298. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13299. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13300. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13301. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  13302. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13303. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13304. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13305. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13306. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13307. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13308. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13309. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13310. {
  13311. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13312. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13313. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13314. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13315. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13316. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13317. period = period + 1;
  13318. }
  13319. }
  13320. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13321. {
  13322. //ChargePointMaxProfile
  13323. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  13324. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  13325. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13326. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  13327. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  13328. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13329. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  13330. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  13331. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  13332. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  13333. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  13334. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  13335. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  13336. {
  13337. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  13338. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  13339. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  13340. period = period + 1;
  13341. }
  13342. }
  13343. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  13344. {
  13345. //TxProfile
  13346. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13347. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13348. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13349. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13350. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13351. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13352. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13353. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13354. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13355. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13356. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13357. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13358. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13359. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13360. {
  13361. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  13362. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  13363. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  13364. }
  13365. }
  13366. confirmPeriods = period;
  13367. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  13368. 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,"
  13369. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  13370. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  13371. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  13372. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  13373. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  13374. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  13375. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  13376. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  13377. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  13378. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  13379. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  13380. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  13381. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  13382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  13383. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  13384. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  13385. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  13386. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  13387. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  13388. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  13389. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  13390. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  13391. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  13392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  13393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  13394. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  13395. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  13396. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  13397. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  13398. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  13399. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  13400. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  13401. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  13402. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  13403. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  13404. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  13405. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  13406. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  13407. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  13408. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  13409. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  13410. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  13411. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  13412. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  13413. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  13414. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  13415. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  13416. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  13417. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  13418. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  13419. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  13420. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  13421. }
  13422. void LWS_Send(char * str)
  13423. {
  13424. //=====================================================
  13425. // Check InternetConn 0: disconnected, 1: connected
  13426. //====================================================
  13427. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13428. {
  13429. DEBUG_INFO("\n offline now !!!\n");
  13430. return;
  13431. }
  13432. pthread_mutex_lock(&lock);
  13433. memset(SendBuffer,0,SendBufLen);
  13434. sprintf((char *)SendBuffer, "%s", str);
  13435. pthread_mutex_unlock(&lock);
  13436. lws_callback_on_writable(wsi_client);
  13437. lws_service(context, 10000);//timeout_ms
  13438. }