MessageHandler.c 594 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555
  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 HeartBeatCountPerHour = 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 void ChageWebSocketPingInterval(int WebSocketPingInterval);
  157. extern pthread_mutex_t mutex1;
  158. extern struct Charger_Info Charger;
  159. extern sqlite3 *db;
  160. int TransactionMessageAttemptsGet(void);
  161. int TransactionMessageRetryIntervalGet(void);
  162. int GetOcppConnStatus(void);
  163. void SetOcppConnStatus(uint8_t status);
  164. int updateSetting(char *key, char *value);
  165. int setKeyValue(char *key, char *value);
  166. void OCPP_get_TableAuthlocalAllData(void);
  167. void processUnkownKey(void);
  168. struct StructOCPPMeterValue
  169. {
  170. unsigned char TimeStamp[28];
  171. struct StructSampledValue SampledValue[10];
  172. };
  173. struct ClientTime
  174. {
  175. unsigned int Heartbeat;
  176. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  177. unsigned int StartTransaction;
  178. unsigned int StopTransaction;
  179. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  180. }clientTime;
  181. typedef union
  182. {
  183. //Operations Initiated by Central System
  184. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  185. struct
  186. {
  187. //CsMsgValue[0]
  188. unsigned char StatusNotificationReq :1; //bit 0,
  189. unsigned char StatusNotificationConf :1; //bit 0,
  190. unsigned char :6; //bit 2~7
  191. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  192. }CpinitiateMsg;
  193. CpinitiateMsg cpinitateMsg;
  194. //==========================================
  195. // Init all Enumeration & Mapping String
  196. //==========================================
  197. /*ChargePointErrorCode*/
  198. typedef enum {
  199. ConnectorLockFailure,
  200. EVCommunicationError,
  201. GroundFailure,
  202. HighTemperature,
  203. InternalError,
  204. LocalListConflict,
  205. NoError,
  206. OtherError,
  207. OverCurrentFailure,
  208. OverVoltage,
  209. PowerMeterFailure,
  210. PowerSwitchFailure,
  211. ReaderFailure,
  212. ResetFailure,
  213. UnderVoltage,
  214. WeakSignal
  215. } ChargePointErrorCode;
  216. #if 0
  217. static char *ChargePointErrorCodeStr[] = {
  218. MACROSTR(ConnectorLockFailure),
  219. MACROSTR(EVCommunicationError),
  220. MACROSTR(GroundFailure),
  221. MACROSTR(HighTemperature),
  222. MACROSTR(InternalError),
  223. MACROSTR(LocalListConflict),
  224. MACROSTR(NoError),
  225. MACROSTR(OtherError),
  226. MACROSTR(OverCurrentFailure),
  227. MACROSTR(OverVoltage),
  228. MACROSTR(PowerMeterFailure),
  229. MACROSTR(PowerSwitchFailure),
  230. MACROSTR(ReaderFailure),
  231. MACROSTR(ResetFailure),
  232. MACROSTR(UnderVoltage),
  233. MACROSTR(WeakSignal)
  234. };
  235. #endif
  236. /*ChargePointStatus*/
  237. typedef enum {
  238. Available =0,
  239. Preparing,
  240. Charging,
  241. SuspendedEVSE,
  242. SuspendedEV,
  243. Finishing,
  244. Reserved,
  245. Unavailable,
  246. Faulted
  247. } ChargePointStatus;
  248. static char * ChargePointStatusStr[] = {
  249. MACROSTR(Available),
  250. MACROSTR(Preparing),
  251. MACROSTR(Charging),
  252. MACROSTR(SuspendedEVSE),
  253. MACROSTR(SuspendedEV),
  254. MACROSTR(Finishing),
  255. MACROSTR(Reserved),
  256. MACROSTR(Unavailable),
  257. MACROSTR(Faulted)
  258. };
  259. /*AvailabilityType*/
  260. typedef enum {
  261. RegistrationStatus_Accepted,
  262. RegistrationStatus_Pending,
  263. RegistrationStatus_Rejected
  264. } RegistrationStatus;
  265. static char *RegistrationStatusStr[] = {
  266. MACROSTR(Accepted),
  267. MACROSTR(Pending),
  268. MACROSTR(Rejected)
  269. };
  270. /*AvailabilityType*/
  271. typedef enum {
  272. Inoperative,
  273. Operative
  274. } AvailabilityType;
  275. static char *AvailabilityTypeStr[] = {
  276. MACROSTR(Inoperative),
  277. MACROSTR(Operative)
  278. };
  279. /*AvailabilityStatus*/
  280. typedef enum {
  281. Accepted,
  282. Rejected,
  283. Scheduled
  284. } AvailabilityStatus;
  285. static char *AvailabilityStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected),
  288. MACROSTR(Scheduled)
  289. };
  290. /*ConfigurationStatus*/
  291. typedef enum {
  292. ConfigurationStatus_Accepted,
  293. ConfigurationStatus_Rejected,
  294. RebootRequired,
  295. NotSupported
  296. } ConfigurationStatus;
  297. static char *ConfigurationStatusStr[] = {
  298. MACROSTR(Accepted),
  299. MACROSTR(Rejected),
  300. MACROSTR(RebootRequired),
  301. MACROSTR(NotSupported)
  302. };
  303. /*ClearCacheStatus*/
  304. typedef enum {
  305. ClearCacheStatus_Accepted,
  306. ClearCacheStatus_Rejected
  307. } ClearCacheStatus;
  308. static char *ClearCacheStatusStr[] = {
  309. MACROSTR(Accepted),
  310. MACROSTR(Rejected)
  311. };
  312. /*ChargingProfilePurposeType*/
  313. typedef enum {
  314. ChargePointMaxProfile,
  315. TxDefaultProfile,
  316. TxProfile
  317. } ChargingProfilePurposeType;
  318. static char *ChargingProfilePurposeTypeStr[] = {
  319. MACROSTR(ChargePointMaxProfile),
  320. MACROSTR(TxDefaultProfile),
  321. MACROSTR(TxProfile)
  322. };
  323. /*ChargingProfileStatus*/
  324. typedef enum {
  325. ChargingProfileStatus_Accepted,
  326. ChargingProfileStatus_Rejected,
  327. ChargingProfileStatus_NotSupported
  328. } ChargingProfileStatus;
  329. static char *ChargingProfileStatusStr[] = {
  330. MACROSTR(Accepted),
  331. MACROSTR(Rejected),
  332. MACROSTR(NotSupported)
  333. };
  334. /*ClearChargingProfileStatus*/
  335. typedef enum {
  336. ClearChargingProfileStatus_Accepted,
  337. ClearChargingProfileStatus_Unknown
  338. } ClearChargingProfileStatus;
  339. static char *ClearChargingProfileStatusStr[] = {
  340. MACROSTR(Accepted),
  341. MACROSTR(Unknown)
  342. };
  343. /*GetCompositeScheduleStatus*/
  344. typedef enum {
  345. GetCompositeScheduleStatus_Accepted,
  346. GetCompositeScheduleStatus_Rejected
  347. } GetCompositeScheduleStatus;
  348. static char *GetCompositeScheduleStatusStr[] = {
  349. MACROSTR(Accepted),
  350. MACROSTR(Rejected)
  351. };
  352. /*ChargingRateUnitType*/
  353. typedef enum {
  354. ChargingRateUnitType_W,
  355. ChargingRateUnitType_A
  356. } ChargingRateUnitType;
  357. /*AuthorizationStatus*/
  358. typedef enum {
  359. AuthorizationStatus_Accepted ,
  360. AuthorizationStatus_Blocked ,
  361. AuthorizationStatus_Expired ,
  362. AuthorizationStatus_Invalid ,
  363. AuthorizationStatus_ConcurrentTx
  364. } AuthorizationStatus;
  365. /*UpdateType*/
  366. typedef enum {
  367. Differential ,
  368. Full
  369. } UpdateType;
  370. static char *UpdateTypeStr[] = {
  371. MACROSTR(Differential),
  372. MACROSTR(Full)
  373. };
  374. /*UpdateStatus*/
  375. typedef enum {
  376. UpdateStatus_Accepted ,
  377. UpdateStatus_Failed ,
  378. UpdateStatus_NotSupported ,
  379. UpdateStatus_VersionMismatch
  380. } UpdateStatus;
  381. static char *UpdateStatusStr[] = {
  382. MACROSTR(Accepted),
  383. MACROSTR(Failed),
  384. MACROSTR(NotSupported),
  385. MACROSTR(VersionMismatch)
  386. };
  387. /*RemoteStartStopStatus*/
  388. typedef enum {
  389. RemoteStartStopStatus_Accepted,
  390. RemoteStartStopStatus_Rejected
  391. } RemoteStartStopStatus;
  392. static char *RemoteStartStopStatusStr[] = {
  393. MACROSTR(Accepted),
  394. MACROSTR(Rejected)
  395. };
  396. /*ReservationStatus*/
  397. typedef enum {
  398. ReservationStatus_Accepted,
  399. ReservationStatus_Faulted,
  400. ReservationStatus_Occupied,
  401. ReservationStatus_Rejected,
  402. ReservationStatus_Unavailable
  403. } ReservationStatus;
  404. static char *ReservationStatusStr[] = {
  405. MACROSTR(Accepted),
  406. MACROSTR(Faulted),
  407. MACROSTR(Occupied),
  408. MACROSTR(Rejected),
  409. MACROSTR(Unavailable)
  410. };
  411. /*ResetType*/
  412. typedef enum {
  413. Hard,
  414. Soft
  415. } ResetType;
  416. static char *ResetTypeStr[] = {
  417. MACROSTR(Hard),
  418. MACROSTR(Soft)
  419. };
  420. /*ResetStatus*/
  421. typedef enum {
  422. ResetStatus_Accepted,
  423. ResetStatus_Rejected
  424. } ResetStatus;
  425. static char *ResetStatusStr[] = {
  426. MACROSTR(Accepted),
  427. MACROSTR(Rejected)
  428. };
  429. /*DiagnosticsStatus*/
  430. typedef enum {
  431. DiagnosticsStatus_Idle,
  432. DiagnosticsStatus_Uploaded,
  433. DiagnosticsStatus_UploadFailed,
  434. DiagnosticsStatus_Uploading
  435. } DiagnosticsStatus;
  436. static char * DiagnosticsStatusStr[] = {
  437. MACROSTR(Idle),
  438. MACROSTR(Uploaded),
  439. MACROSTR(UploadFailed),
  440. MACROSTR(Uploading)
  441. };
  442. /*FirmwareStatus*/
  443. typedef enum {
  444. FirmwareStatus_Downloaded,
  445. FirmwareStatus_DownloadFailed,
  446. FirmwareStatus_Downloading,
  447. FirmwareStatus_Idle,
  448. FirmwareStatus_InstallationFailed,
  449. FirmwareStatus_Installing,
  450. FirmwareStatus_Installed
  451. } FirmwareStatus;
  452. static char * FirmwareStatusStr[] = {
  453. MACROSTR(Downloaded),
  454. MACROSTR(DownloadFailed),
  455. MACROSTR(Downloading),
  456. MACROSTR(Idle),
  457. MACROSTR(InstallationFailed),
  458. MACROSTR(Installing),
  459. MACROSTR(Installed)
  460. };
  461. /*MessageTrigger*/
  462. typedef enum {
  463. BootNotification,
  464. DiagnosticsStatusNotification,
  465. FirmwareStatusNotification,
  466. Heartbeat,
  467. MeterValues,
  468. StatusNotification
  469. } MessageTrigger;
  470. static char * MessageTriggerStr[] = {
  471. MACROSTR(BootNotification),
  472. MACROSTR(DiagnosticsStatusNotification),
  473. MACROSTR(FirmwareStatusNotification),
  474. MACROSTR(Heartbeat),
  475. MACROSTR(MeterValues),
  476. MACROSTR(StatusNotification)
  477. };
  478. /*TriggerMessageStatus*/
  479. typedef enum {
  480. TriggerMessageStatus_Accepted ,
  481. TriggerMessageStatus_Rejected ,
  482. TriggerMessageStatus_NotImplemented
  483. } TriggerMessageStatus;
  484. static char * TriggerMessageStatusStr[] = {
  485. MACROSTR(Accepted),
  486. MACROSTR(Rejected),
  487. MACROSTR(NotImplemented)
  488. };
  489. /*UnlockStatus*/
  490. typedef enum {
  491. Unlocked,
  492. UnlockFailed,
  493. UnlockStatus_NotSupported
  494. } UnlockStatus;
  495. static char * UnlockStatusStr[] = {
  496. MACROSTR(Unlocked),
  497. MACROSTR(UnlockFailed),
  498. MACROSTR(NotSupported)
  499. };
  500. /*StopTransactionReason*/
  501. typedef enum {
  502. EmergencyStop,
  503. EVDisconnected,
  504. HardReset,
  505. Local,
  506. Other,
  507. PowerLoss,
  508. Reboot,
  509. Remote,
  510. SoftReset,
  511. UnlockCommand,
  512. DeAuthorized
  513. } StopTransactionReason;
  514. #if 0
  515. static char * StopTransactionReasonStr[] = {
  516. MACROSTR(EmergencyStop),
  517. MACROSTR(EVDisconnected),
  518. MACROSTR(HardReset),
  519. MACROSTR(Local),
  520. MACROSTR(Other),
  521. MACROSTR(PowerLoss),
  522. MACROSTR(Reboot),
  523. MACROSTR(Remote),
  524. MACROSTR(SoftReset),
  525. MACROSTR(UnlockCommand),
  526. MACROSTR(DeAuthorized)
  527. };
  528. #endif
  529. /*CancelReservationStatus*/
  530. typedef enum {
  531. CancelReservationStatus_Accepted,
  532. CancelReservationStatus_Rejected
  533. } CancelReservationStatus;
  534. static char * CancelReservationStatusStr[] = {
  535. MACROSTR(Accepted),
  536. MACROSTR(Rejected)
  537. };
  538. /*ReadingContext*/
  539. typedef enum {
  540. ReadingContext_Interruption_Begin,
  541. ReadingContext_Interruption_End,
  542. ReadingContext_Other,
  543. ReadingContext_Sample_Clock,
  544. ReadingContext_Sample_Periodic ,
  545. ReadingContext_Transaction_Begin ,
  546. ReadingContext_Transaction_End,
  547. ReadingContext_Trigger
  548. } ReadingContext;
  549. static char * ReadingContextStr[] = {
  550. MACROSTR(Interruption.Begin),
  551. MACROSTR(Interruption.End),
  552. MACROSTR(Other),
  553. MACROSTR(Sample.Clock),
  554. MACROSTR(Sample.Periodic),
  555. MACROSTR(Transaction.Begin),
  556. MACROSTR(Transaction.End),
  557. MACROSTR(Trigger)
  558. };
  559. /*ValueFormat*/
  560. typedef enum {
  561. Raw,
  562. SignedData
  563. } ValueFormat;
  564. static char * ValueFormatStr[] = {
  565. MACROSTR(Raw),
  566. MACROSTR(SignedData)
  567. };
  568. /*Measurand*/
  569. typedef enum {
  570. Current_Export ,
  571. Current_Import,
  572. Current_Offered,
  573. Energy_Active_Export_Register,
  574. Energy_Active_Import_Register,
  575. Energy_Reactive_Export_Register,
  576. Energy_Reactive_Import_Register,
  577. Energy_Active_Export_Interval,
  578. Energy_Active_Import_Interval,
  579. Energy_Reactive_Export_Interval,
  580. Energy_Reactive_Import_Interval,
  581. Frequency,
  582. Power_Active_Export ,
  583. Power_Active_Import,
  584. Power_Factor,
  585. Power_Offered,
  586. Power_Reactive_Export,
  587. Power_Reactive_Import,
  588. RPM,
  589. SoC,
  590. Temperature ,
  591. Voltage
  592. } Measurand;
  593. static char * MeasurandStr[] = {
  594. MACROSTR(Current.Export),
  595. MACROSTR(Current.Import),
  596. MACROSTR(Current.Offered),
  597. MACROSTR(Energy.Active.Export.Register),
  598. MACROSTR(Energy.Active.Import.Register),
  599. MACROSTR(Energy.Reactive.Export.Register),
  600. MACROSTR(Energy.Reactive.Import.Register),
  601. MACROSTR(Energy.Active.Export.Interval),
  602. MACROSTR(Energy.Active.Import.Interval),
  603. MACROSTR(Energy.Reactive.Export.Interval),
  604. MACROSTR(Energy.Reactive.Import.Interval),
  605. MACROSTR(Frequency),
  606. MACROSTR(Power.Active.Export),
  607. MACROSTR(Power.Active.Import),
  608. MACROSTR(Power.Factor),
  609. MACROSTR(Power.Offered),
  610. MACROSTR(Power.Reactive.ExportMACROSTR),
  611. MACROSTR(Power.Reactive.Import),
  612. MACROSTR(RPM),
  613. MACROSTR(SoC),
  614. MACROSTR(Temperature),
  615. MACROSTR(Voltage)
  616. };
  617. /*Location*/
  618. typedef enum {
  619. Location_Body,
  620. Location_Cable,
  621. Location_EV,
  622. Location_Inlet ,
  623. Location_Outlet
  624. } Location;
  625. static char * LocationStr[] = {
  626. MACROSTR(Body),
  627. MACROSTR(Cable),
  628. MACROSTR(EV),
  629. MACROSTR(Inlet),
  630. MACROSTR(Outlet)
  631. };
  632. /*Phase*/
  633. typedef enum {
  634. L1,
  635. L2,
  636. L3,
  637. N,
  638. L1_N,
  639. L2_N,
  640. L3_N,
  641. L1_L2,
  642. L2_L3,
  643. L3_L1
  644. } Phase;
  645. static char * PhaseStr[] = {
  646. MACROSTR(L1),
  647. MACROSTR(L2),
  648. MACROSTR(L3),
  649. MACROSTR(N),
  650. MACROSTR(L1-N),
  651. MACROSTR(L2-N),
  652. MACROSTR(L3-N),
  653. MACROSTR(L1-L2),
  654. MACROSTR(L2-L3),
  655. MACROSTR(L3-L1)
  656. };
  657. /*UnitOfMeasure*/
  658. typedef enum {
  659. UnitOfMeasure_Wh,
  660. UnitOfMeasure_kWh ,
  661. UnitOfMeasure_varh ,
  662. UnitOfMeasure_kvarh ,
  663. UnitOfMeasure_W ,
  664. UnitOfMeasure_kW ,
  665. UnitOfMeasure_VA ,
  666. UnitOfMeasure_kVA ,
  667. UnitOfMeasure_var ,
  668. UnitOfMeasure_kvar ,
  669. UnitOfMeasure_A ,
  670. UnitOfMeasure_V ,
  671. UnitOfMeasure_Celsius ,
  672. UnitOfMeasure_Fahrenheit ,
  673. UnitOfMeasure_K ,
  674. UnitOfMeasure_Percent
  675. } UnitOfMeasure;
  676. static char * UnitOfMeasureStr[] = {
  677. MACROSTR(Wh),
  678. MACROSTR(kWh),
  679. MACROSTR(varh),
  680. MACROSTR(kvarh),
  681. MACROSTR(W),
  682. MACROSTR(kW),
  683. MACROSTR(VA),
  684. MACROSTR(kVA),
  685. MACROSTR(var),
  686. MACROSTR(kvar),
  687. MACROSTR(A),
  688. MACROSTR(V),
  689. MACROSTR(Celsius),
  690. MACROSTR(Fahrenheit),
  691. MACROSTR(K),
  692. MACROSTR(Percent)
  693. };
  694. #if 0
  695. /*Configuration enum*/
  696. enum CoreProfile {
  697. AllowOfflineTxForUnknownId=0,
  698. AuthorizationCacheEnabled,
  699. AuthorizeRemoteTxRequests,
  700. BlinkRepeat,
  701. ClockAlignedDataInterval,
  702. ConnectionTimeOut,
  703. GetConfigurationMaxKeys,
  704. HeartbeatInterval,
  705. LightIntensity,
  706. LocalAuthorizeOffline,
  707. LocalPreAuthorize,
  708. MaxEnergyOnInvalidId,
  709. MeterValuesAlignedData,
  710. MeterValuesAlignedDataMaxLength,
  711. MeterValuesSampledData,
  712. MeterValuesSampledDataMaxLength,
  713. MeterValueSampleInterval,
  714. MinimumStatusDuration,
  715. NumberOfConnectors,
  716. ResetRetries,
  717. ConnectorPhaseRotation,
  718. ConnectorPhaseRotationMaxLength,
  719. StopTransactionOnEVSideDisconnect,
  720. StopTransactionOnInvalidId,
  721. StopTxnAlignedData,
  722. StopTxnAlignedDataMaxLength,
  723. StopTxnSampledData,
  724. StopTxnSampledDataMaxLength,
  725. SupportedFeatureProfiles,
  726. SupportedFeatureProfilesMaxLength,
  727. TransactionMessageAttempts,
  728. TransactionMessageRetryInterval,
  729. UnlockConnectorOnEVSideDisconnect,
  730. WebSocketPingInterval,
  731. _CoreProfile_CNT
  732. };
  733. #endif
  734. enum LocalAuthListManagementProfile{
  735. LocalAuthListEnabled=0,
  736. LocalAuthListMaxLength,
  737. SendLocalListMaxLength,
  738. _LocalAuthListManagementProfile_CNT
  739. };
  740. enum ReservationProfile{
  741. ReserveConnectorZeroSupported
  742. };
  743. enum SmartChargingProfile{
  744. ChargeProfileMaxStackLevel,
  745. ChargingScheduleAllowedChargingRateUnit,
  746. ChargingScheduleMaxPeriods,
  747. ConnectorSwitch3to1PhaseSupported,
  748. MaxChargingProfilesInstalled
  749. };
  750. enum ChargerSystemStatus{
  751. ChargerSystemStatus_Booting,
  752. ChargerSystemStatus_Idle,
  753. ChargerSystemStatus_Authorizing,
  754. ChargerSystemStatus_Preparing,
  755. ChargerSystemStatus_Charging,
  756. ChargerSystemStatus_Terminating,
  757. ChargerSystemStatus_Alarm,
  758. ChargerSystemStatus_Fault
  759. };
  760. enum GetConfigurationKey {
  761. GetConfiguration_AllowOfflineTxForUnknownId=0,
  762. GetConfiguration_AuthorizationCacheEnabled,
  763. GetConfiguration_AuthorizeRemoteTxRequests,
  764. GetConfiguration_BlinkRepeat,
  765. GetConfiguration_ClockAlignedDataInterval,
  766. GetConfiguration_ConnectionTimeOut,
  767. GetConfiguration_GetConfigurationMaxKeys,
  768. GetConfiguration_HeartbeatInterval,
  769. GetConfiguration_LightIntensity,
  770. GetConfiguration_LocalAuthorizeOffline,
  771. GetConfiguration_LocalPreAuthorize,
  772. GetConfiguration_MaxEnergyOnInvalidId,
  773. GetConfiguration_MeterValuesAlignedData,
  774. GetConfiguration_MeterValuesAlignedDataMaxLength,
  775. GetConfiguration_MeterValuesSampledData,
  776. GetConfiguration_MeterValuesSampledDataMaxLength,
  777. GetConfiguration_MeterValueSampleInterval,
  778. GetConfiguration_MinimumStatusDuration,
  779. GetConfiguration_NumberOfConnectors,
  780. GetConfiguration_ResetRetries,
  781. GetConfiguration_ConnectorPhaseRotation,
  782. GetConfiguration_ConnectorPhaseRotationMaxLength,
  783. GetConfiguration_StopTransactionOnEVSideDisconnect,
  784. GetConfiguration_StopTransactionOnInvalidId,
  785. GetConfiguration_StopTxnAlignedData,
  786. GetConfiguration_StopTxnAlignedDataMaxLength,
  787. GetConfiguration_StopTxnSampledData,
  788. GetConfiguration_StopTxnSampledDataMaxLength,
  789. GetConfiguration_SupportedFeatureProfiles,
  790. GetConfiguration_SupportedFeatureProfilesMaxLength,
  791. GetConfiguration_TransactionMessageAttempts,
  792. GetConfiguration_TransactionMessageRetryInterval,
  793. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  794. GetConfiguration_WebSocketPingInterval,
  795. GetConfiguration_LocalAuthListEnabled,
  796. GetConfiguration_LocalAuthListMaxLength,
  797. GetConfiguration_SendLocalListMaxLength,
  798. GetConfiguration_ReserveConnectorZeroSupported,
  799. GetConfiguration_ChargeProfileMaxStackLevel,
  800. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  801. GetConfiguration_ChargingScheduleMaxPeriods,
  802. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  803. GetConfiguration_MaxChargingProfilesInstalled,
  804. };
  805. //GetConfiguration Array
  806. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  807. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  808. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  809. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  810. //==========================================
  811. // Init all share memory
  812. //==========================================
  813. int InitShareMemory()
  814. {
  815. int result = PASS;
  816. int MeterSMId;
  817. //creat ShmSysConfigAndInfo
  818. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  819. {
  820. #ifdef SystemLogMessage
  821. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  822. #endif
  823. result = FAIL;
  824. }
  825. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  826. {
  827. #ifdef SystemLogMessage
  828. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  829. #endif
  830. result = FAIL;
  831. }
  832. else
  833. {}
  834. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  835. {
  836. #ifdef SystemLogMessage
  837. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  838. #endif
  839. result = FAIL;
  840. }
  841. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  842. {
  843. #ifdef SystemLogMessage
  844. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  845. #endif
  846. result = FAIL;
  847. }
  848. else
  849. {}
  850. //creat ShmPsuData
  851. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  852. {
  853. #ifdef SystemLogMessage
  854. DEBUG_ERROR("shmget ShmPsuData NG\n");
  855. #endif
  856. result = FAIL;
  857. }
  858. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  859. {
  860. #ifdef SystemLogMessage
  861. DEBUG_ERROR("shmat ShmPsuData NG\n");
  862. #endif
  863. result = FAIL;
  864. }
  865. else
  866. {}
  867. //creat ShmOCPP16Data
  868. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  872. #endif
  873. result = FAIL;
  874. }
  875. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  876. {
  877. #ifdef SystemLogMessage
  878. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  879. #endif
  880. result = FAIL;
  881. }
  882. else
  883. {}
  884. /****************************** For Initial Settings************************************************/
  885. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  886. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  887. {
  888. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  889. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  890. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  891. }
  892. // Charger PRE_SYS_MODE
  893. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  894. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  895. clientTime.Heartbeat=time((time_t*)NULL);
  896. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  897. {
  898. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  899. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  900. }
  901. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  902. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  903. // allocate Configuration memory address
  904. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  905. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  906. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  907. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  909. {
  910. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  911. DEBUG_INFO("DC ...\n");
  912. }
  913. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  914. {
  915. SystemInitial = AC_QUANTITY;
  916. DEBUG_INFO("AC ...\n");
  917. }
  918. //Status Setting
  919. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  920. {
  921. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  922. }
  923. for (int index = 0; index < CCS_QUANTITY; index++)
  924. {
  925. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  926. }
  927. for (int index = 0; index < GB_QUANTITY; index++)
  928. {
  929. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  930. }
  931. for (int index = 0; index < AC_QUANTITY; index++)
  932. {
  933. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  934. }
  935. return result;
  936. }
  937. int ProcessShareMemory()
  938. {
  939. if(InitShareMemory() == FAIL)
  940. {
  941. #ifdef SystemLogMessage
  942. DEBUG_ERROR("InitShareMemory NG\n");
  943. #endif
  944. if(ShmStatusCodeData!=NULL)
  945. {
  946. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  947. }
  948. sleep(5);
  949. return FAIL;
  950. }
  951. return PASS;
  952. }
  953. //---------------------------------------------
  954. // new:
  955. // enum SYSTEM_STATUS
  956. // {
  957. // SYS_MODE_BOOTING = 0,
  958. // SYS_MODE_IDLE = 1,
  959. // SYS_MODE_AUTHORIZING = 2,
  960. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  961. // SYS_MODE_REASSIGN = 4,
  962. // SYS_MODE_PREPARING = 5,
  963. // SYS_MODE_PREPARE_FOR_EV = 6,
  964. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  965. // SYS_MODE_CHARGING = 8,
  966. // SYS_MODE_TERMINATING = 9,
  967. // SYS_MODE_COMPLETE = 10,
  968. // SYS_MODE_ALARM = 11,
  969. // SYS_MODE_FAULT = 12,
  970. // SYS_MODE_RESERVATION = 13,
  971. // SYS_MODE_BOOKING = 14,
  972. // SYS_MODE_MAINTAIN = 15,
  973. // SYS_MODE_DEBUG = 16,
  974. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  975. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  976. // SYS_MODE_UPDATE = 19
  977. // };
  978. //
  979. //
  980. //-----------------------------------------
  981. void CheckSystemValue(void)
  982. {
  983. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  984. int IdleModeCnt = 0;
  985. char filenmae[100]={0};
  986. char str[100]={0};
  987. //===============================
  988. // send Heartbeat
  989. //===============================
  990. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  991. {
  992. printf("Heartbeat !!!\n");
  993. //parameter for test
  994. sendHeartbeatRequest(0);
  995. //==============================================
  996. // Reset Waiting Time
  997. //==============================================
  998. clientTime.Heartbeat=time((time_t*)NULL);
  999. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1000. }
  1001. //==============================================
  1002. // Update firmware request
  1003. //==============================================
  1004. if(isUpdateRequest == TRUE )
  1005. {
  1006. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1007. {
  1008. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1009. {
  1010. //check SystemStatus
  1011. /*************************DC*******************************/
  1012. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1013. {
  1014. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1015. {
  1016. IdleModeCnt = IdleModeCnt + 1;
  1017. }
  1018. }
  1019. for (int index = 0; index < CCS_QUANTITY; index++)
  1020. {
  1021. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1022. {
  1023. IdleModeCnt = IdleModeCnt + 1;
  1024. }
  1025. }
  1026. for (int index = 0; index < GB_QUANTITY; index++)
  1027. {
  1028. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1029. {
  1030. IdleModeCnt = IdleModeCnt + 1;
  1031. }
  1032. }
  1033. }
  1034. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1035. {
  1036. isUpdateRequest = FALSE;
  1037. }
  1038. }
  1039. else
  1040. {
  1041. /*************************AC*******************************/
  1042. for (int index = 0; index < AC_QUANTITY; index++)
  1043. {
  1044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1045. {
  1046. IdleModeCnt = IdleModeCnt + 1;
  1047. }
  1048. }
  1049. if(IdleModeCnt == AC_QUANTITY)
  1050. {
  1051. isUpdateRequest = FALSE;
  1052. }
  1053. }
  1054. }
  1055. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1056. {
  1057. //===============================
  1058. // CSU Trigger Reset Conf
  1059. //===============================
  1060. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1061. {
  1062. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1063. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1064. {
  1065. server_sign = FALSE;
  1066. }
  1067. }
  1068. //===============================
  1069. // CSU Trigger Authorize Request
  1070. //===============================
  1071. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1072. {
  1073. sendAuthorizeRequest(0);
  1074. authorizeRetryTimes = authorizeRetryTimes + 1;
  1075. // authenrequest = TRUE
  1076. if(authorizeRetryTimes < 3)
  1077. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1078. }
  1079. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1080. {
  1081. authorizeRetryTimes = 0;
  1082. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1083. server_sign = FALSE;
  1084. }
  1085. 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))
  1086. {
  1087. sendAuthorizeRequest(0);
  1088. }
  1089. //===============================
  1090. // CSU Trigger Smart Charging Profilw
  1091. //===============================
  1092. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1093. {
  1094. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1095. GetChargingProfileRequest(gun_index);
  1096. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1097. }
  1098. //==============================================
  1099. // Charger start transaction
  1100. //==============================================
  1101. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1102. {
  1103. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1104. sendStartTransactionRequest(gun_index);
  1105. clientTime.StartTransaction = time((time_t*)NULL);
  1106. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1107. }
  1108. //==============================================
  1109. // Charger stop transaction
  1110. //==============================================
  1111. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1112. {
  1113. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1114. sendStopTransactionRequest(gun_index);
  1115. clientTime.StopTransaction = time((time_t*)NULL);
  1116. }
  1117. //==============================================
  1118. // Charger status report
  1119. //==============================================
  1120. /* Check Mode Change */
  1121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1122. {
  1123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1124. {
  1125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1126. {
  1127. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1128. {
  1129. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1130. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1131. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1132. statusModeChage[gun_index] = TRUE;
  1133. }
  1134. }
  1135. }
  1136. for (int index = 0; index < CCS_QUANTITY; index++)
  1137. {
  1138. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1139. {
  1140. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1141. {
  1142. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1143. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1144. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1145. statusModeChage[gun_index] = TRUE;
  1146. }
  1147. }
  1148. }
  1149. for (int index = 0; index < GB_QUANTITY; index++)
  1150. {
  1151. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1152. {
  1153. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1154. {
  1155. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1156. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1157. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1158. statusModeChage[gun_index] = TRUE;
  1159. }
  1160. }
  1161. }
  1162. }
  1163. else //AC
  1164. {
  1165. for (int index = 0; index < AC_QUANTITY; index++)
  1166. {
  1167. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1168. {
  1169. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1170. {
  1171. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1172. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1173. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1174. statusModeChage[gun_index] = TRUE;
  1175. }
  1176. }
  1177. }// END OF FOR
  1178. }// END OF ELSE
  1179. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1180. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1181. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1182. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1183. {
  1184. if(SystemInitial != 0)
  1185. SystemInitial = SystemInitial -1;
  1186. sendStatusNotificationRequest(gun_index);
  1187. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1188. statusModeChage[gun_index] = FALSE;
  1189. }
  1190. //==============================================
  1191. // Meter report
  1192. //==============================================
  1193. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1194. {
  1195. //check Transaction active
  1196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1197. {
  1198. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1199. {
  1200. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1201. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1202. {
  1203. meterValueSend[gun_index] =1;
  1204. }
  1205. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1206. {
  1207. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1208. if((access(filenmae,F_OK))!=-1)
  1209. {
  1210. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1211. sprintf(str,"rm -f %s",filenmae);
  1212. system(str);
  1213. }
  1214. }
  1215. }// End for CHAdeMO
  1216. for (int index = 0; index < CCS_QUANTITY; index++)
  1217. {
  1218. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1219. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1220. {
  1221. meterValueSend[gun_index] =1;
  1222. }
  1223. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1224. {
  1225. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1226. if((access(filenmae,F_OK))!=-1)
  1227. {
  1228. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1229. sprintf(str,"rm -f %s",filenmae);
  1230. system(str);
  1231. }
  1232. }
  1233. } // End for CCS
  1234. for (int index = 0; index < GB_QUANTITY; index++)
  1235. {
  1236. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1237. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1238. {
  1239. meterValueSend[gun_index] =1;
  1240. }
  1241. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1242. {
  1243. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1244. if((access(filenmae,F_OK))!=-1)
  1245. {
  1246. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1247. sprintf(str,"rm -f %s",filenmae);
  1248. system(str);
  1249. }
  1250. }
  1251. }// End for GB
  1252. }
  1253. else
  1254. {
  1255. for (int index = 0; index < AC_QUANTITY; index++)
  1256. {
  1257. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1258. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1259. {
  1260. meterValueSend[gun_index] =1;
  1261. }
  1262. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1263. {
  1264. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1265. if((access(filenmae,F_OK))!=-1)
  1266. {
  1267. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1268. sprintf(str,"rm -f %s",filenmae);
  1269. system(str);
  1270. }
  1271. }
  1272. }//End for AC
  1273. }//END OF ELSE
  1274. // sleep(1);
  1275. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1276. if(meterValueSend[gun_index] == 1)
  1277. sendMeterValuesRequest(gun_index);
  1278. }
  1279. //==============================================
  1280. // Check Connector reserved
  1281. //==============================================
  1282. //===============================
  1283. // Check if Reserve is expired
  1284. //===============================
  1285. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1286. {
  1287. double diff_t;
  1288. struct tm tp;
  1289. // current time
  1290. time_t t = time(NULL);
  1291. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1292. tp.tm_isdst = -1;
  1293. time_t utc = mktime(&tp);
  1294. diff_t = difftime(utc, t);
  1295. if(diff_t <= 0)
  1296. {
  1297. DEBUG_INFO("reserve expired !!! \n");
  1298. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1299. }
  1300. }//END OF Check if Reserve is expired
  1301. //==========================================
  1302. // csu trigger FirmwareStatusNotificationReq
  1303. //==========================================
  1304. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1305. {
  1306. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1307. }
  1308. //==========================================
  1309. // csu trigger CancelReservationConf
  1310. //==========================================
  1311. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1312. {
  1313. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1314. }
  1315. //==========================================
  1316. // csu trigger ChangeAvailabilityConf
  1317. //==========================================
  1318. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1319. {
  1320. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1321. }
  1322. //==========================================
  1323. // csu trigger UnlockConnectorConf
  1324. //==========================================
  1325. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1326. {
  1327. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1328. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1329. }
  1330. //==========================================
  1331. // csu trigger ReserveNowConf
  1332. //==========================================
  1333. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1334. {
  1335. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1336. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1337. }
  1338. //==========================================
  1339. // csu trigger DataTransferReq
  1340. //==========================================
  1341. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1342. {
  1343. sendDataTransferRequest(gun_index);
  1344. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1345. }
  1346. }
  1347. }
  1348. //==========================================
  1349. // send request routine
  1350. //==========================================
  1351. int sendAuthorizeRequest(int gun_index)
  1352. {
  1353. mtrace();
  1354. int result = FAIL;
  1355. char message[100]={0};
  1356. char guid[37];
  1357. char tempdata[65]={0};
  1358. DEBUG_INFO("sendAuthorizeRequest \n");
  1359. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1360. //Local Authorize
  1361. if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1362. {
  1363. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1364. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1365. {
  1366. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1367. {
  1368. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1369. }
  1370. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1371. {
  1372. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1373. }
  1374. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1375. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1376. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1377. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1378. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1379. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1380. authorizeRetryTimes = 0;
  1381. return result;
  1382. }
  1383. else
  1384. {
  1385. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1386. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1387. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1388. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1389. result = PASS;
  1390. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1391. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1392. authorizeRetryTimes = 0;
  1393. return result;
  1394. }
  1395. }
  1396. //initailize struct Authorize
  1397. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1398. //get data from shared memory
  1399. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1400. random_uuid(guid);
  1401. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1402. LWS_Send(message);
  1403. sprintf(tempdata, "Authorize,%d", gun_index);
  1404. if(hashmap_operation(0, guid, tempdata) == 1)
  1405. {
  1406. result = PASS;
  1407. DEBUG_ERROR("Authorize mapItem pass\n");
  1408. }
  1409. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1410. return result;
  1411. }
  1412. int sendBootNotificationRequest(void)
  1413. {
  1414. mtrace();
  1415. int result = FAIL;
  1416. char message[500]={0}, payload[700]={0};
  1417. char guid[37]={0};
  1418. char tempdata[65]={0};
  1419. int IsGunCharging = FALSE;
  1420. //check Transaction active
  1421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1422. {
  1423. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1424. {
  1425. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1426. {
  1427. IsGunCharging = TRUE;
  1428. }
  1429. }
  1430. for (int index = 0; index < CCS_QUANTITY; index++)
  1431. {
  1432. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1433. {
  1434. IsGunCharging = TRUE;
  1435. }
  1436. }
  1437. for (int index = 0; index < GB_QUANTITY; index++)
  1438. {
  1439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1440. {
  1441. IsGunCharging = TRUE;
  1442. }
  1443. }
  1444. }
  1445. else
  1446. {
  1447. for (int index = 0; index < AC_QUANTITY; index++)
  1448. {
  1449. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1450. {
  1451. IsGunCharging = TRUE;
  1452. }
  1453. }
  1454. }
  1455. if(IsGunCharging == TRUE)
  1456. {
  1457. server_sign = TRUE;
  1458. return result;
  1459. }
  1460. // Fill BootNotification fields
  1461. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1462. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1463. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1464. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1465. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1466. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1467. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1468. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1469. ShmOCPP16Data->ChargeBoxId
  1470. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1471. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1472. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1473. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1474. ,ShmOCPP16Data->BootNotification.CpIccid
  1475. ,ShmOCPP16Data->BootNotification.CpImsi
  1476. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1477. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1478. random_uuid(guid);
  1479. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1480. LWS_Send(message);
  1481. sprintf(tempdata, "BootNotification,0");
  1482. 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*/)
  1483. {
  1484. result = PASS;
  1485. }
  1486. memset(queuedata, 0, sizeof(queuedata));
  1487. strcpy(queuedata,message);
  1488. return result;
  1489. }
  1490. int sendDataTransferRequest(int gun_index)
  1491. {
  1492. mtrace();
  1493. char message[1000]={0};
  1494. char guid[37]={0};
  1495. char tempdata[65]={0};
  1496. int result = FAIL;
  1497. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1498. random_uuid(guid);
  1499. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1500. MESSAGE_TYPE_CALL,
  1501. guid,
  1502. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1503. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1504. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1505. LWS_Send(message);
  1506. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1507. 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*/)
  1508. {
  1509. result = PASS;
  1510. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1511. }
  1512. return result;
  1513. }
  1514. int sendDiagnosticsStatusNotificationRequest(char *status)
  1515. {
  1516. mtrace();
  1517. int result = FAIL;
  1518. char message[110]={0};
  1519. char guid[37]={0};
  1520. char tempdata[65]={0};
  1521. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1522. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1523. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1524. random_uuid(guid);
  1525. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1526. LWS_Send(message);
  1527. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1528. if(hashmap_operation(0, guid, tempdata) == 1)
  1529. {
  1530. result = PASS;
  1531. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1532. }
  1533. //#ifdef SystemLogMessage
  1534. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1535. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1536. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1537. //#endif
  1538. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1539. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1540. //record status
  1541. if(strcmp(status,"Idle")==0)
  1542. {
  1543. DiagnosticsStatusNotificationStatus = 0;
  1544. }
  1545. else if(strcmp(status,"Uploaded")==0)
  1546. {
  1547. DiagnosticsStatusNotificationStatus = 1;
  1548. }
  1549. else if(strcmp(status,"UploadFailed")==0)
  1550. {
  1551. DiagnosticsStatusNotificationStatus = 2;
  1552. }
  1553. else if(strcmp(status,"Uploading")==0)
  1554. {
  1555. DiagnosticsStatusNotificationStatus = 3;
  1556. }
  1557. return result;
  1558. }
  1559. int sendFirmwareStatusNotificationRequest(char *status)
  1560. {
  1561. mtrace();
  1562. int result = FAIL;
  1563. char message[110]={0};
  1564. char guid[37]={0};
  1565. char tempdata[65]={0};
  1566. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1567. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1568. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1569. random_uuid(guid);
  1570. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1571. LWS_Send(message);
  1572. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1573. 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*/)
  1574. {
  1575. result = PASS;
  1576. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1577. }
  1578. //#ifdef SystemLogMessage
  1579. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1580. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1581. //#endif
  1582. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1583. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1584. //record status
  1585. if(strcmp(status,"Downloaded")==0)
  1586. {
  1587. FirmwareStatusNotificationStatus = 0;
  1588. }
  1589. else if(strcmp(status,"DownloadFailed")==0)
  1590. {
  1591. FirmwareStatusNotificationStatus = 1;
  1592. }
  1593. else if(strcmp(status,"Downloading")==0)
  1594. {
  1595. FirmwareStatusNotificationStatus = 2;
  1596. }
  1597. else if(strcmp(status,"Idle")==0)
  1598. {
  1599. FirmwareStatusNotificationStatus = 3;
  1600. }
  1601. else if(strcmp(status,"InstallationFailed")==0)
  1602. {
  1603. FirmwareStatusNotificationStatus = 4;
  1604. }
  1605. else if(strcmp(status,"Installing")==0)
  1606. {
  1607. FirmwareStatusNotificationStatus = 5;
  1608. }
  1609. else if(strcmp(status,"Installed")==0)
  1610. {
  1611. FirmwareStatusNotificationStatus = 6;
  1612. }
  1613. return result;
  1614. }
  1615. int sendHeartbeatRequest(int gun_index)
  1616. {
  1617. mtrace();
  1618. int result = FAIL;
  1619. char message[80]={0};
  1620. char guid[37]={0};
  1621. char tempdata[65]={0};
  1622. random_uuid(guid);
  1623. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1624. , MESSAGE_TYPE_CALL
  1625. , guid );
  1626. LWS_Send(message);
  1627. sprintf(tempdata, "Heartbeat,%d", 0);
  1628. 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*/)
  1629. {
  1630. result = PASS;
  1631. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1632. }
  1633. return result;
  1634. }
  1635. int sendStartTransactionRequest(int gun_index)
  1636. {
  1637. mtrace();
  1638. int result = FAIL;
  1639. char message[250]={0};
  1640. char guid[37]={0};
  1641. struct timeval tmnow;
  1642. struct tm *tm;
  1643. char buf[28];//, usec_buf[6];
  1644. char tempdata[65]={0};
  1645. DEBUG_INFO("sendStartTransactionRequest...");
  1646. gettimeofday(&tmnow, NULL);
  1647. time_t t;
  1648. t = time(NULL);
  1649. /*UTC time and date*/
  1650. tm = gmtime(&t);
  1651. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1652. #if 0 // remove temporally
  1653. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1654. strcat(buf,".");
  1655. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1656. strcat(buf,usec_buf);
  1657. #endif
  1658. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1659. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1660. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1662. {
  1663. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1664. {
  1665. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1666. {
  1667. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1668. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1669. }
  1670. }
  1671. for (int index = 0; index < CCS_QUANTITY; index++)
  1672. {
  1673. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1674. {
  1675. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1676. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1677. }
  1678. }
  1679. for (int index = 0; index < GB_QUANTITY; index++)
  1680. {
  1681. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1682. {
  1683. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1684. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1685. }
  1686. }
  1687. }
  1688. else
  1689. {
  1690. for (int index = 0; index < AC_QUANTITY; index++)
  1691. {
  1692. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1693. {
  1694. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1695. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1696. }
  1697. }
  1698. }//END OF ELSE
  1699. random_uuid(guid);
  1700. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1701. , MESSAGE_TYPE_CALL
  1702. , guid
  1703. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1704. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1705. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1706. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1707. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1708. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1709. 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*/)
  1710. {
  1711. result = PASS;
  1712. }
  1713. strcpy(queuedata, message);
  1714. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1715. LWS_Send(message);
  1716. #if 0
  1717. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1718. 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*/)
  1719. {
  1720. result = PASS;
  1721. }
  1722. strcpy(queuedata, message);
  1723. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1724. #endif
  1725. //#ifdef SystemLogMessage
  1726. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1727. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1728. //#endif
  1729. return result;
  1730. }
  1731. int sendStatusNotificationRequest(int gun_index)
  1732. {
  1733. mtrace();
  1734. int result = FAIL;
  1735. char message[600]={0};
  1736. char guid[37];
  1737. int currentStatus = 0;
  1738. struct timeval tmnow;
  1739. struct tm *tm;
  1740. char buf[28];//, usec_buf[6];
  1741. char tempdata[65]={0};
  1742. gettimeofday(&tmnow, NULL);
  1743. time_t t;
  1744. t = time(NULL);
  1745. /*UTC time and date*/
  1746. tm = gmtime(&t);
  1747. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1748. #if 0 // remove temporally
  1749. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1750. strcat(buf,".");
  1751. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1752. strcat(buf,usec_buf);
  1753. #endif
  1754. printf("%s",buf);
  1755. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1756. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1757. // it's option
  1758. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1759. /*
  1760. enum _SYSTEM_STATUS
  1761. {
  1762. S_BOOTING = 0,
  1763. S_IDLE, = 1
  1764. S_AUTHORIZING, =2
  1765. S_REASSIGN_CHECK, =3
  1766. S_REASSIGN, =4
  1767. S_PRECHARGE, =5
  1768. S_PREPARING_FOR_EV, =6
  1769. S_PREPARING_FOR_EVSE, =7
  1770. S_CHARGING, =8
  1771. S_TERMINATING, =9
  1772. S_COMPLETE, =10
  1773. S_ALARM, =11
  1774. S_FAULT =12
  1775. }
  1776. */
  1777. //check Transaction active
  1778. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1779. {
  1780. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1781. {
  1782. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1783. {
  1784. currentStatus = 0; //OCPP Status: Available
  1785. }
  1786. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1787. {
  1788. currentStatus = 1; //OCPP Status: Preparing
  1789. }
  1790. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1791. {
  1792. currentStatus = 2; //OCPP Status: Charging
  1793. }
  1794. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1795. {
  1796. currentStatus = 5; //OCPP Status: Finishing
  1797. }
  1798. 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
  1799. {
  1800. currentStatus = 4; //OCPP Status: SuspendedEV
  1801. }
  1802. 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
  1803. {
  1804. currentStatus = 7; //OCPP Status: Unavailable
  1805. }
  1806. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1807. {
  1808. currentStatus = 8; //OCPP Status: Faulted
  1809. }
  1810. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1811. {
  1812. currentStatus = 6; //OCPP Status: Reserved
  1813. }
  1814. }//end of for CHAdeMO_QUANTITY
  1815. for (int index = 0; index < CCS_QUANTITY; index++)
  1816. {
  1817. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1818. {
  1819. currentStatus = 0; //OCPP Status: Available
  1820. }
  1821. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1822. {
  1823. currentStatus = 1; //OCPP Status: Preparing
  1824. }
  1825. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1826. {
  1827. currentStatus = 2; //OCPP Status: Charging
  1828. }
  1829. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1830. {
  1831. currentStatus = 5; //OCPP Status: Finishing
  1832. }
  1833. 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
  1834. {
  1835. currentStatus = 4; //OCPP Status: SuspendedEV
  1836. }
  1837. 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
  1838. {
  1839. currentStatus = 7; //OCPP Status : Unavailable
  1840. }
  1841. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1842. {
  1843. currentStatus = 8; //OCPP Status: Faulted
  1844. }
  1845. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1846. {
  1847. currentStatus = 6; //OCPP Status: Reserved
  1848. }
  1849. }
  1850. for (int index = 0; index < GB_QUANTITY; index++)
  1851. {
  1852. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1853. {
  1854. currentStatus = 0; //OCPP Status: Available
  1855. }
  1856. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1857. {
  1858. currentStatus = 1; //OCPP Status: Preparing
  1859. }
  1860. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1861. {
  1862. currentStatus = 2; //OCPP Status: Charging
  1863. }
  1864. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1865. {
  1866. currentStatus = 5; //OCPP Status: Finishing
  1867. }
  1868. 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
  1869. {
  1870. currentStatus = 4; //OCPP Status: SuspendedEV
  1871. }
  1872. 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
  1873. {
  1874. currentStatus = 7; //OCPP Status: Unavailable
  1875. }
  1876. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1877. {
  1878. currentStatus = 8; //OCPP Status: Faulted
  1879. }
  1880. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1881. {
  1882. currentStatus = 6; //OCPP Status: Reserved
  1883. }
  1884. }
  1885. }
  1886. else
  1887. {
  1888. for (int index = 0; index < AC_QUANTITY; index++)
  1889. {
  1890. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1891. {
  1892. currentStatus = 0; //OCPP Status: Available
  1893. }
  1894. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1895. {
  1896. currentStatus = 1; //OCPP Status: Preparing
  1897. }
  1898. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1899. {
  1900. currentStatus = 2; //OCPP Status: Charging
  1901. }
  1902. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1903. {
  1904. currentStatus = 5; //OCPP Status: Finishing
  1905. }
  1906. 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
  1907. {
  1908. currentStatus = 4; //OCPP Status: SuspendedEV
  1909. }
  1910. 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
  1911. {
  1912. currentStatus = 7; //OCPP Status: Unavailable
  1913. }
  1914. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1915. {
  1916. currentStatus = 8; //OCPP Status: Faulted
  1917. }
  1918. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1919. {
  1920. currentStatus = 6; //OCPP Status: Reserved
  1921. }
  1922. }//end of for AC_QUANTITY
  1923. }//END OF ELSE
  1924. //it's option
  1925. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1926. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1927. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1928. random_uuid(guid);
  1929. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1930. , MESSAGE_TYPE_CALL
  1931. , guid
  1932. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1933. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1934. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1935. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1936. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1937. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1938. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1939. LWS_Send(message);
  1940. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1941. 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*/)
  1942. {
  1943. //DEBUG_ERROR("statusNotification mapitem pass");
  1944. result = PASS;
  1945. }
  1946. return result;
  1947. }
  1948. int sendStopTransactionRequest(int gun_index)
  1949. {
  1950. mtrace();
  1951. int result = FAIL;
  1952. //char message[1500]={0};
  1953. char guid[37]={0};
  1954. char tempdata[65]={0};
  1955. //int idx_sample=0;
  1956. DEBUG_ERROR("sendStopTransactionRequest \n");
  1957. memset(queuedata, 0, sizeof(queuedata));
  1958. //ENERGY_ACTIVE_IMPORT_REGISTER
  1959. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1960. {
  1961. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1962. {
  1963. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1964. {
  1965. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1966. }
  1967. }// END OF CHAdeMO_QUANTITY
  1968. for (int index = 0; index < CCS_QUANTITY; index++)
  1969. {
  1970. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1971. {
  1972. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1973. }
  1974. }// END OF CCS_QUANTITY
  1975. for (int index = 0; index < GB_QUANTITY; index++)
  1976. {
  1977. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1978. {
  1979. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1980. }
  1981. }// END OF GB_QUANTITY
  1982. }
  1983. else
  1984. {
  1985. for (int index = 0; index < AC_QUANTITY; index++)
  1986. {
  1987. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1988. {
  1989. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1990. }
  1991. }// END OF AC_QUANTITY
  1992. }//END OF ELSE
  1993. //Stop Transaction Time
  1994. struct timeval tmnow;
  1995. struct tm *tm;
  1996. char buf[28];//, usec_buf[6];
  1997. gettimeofday(&tmnow, NULL);
  1998. time_t t;
  1999. t = time(NULL);
  2000. /*UTC time and date*/
  2001. tm = gmtime(&t);
  2002. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2004. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2005. random_uuid(guid);
  2006. /***********************************transactionData******************************************************/
  2007. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2009. //=================================
  2010. // Transaction_Begin
  2011. //=================================
  2012. // Energy.Active.Export.Interval
  2013. //idx_sample=0;
  2014. 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
  2015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2017. 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*/]);
  2018. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2019. {
  2020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2021. }
  2022. else
  2023. {
  2024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2025. }
  2026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2028. //=================================
  2029. // Transaction_End
  2030. //=================================
  2031. //Current.Export
  2032. //idx_sample=1;
  2033. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2034. {
  2035. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2036. {
  2037. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2038. {
  2039. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2040. }
  2041. }
  2042. for (int index = 0; index < CCS_QUANTITY; index++)
  2043. {
  2044. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2045. {
  2046. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2047. }
  2048. }
  2049. for (int index = 0; index < GB_QUANTITY; index++)
  2050. {
  2051. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2052. {
  2053. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2054. }
  2055. }
  2056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2057. }
  2058. else
  2059. {
  2060. for (int index = 0; index < AC_QUANTITY; index++)
  2061. {
  2062. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2063. {
  2064. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2065. }
  2066. }
  2067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2068. }// END FOR AC ELSE
  2069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2072. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2075. //Energy.Active.Export.Interval
  2076. //idx_sample=2;
  2077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2078. {
  2079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2080. {
  2081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2082. {
  2083. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2084. }
  2085. }
  2086. for (int index = 0; index < CCS_QUANTITY; index++)
  2087. {
  2088. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2089. {
  2090. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2091. }
  2092. }
  2093. for (int index = 0; index < GB_QUANTITY; index++)
  2094. {
  2095. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2096. {
  2097. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2098. }
  2099. }
  2100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2101. }
  2102. else
  2103. {
  2104. for (int index = 0; index < AC_QUANTITY; index++)
  2105. {
  2106. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2107. {
  2108. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2109. }
  2110. }
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2112. }// END FOR AC ELSE
  2113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2116. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2119. //Power.Active.Export
  2120. //idx_sample=3;
  2121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2122. {
  2123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2124. {
  2125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2126. {
  2127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2128. }
  2129. }
  2130. for (int index = 0; index < CCS_QUANTITY; index++)
  2131. {
  2132. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2133. {
  2134. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2135. }
  2136. }
  2137. for (int index = 0; index < GB_QUANTITY; index++)
  2138. {
  2139. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2140. {
  2141. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2142. }
  2143. }
  2144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2145. }
  2146. else
  2147. {
  2148. for (int index = 0; index < AC_QUANTITY; index++)
  2149. {
  2150. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2151. {
  2152. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2153. }
  2154. }
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2156. }// END FOR AC ELSE
  2157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2160. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2163. //Voltage
  2164. //idx_sample=4;
  2165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2166. {
  2167. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2168. {
  2169. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2170. {
  2171. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2172. }
  2173. }
  2174. for (int index = 0; index < CCS_QUANTITY; index++)
  2175. {
  2176. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2177. {
  2178. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2179. }
  2180. }
  2181. for (int index = 0; index < GB_QUANTITY; index++)
  2182. {
  2183. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2184. {
  2185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2186. }
  2187. }
  2188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2189. }
  2190. else
  2191. {
  2192. for (int index = 0; index < AC_QUANTITY; index++)
  2193. {
  2194. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2195. {
  2196. 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
  2197. }
  2198. }
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2200. }// END FOR AC ELSE
  2201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2204. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2207. //SoC
  2208. //idx_sample=5;
  2209. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2210. {
  2211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2212. {
  2213. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2214. {
  2215. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2216. }
  2217. }
  2218. for (int index = 0; index < CCS_QUANTITY; index++)
  2219. {
  2220. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2221. {
  2222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2223. }
  2224. }
  2225. for (int index = 0; index < GB_QUANTITY; index++)
  2226. {
  2227. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2228. {
  2229. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2230. }
  2231. }
  2232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2238. } // END FOR DC CASE
  2239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2240. {
  2241. 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\"}]}]}]"
  2242. ,MESSAGE_TYPE_CALL
  2243. ,guid
  2244. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2245. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2246. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2247. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2248. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2249. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2250. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2251. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2252. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2253. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2254. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2255. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2256. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2257. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2258. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2259. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2260. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2261. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2262. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2263. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2264. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2265. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2266. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2267. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2268. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2269. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2270. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2271. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2272. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2273. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2274. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2275. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2276. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2277. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2278. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2279. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2280. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2281. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2282. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2283. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2284. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2285. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2286. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2287. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2288. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2289. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2290. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2291. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2292. );
  2293. }
  2294. else
  2295. {
  2296. 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\"}]}]}]"
  2297. ,MESSAGE_TYPE_CALL
  2298. ,guid
  2299. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2304. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2336. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2340. );
  2341. }
  2342. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2343. if(hashmap_operation(0, guid, tempdata) == 1)
  2344. {
  2345. result = PASS;
  2346. DEBUG_INFO("StopTransaction mapitem pass\n");
  2347. }
  2348. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2349. LWS_Send(queuedata);
  2350. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2351. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2352. {
  2353. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2354. }
  2355. #if 0
  2356. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2357. if(hashmap_operation(0, guid, tempdata) == 1)
  2358. {
  2359. result = PASS;
  2360. DEBUG_INFO("StopTransaction mapitem pass\n");
  2361. }
  2362. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2363. #endif
  2364. //for test
  2365. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2366. return result;
  2367. }
  2368. int sendMeterValuesRequest(int gun_index)
  2369. {
  2370. mtrace();
  2371. int result = FAIL;
  2372. // char message[1500]={0};
  2373. char guid[37]={0};
  2374. //int idx_sample=0;
  2375. //int length = 0;
  2376. char tempdata[65]={0};
  2377. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2378. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2379. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2380. {
  2381. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2382. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2383. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2384. return result;
  2385. }
  2386. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2387. {
  2388. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2389. }
  2390. memset(queuedata, 0, sizeof(queuedata));
  2391. //set value
  2392. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2393. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2394. random_uuid(guid);
  2395. //UTC Date time
  2396. struct timeval tmnow;
  2397. struct tm *tm;
  2398. char buf[28];//, usec_buf[6];
  2399. gettimeofday(&tmnow, NULL);
  2400. time_t t;
  2401. t = time(NULL);
  2402. /*UTC time and date*/
  2403. tm = gmtime(&t);
  2404. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2406. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2407. //idx_sample=0;
  2408. //********************************(1)Current.Export************************************************/
  2409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2410. {
  2411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2412. {
  2413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2414. {
  2415. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2416. }
  2417. }
  2418. for (int index = 0; index < CCS_QUANTITY; index++)
  2419. {
  2420. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2421. {
  2422. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2423. }
  2424. }
  2425. for (int index = 0; index < GB_QUANTITY; index++)
  2426. {
  2427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2428. {
  2429. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2430. }
  2431. }
  2432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2433. }
  2434. else
  2435. {
  2436. for (int index = 0; index < AC_QUANTITY; index++)
  2437. {
  2438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2439. {
  2440. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2441. }
  2442. }
  2443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2444. }// END FOR AC ELSE
  2445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2448. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2451. //idx_sample=1;
  2452. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2454. {
  2455. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2456. {
  2457. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2458. {
  2459. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2460. }
  2461. }
  2462. for (int index = 0; index < CCS_QUANTITY; index++)
  2463. {
  2464. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2465. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2466. {
  2467. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2468. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2469. }
  2470. }
  2471. for (int index = 0; index < GB_QUANTITY; index++)
  2472. {
  2473. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2474. {
  2475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2476. }
  2477. }
  2478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2479. }
  2480. else
  2481. {
  2482. for (int index = 0; index < AC_QUANTITY; index++)
  2483. {
  2484. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2485. {
  2486. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2487. }
  2488. }
  2489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2490. }//END FOR AC ELSE
  2491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2494. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2497. //idx_sample=2;
  2498. //********************************(4)Power.Active.Export************************************************/
  2499. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2500. {
  2501. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2502. {
  2503. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2504. {
  2505. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2506. }
  2507. }
  2508. for (int index = 0; index < CCS_QUANTITY; index++)
  2509. {
  2510. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2511. {
  2512. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2513. }
  2514. }
  2515. for (int index = 0; index < GB_QUANTITY; index++)
  2516. {
  2517. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2518. {
  2519. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2521. }
  2522. }
  2523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2524. }
  2525. else
  2526. {
  2527. for (int index = 0; index < AC_QUANTITY; index++)
  2528. {
  2529. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2530. {
  2531. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2532. }
  2533. }
  2534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2535. }// END FOR AC ELSE
  2536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2537. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2538. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2539. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2540. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2542. //idx_sample=3;
  2543. //***********************************************(5)VOLTAGE******************************************************/
  2544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2545. {
  2546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2547. {
  2548. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2549. {
  2550. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2551. }
  2552. }
  2553. for (int index = 0; index < CCS_QUANTITY; index++)
  2554. {
  2555. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2556. {
  2557. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2558. }
  2559. }
  2560. for (int index = 0; index < GB_QUANTITY; index++)
  2561. {
  2562. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2563. {
  2564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2565. }
  2566. }
  2567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2568. }
  2569. else
  2570. {
  2571. for (int index = 0; index < AC_QUANTITY; index++)
  2572. {
  2573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2574. {
  2575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2576. }
  2577. }
  2578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2579. }//END FOR AC ELSE
  2580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2583. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2587. {
  2588. //idx_sample=4;
  2589. //sampledValue = NULL;
  2590. //***********************************************(6)SOC******************************************************/
  2591. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2592. {
  2593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2594. {
  2595. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2596. }
  2597. }
  2598. for (int index = 0; index < CCS_QUANTITY; index++)
  2599. {
  2600. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2601. {
  2602. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2603. }
  2604. }
  2605. for (int index = 0; index < GB_QUANTITY; index++)
  2606. {
  2607. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2608. {
  2609. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2610. }
  2611. }
  2612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2618. }
  2619. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2620. {
  2621. 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\"}]}]}]"
  2622. ,MESSAGE_TYPE_CALL
  2623. ,guid
  2624. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2625. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2626. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2651. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2652. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2653. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2654. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2655. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2656. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2657. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2658. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2659. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2660. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2662. );
  2663. }
  2664. else
  2665. {
  2666. 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\"}]}]}]"
  2667. ,MESSAGE_TYPE_CALL
  2668. ,guid
  2669. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2670. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2671. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2700. );
  2701. }
  2702. // Put request guid to hash map
  2703. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2704. 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*/)
  2705. {
  2706. result = PASS;
  2707. DEBUG_INFO("MeterValues mapitem pass\n");
  2708. }
  2709. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2710. LWS_Send(queuedata);
  2711. #if 0
  2712. // Put request guid to hash map
  2713. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2714. 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*/)
  2715. {
  2716. result = PASS;
  2717. DEBUG_INFO("MeterValues mapitem pass\n");
  2718. }
  2719. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2720. #endif
  2721. return result;
  2722. }
  2723. //==========================================
  2724. // send confirm routine
  2725. //==========================================
  2726. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2727. {
  2728. mtrace();
  2729. int result = FAIL;
  2730. char message[100]={0};
  2731. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2732. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2733. LWS_Send(message);
  2734. result = TRUE;
  2735. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2736. return result;
  2737. }
  2738. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2739. {
  2740. mtrace();
  2741. int result = FAIL;
  2742. char message[100]={0};
  2743. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\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 sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2750. {
  2751. mtrace();
  2752. int result = FAIL;
  2753. char message[100]={0};
  2754. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2755. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2756. LWS_Send(message);
  2757. result = TRUE;
  2758. return result;
  2759. }
  2760. int sendClearCacheConfirmation(char *uuid,char *payload)
  2761. {
  2762. mtrace();
  2763. int result = FAIL;
  2764. char message[500]={0};
  2765. // int count = 0;
  2766. // int gun_index = 0;
  2767. // char guid[37];
  2768. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2769. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2770. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2771. LWS_Send(message);
  2772. return result;
  2773. }
  2774. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2775. {
  2776. mtrace();
  2777. int result = FAIL;
  2778. char message[500]={0};
  2779. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2780. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2781. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2782. LWS_Send(message);
  2783. return result;
  2784. }
  2785. int sendDataTransferConfirmation(char *uuid,char *payload)
  2786. {
  2787. mtrace();
  2788. char statusStr[20]={0};
  2789. char dataStr[10]={0};
  2790. char sstr[20]={0};
  2791. int c = 0;
  2792. char *loc;
  2793. int result = FAIL;
  2794. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2795. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2796. /**********************status**************************/
  2797. loc = strstr(payload, "status");
  2798. memset(sstr ,0, sizeof(sstr) );
  2799. c = 0;
  2800. while (loc[3+strlen("status")+c] != '\"')
  2801. {
  2802. sstr[c] = loc[3+strlen("status")+c];
  2803. c++;
  2804. }
  2805. sstr[c] = '\0';
  2806. strcpy(statusStr, sstr);
  2807. /**********************data**************************/
  2808. loc = strstr(payload, "data");
  2809. memset(sstr ,0, sizeof(sstr) );
  2810. c = 0;
  2811. while (loc[3+strlen("data")+c] != '\"')
  2812. {
  2813. sstr[c] = loc[3+strlen("data")+c];
  2814. c++;
  2815. }
  2816. sstr[c] = '\0';
  2817. strcpy(dataStr, sstr);
  2818. return result;
  2819. }
  2820. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2821. {
  2822. mtrace();
  2823. int result = FAIL;
  2824. char message[1000]={0};
  2825. double diff_f = 0.0;
  2826. int diff_i = 0;
  2827. int diffSeconds = 0;
  2828. struct tm tp;
  2829. int TimeZero = FALSE;
  2830. int CompositeScheduleIndex = 0;
  2831. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2832. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2833. {
  2834. TimeZero = TRUE;
  2835. }
  2836. else
  2837. {
  2838. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2839. }
  2840. if(TimeZero == FALSE)
  2841. {
  2842. tp.tm_isdst = -1;
  2843. time_t utc = mktime(&tp);
  2844. time_t t = time(NULL);
  2845. diff_f = difftime(t, utc);
  2846. diff_i = (int)diff_f;
  2847. diffSeconds = diff_i % 86400;//86400 seconds/day
  2848. }
  2849. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2850. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2851. #if 0 //remove temporally
  2852. 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}"
  2853. ,MESSAGE_TYPE_CALLRESULT
  2854. ,uuid
  2855. ,payload
  2856. ,connectorIdInt
  2857. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2858. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2859. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2860. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2861. #endif
  2862. if(nPeriod == 0)
  2863. {
  2864. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2865. ,MESSAGE_TYPE_CALLRESULT
  2866. ,uuid
  2867. ,payload
  2868. ,connectorIdInt
  2869. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2870. }
  2871. else
  2872. {
  2873. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2874. ,MESSAGE_TYPE_CALLRESULT
  2875. ,uuid
  2876. ,payload
  2877. ,connectorIdInt
  2878. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2879. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2880. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2881. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2882. int len = nPeriod;
  2883. //Last Period StartPriod is less than diffSeconds
  2884. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2885. {
  2886. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2887. , 0
  2888. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2889. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2890. }
  2891. else
  2892. {
  2893. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2894. {
  2895. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2896. {
  2897. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2898. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2899. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2900. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2901. }
  2902. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2903. {
  2904. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2905. , (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*/))
  2906. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2907. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2908. }
  2909. }
  2910. }
  2911. sprintf(message + strlen(message), "]}}]");
  2912. }
  2913. LWS_Send(message);
  2914. result = TRUE;
  2915. return result;
  2916. }
  2917. int sendGetConfigurationConfirmation(char *uuid)
  2918. {
  2919. mtrace();
  2920. int result = FAIL;
  2921. int MaxKeySupported = 0;
  2922. int sentConfigurationNumber= 0;
  2923. int sentunConfigurationNumber= 0;
  2924. char message[4000]={0};
  2925. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2926. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2927. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2928. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  2929. ,MESSAGE_TYPE_CALLRESULT
  2930. ,uuid );
  2931. //configuration key
  2932. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2933. {
  2934. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2935. {
  2936. if (sentConfigurationNumber == 0)
  2937. {
  2938. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2939. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2940. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2941. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2942. }
  2943. else
  2944. {
  2945. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2946. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2947. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2948. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2949. }
  2950. sentConfigurationNumber = sentConfigurationNumber + 1;
  2951. }
  2952. }
  2953. sprintf(message + strlen(message), "]");
  2954. if(UnknownKeynum != 0)
  2955. {
  2956. sprintf(message + strlen(message), ",\"unknownKey\":[");
  2957. //unkown key
  2958. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  2959. {
  2960. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  2961. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  2962. if(sentunConfigurationNumber == 0)
  2963. {
  2964. sprintf(message + strlen(message), "\"%s\""
  2965. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2966. }
  2967. else
  2968. {
  2969. sprintf(message + strlen(message), ",\"%s\""
  2970. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2971. }
  2972. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  2973. }
  2974. sprintf(message + strlen(message), "]");
  2975. }
  2976. sprintf(message + strlen(message), "}]");
  2977. LWS_Send(message);
  2978. return result;
  2979. }
  2980. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  2981. {
  2982. mtrace();
  2983. int result = FAIL;
  2984. char message[400]={0};
  2985. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  2986. if(strcmp(payload,"")==0)
  2987. {
  2988. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  2989. }
  2990. else
  2991. {
  2992. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  2993. }
  2994. LWS_Send(message);
  2995. result = TRUE;
  2996. return result;
  2997. }
  2998. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  2999. {
  3000. mtrace();
  3001. int result = FAIL;
  3002. char message[80]={0};
  3003. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3004. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3005. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3006. LWS_Send(message);
  3007. result = TRUE;
  3008. return result;
  3009. }
  3010. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3011. {
  3012. mtrace();
  3013. int result = FAIL;
  3014. char message[80]={0};
  3015. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3016. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3017. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3018. LWS_Send(message);
  3019. result = TRUE;
  3020. return result;
  3021. }
  3022. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3023. {
  3024. mtrace();
  3025. int result = FAIL;
  3026. char message[80]={0};
  3027. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3028. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3029. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3030. LWS_Send(message);
  3031. result = TRUE;
  3032. return result;
  3033. }
  3034. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3035. {
  3036. mtrace();
  3037. int result = FAIL;
  3038. char message[80]={0};
  3039. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3040. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3041. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3042. LWS_Send(message);
  3043. result = TRUE;
  3044. return result;
  3045. }
  3046. int sendResetConfirmation(char *uuid,char *payload)
  3047. {
  3048. mtrace();
  3049. int result = FAIL;
  3050. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3051. char message[80]={0};
  3052. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3053. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3054. LWS_Send(message);
  3055. result = TRUE;
  3056. return result;
  3057. }
  3058. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3059. {
  3060. mtrace();
  3061. int result = FAIL;
  3062. char message[500]={0};
  3063. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3064. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3065. LWS_Send(message);
  3066. result = TRUE;
  3067. return result;
  3068. }
  3069. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3070. {
  3071. mtrace();
  3072. int result = FAIL;
  3073. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3074. char message[80]={0};
  3075. DEBUG_INFO("sendSetChargingProfileConfirmation\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 sendTriggerMessageConfirmation(char *uuid,char *payload)
  3082. {
  3083. mtrace();
  3084. int result = FAIL;
  3085. char message[80]={0};
  3086. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3087. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3088. LWS_Send(message);
  3089. result = TRUE;
  3090. return result;
  3091. }
  3092. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3093. {
  3094. mtrace();
  3095. int result = FAIL;
  3096. char message[80]={0};
  3097. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3098. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3099. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3100. LWS_Send(message);
  3101. result = TRUE;
  3102. return result;
  3103. }
  3104. int sendUpdateFirmwareConfirmation(char *uuid)
  3105. {
  3106. mtrace();
  3107. int result = FAIL;
  3108. char message[60]={0};
  3109. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3110. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3111. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3112. LWS_Send(message);
  3113. result = TRUE;
  3114. return result;
  3115. }
  3116. //==========================================
  3117. // send CallError routine
  3118. //==========================================
  3119. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3120. {
  3121. mtrace();
  3122. //int result = FAIL;
  3123. char message[220]={0};
  3124. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3125. #ifdef SystemLogMessage
  3126. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3127. uniqueId, action, errorCode, errorDescription);
  3128. #endif
  3129. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3130. LWS_Send(message);
  3131. //result = TRUE;
  3132. }
  3133. //==========================================
  3134. // Handle server request routine Start
  3135. //==========================================
  3136. #define GUN_NUM 1
  3137. int handleCancelReservationRequest(char *uuid, char *payload)
  3138. {
  3139. mtrace();
  3140. int result = FAIL;
  3141. int gunNO = 0;
  3142. int reservationIdInt =0;
  3143. char comfirmstr[20];
  3144. int c = 0;
  3145. char *loc;
  3146. char sstr[100]={0};
  3147. DEBUG_INFO("handle CancelReservationRequest\n");
  3148. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3149. c = 0;
  3150. loc = strstr(payload, "reservationId");
  3151. memset(sstr ,0, sizeof(sstr) );
  3152. while (loc[strlen("reservationId")+2+c] != '}')
  3153. {
  3154. sstr[c] = loc[strlen("reservationId")+2+c];
  3155. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3156. c++;
  3157. }
  3158. sstr[c] = '\0';
  3159. reservationIdInt = atoi(sstr);
  3160. memset(comfirmstr, 0, sizeof comfirmstr);
  3161. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3162. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3163. //check Transaction active
  3164. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3165. {
  3166. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3167. {
  3168. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3169. {
  3170. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3171. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3172. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3173. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3174. goto end;
  3175. }
  3176. }
  3177. for (int index = 0; index < CCS_QUANTITY; index++)
  3178. {
  3179. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3180. {
  3181. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3182. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3183. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3184. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3185. goto end;
  3186. }
  3187. }
  3188. for (int index = 0; index < GB_QUANTITY; index++)
  3189. {
  3190. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3191. {
  3192. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3193. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3194. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3195. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3196. goto end;
  3197. }
  3198. }
  3199. }
  3200. else
  3201. {
  3202. for (int index = 0; index < AC_QUANTITY; index++)
  3203. {
  3204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3205. {
  3206. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3207. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3208. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3209. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3210. goto end;
  3211. }
  3212. }
  3213. }// END FOR AC ELSE
  3214. //The reservationId does NOT match the reservationId
  3215. sendCancelReservationConfirmation(uuid, comfirmstr);
  3216. end:
  3217. // Fill in ocpp packet uuid
  3218. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3219. return result;
  3220. }
  3221. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3222. {
  3223. mtrace();
  3224. int result = FAIL;
  3225. int gunIndex = 0;
  3226. char sstr[90]={0};
  3227. char typeStr[16]={0};
  3228. char comfirmstr[20];
  3229. int specificId = FALSE;
  3230. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3231. char *loc;
  3232. //int intervalInt = 0;
  3233. int c = 0;
  3234. /*** connectorId ****/
  3235. c = 0;
  3236. loc = strstr(payload, "connectorId");
  3237. memset(sstr ,0, sizeof(sstr) );
  3238. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3239. {
  3240. sstr[c] = loc[strlen("connectorId")+2+c];
  3241. c++;
  3242. }
  3243. sstr[c] = '\0';
  3244. gunIndex = atoi(sstr);
  3245. /***type ****/
  3246. loc = strstr(payload, "type");
  3247. memset(sstr ,0, sizeof(sstr) );
  3248. c = 0;
  3249. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3250. {
  3251. sstr[c] = loc[3+strlen("type")+c];
  3252. c++;
  3253. }
  3254. sstr[c] = '\0';
  3255. strcpy(typeStr, sstr);
  3256. if(gunIndex != 0)
  3257. {
  3258. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3259. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3260. }
  3261. else
  3262. {
  3263. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3264. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3265. }
  3266. memset(comfirmstr, 0, sizeof comfirmstr);
  3267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3268. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3269. {
  3270. specificId = TRUE;
  3271. }
  3272. if(specificId == FALSE)
  3273. goto end;
  3274. if(gunIndex != 0)
  3275. {
  3276. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3277. }
  3278. else
  3279. {
  3280. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3281. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3282. }
  3283. /*
  3284. enum SYSTEM_STATUS
  3285. {
  3286. SYS_MODE_BOOTING = 0,
  3287. SYS_MODE_IDLE = 1,
  3288. SYS_MODE_AUTHORIZING = 2,
  3289. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3290. SYS_MODE_REASSIGN = 4,
  3291. SYS_MODE_PREPARING = 5,
  3292. SYS_MODE_PREPARE_FOR_EV = 6,
  3293. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3294. SYS_MODE_CHARGING = 8,
  3295. SYS_MODE_TERMINATING = 9,
  3296. SYS_MODE_COMPLETE = 10,
  3297. SYS_MODE_ALARM = 11,
  3298. SYS_MODE_FAULT = 12,
  3299. SYS_MODE_RESERVATION = 13,
  3300. SYS_MODE_BOOKING = 14,
  3301. SYS_MODE_MAINTAIN = 15,
  3302. SYS_MODE_DEBUG = 16,
  3303. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3304. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3305. SYS_MODE_UPDATE = 19
  3306. };
  3307. */
  3308. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3309. {
  3310. //check Transaction active
  3311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3312. {
  3313. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3314. {
  3315. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3316. {
  3317. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3318. {
  3319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3320. }
  3321. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3322. {
  3323. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3324. }
  3325. else
  3326. {
  3327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3328. }
  3329. goto end;
  3330. }
  3331. }//END FOR CHAdeMO_QUANTITY
  3332. for (int index = 0; index < CCS_QUANTITY; index++)
  3333. {
  3334. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3335. {
  3336. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3337. {
  3338. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3339. }
  3340. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3341. {
  3342. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3343. }
  3344. else
  3345. {
  3346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3347. }
  3348. goto end;
  3349. }
  3350. }//END FOR CCS_QUANTITY
  3351. for (int index = 0; index < GB_QUANTITY; index++)
  3352. {
  3353. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3354. {
  3355. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3356. {
  3357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3358. }
  3359. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3360. {
  3361. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3362. }
  3363. else
  3364. {
  3365. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3366. }
  3367. goto end;
  3368. }
  3369. }// END FOR GB_QUANTITY
  3370. }
  3371. else
  3372. {
  3373. for (int index = 0; index < AC_QUANTITY; index++)
  3374. {
  3375. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3376. {
  3377. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3378. {
  3379. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3380. }
  3381. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3382. {
  3383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3384. }
  3385. else
  3386. {
  3387. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3388. }
  3389. goto end;
  3390. }
  3391. }//END FOR AC_QUANTITY
  3392. }// END FOR AC ELSE
  3393. }//END FOR AvailabilityTypeStr[Inoperative]
  3394. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3395. {
  3396. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3397. //check Transaction active
  3398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3399. {
  3400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3401. {
  3402. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3403. {
  3404. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3405. goto end;
  3406. }
  3407. }//END FOR CHAdeMO_QUANTITY
  3408. for (int index = 0; index < CCS_QUANTITY; index++)
  3409. {
  3410. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3411. {
  3412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3413. goto end;
  3414. }
  3415. }//END FOR CCS_QUANTITY
  3416. for (int index = 0; index < GB_QUANTITY; index++)
  3417. {
  3418. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3419. {
  3420. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3421. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3422. goto end;
  3423. }
  3424. }// END FOR GB_QUANTITY
  3425. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3426. }
  3427. else
  3428. {
  3429. for (int index = 0; index < AC_QUANTITY; index++)
  3430. {
  3431. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3432. {
  3433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3434. goto end;
  3435. }
  3436. }//END FOR CHAdeMO_QUANTITY
  3437. }//END FOR AC ELSE
  3438. }//END FOR AvailabilityTypeStr[Operative]
  3439. end:
  3440. if(gunIndex != 0)
  3441. {
  3442. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3443. }
  3444. else
  3445. {
  3446. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3447. }
  3448. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3449. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3450. return result;
  3451. }
  3452. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3453. {
  3454. mtrace();
  3455. int result = FAIL;
  3456. char sstr[100]={0};
  3457. char keystr[40]={0};
  3458. char valuestr[100]={0};
  3459. char *loc;
  3460. int c = 0;
  3461. char comfirmstr[20]={0};
  3462. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3463. /***key ****/
  3464. loc = strstr(payload, "key");
  3465. memset(sstr ,0, sizeof(sstr) );
  3466. c = 0;
  3467. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3468. {
  3469. sstr[c] = loc[3+strlen("key")+c];
  3470. c++;
  3471. }
  3472. sstr[c] = '\0';
  3473. strcpy(keystr, sstr);
  3474. //DEBUG_INFO( "keystr=%s\n",keystr);
  3475. /***value ****/
  3476. loc = strstr(payload, "value");
  3477. memset(sstr ,0, sizeof(sstr) );
  3478. c = 0;
  3479. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3480. {
  3481. sstr[c] = loc[3+strlen("value")+c];
  3482. c++;
  3483. }
  3484. sstr[c] = '\0';
  3485. strcpy(valuestr, sstr);
  3486. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3487. if((uuid==NULL) || (payload ==NULL) )
  3488. {
  3489. #ifdef Debug
  3490. DEBUG_INFO("payload is null\n");
  3491. #endif
  3492. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3493. }
  3494. else
  3495. {
  3496. int status = setKeyValue(keystr, valuestr);
  3497. switch(status)
  3498. {
  3499. case ConfigurationStatus_Accepted:
  3500. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3501. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3502. StoreConfigurationTable();
  3503. break;
  3504. case ConfigurationStatus_Rejected:
  3505. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3506. break;
  3507. case RebootRequired:
  3508. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3509. StoreConfigurationTable();
  3510. break;
  3511. case NotSupported:
  3512. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3513. break;
  3514. default:
  3515. break;
  3516. }
  3517. }
  3518. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3519. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3520. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3521. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3522. {
  3523. ChageWebSocketPingInterval(atoi(valuestr));
  3524. }
  3525. return result;
  3526. }
  3527. int handleClearCacheRequest(char *uuid, char *payload)
  3528. {
  3529. mtrace();
  3530. int result = FAIL;
  3531. char comfirmstr[20];
  3532. int fd;
  3533. char rmFileCmd[100]={0};
  3534. struct stat stats;
  3535. DEBUG_INFO("handle ClearCacheRequest\n");
  3536. stat("/Storage/OCPP", &stats);
  3537. // Check for directory existence
  3538. if (S_ISDIR(stats.st_mode) == 1)
  3539. {
  3540. //DEBUG_ERROR("\n OCPP directory exist \n");
  3541. }
  3542. else
  3543. {
  3544. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3545. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3546. system(rmFileCmd);
  3547. }
  3548. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3549. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3550. {
  3551. DEBUG_INFO("AuthorizationCache file exist.\n");
  3552. }
  3553. else
  3554. {
  3555. DEBUG_INFO("AuthorizationCache file not exist\n");
  3556. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3557. if(log == NULL)
  3558. {
  3559. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3560. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3561. goto end;
  3562. }
  3563. else
  3564. {
  3565. fclose(log);
  3566. }
  3567. }
  3568. fd = open(AuthorizationCache_JSON,O_RDWR);
  3569. if(fd < 0)
  3570. {
  3571. DEBUG_INFO("open AuthorizationCache file failed\n");
  3572. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3573. }
  3574. else
  3575. {
  3576. DEBUG_INFO("open AuthorizationCache file successful\n");
  3577. //* 清空? 件 */
  3578. ftruncate(fd,0);
  3579. //* ? 新设置? 件? 移??*/
  3580. lseek(fd,0,SEEK_SET);
  3581. close(fd);
  3582. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3583. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3584. }
  3585. end:
  3586. sendClearCacheConfirmation(uuid, comfirmstr);
  3587. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3588. return result;
  3589. }
  3590. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3591. {
  3592. mtrace();
  3593. int result = FAIL;
  3594. int resultRename;
  3595. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3596. char chargingProfilePurposeStr[26]={0};
  3597. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3598. char tempchargingProfilePurposeStr[26]={0};
  3599. char sstr[160]={0};//sstr[200]={ 0 };
  3600. char str[100]={0};
  3601. int c = 0;
  3602. //int i = 0;
  3603. //char * pch;
  3604. char *loc;
  3605. char fname[200]={0};
  3606. char comfirmstr[20]={0};
  3607. char word[1600]={0};
  3608. int clearflag = FALSE;
  3609. int chargingProfileIdIsNULL = FALSE;
  3610. int connectorIsNULL = FALSE;
  3611. int chargingProfilePurposeIsNULL = FALSE;
  3612. int stackLevelIsNULL = FALSE;
  3613. //int GotoEnd = FALSE;
  3614. FILE *fptr1, *fptr2;
  3615. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3616. int n_chargingProfile=0;
  3617. int isEmptyFile = FALSE;
  3618. char sLineWord[1600]={0};
  3619. char chargingProfiles[10][100]={0};
  3620. int ChargeProfileCount = 0;
  3621. char ch;
  3622. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3623. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3624. //***id ****/
  3625. c = 0;
  3626. loc = strstr(payload, "id");
  3627. memset(sstr ,0, sizeof(sstr) );
  3628. if(loc == NULL)
  3629. {
  3630. chargingProfileIdIsNULL = TRUE;
  3631. }
  3632. else
  3633. {
  3634. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3635. {
  3636. sstr[c] = loc[strlen("id")+2+c];
  3637. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3638. c++;
  3639. }
  3640. sstr[c] = '\0';
  3641. chargingProfileIdInt = atoi(sstr);
  3642. }
  3643. //***connectorId ****/
  3644. c=0;
  3645. loc = strstr(payload, "connectorId");
  3646. memset(sstr ,0, sizeof(sstr) );
  3647. if(loc == NULL)
  3648. {
  3649. connectorIsNULL = TRUE;
  3650. }
  3651. else
  3652. {
  3653. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3654. {
  3655. sstr[c] = loc[strlen("connectorId")+2+c];
  3656. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3657. c++;
  3658. }
  3659. sstr[c] = '\0';
  3660. connectorIdInt = atoi(sstr);
  3661. }
  3662. //***chargingProfilePurpose ****/
  3663. loc = strstr(payload, "chargingProfilePurpose");
  3664. memset(sstr ,0, sizeof(sstr) );
  3665. c = 0;
  3666. if(loc == NULL)
  3667. {
  3668. chargingProfilePurposeIsNULL = TRUE;
  3669. }
  3670. else
  3671. {
  3672. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3673. {
  3674. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3675. c++;
  3676. }
  3677. sstr[c] = '\0';
  3678. strcpy(chargingProfilePurposeStr, sstr);
  3679. }
  3680. //***stackLevel ****/
  3681. c=0;
  3682. loc = strstr(payload, "stackLevel");
  3683. memset(sstr ,0, sizeof(sstr) );
  3684. if(loc == NULL)
  3685. {
  3686. stackLevelIsNULL = TRUE;
  3687. }
  3688. else
  3689. {
  3690. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3691. {
  3692. sstr[c] = loc[strlen("stackLevel")+2+c];
  3693. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3694. c++;
  3695. }
  3696. sstr[c] = '\0';
  3697. stackLevelInt = atoi(sstr);
  3698. }
  3699. if(connectorIsNULL == FALSE)
  3700. {
  3701. switch(connectorIdInt)
  3702. {
  3703. case 0:
  3704. if(chargingProfilePurposeIsNULL == TRUE)
  3705. {
  3706. int l = 0;
  3707. strcpy(fname, ChargePointMaxProfile_JSON);
  3708. if((access(fname,F_OK))!=-1)
  3709. {
  3710. strcpy(chargingProfiles[l], fname);
  3711. l = l + 1;
  3712. }
  3713. strcpy(fname, TxDefaultProfile_0_JSON);
  3714. if((access(fname,F_OK))!=-1)
  3715. {
  3716. strcpy(chargingProfiles[l], fname);
  3717. l = l + 1;
  3718. }
  3719. ChargeProfileCount = l;
  3720. }
  3721. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3722. {
  3723. strcpy(fname, ChargePointMaxProfile_JSON);
  3724. if((access(fname,F_OK))!=-1)
  3725. {
  3726. strcpy(chargingProfiles[0], fname);
  3727. ChargeProfileCount = 1;
  3728. }
  3729. }
  3730. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3731. {
  3732. strcpy(fname, TxDefaultProfile_0_JSON);
  3733. if((access(fname,F_OK))!=-1)
  3734. {
  3735. strcpy(chargingProfiles[0], fname);
  3736. ChargeProfileCount = 1;
  3737. }
  3738. }
  3739. break;
  3740. default:
  3741. if(chargingProfilePurposeIsNULL == TRUE)
  3742. {
  3743. int m = 0;
  3744. memset(fname, 0, sizeof fname);
  3745. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3746. if((access(fname,F_OK))!=-1)
  3747. {
  3748. strcpy(chargingProfiles[m], fname);
  3749. m = m + 1;
  3750. }
  3751. memset(fname, 0, sizeof fname);
  3752. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3753. if((access(fname,F_OK))!=-1)
  3754. {
  3755. strcpy(chargingProfiles[m], fname);
  3756. m = m + 1;
  3757. }
  3758. ChargeProfileCount = m;
  3759. }
  3760. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3761. {
  3762. //strcpy(fname, TxDefaultProfile_1_JSON);
  3763. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3764. if((access(fname,F_OK))!=-1)
  3765. {
  3766. strcpy(chargingProfiles[0], fname);
  3767. ChargeProfileCount = 1;
  3768. }
  3769. }
  3770. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3771. {
  3772. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3773. if((access(fname,F_OK))!=-1)
  3774. {
  3775. strcpy(chargingProfiles[0], fname);
  3776. ChargeProfileCount = 1;
  3777. }
  3778. //strcpy(fname, TxProfile_1_JSON);
  3779. }
  3780. //strcpy(fname, ChargePointMaxProfile_JSON );
  3781. break;
  3782. }
  3783. }
  3784. else // Check all Charging Profiles
  3785. {
  3786. int i = 0;
  3787. char fnametemp[200]={0};
  3788. ChargeProfileCount = 0;
  3789. //Check ChargePointMaxProfile.json exit
  3790. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3791. {
  3792. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3793. i = i + 1;
  3794. }
  3795. //Check TxDefaultProfile_0.json exit
  3796. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3797. {
  3798. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3799. i = i + 1;
  3800. }
  3801. //Check TxDefaultProfile_%d.json
  3802. for(int j=1; j <= gunTotalNumber; j++)
  3803. {
  3804. memset(fnametemp, 0, sizeof fnametemp);
  3805. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3806. if((access(fnametemp,F_OK))!=-1)
  3807. {
  3808. strcpy(chargingProfiles[i], fnametemp);
  3809. i = i + 1;
  3810. }
  3811. }
  3812. //Check TxProfile_%d.json
  3813. for(int j=1; j <= gunTotalNumber; j++)
  3814. {
  3815. memset(fnametemp, 0, sizeof fnametemp);
  3816. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3817. if((access(fnametemp,F_OK))!=-1)
  3818. {
  3819. strcpy(chargingProfiles[i], fnametemp);
  3820. i = i + 1;
  3821. }
  3822. }
  3823. ChargeProfileCount = i;
  3824. }// End connectorIsNULL is TRUE
  3825. if(ChargeProfileCount == 0)
  3826. {
  3827. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3828. goto end;
  3829. }
  3830. #if 0
  3831. fptr1 = fopen(fname, "r");
  3832. if (!fptr1)
  3833. {
  3834. //file not exist
  3835. DEBUG_INFO("Unable to open the input file!!\n");
  3836. fptr1 = fopen(fname, "w+");
  3837. }
  3838. fclose(fptr1);
  3839. #endif
  3840. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3841. {
  3842. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3843. goto end;
  3844. }
  3845. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3846. {
  3847. //clear file in C
  3848. sprintf(str,"rm -f %s",fname);
  3849. system(str);
  3850. // clear temp file
  3851. sprintf(str,"rm -f %s",temp);
  3852. system(str);
  3853. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3854. goto end;
  3855. }
  3856. else if(connectorIsNULL == TRUE)
  3857. {
  3858. for(int k=0; k < ChargeProfileCount; k++)
  3859. {
  3860. fptr1 = fopen(chargingProfiles[k], "r");
  3861. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  3862. //Check Charging Profile Count
  3863. while(fscanf(fptr1, "%s", word) != EOF)
  3864. {
  3865. //DEBUG_INFO("word=%s\n",word);
  3866. if(strstr(word, "chargingProfileId")!= NULL)
  3867. {
  3868. //DEBUG_INFO("test chargingProfileId \n");
  3869. n_chargingProfile = n_chargingProfile + 1;
  3870. //DEBUG_INFO("chargingProfileId Found\n");
  3871. }
  3872. }
  3873. rewind(fptr1);
  3874. //search Charging Profile Element
  3875. //int i= 0;
  3876. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3877. {
  3878. //------------------------tempconnectorIdInt------------------------//
  3879. loc = strstr(sLineWord, "connectorId");
  3880. c = 0;
  3881. memset(sstr ,0, sizeof(sstr) );
  3882. while (loc[strlen("connectorId")+2+c] != ',')
  3883. {
  3884. sstr[c] = loc[strlen("connectorId")+2+c];
  3885. c++;
  3886. }
  3887. sstr[c] = '\0';
  3888. tempconnectorIdInt = atoi(sstr);
  3889. printf("file's gun number is %d\n", tempconnectorIdInt);
  3890. //--------------------------chargingProfileId--------------------//
  3891. c = 0;
  3892. loc = strstr(sLineWord, "chargingProfileId");
  3893. memset(sstr ,0, sizeof(sstr) );
  3894. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3895. {
  3896. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3897. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3898. c++;
  3899. }
  3900. sstr[c] = '\0';
  3901. tempchargingProfileIdInt = atoi(sstr);
  3902. //stackLevel
  3903. c = 0;
  3904. loc = strstr(sLineWord, "stackLevel");
  3905. memset(sstr ,0, sizeof(sstr) );
  3906. while (loc[strlen("stackLevel")+2+c] != ',')
  3907. {
  3908. sstr[c] = loc[strlen("stackLevel")+2+c];
  3909. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3910. c++;
  3911. }
  3912. sstr[c] = '\0';
  3913. tempstackLevelInt = atoi(sstr);
  3914. c = 0;
  3915. loc = strstr(sLineWord, "chargingProfilePurpose");
  3916. memset(sstr ,0, sizeof(sstr) );
  3917. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3918. {
  3919. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3920. c++;
  3921. }
  3922. sstr[c] = '\0';
  3923. strcpy(tempchargingProfilePurposeStr, sstr);
  3924. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  3925. {
  3926. //------- not write to fptr2-------//
  3927. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3928. //clearflag = TRUE;
  3929. }
  3930. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  3931. {
  3932. //------- not write to fptr2-------//
  3933. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3934. }
  3935. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  3936. {
  3937. //------- not write to fptr2-------//
  3938. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3939. }
  3940. else
  3941. {
  3942. fprintf(fptr2, sLineWord);//writing data into file
  3943. }
  3944. memset(sLineWord, 0, sizeof sLineWord);
  3945. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3946. if(clearflag == TRUE)
  3947. {
  3948. fclose(fptr1);
  3949. fclose(fptr2);
  3950. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3951. system(str);
  3952. // clear temp file
  3953. sprintf(str,"rm -f %s",temp);
  3954. system(str);
  3955. }
  3956. else
  3957. {
  3958. fclose(fptr1);
  3959. fclose(fptr2);
  3960. memset(str, 0, sizeof str);
  3961. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3962. system(str);
  3963. resultRename = rename(temp, chargingProfiles[k]);
  3964. if(resultRename == 0)
  3965. {
  3966. DEBUG_INFO("File ChargingProfile renamed successfully");
  3967. }
  3968. else
  3969. {
  3970. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  3971. }
  3972. if(comfirmstr[0]== 0)
  3973. {
  3974. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3975. }
  3976. //Check chargingProfile is empty file
  3977. /*------ Read the file ----------------*/
  3978. fptr1=fopen(chargingProfiles[k],"r");
  3979. ch=fgetc(fptr1);
  3980. rewind(fptr1);
  3981. memset(sLineWord, 0, sizeof sLineWord);
  3982. if(ch!=EOF)
  3983. {
  3984. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  3985. {
  3986. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  3987. if(sLineWord[0]=='\0')
  3988. {
  3989. isEmptyFile = TRUE;
  3990. break;
  3991. }
  3992. else
  3993. {
  3994. isEmptyFile = FALSE;
  3995. break;
  3996. }
  3997. }
  3998. }
  3999. fclose(fptr1);
  4000. if(isEmptyFile == TRUE)
  4001. {
  4002. memset(str, 0, sizeof str);
  4003. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4004. system(str);
  4005. }
  4006. }
  4007. }// End of while(int k=0; k < ChargePointCount; k++)
  4008. }
  4009. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4010. {
  4011. for(int k=0; k < ChargeProfileCount; k++)
  4012. {
  4013. fptr1 = fopen(chargingProfiles[k], "r");
  4014. fptr2 = fopen(temp, "w+");
  4015. //Check Charging Profile Count
  4016. while(fscanf(fptr1, "%s", word) != EOF)
  4017. {
  4018. //DEBUG_INFO("word=%s\n",word);
  4019. if(strstr(word, "chargingProfileId")!= NULL)
  4020. {
  4021. //DEBUG_INFO("test chargingProfileId \n");
  4022. n_chargingProfile = n_chargingProfile + 1;
  4023. //DEBUG_INFO("chargingProfileId Found\n");
  4024. }
  4025. }
  4026. rewind(fptr1);
  4027. //search Charging Profile Element
  4028. //int i= 0;
  4029. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4030. {
  4031. //*************************tempconnectorIdInt*********************************/
  4032. loc = strstr(sLineWord, "connectorId");
  4033. c = 0;
  4034. memset(sstr ,0, sizeof(sstr) );
  4035. while (loc[strlen("connectorId")+2+c] != ',')
  4036. {
  4037. sstr[c] = loc[strlen("connectorId")+2+c];
  4038. c++;
  4039. }
  4040. sstr[c] = '\0';
  4041. tempconnectorIdInt = atoi(sstr);
  4042. //chargingProfileId
  4043. c = 0;
  4044. loc = strstr(sLineWord, "chargingProfileId");
  4045. memset(sstr ,0, sizeof(sstr) );
  4046. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4047. {
  4048. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4049. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4050. c++;
  4051. }
  4052. sstr[c] = '\0';
  4053. tempchargingProfileIdInt = atoi(sstr);
  4054. //stackLevel
  4055. c = 0;
  4056. loc = strstr(sLineWord, "stackLevel");
  4057. memset(sstr ,0, sizeof(sstr) );
  4058. while (loc[strlen("stackLevel")+2+c] != ',')
  4059. {
  4060. sstr[c] = loc[strlen("stackLevel")+2+c];
  4061. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4062. c++;
  4063. }
  4064. sstr[c] = '\0';
  4065. tempstackLevelInt = atoi(sstr);
  4066. c = 0;
  4067. loc = strstr(sLineWord, "chargingProfilePurpose");
  4068. memset(sstr ,0, sizeof(sstr) );
  4069. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4070. {
  4071. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4072. c++;
  4073. }
  4074. sstr[c] = '\0';
  4075. strcpy(tempchargingProfilePurposeStr, sstr);
  4076. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4077. {
  4078. //------- not write to fptr2-------//
  4079. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4080. //clearflag = TRUE;
  4081. }
  4082. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4083. {
  4084. //------- not write to fptr2-------//
  4085. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4086. }
  4087. else if(stackLevelIsNULL == TRUE)
  4088. {
  4089. //Clear Whole File
  4090. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4091. clearflag = TRUE;
  4092. break;
  4093. }
  4094. else
  4095. {
  4096. fprintf(fptr2, sLineWord);//writing data into file
  4097. }
  4098. memset(sLineWord, 0, sizeof sLineWord);
  4099. }
  4100. if(clearflag == TRUE)
  4101. {
  4102. fclose(fptr1);
  4103. fclose(fptr2);
  4104. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4105. system(str);
  4106. // clear temp file
  4107. sprintf(str,"rm -f %s",temp);
  4108. system(str);
  4109. }
  4110. else
  4111. {
  4112. fclose(fptr1);
  4113. fclose(fptr2);
  4114. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4115. system(str);
  4116. resultRename = rename(temp, chargingProfiles[k]);
  4117. if(resultRename == 0)
  4118. {
  4119. DEBUG_INFO("File ChargingProfile renamed successfully");
  4120. }
  4121. else
  4122. {
  4123. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4124. }
  4125. if(comfirmstr[0]== 0)
  4126. {
  4127. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4128. }
  4129. //Check chargingProfile is empty file
  4130. /*------ Read the file ----------------*/
  4131. fptr1=fopen(chargingProfiles[k],"r");
  4132. ch=fgetc(fptr1);
  4133. rewind(fptr1);
  4134. memset(sLineWord, 0, sizeof sLineWord);
  4135. if(ch!=EOF)
  4136. {
  4137. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4138. {
  4139. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4140. if(sLineWord[0]=='\0')
  4141. {
  4142. isEmptyFile = TRUE;
  4143. break;
  4144. }
  4145. else
  4146. {
  4147. isEmptyFile = FALSE;
  4148. break;
  4149. }
  4150. }
  4151. }
  4152. fclose(fptr1);
  4153. if(isEmptyFile == TRUE)
  4154. {
  4155. memset(str, 0, sizeof str);
  4156. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4157. system(str);
  4158. }
  4159. /*------- End of reading ---------------*/
  4160. }
  4161. } // while(int k=0; k < ChargeProfileCount; k++)
  4162. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4163. end:
  4164. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4165. return result;
  4166. }
  4167. int handleDataTransferRequest(char *uuid, char *payload)
  4168. {
  4169. mtrace();
  4170. int result = FAIL;
  4171. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4172. char tempvendorId[255]={0};
  4173. char tempmessageId[50]={0};
  4174. char tempdata[50]={0};
  4175. char sstr[160]={0};//sstr[200]={ 0 };
  4176. char message[80]={0};
  4177. int c = 0;
  4178. char *loc;
  4179. DEBUG_INFO("handle DataTransferRequest\n");
  4180. if((uuid != NULL) && (payload != NULL))
  4181. {
  4182. //===============================
  4183. // vendorId
  4184. //===============================
  4185. c = 0;
  4186. loc = strstr(payload, "vendorId");
  4187. while (loc[strlen("vendorId")+3+c] != '\"')
  4188. {
  4189. sstr[c] = loc[strlen("vendorId")+3+c];
  4190. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4191. c++;
  4192. }
  4193. sstr[c] = '\0';
  4194. strcpy(tempvendorId,sstr);
  4195. //===============================
  4196. // messageId
  4197. //===============================
  4198. memset(sstr ,0, sizeof(sstr) );
  4199. c = 0;
  4200. loc = strstr(payload, "messageId");
  4201. while (loc[strlen("messageId")+3+c] != '\"')
  4202. {
  4203. sstr[c] = loc[strlen("messageId")+3+c];
  4204. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4205. c++;
  4206. }
  4207. sstr[c] = '\0';
  4208. strcpy(tempmessageId,sstr);
  4209. //===============================
  4210. // data
  4211. //===============================
  4212. memset(sstr ,0, sizeof(sstr) );
  4213. c = 0;
  4214. loc = strstr(payload, "data");
  4215. printf("loc=%s\n",loc);
  4216. while (loc[strlen("data")+3+c] != '\"')
  4217. {
  4218. sstr[c] = loc[strlen("data")+3+c];
  4219. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4220. c++;
  4221. }
  4222. sstr[c] = '\0';
  4223. strcpy(tempdata,sstr);
  4224. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4225. }
  4226. else
  4227. {
  4228. char guid[37]={0};
  4229. random_uuid(guid);
  4230. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4231. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4232. }
  4233. LWS_Send(message);
  4234. return result;
  4235. }
  4236. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4237. {
  4238. mtrace();
  4239. int result = FAIL;
  4240. int connectorIdInt, durationInt;
  4241. char chargingRateUnitStr[4]={0};
  4242. //int tempconnectorIdInt,
  4243. int tempdurationInt;
  4244. float tempminChargingRateFloat = 0.0;
  4245. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4246. int tempStartPeriodInt=0;
  4247. float tempLimitInt=0.0;//0.1;
  4248. int tempNumberPhasesInt=0;
  4249. char fname[200];
  4250. char comfirmstr[20];
  4251. //float totallimit =0.0;
  4252. float MinChargingRate =0.0;
  4253. //double diff_t;
  4254. //struct tm tp;
  4255. FILE *fptr1;
  4256. int c = 0;
  4257. //int i = 0;
  4258. char * pch;
  4259. char *loc;
  4260. char sstr[200]={ 0 };
  4261. int n_chargingProfile = 0;
  4262. int n_SchedulePeriods = 0;
  4263. char SchedulePeriodList[10][200]={0};
  4264. char sLineWord[800]={0};
  4265. //int n_periods = 0;
  4266. char word[1000]={0};
  4267. int confirmPeriods = 0;
  4268. struct StructProfile ChargePointMaxProfile;
  4269. struct StructProfile TxDefaultProfile;
  4270. struct StructProfile TxProfile;
  4271. struct StructProfile TxDefaultProfiletemp[2]={0};
  4272. int TxDefaultProfileFileIsNull=FALSE;
  4273. int ChargePointMaxProfileIsNull=FALSE;
  4274. int TxProfileIsNull=FALSE;
  4275. int CompositeSceduleIndex = 0;
  4276. char ChargePointMaxProfileScheduleStr[30]={0};
  4277. char TxDefaultProfileScheduleStr[30]={0};
  4278. char TxProfileScheduleStr[30]={0};
  4279. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4280. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4281. memset(&TxProfile,0,sizeof(struct StructProfile));
  4282. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4283. c=0;
  4284. loc = strstr(payload, "connectorId");
  4285. memset(sstr ,0, sizeof(sstr) );
  4286. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4287. {
  4288. sstr[c] = loc[strlen("connectorId")+2+c];
  4289. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4290. c++;
  4291. }
  4292. sstr[c] = '\0';
  4293. connectorIdInt = atoi(sstr);
  4294. c=0;
  4295. loc = strstr(payload, "duration");
  4296. memset(sstr ,0, sizeof(sstr) );
  4297. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4298. {
  4299. sstr[c] = loc[strlen("duration")+2+c];
  4300. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4301. c++;
  4302. }
  4303. sstr[c] = '\0';
  4304. durationInt = atoi(sstr);
  4305. c = 0;
  4306. loc = strstr(payload, "chargingRateUnit");
  4307. memset(sstr ,0, sizeof(sstr) );
  4308. if(loc == NULL)
  4309. {
  4310. }
  4311. else
  4312. {
  4313. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4314. {
  4315. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4316. c++;
  4317. }
  4318. sstr[c] = '\0';
  4319. strcpy(chargingRateUnitStr, sstr);
  4320. }
  4321. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4322. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4323. if(connectorIdInt==0) // connectorId is 0
  4324. {
  4325. //******************************ChargePointMaxProfile*****************************************************/
  4326. strcpy(fname, ChargePointMaxProfile_JSON );
  4327. char word[30]={0};
  4328. char sLineWord[1060]={0};
  4329. int n_chargingProfile=0;
  4330. ChargePointMaxProfileIsNull=TRUE;
  4331. if((access(fname,F_OK))!=-1)
  4332. {
  4333. fptr1 = fopen(fname, "r");
  4334. int c;
  4335. c = fgetc(fptr1);
  4336. //DEBUG_INFO("c:%d\n",c);
  4337. rewind(fptr1);
  4338. if(c == EOF)
  4339. {
  4340. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4341. ChargePointMaxProfileIsNull=TRUE;
  4342. fclose(fptr1);
  4343. }
  4344. else
  4345. {
  4346. ChargePointMaxProfileIsNull=FALSE;
  4347. while(fscanf(fptr1, "%s", word) != EOF)
  4348. {
  4349. if(strcmp(word, "chargingProfileId") == 0)
  4350. {
  4351. n_chargingProfile = n_chargingProfile + 1;
  4352. printf("Found\n");
  4353. }
  4354. }
  4355. rewind(fptr1);
  4356. //search Charging Profile Element
  4357. int i= 0;
  4358. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4359. #if 0
  4360. /***********connectorId****************/
  4361. c = 0;
  4362. loc = strstr(sLineWord, "connectorId");
  4363. // printf("loc=%s\n",loc);
  4364. memset(sstr ,0, sizeof(sstr) );
  4365. while (loc[strlen("connectorId")+2+c] != ',')
  4366. {
  4367. sstr[c] = loc[strlen("connectorId")+2+c];
  4368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4369. c++;
  4370. }
  4371. sstr[c] = '\0';
  4372. tempconnectorIdInt = atoi(sstr);
  4373. #endif
  4374. //***********validFrom**************/
  4375. c = 0;
  4376. loc = strstr(sLineWord, "validFrom");
  4377. //DEBUG_INFO("loc=%s\n",loc);
  4378. memset(sstr ,0, sizeof(sstr) );
  4379. if(loc != NULL)
  4380. {
  4381. while (loc[3+strlen("validFrom")+c] != '\"')
  4382. {
  4383. sstr[c] = loc[3+strlen("validFrom")+c];
  4384. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4385. c++;
  4386. }
  4387. sstr[c] = '\0';
  4388. DEBUG_INFO("validFrom=%s\n",sstr);
  4389. strcpy(tempvalidFromStr,sstr);
  4390. }
  4391. else
  4392. {
  4393. strcpy(tempvalidFromStr,"");
  4394. }
  4395. //**********startSchedule**********/
  4396. c = 0;
  4397. loc = strstr(sLineWord, "startSchedule");
  4398. //DEBUG_INFO("loc=%s\n",loc);
  4399. memset(sstr ,0, sizeof(sstr) );
  4400. while (loc[3+strlen("startSchedule")+c] != '\"')
  4401. {
  4402. sstr[c] = loc[3+strlen("startSchedule")+c];
  4403. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4404. c++;
  4405. }
  4406. sstr[c] = '\0';
  4407. strcpy(tempstartScheduleStr, sstr);
  4408. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4409. //**********chargingRateUnit**********/
  4410. c = 0;
  4411. loc = strstr(sLineWord, "chargingRateUnit");
  4412. memset(sstr ,0, sizeof(sstr) );
  4413. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4414. {
  4415. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4416. c++;
  4417. }
  4418. sstr[c] = '\0';
  4419. strcpy(tempchargingRateUnitStr, sstr);
  4420. //**********minChargingRate*******/
  4421. c = 0;
  4422. loc = strstr(sLineWord, "minChargingRate");
  4423. //printf("loc=%s\n",loc);
  4424. if(loc != NULL)
  4425. {
  4426. memset(sstr ,0, sizeof(sstr) );
  4427. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4428. {
  4429. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4430. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4431. c++;
  4432. }
  4433. sstr[c] = '\0';
  4434. tempminChargingRateFloat = atof(sstr);
  4435. }
  4436. else
  4437. {
  4438. tempminChargingRateFloat = 0.0;
  4439. }
  4440. //
  4441. #if 0
  4442. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4443. tp.tm_isdst = -1;
  4444. time_t utc = mktime(&tp);
  4445. // current time
  4446. time_t t = time(NULL);
  4447. #endif
  4448. //diff_t = difftime(t, utc);
  4449. //parsing strings to words
  4450. i = 0;
  4451. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4452. loc = loc+3+strlen("chargingSchedulePeriod");
  4453. pch = strtok(loc ,"{");
  4454. while (pch != NULL)
  4455. {
  4456. strcpy(SchedulePeriodList[i], pch);
  4457. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4458. //printf ("%s\n",pch);
  4459. pch = strtok (NULL, "{");
  4460. i = i + 1;
  4461. }
  4462. n_SchedulePeriods = i;
  4463. for(int i=0;i<n_SchedulePeriods;i++)
  4464. {
  4465. //*************startPeriod****************/
  4466. c = 0;
  4467. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4468. memset(sstr ,0, sizeof(sstr) );
  4469. while (loc[strlen("startPeriod")+2+c] != ',')
  4470. {
  4471. sstr[c] = loc[strlen("startPeriod")+2+c];
  4472. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4473. c++;
  4474. }
  4475. sstr[c] = '\0';
  4476. tempStartPeriodInt = atoi(sstr);
  4477. //*************limit****************/
  4478. c = 0;
  4479. loc = strstr(SchedulePeriodList[i], "limit");
  4480. memset(sstr ,0, sizeof(sstr) );
  4481. while (loc[strlen("limit")+2+c] != ',')
  4482. {
  4483. sstr[c] = loc[strlen("limit")+2+c];
  4484. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4485. c++;
  4486. }
  4487. sstr[c] = '\0';
  4488. tempLimitInt = atof(sstr);
  4489. //*************numberPhases****************/
  4490. c = 0;
  4491. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4492. memset(sstr ,0, sizeof(sstr) );
  4493. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4494. {
  4495. sstr[c] = loc[strlen("numberPhases")+2+c];
  4496. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4497. c++;
  4498. }
  4499. sstr[c] = '\0';
  4500. tempNumberPhasesInt = atoi(sstr);
  4501. ChargePointMaxProfile.Duration = durationInt;
  4502. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4503. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4504. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4505. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4506. }
  4507. if(MinChargingRate < tempminChargingRateFloat)
  4508. MinChargingRate = tempminChargingRateFloat;
  4509. }
  4510. }// End of file ChargingProfile
  4511. } //THE END OF ACCESS ChargePointMaxProfile
  4512. //******************************TxDefaultProfile***********************************************/
  4513. strcpy(fname, TxDefaultProfile_0_JSON);
  4514. memset(word, 0, 30);
  4515. memset(sLineWord, 0, 1060);
  4516. //char word[30]={0};
  4517. //char sLineWord[1060]={0};
  4518. n_chargingProfile=0;
  4519. TxDefaultProfileFileIsNull=TRUE;
  4520. if((access(fname,F_OK))!=-1)
  4521. {
  4522. fptr1 = fopen(fname, "r");
  4523. c = 0;
  4524. c = fgetc(fptr1);
  4525. //DEBUG_INFO("c:%d\n",c);
  4526. rewind(fptr1);
  4527. if(c == EOF)
  4528. {
  4529. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4530. TxDefaultProfileFileIsNull=TRUE;
  4531. fclose(fptr1);
  4532. }
  4533. else
  4534. {
  4535. TxDefaultProfileFileIsNull=FALSE;
  4536. while(fscanf(fptr1, "%s", word) != EOF)
  4537. {
  4538. if(strcmp(word, "chargingProfileId") == 0)
  4539. {
  4540. n_chargingProfile = n_chargingProfile + 1;
  4541. printf("Found\n");
  4542. }
  4543. }
  4544. rewind(fptr1);
  4545. //search Charging Profile Element
  4546. int i= 0;
  4547. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4548. #if 0
  4549. /***********connectorId****************/
  4550. c = 0;
  4551. loc = strstr(sLineWord, "connectorId");
  4552. // printf("loc=%s\n",loc);
  4553. memset(sstr ,0, sizeof(sstr) );
  4554. while (loc[strlen("connectorId")+2+c] != ',')
  4555. {
  4556. sstr[c] = loc[strlen("connectorId")+2+c];
  4557. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4558. c++;
  4559. }
  4560. sstr[c] = '\0';
  4561. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4562. tempconnectorIdInt = atoi(sstr);
  4563. #endif
  4564. //***********validFrom**************/
  4565. c = 0;
  4566. loc = strstr(sLineWord, "validFrom");
  4567. //DEBUG_INFO("loc=%s\n",loc);
  4568. memset(sstr ,0, sizeof(sstr) );
  4569. if(loc != NULL)
  4570. {
  4571. while (loc[3+strlen("validFrom")+c] != '\"')
  4572. {
  4573. sstr[c] = loc[3+strlen("validFrom")+c];
  4574. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4575. c++;
  4576. }
  4577. sstr[c] = '\0';
  4578. DEBUG_INFO("validFrom=%s\n",sstr);
  4579. strcpy(tempvalidFromStr,sstr);
  4580. }
  4581. else
  4582. {
  4583. strcpy(tempvalidFromStr,"");
  4584. }
  4585. //**********startSchedule**********/
  4586. c = 0;
  4587. loc = strstr(sLineWord, "startSchedule");
  4588. //DEBUG_INFO("loc=%s\n",loc);
  4589. memset(sstr ,0, sizeof(sstr) );
  4590. while (loc[3+strlen("startSchedule")+c] != '\"')
  4591. {
  4592. sstr[c] = loc[3+strlen("startSchedule")+c];
  4593. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4594. c++;
  4595. }
  4596. sstr[c] = '\0';
  4597. strcpy(tempstartScheduleStr, sstr);
  4598. strcpy(TxDefaultProfileScheduleStr, sstr);
  4599. DEBUG_INFO(" debug 3-1\n");
  4600. //**********chargingRateUnit**********/
  4601. c = 0;
  4602. loc = strstr(sLineWord, "chargingRateUnit");
  4603. memset(sstr ,0, sizeof(sstr) );
  4604. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4605. {
  4606. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4607. c++;
  4608. }
  4609. sstr[c] = '\0';
  4610. strcpy(tempchargingRateUnitStr, sstr);
  4611. //**********minChargingRate*******/
  4612. c = 0;
  4613. loc = strstr(sLineWord, "minChargingRate");
  4614. //printf("loc=%s\n",loc);
  4615. if(loc != NULL)
  4616. {
  4617. memset(sstr ,0, sizeof(sstr) );
  4618. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4619. {
  4620. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4621. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4622. c++;
  4623. }
  4624. sstr[c] = '\0';
  4625. tempminChargingRateFloat = atof(sstr);
  4626. }
  4627. else
  4628. {
  4629. tempminChargingRateFloat = 0.0;
  4630. }
  4631. #if 0
  4632. //
  4633. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4634. tp.tm_isdst = -1;
  4635. time_t utc = mktime(&tp);
  4636. // current time
  4637. time_t t = time(NULL);
  4638. //diff_t = difftime(t, utc);
  4639. #endif
  4640. //parsing strings to words
  4641. i = 0;
  4642. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4643. loc = loc+3+strlen("chargingSchedulePeriod");
  4644. pch = strtok(loc ,"{");
  4645. while (pch != NULL)
  4646. {
  4647. strcpy(SchedulePeriodList[i], pch);
  4648. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4649. //printf ("%s\n",pch);
  4650. pch = strtok (NULL, "{");
  4651. i = i + 1;
  4652. }
  4653. n_SchedulePeriods = i;
  4654. for(int i=0;i<n_SchedulePeriods;i++)
  4655. {
  4656. //*************startPeriod****************/
  4657. c = 0;
  4658. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4659. memset(sstr ,0, sizeof(sstr) );
  4660. while (loc[strlen("startPeriod")+2+c] != ',')
  4661. {
  4662. sstr[c] = loc[strlen("startPeriod")+2+c];
  4663. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4664. c++;
  4665. }
  4666. sstr[c] = '\0';
  4667. tempStartPeriodInt = atoi(sstr);
  4668. //*************limit****************/
  4669. c = 0;
  4670. loc = strstr(SchedulePeriodList[i], "limit");
  4671. memset(sstr ,0, sizeof(sstr) );
  4672. while (loc[strlen("limit")+2+c] != ',')
  4673. {
  4674. sstr[c] = loc[strlen("limit")+2+c];
  4675. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4676. c++;
  4677. }
  4678. sstr[c] = '\0';
  4679. tempLimitInt = atof(sstr);
  4680. //*************numberPhases****************/
  4681. c = 0;
  4682. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4683. memset(sstr ,0, sizeof(sstr) );
  4684. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4685. {
  4686. sstr[c] = loc[strlen("numberPhases")+2+c];
  4687. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4688. c++;
  4689. }
  4690. sstr[c] = '\0';
  4691. tempNumberPhasesInt = atoi(sstr);
  4692. TxDefaultProfile.Duration = durationInt;
  4693. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4694. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4695. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4696. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4697. }
  4698. if(MinChargingRate < tempminChargingRateFloat)
  4699. MinChargingRate = tempminChargingRateFloat;
  4700. }
  4701. }
  4702. }// the end of ACCESS TxDefaultProfile
  4703. // Composite Schedule
  4704. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4705. {
  4706. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4707. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4708. {
  4709. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4710. {
  4711. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4712. }
  4713. else
  4714. {
  4715. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4716. }
  4717. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4718. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4719. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4720. }
  4721. }
  4722. //* Define temporary variables */
  4723. struct tm *gtime;
  4724. time_t now;
  4725. char buf[28];
  4726. /* Read the current system time */
  4727. time(&now);
  4728. /* Convert the system time to GMT (now UTC) */
  4729. gtime = gmtime(&now);
  4730. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4731. // make .conf
  4732. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4733. //MaxChargingProfilesInstalled is 10
  4734. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4735. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4736. //nPeriod = 1;
  4737. if(chargingRateUnitStr[0] != 0)
  4738. {
  4739. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4740. }
  4741. else
  4742. {
  4743. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4744. }
  4745. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4746. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4747. confirmPeriods = 1;
  4748. }
  4749. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4750. {
  4751. //*****************************ChargePointMaxProfile******************************************/
  4752. strcpy(fname, ChargePointMaxProfile_JSON);
  4753. ChargePointMaxProfileIsNull=TRUE;
  4754. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4755. {
  4756. fptr1 = fopen(fname, "r");
  4757. int c;
  4758. c = fgetc(fptr1);
  4759. //DEBUG_INFO("c:%d\n",c);
  4760. rewind(fptr1);
  4761. if(c == EOF)
  4762. {
  4763. DEBUG_INFO("\n End of file reached.");
  4764. ChargePointMaxProfileIsNull=TRUE;
  4765. fclose(fptr1);
  4766. }
  4767. else
  4768. {
  4769. ChargePointMaxProfileIsNull=FALSE;
  4770. while(fscanf(fptr1, "%s", word) != EOF)
  4771. {
  4772. if(strcmp(word, "chargingProfileId") == 0)
  4773. {
  4774. n_chargingProfile = n_chargingProfile + 1;
  4775. }
  4776. }
  4777. rewind(fptr1);
  4778. //search Charging Profile Element
  4779. int i = 0;
  4780. int j = 0;
  4781. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4782. #if 0
  4783. /***********connectorId****************/
  4784. c = 0;
  4785. loc = strstr(sLineWord, "connectorId");
  4786. memset(sstr ,0, sizeof(sstr) );
  4787. while (loc[strlen("connectorId")+2+c] != ',')
  4788. {
  4789. sstr[c] = loc[strlen("connectorId")+2+c];
  4790. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4791. c++;
  4792. }
  4793. sstr[c] = '\0';
  4794. tempconnectorIdInt = atoi(sstr);
  4795. #endif
  4796. //***********validFrom**************/
  4797. c = 0;
  4798. loc = strstr(sLineWord, "validFrom");
  4799. if(loc != NULL)
  4800. {
  4801. memset(sstr ,0, sizeof(sstr) );
  4802. while (loc[3+strlen("validFrom")+c] != '\"')
  4803. {
  4804. sstr[c] = loc[3+strlen("validFrom")+c];
  4805. c++;
  4806. }
  4807. sstr[c] = '\0';
  4808. strcpy(tempvalidFromStr,sstr);
  4809. }
  4810. else
  4811. {
  4812. strcpy(tempvalidFromStr,"");
  4813. }
  4814. //***********validFrom**************/
  4815. c = 0;
  4816. loc = strstr(sLineWord, "duration");
  4817. if(loc != NULL)
  4818. {
  4819. memset(sstr ,0, sizeof(sstr) );
  4820. while (loc[2+strlen("duration")+c] != ',')
  4821. {
  4822. sstr[c] = loc[2+strlen("duration")+c];
  4823. c++;
  4824. }
  4825. sstr[c] = '\0';
  4826. tempdurationInt = atoi(sstr);
  4827. }
  4828. else
  4829. {
  4830. tempdurationInt = 0;
  4831. }
  4832. //**********startSchedule**********/
  4833. c = 0;
  4834. loc = strstr(sLineWord, "startSchedule");
  4835. memset(sstr ,0, sizeof(sstr) );
  4836. while (loc[3+strlen("startSchedule")+c] != '\"')
  4837. {
  4838. sstr[c] = loc[3+strlen("startSchedule")+c];
  4839. c++;
  4840. }
  4841. sstr[c] = '\0';
  4842. strcpy(tempstartScheduleStr, sstr);
  4843. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4844. //**********chargingRateUnit**********/
  4845. c = 0;
  4846. loc = strstr(sLineWord, "chargingRateUnit");
  4847. memset(sstr ,0, sizeof(sstr) );
  4848. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4849. {
  4850. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4851. c++;
  4852. }
  4853. sstr[c] = '\0';
  4854. strcpy(tempchargingRateUnitStr, sstr);
  4855. //**********minChargingRate*******/
  4856. c = 0;
  4857. loc = strstr(sLineWord, "minChargingRate");
  4858. if(loc != NULL)
  4859. {
  4860. memset(sstr ,0, sizeof(sstr) );
  4861. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4862. {
  4863. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4864. c++;
  4865. }
  4866. sstr[c] = '\0';
  4867. tempminChargingRateFloat = atof(sstr);
  4868. }
  4869. else
  4870. {
  4871. tempminChargingRateFloat = 0.0;
  4872. }
  4873. #if 0
  4874. //
  4875. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4876. tp.tm_isdst = -1;
  4877. time_t utc = mktime(&tp);
  4878. time_t t = time(NULL);
  4879. //diff_t = difftime(t, utc);
  4880. #endif
  4881. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4882. //DEBUG_INFO(" debug 5 -1\n");
  4883. //parsing strings to words
  4884. i = 0;
  4885. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4886. loc = loc+3+strlen("chargingSchedulePeriod");
  4887. pch = strtok(loc ,"{");
  4888. while (pch != NULL)
  4889. {
  4890. strcpy(SchedulePeriodList[i], pch);
  4891. pch = strtok (NULL, "{");
  4892. i = i + 1;
  4893. }
  4894. n_SchedulePeriods = i;
  4895. for(int i=0;i<n_SchedulePeriods;i++)
  4896. {
  4897. //*************startPeriod****************/
  4898. c = 0;
  4899. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4900. memset(sstr ,0, sizeof(sstr) );
  4901. while (loc[strlen("startPeriod")+2+c] != ',')
  4902. {
  4903. sstr[c] = loc[strlen("startPeriod")+2+c];
  4904. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4905. c++;
  4906. }
  4907. sstr[c] = '\0';
  4908. tempStartPeriodInt = atoi(sstr);
  4909. //*************limit****************/
  4910. c = 0;
  4911. loc = strstr(SchedulePeriodList[i], "limit");
  4912. memset(sstr ,0, sizeof(sstr) );
  4913. while (loc[strlen("limit")+2+c] != ',')
  4914. {
  4915. sstr[c] = loc[strlen("limit")+2+c];
  4916. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4917. c++;
  4918. }
  4919. sstr[c] = '\0';
  4920. tempLimitInt = atof(sstr);
  4921. //*************numberPhases****************/
  4922. c = 0;
  4923. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4924. memset(sstr ,0, sizeof(sstr) );
  4925. while (loc[strlen("numberPhases")+2+c] != '}')
  4926. {
  4927. sstr[c] = loc[strlen("numberPhases")+2+c];
  4928. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4929. c++;
  4930. }
  4931. sstr[c] = '\0';
  4932. tempNumberPhasesInt = atoi(sstr);
  4933. if(j == 0)
  4934. {
  4935. ChargePointMaxProfile.Duration = tempdurationInt;
  4936. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4937. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4938. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4939. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4940. }
  4941. }
  4942. if(MinChargingRate < tempminChargingRateFloat)
  4943. {
  4944. MinChargingRate = tempminChargingRateFloat;
  4945. }
  4946. if(confirmPeriods < n_SchedulePeriods)
  4947. {
  4948. confirmPeriods = n_SchedulePeriods;
  4949. }
  4950. j = j + 1;
  4951. }
  4952. fclose(fptr1);
  4953. }
  4954. }// the end of access file ChargePointMaxProfile
  4955. //****************************TxDefaultProfile************************************************/
  4956. switch(connectorIdInt)
  4957. {
  4958. case 0:
  4959. break;
  4960. case 1:
  4961. strcpy(fname, TxDefaultProfile_1_JSON );
  4962. break;
  4963. case 2:
  4964. strcpy(fname, TxDefaultProfile_2_JSON );
  4965. break;
  4966. default:
  4967. strcpy(fname, TxDefaultProfile_1_JSON );
  4968. break;
  4969. }
  4970. TxDefaultProfileFileIsNull=TRUE;
  4971. if((access(fname,F_OK))!=-1)
  4972. {
  4973. fptr1 = fopen(fname, "r");
  4974. c = 0;
  4975. c = fgetc(fptr1);
  4976. //DEBUG_INFO("c:%d\n",c);
  4977. rewind(fptr1);
  4978. if(c == EOF)
  4979. {
  4980. DEBUG_INFO("\n End of file reached.");
  4981. TxDefaultProfileFileIsNull=TRUE;
  4982. fclose(fptr1);
  4983. }
  4984. else
  4985. {
  4986. TxDefaultProfileFileIsNull=FALSE;
  4987. while(fscanf(fptr1, "%s", word) != EOF)
  4988. {
  4989. if(strcmp(word, "chargingProfileId") == 0)
  4990. {
  4991. n_chargingProfile = n_chargingProfile + 1;
  4992. }
  4993. }
  4994. rewind(fptr1);
  4995. //search Charging Profile Element
  4996. int i = 0;
  4997. int j = 0;
  4998. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4999. //DEBUG_INFO(" 1-1\n");
  5000. #if 0
  5001. /***********connectorId****************/
  5002. c = 0;
  5003. loc = strstr(sLineWord, "connectorId");
  5004. memset(sstr ,0, sizeof(sstr) );
  5005. while (loc[strlen("connectorId")+2+c] != ',')
  5006. {
  5007. sstr[c] = loc[strlen("connectorId")+2+c];
  5008. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5009. c++;
  5010. }
  5011. sstr[c] = '\0';
  5012. tempconnectorIdInt = atoi(sstr);
  5013. #endif
  5014. //***********validFrom**************/
  5015. c = 0;
  5016. loc = strstr(sLineWord, "validFrom");
  5017. if(loc != NULL)
  5018. {
  5019. memset(sstr ,0, sizeof(sstr) );
  5020. while (loc[3+strlen("validFrom")+c] != '\"')
  5021. {
  5022. sstr[c] = loc[3+strlen("validFrom")+c];
  5023. c++;
  5024. }
  5025. sstr[c] = '\0';
  5026. strcpy(tempvalidFromStr,sstr);
  5027. }
  5028. else
  5029. {
  5030. strcpy(tempvalidFromStr,"");
  5031. }
  5032. //***********validFrom**************/
  5033. c = 0;
  5034. loc = strstr(sLineWord, "duration");
  5035. if(loc != NULL)
  5036. {
  5037. memset(sstr ,0, sizeof(sstr) );
  5038. while (loc[2+strlen("duration")+c] != ',')
  5039. {
  5040. sstr[c] = loc[2+strlen("duration")+c];
  5041. c++;
  5042. }
  5043. sstr[c] = '\0';
  5044. tempdurationInt = atoi(sstr);
  5045. }
  5046. else
  5047. {
  5048. tempdurationInt = 0;
  5049. }
  5050. //**********startSchedule**********/
  5051. c = 0;
  5052. loc = strstr(sLineWord, "startSchedule");
  5053. memset(sstr ,0, sizeof(sstr) );
  5054. while (loc[3+strlen("startSchedule")+c] != '\"')
  5055. {
  5056. sstr[c] = loc[3+strlen("startSchedule")+c];
  5057. c++;
  5058. }
  5059. sstr[c] = '\0';
  5060. strcpy(tempstartScheduleStr, sstr);
  5061. strcpy(TxDefaultProfileScheduleStr, sstr);
  5062. //**********chargingRateUnit**********/
  5063. c = 0;
  5064. loc = strstr(sLineWord, "chargingRateUnit");
  5065. memset(sstr ,0, sizeof(sstr) );
  5066. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5067. {
  5068. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5069. c++;
  5070. }
  5071. sstr[c] = '\0';
  5072. strcpy(tempchargingRateUnitStr, sstr);
  5073. //**********minChargingRate*******/
  5074. c = 0;
  5075. loc = strstr(sLineWord, "minChargingRate");
  5076. if(loc != NULL)
  5077. {
  5078. memset(sstr ,0, sizeof(sstr) );
  5079. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5080. {
  5081. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5082. c++;
  5083. }
  5084. sstr[c] = '\0';
  5085. tempminChargingRateFloat = atof(sstr);
  5086. }
  5087. else
  5088. {
  5089. tempminChargingRateFloat = 0.0;
  5090. }
  5091. #if 0
  5092. //
  5093. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5094. tp.tm_isdst = -1;
  5095. time_t utc = mktime(&tp);
  5096. time_t t = time(NULL);
  5097. //diff_t = difftime(t, utc);
  5098. #endif
  5099. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5100. //parsing strings to words
  5101. i = 0;
  5102. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5103. loc = loc+3+strlen("chargingSchedulePeriod");
  5104. pch = strtok(loc ,"{");
  5105. while (pch != NULL)
  5106. {
  5107. strcpy(SchedulePeriodList[i], pch);
  5108. pch = strtok (NULL, "{");
  5109. i = i + 1;
  5110. }
  5111. n_SchedulePeriods = i;
  5112. for(int i=0;i<n_SchedulePeriods;i++)
  5113. {
  5114. //*************startPeriod****************/
  5115. c = 0;
  5116. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5117. memset(sstr ,0, sizeof(sstr) );
  5118. while (loc[strlen("startPeriod")+2+c] != ',')
  5119. {
  5120. sstr[c] = loc[strlen("startPeriod")+2+c];
  5121. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5122. c++;
  5123. }
  5124. sstr[c] = '\0';
  5125. tempStartPeriodInt = atoi(sstr);
  5126. //*************limit****************/
  5127. c = 0;
  5128. loc = strstr(SchedulePeriodList[i], "limit");
  5129. memset(sstr ,0, sizeof(sstr) );
  5130. while (loc[strlen("limit")+2+c] != ',')
  5131. {
  5132. sstr[c] = loc[strlen("limit")+2+c];
  5133. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5134. c++;
  5135. }
  5136. sstr[c] = '\0';
  5137. tempLimitInt = atof(sstr);
  5138. //*************numberPhases****************/
  5139. c = 0;
  5140. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5141. memset(sstr ,0, sizeof(sstr) );
  5142. while (loc[strlen("numberPhases")+2+c] != '}')
  5143. {
  5144. sstr[c] = loc[strlen("numberPhases")+2+c];
  5145. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5146. c++;
  5147. }
  5148. sstr[c] = '\0';
  5149. tempNumberPhasesInt = atoi(sstr);
  5150. if(j == 0)
  5151. {
  5152. TxDefaultProfile.Duration = tempdurationInt;
  5153. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5154. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5155. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5156. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5157. }
  5158. else
  5159. {
  5160. //other stack level charging Profile
  5161. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5162. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5163. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5164. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5165. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5166. }
  5167. }
  5168. if(MinChargingRate < tempminChargingRateFloat)
  5169. MinChargingRate = tempminChargingRateFloat;
  5170. if(confirmPeriods < n_SchedulePeriods)
  5171. confirmPeriods = n_SchedulePeriods;
  5172. j = j + 1;
  5173. //DEBUG_INFO(" 1-2\n");
  5174. }
  5175. fclose(fptr1);
  5176. //Stacking Charging Profiles
  5177. for(int l=0; l <(j-1) ;l++)
  5178. {
  5179. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5180. {
  5181. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5182. {
  5183. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5184. {
  5185. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5186. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5187. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5188. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5189. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5190. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5191. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5192. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5193. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5194. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5195. }
  5196. else
  5197. {
  5198. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5199. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5200. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5201. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5202. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5203. }
  5204. }
  5205. }
  5206. }
  5207. //end of Stacking Charging Profiles
  5208. }
  5209. }// the end of ACCESS TxDefaultProfile
  5210. //****************************TxProfile************************************************/
  5211. switch(connectorIdInt)
  5212. {
  5213. case 0:
  5214. break;
  5215. case 1:
  5216. strcpy(fname, TxProfile_1_JSON );
  5217. break;
  5218. case 2:
  5219. strcpy(fname, TxProfile_2_JSON );
  5220. break;
  5221. default:
  5222. strcpy(fname, TxProfile_1_JSON );
  5223. break;
  5224. }
  5225. TxProfileIsNull=TRUE;
  5226. if((access(fname,F_OK))!=-1)
  5227. {
  5228. fptr1 = fopen(fname, "r");
  5229. c = 0;
  5230. c = fgetc(fptr1);
  5231. //DEBUG_INFO("c:%d\n",c);
  5232. rewind(fptr1);
  5233. if(c == EOF)
  5234. {
  5235. DEBUG_INFO("\n End of file reached.");
  5236. TxProfileIsNull=TRUE;
  5237. fclose(fptr1);
  5238. }
  5239. else
  5240. {
  5241. TxProfileIsNull=FALSE;
  5242. while(fscanf(fptr1, "%s", word) != EOF)
  5243. {
  5244. if(strcmp(word, "chargingProfileId") == 0)
  5245. {
  5246. n_chargingProfile = n_chargingProfile + 1;
  5247. }
  5248. }
  5249. rewind(fptr1);
  5250. //search Charging Profile Element
  5251. int i= 0;
  5252. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5253. #if 0
  5254. /***********connectorId****************/
  5255. c = 0;
  5256. loc = strstr(sLineWord, "connectorId");
  5257. memset(sstr ,0, sizeof(sstr) );
  5258. while (loc[strlen("connectorId")+2+c] != ',')
  5259. {
  5260. sstr[c] = loc[strlen("connectorId")+2+c];
  5261. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5262. c++;
  5263. }
  5264. sstr[c] = '\0';
  5265. tempconnectorIdInt = atoi(sstr);
  5266. #endif
  5267. //***********validFrom**************/
  5268. c = 0;
  5269. loc = strstr(sLineWord, "validFrom");
  5270. if(loc != NULL)
  5271. {
  5272. memset(sstr ,0, sizeof(sstr) );
  5273. while (loc[3+strlen("validFrom")+c] != '\"')
  5274. {
  5275. sstr[c] = loc[3+strlen("validFrom")+c];
  5276. c++;
  5277. }
  5278. sstr[c] = '\0';
  5279. strcpy(tempvalidFromStr,sstr);
  5280. }
  5281. else
  5282. {
  5283. strcpy(tempvalidFromStr,"");
  5284. }
  5285. //**********startSchedule**********/
  5286. c = 0;
  5287. loc = strstr(sLineWord, "startSchedule");
  5288. memset(sstr ,0, sizeof(sstr) );
  5289. while (loc[3+strlen("startSchedule")+c] != '\"')
  5290. {
  5291. sstr[c] = loc[3+strlen("startSchedule")+c];
  5292. c++;
  5293. }
  5294. sstr[c] = '\0';
  5295. strcpy(tempstartScheduleStr, sstr);
  5296. strcpy(TxProfileScheduleStr, sstr);
  5297. //**********chargingRateUnit**********/
  5298. c = 0;
  5299. loc = strstr(sLineWord, "chargingRateUnit");
  5300. memset(sstr ,0, sizeof(sstr) );
  5301. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5302. {
  5303. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5304. c++;
  5305. }
  5306. sstr[c] = '\0';
  5307. strcpy(tempchargingRateUnitStr, sstr);
  5308. //**********minChargingRate*******/
  5309. c = 0;
  5310. loc = strstr(sLineWord, "minChargingRate");
  5311. if(loc != NULL)
  5312. {
  5313. memset(sstr ,0, sizeof(sstr) );
  5314. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5315. {
  5316. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5317. c++;
  5318. }
  5319. sstr[c] = '\0';
  5320. tempminChargingRateFloat = atof(sstr);
  5321. }
  5322. else
  5323. {
  5324. tempminChargingRateFloat = 0.0;
  5325. }
  5326. #if 0
  5327. //
  5328. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5329. tp.tm_isdst = -1;
  5330. time_t utc = mktime(&tp);
  5331. time_t t = time(NULL);
  5332. //diff_t = difftime(t, utc);
  5333. #endif
  5334. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5335. //parsing strings to words
  5336. i = 0;
  5337. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5338. loc = loc+3+strlen("chargingSchedulePeriod");
  5339. pch = strtok(loc ,"{");
  5340. while (pch != NULL)
  5341. {
  5342. strcpy(SchedulePeriodList[i], pch);
  5343. pch = strtok (NULL, "{");
  5344. i = i + 1;
  5345. }
  5346. n_SchedulePeriods = i;
  5347. for(int i=0;i<n_SchedulePeriods;i++)
  5348. {
  5349. //*************startPeriod****************/
  5350. c = 0;
  5351. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5352. memset(sstr ,0, sizeof(sstr) );
  5353. while (loc[strlen("startPeriod")+2+c] != ',')
  5354. {
  5355. sstr[c] = loc[strlen("startPeriod")+2+c];
  5356. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5357. c++;
  5358. }
  5359. sstr[c] = '\0';
  5360. tempStartPeriodInt = atoi(sstr);
  5361. //*************limit****************/
  5362. c = 0;
  5363. loc = strstr(SchedulePeriodList[i], "limit");
  5364. memset(sstr ,0, sizeof(sstr) );
  5365. while (loc[strlen("limit")+2+c] != ',')
  5366. {
  5367. sstr[c] = loc[strlen("limit")+2+c];
  5368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5369. c++;
  5370. }
  5371. sstr[c] = '\0';
  5372. tempLimitInt = atof(sstr);
  5373. //*************numberPhases****************/
  5374. c = 0;
  5375. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5376. memset(sstr ,0, sizeof(sstr) );
  5377. while (loc[strlen("numberPhases")+2+c] != '}')
  5378. {
  5379. sstr[c] = loc[strlen("numberPhases")+2+c];
  5380. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5381. c++;
  5382. }
  5383. sstr[c] = '\0';
  5384. tempNumberPhasesInt = atoi(sstr);
  5385. TxProfile.Duration = durationInt;
  5386. TxProfile.TotalPeriod = n_SchedulePeriods;
  5387. TxProfile.Period[i].Limit = tempLimitInt;
  5388. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5389. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5390. }
  5391. if(MinChargingRate < tempminChargingRateFloat)
  5392. MinChargingRate = tempminChargingRateFloat;
  5393. if(confirmPeriods < n_SchedulePeriods)
  5394. confirmPeriods = n_SchedulePeriods;
  5395. }
  5396. fclose(fptr1);
  5397. }
  5398. }// the end of ACCESS TxProfile
  5399. //CompositeSchedule
  5400. int period=0;
  5401. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5402. {
  5403. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5404. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5405. {
  5406. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5407. {
  5408. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5409. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5410. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5411. period = period + 1;
  5412. }
  5413. else
  5414. {
  5415. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5416. {
  5417. }
  5418. else
  5419. {
  5420. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5421. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5422. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5423. period = period + 1;
  5424. }
  5425. }
  5426. }
  5427. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5428. {
  5429. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5430. {
  5431. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5432. {
  5433. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5434. }
  5435. else
  5436. {
  5437. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5438. }
  5439. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5440. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5441. period = period + 1;
  5442. }
  5443. }
  5444. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5445. {
  5446. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5447. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5448. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5449. period = period + 1;
  5450. }
  5451. }
  5452. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5453. {
  5454. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5455. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5456. {
  5457. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5458. {
  5459. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5460. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5461. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5462. period = period + 1;
  5463. }
  5464. else
  5465. {
  5466. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5467. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5468. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5469. period = period + 1;
  5470. }
  5471. }
  5472. }
  5473. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5474. {
  5475. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5476. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5477. {
  5478. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5479. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5480. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5481. period = period + 1;
  5482. }
  5483. }
  5484. confirmPeriods = period;
  5485. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5486. //* Define temporary variables */
  5487. struct tm *gtime;
  5488. time_t now;
  5489. char buf[28];
  5490. //* Read the current system time */
  5491. time(&now);
  5492. //* Convert the system time to GMT (now UTC) */
  5493. gtime = gmtime(&now);
  5494. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5495. // make .conf
  5496. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5497. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5498. //DEBUG_INFO(" debug 11\n");
  5499. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5500. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5501. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5502. }
  5503. else
  5504. {
  5505. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5506. }
  5507. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5508. return result;
  5509. }
  5510. int handleGetConfigurationRequest(char *uuid, char *payload)
  5511. {
  5512. mtrace();
  5513. int result = FAIL;
  5514. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5515. //struct json_object *jsonitem;
  5516. int MaxKeySupported = 0;
  5517. int n_keys = 0;
  5518. char requestKey[43][50]={0};
  5519. char search[]="[";
  5520. char sstr[500]={ 0 };
  5521. //int pos;
  5522. int l, c = 0;
  5523. int i = 0;
  5524. char *delim = "\",\"";
  5525. char * pch;
  5526. char *loc = strstr(payload, search);
  5527. //********************* Parsing String ***********************************/
  5528. if(loc == NULL) {
  5529. DEBUG_INFO("no key match in Configuration \n");
  5530. }
  5531. else {
  5532. //pos = loc - payload;
  5533. l = strlen(loc)-4;
  5534. while (c < l)
  5535. {
  5536. sstr[c] = loc[c+2];
  5537. c++;
  5538. }
  5539. sstr[c] = '\0';
  5540. //parsing strings to words
  5541. pch = strtok(sstr,delim);
  5542. if(pch == NULL)
  5543. {
  5544. strcpy(requestKey[0], sstr);
  5545. }
  5546. else
  5547. {
  5548. while (pch != NULL)
  5549. {
  5550. strcpy(requestKey[i], pch);
  5551. pch = strtok (NULL, delim);
  5552. i = i + 1;
  5553. }
  5554. n_keys = i;
  5555. }
  5556. }
  5557. UnknownKeynum = 0;
  5558. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5559. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5560. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5561. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5562. if(n_keys != 0)
  5563. {
  5564. for(int i=0;i<n_keys;i++)
  5565. {
  5566. getKeyValue(requestKey[i]);
  5567. //json_object_put(jsonitem);
  5568. }
  5569. }
  5570. else
  5571. {
  5572. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5573. getKeyValue("");
  5574. }
  5575. processUnkownKey();
  5576. sendGetConfigurationConfirmation(uuid);
  5577. return result;
  5578. }
  5579. static char fnamePlusPath[100]={0};
  5580. static char fnamePWithNoPath[60]={0};
  5581. void checkUploadLog(void)
  5582. {
  5583. FILE *fp;
  5584. /* Open the command for reading. */
  5585. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5586. if (fp == NULL) {
  5587. printf("Failed to run command\n" );
  5588. exit(1);
  5589. }
  5590. int ftppathlen = 0;
  5591. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5592. int i = 0;
  5593. /* Read the output a line at a time - output it. */
  5594. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5595. if(i==0)
  5596. {
  5597. ftppathlen = strlen(fnamePlusPath);
  5598. printf("%s\n", fnamePlusPath);
  5599. fnamePlusPath[ftppathlen]='\0';
  5600. break;
  5601. }
  5602. i= i+1;
  5603. }
  5604. /* close */
  5605. pclose(fp);
  5606. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5607. {
  5608. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5609. {
  5610. fnamePlusPath[k]='\0';
  5611. }
  5612. }
  5613. i=1;
  5614. //char fname[60]={0};
  5615. while(i < ftppathlen)
  5616. {
  5617. int len=ftppathlen-i;
  5618. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5619. {
  5620. printf("compare '/' all right\n");
  5621. break;
  5622. }
  5623. i=i+1;
  5624. }
  5625. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5626. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5627. fnamePWithNoPath[i+1] = '\0';
  5628. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5629. {
  5630. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5631. {
  5632. fnamePWithNoPath[j]='\0';
  5633. }
  5634. }
  5635. FILE* fp1 = fopen(fnamePlusPath, "r");
  5636. if (fp1)
  5637. {
  5638. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5639. // file exists
  5640. fclose(fp1);
  5641. }
  5642. else
  5643. {
  5644. // file doesn't exist
  5645. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5646. }
  5647. }
  5648. static char GetDiagnosticspayloadData[300]={0};
  5649. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5650. {
  5651. mtrace();
  5652. int result = FAIL;
  5653. pthread_t t; // pthread 變數
  5654. system("exec /root/logPackTools 'log' 6");
  5655. #if 0
  5656. //char buffer [128];
  5657. time (&rawtime);
  5658. //printf("%ld\n", rawtime);
  5659. timeinfo = localtime (&rawtime);
  5660. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5661. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5662. if((access(fnamePlusPath,F_OK))!=-1)
  5663. {
  5664. DEBUG_INFO("fnamePlusPath exist.\n");
  5665. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5666. }
  5667. else
  5668. {
  5669. DEBUG_INFO("fnamePlusPath not exist!\n");
  5670. }
  5671. #endif
  5672. checkUploadLog();
  5673. memset(GetDiagnosticspayloadData, 0, 300);
  5674. strcpy(GetDiagnosticspayloadData, payload);
  5675. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5676. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5677. return result;
  5678. }
  5679. void* GetDiagnosticsProcess(void* data)
  5680. {
  5681. pthread_detach(pthread_self());
  5682. mtrace();
  5683. int retriesInt=0, retryIntervalInt=0;
  5684. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5685. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5686. 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};
  5687. int port=0;
  5688. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5689. int c = 0;
  5690. char *loc;
  5691. int isSuccess = FALSE;
  5692. char ftpbuf[200]={0};
  5693. //char temp[100]={0};
  5694. char * pch;
  5695. // [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"}]
  5696. char str[300]={ 0 };
  5697. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5698. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5699. DEBUG_INFO("GetDiagnosticsProcess\n");
  5700. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5701. //****************location*******************/
  5702. c = 0;
  5703. memset(sstr ,0, sizeof(sstr) );
  5704. loc = strstr(str, "location");
  5705. while (loc[3+strlen("location")+c] != '\"')
  5706. {
  5707. sstr[c] = loc[3+strlen("location")+c];
  5708. c++;
  5709. }
  5710. sstr[c] = '\0';
  5711. strcpy(locationstr,sstr);
  5712. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5713. if(strcmp(locationstr,"")==0)
  5714. {
  5715. DEBUG_INFO("location is <Empty>!\n");
  5716. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5717. goto end;
  5718. }
  5719. //****************retries*******************/
  5720. c = 0;
  5721. loc = strstr(str, "retries");
  5722. if(loc == NULL)
  5723. {
  5724. retriesIsNULL = TRUE;
  5725. }
  5726. else
  5727. {
  5728. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5729. {
  5730. sstr[c] = loc[strlen("retries")+2+c];
  5731. c++;
  5732. }
  5733. sstr[c] = '\0';
  5734. retriesInt = atoi(sstr);
  5735. }
  5736. if(retriesIsNULL == TRUE)
  5737. {
  5738. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5739. }
  5740. //****************retryInterval*******************/
  5741. c = 0;
  5742. loc = strstr(str, "retryInterval");
  5743. if(loc == NULL)
  5744. {
  5745. retryIntervalIsNULL = TRUE;
  5746. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5747. }
  5748. else
  5749. {
  5750. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5751. {
  5752. sstr[c] = loc[strlen("retryInterval")+2+c];
  5753. c++;
  5754. }
  5755. sstr[c] = '\0';
  5756. retryIntervalInt = atoi(sstr);
  5757. }
  5758. //****************startTime*******************/
  5759. c = 0;
  5760. memset(sstr ,0, sizeof(sstr) );
  5761. loc = strstr(str, "startTime");
  5762. if(loc == NULL)
  5763. {
  5764. startTimeIsNULL = TRUE;
  5765. }
  5766. else
  5767. {
  5768. while (loc[3+strlen("startTime")+c] != '\"')
  5769. {
  5770. sstr[c] = loc[3+strlen("startTime")+c];
  5771. c++;
  5772. }
  5773. sstr[c] = '\0';
  5774. strcpy(startTimestr,sstr);
  5775. }
  5776. //****************stopTime*******************/
  5777. c = 0;
  5778. memset(sstr ,0, sizeof(sstr) );
  5779. loc = strstr(str, "stopTime");
  5780. if(loc == NULL)
  5781. {
  5782. stopTimeIsNULL = TRUE;
  5783. }
  5784. else
  5785. {
  5786. while (loc[3+strlen("stopTime")+c] != '\"')
  5787. {
  5788. sstr[c] = loc[3+strlen("stopTime")+c];
  5789. c++;
  5790. }
  5791. sstr[c] = '\0';
  5792. strcpy(stopTimestr,sstr);
  5793. }
  5794. memset(protocol, 0, sizeof(protocol));
  5795. memset(user, 0, sizeof(user) );
  5796. memset(password, 0, sizeof(password));
  5797. memset(host, 0, sizeof(host));
  5798. memset(path, 0, sizeof(path));
  5799. memset(ftppath, 0, sizeof(ftppath));
  5800. memset(host1, 0, sizeof(host1));
  5801. memset(path1, 0, sizeof(path1));
  5802. /*location: ftp://user:password@host:port/path*/
  5803. #if 0
  5804. time_t rawtime;
  5805. struct tm * timeinfo;
  5806. //char buffer [128];
  5807. time (&rawtime);
  5808. //printf("%ld\n", rawtime);
  5809. timeinfo = localtime (&rawtime);
  5810. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5811. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5812. #endif
  5813. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5814. if((access(fnamePlusPath,F_OK))!=-1)
  5815. {
  5816. DEBUG_INFO("fnamePlusPath exist.\n");
  5817. }
  5818. else
  5819. {
  5820. DEBUG_INFO("fnamePlusPath not exist!\n");
  5821. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5822. goto end;
  5823. }
  5824. pch=strchr(locationstr,'@');
  5825. if(pch==NULL)
  5826. {
  5827. sscanf(locationstr,
  5828. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5829. protocol, host, &port, path);
  5830. strcpy(user,"anonymous");
  5831. strcpy(password,"");
  5832. }
  5833. else
  5834. {
  5835. //DEBUG_INFO("pch=%s\n", pch);
  5836. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5837. protocol, user, password, host, &port, path);
  5838. }
  5839. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5840. {
  5841. DEBUG_INFO("protocol is not ftp/http ! \n");
  5842. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5843. goto end;
  5844. }
  5845. if(strncmp(locationstr,"http", 4) == 0)
  5846. {
  5847. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  5848. sprintf(ftppath,"/%s", path);
  5849. do{
  5850. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5851. sleep(retryIntervalInt);
  5852. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5853. if(!isSuccess)
  5854. {
  5855. DEBUG_INFO("Diagnostics fail.\n");
  5856. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5857. }
  5858. else
  5859. {
  5860. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5861. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5862. }
  5863. }
  5864. else
  5865. {
  5866. sscanf(host,"%[^/]%s",host1, path1);
  5867. sprintf(ftppath,"%s", path1);
  5868. int ftppathlen=strlen(ftppath);
  5869. int i=1;
  5870. char filenametemp[50];
  5871. while(i < ftppathlen)
  5872. {
  5873. int len=ftppathlen-i;
  5874. if(ftppath[len]== 47) // '/' ascll code: 47
  5875. {
  5876. DEBUG_INFO("find '/' all right\n");
  5877. break;
  5878. }
  5879. i=i+1;
  5880. }
  5881. memset(filenametemp, 0, sizeof(filenametemp));
  5882. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5883. filenametemp[i+1] = 0;
  5884. memset(ftpbuf, 0, sizeof(ftpbuf));
  5885. if(port == 0)
  5886. port = 21;
  5887. do{
  5888. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  5889. sleep(retryIntervalInt);
  5890. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5891. if(!isSuccess)
  5892. {
  5893. DEBUG_INFO("Diagnostics fail.\n");
  5894. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5895. }
  5896. else
  5897. {
  5898. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5899. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5900. }
  5901. }
  5902. end:
  5903. DiagnosticsStatusNotificationStatus = 0; //Idle
  5904. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5905. }
  5906. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5907. {
  5908. mtrace();
  5909. int result = FAIL;
  5910. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5911. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5912. {
  5913. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5914. localversion = -1;
  5915. }
  5916. else
  5917. {
  5918. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5919. OCPP_getListVerion();
  5920. }
  5921. //from db.OCPP_getListVerion
  5922. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5923. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5924. sendGetLocalListVersionConfirmation(uuid,"");
  5925. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5926. return result;
  5927. }
  5928. int handleRemoteStartRequest(char *uuid, char *payload)
  5929. {
  5930. mtrace();
  5931. int result = FAIL;
  5932. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5933. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5934. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5935. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5936. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5937. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5938. int chargingSchedulePeriodCount = 0;
  5939. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5940. int c = 0;
  5941. char *loc;
  5942. char comfirmstr[20]={0};
  5943. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5944. if(server_pending == TRUE)
  5945. {
  5946. return 0;
  5947. }
  5948. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5949. //**********connectorId****************/
  5950. c = 0;
  5951. memset(sstr ,0, sizeof(sstr) );
  5952. loc = strstr(payload, "connectorId");
  5953. if(loc == NULL)
  5954. {
  5955. connectorIdIsNULL = TRUE;
  5956. }
  5957. else
  5958. {
  5959. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5960. {
  5961. sstr[c] = loc[strlen("connectorId")+2+c];
  5962. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5963. c++;
  5964. }
  5965. sstr[c] = '\0';
  5966. connectorIdInt = atoi(sstr);
  5967. }
  5968. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  5969. {
  5970. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5971. goto end;
  5972. }
  5973. //****************idTag*******************/
  5974. c = 0;
  5975. memset(sstr ,0, sizeof(sstr) );
  5976. loc = strstr(payload, "idTag");
  5977. while (loc[3+strlen("idTag")+c] != '\"')
  5978. {
  5979. sstr[c] = loc[3+strlen("idTag")+c];
  5980. c++;
  5981. }
  5982. sstr[c] = '\0';
  5983. strcpy(idTagstr,sstr);
  5984. //****************chargingProfile*******************/
  5985. c = 0;
  5986. memset(sstr ,0, sizeof(sstr) );
  5987. loc = strstr(payload, "chargingProfile");
  5988. if(loc == NULL)
  5989. {
  5990. chargingProfileIsNULL = TRUE;
  5991. }
  5992. else
  5993. {
  5994. //****************chargingProfileId*******************/
  5995. c=0;
  5996. loc = strstr(payload, "chargingProfileId");
  5997. memset(sstr ,0, sizeof(sstr) );
  5998. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5999. {
  6000. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6001. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6002. c++;
  6003. }
  6004. sstr[c] = '\0';
  6005. chargingProfileIdInt = atoi(sstr);
  6006. //****************transactionId*******************/
  6007. loc = strstr(payload, "transactionId");
  6008. if(loc == NULL)
  6009. {
  6010. transactionIdIsNULL = TRUE;
  6011. }
  6012. else
  6013. {
  6014. c=0;
  6015. memset(sstr ,0, sizeof(sstr) );
  6016. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6017. {
  6018. sstr[c] = loc[strlen("transactionId")+2+c];
  6019. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6020. c++;
  6021. }
  6022. sstr[c] = '\0';
  6023. transactionIdInt = atoi(sstr);
  6024. }
  6025. //****************stackLevel*******************/
  6026. c=0;
  6027. loc = strstr(payload, "stackLevel");
  6028. memset(sstr ,0, sizeof(sstr) );
  6029. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6030. {
  6031. sstr[c] = loc[strlen("stackLevel")+2+c];
  6032. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6033. c++;
  6034. }
  6035. sstr[c] = '\0';
  6036. stackLevelInt = atoi(sstr);
  6037. //****************chargingProfilePurpose*******************/
  6038. c = 0;
  6039. memset(sstr ,0, sizeof(sstr) );
  6040. loc = strstr(payload, "chargingProfilePurpose");
  6041. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6042. {
  6043. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6044. c++;
  6045. }
  6046. sstr[c] = '\0';
  6047. strcpy(chargingProfilePurposestr,sstr);
  6048. //****************chargingProfileKind*******************/
  6049. c = 0;
  6050. memset(sstr ,0, sizeof(sstr) );
  6051. loc = strstr(payload, "chargingProfileKind");
  6052. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6053. {
  6054. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6055. c++;
  6056. }
  6057. sstr[c] = '\0';
  6058. strcpy(chargingProfileKindstr,sstr);
  6059. //****************recurrencyKind*******************/
  6060. loc = strstr(payload, "recurrencyKind");
  6061. if(loc == NULL)
  6062. {
  6063. recurrencyKindIsNULL = TRUE;
  6064. }
  6065. else
  6066. {
  6067. c = 0;
  6068. memset(sstr ,0, sizeof(sstr) );
  6069. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6070. {
  6071. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6072. c++;
  6073. }
  6074. sstr[c] = '\0';
  6075. strcpy(recurrencyKindstr,sstr);
  6076. }
  6077. //****************validFrom*******************/
  6078. loc = strstr(payload, "validFrom");
  6079. if(loc == NULL)
  6080. {
  6081. validFromIsNULL = TRUE;
  6082. }
  6083. else
  6084. {
  6085. c = 0;
  6086. memset(sstr ,0, sizeof(sstr) );
  6087. while (loc[3+strlen("validFrom")+c] != '\"')
  6088. {
  6089. sstr[c] = loc[3+strlen("validFrom")+c];
  6090. c++;
  6091. }
  6092. sstr[c] = '\0';
  6093. strcpy(validFromstr,sstr);
  6094. }
  6095. //****************validTo*******************/
  6096. loc = strstr(payload, "validTo");
  6097. if(loc == NULL)
  6098. {
  6099. validToIsNULL = TRUE;
  6100. }
  6101. else
  6102. {
  6103. c = 0;
  6104. memset(sstr ,0, sizeof(sstr) );
  6105. while (loc[3+strlen("validTo")+c] != '\"')
  6106. {
  6107. sstr[c] = loc[3+strlen("validTo")+c];
  6108. c++;
  6109. }
  6110. sstr[c] = '\0';
  6111. strcpy(validTostr,sstr);
  6112. }
  6113. //****************chargingSchedule*******************/
  6114. loc = strstr(payload, "chargingSchedule");
  6115. if(loc != NULL)
  6116. {
  6117. //****************duration*******************/
  6118. loc = strstr(payload, "duration");
  6119. if(loc == NULL)
  6120. {
  6121. durationIsNULL = TRUE;
  6122. }
  6123. else
  6124. {
  6125. c=0;
  6126. memset(sstr ,0, sizeof(sstr) );
  6127. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6128. {
  6129. sstr[c] = loc[strlen("duration")+2+c];
  6130. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6131. c++;
  6132. }
  6133. sstr[c] = '\0';
  6134. durationInt = atoi(sstr);
  6135. }
  6136. //****************startSchedule******************/
  6137. loc = strstr(payload, "startSchedule");
  6138. if(loc == NULL)
  6139. {
  6140. startScheduleIsNULL = TRUE;
  6141. }
  6142. else
  6143. {
  6144. c = 0;
  6145. memset(sstr ,0, sizeof(sstr) );
  6146. while (loc[3+strlen("startSchedule")+c] != '\"')
  6147. {
  6148. sstr[c] = loc[3+strlen("startSchedule")+c];
  6149. c++;
  6150. }
  6151. sstr[c] = '\0';
  6152. strcpy(startSchedulestr,sstr);
  6153. }
  6154. //****************chargingRateUnit*******************/
  6155. c = 0;
  6156. memset(sstr ,0, sizeof(sstr) );
  6157. loc = strstr(payload, "chargingRateUnit");
  6158. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6159. {
  6160. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6161. c++;
  6162. }
  6163. sstr[c] = '\0';
  6164. strcpy(chargingRateUnitstr,sstr);
  6165. //****************minChargingRate*******************/
  6166. loc = strstr(payload, "minChargingRate");
  6167. if(loc == NULL)
  6168. {
  6169. minChargingRateIsNULL = TRUE;
  6170. }
  6171. else
  6172. {
  6173. c=0;
  6174. memset(sstr ,0, sizeof(sstr) );
  6175. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6176. {
  6177. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6178. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6179. c++;
  6180. }
  6181. sstr[c] = '\0';
  6182. minChargingRateflaot = atof(sstr);
  6183. }
  6184. //****************chargingSchedulePeriod count*******************/
  6185. int what_len = strlen("startPeriod");
  6186. char *where = payload;
  6187. while ((where = strstr(where, "startPeriod"))) {
  6188. where += what_len;
  6189. chargingSchedulePeriodCount++;
  6190. }
  6191. where = payload;
  6192. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6193. {
  6194. //****************startPeriod*******************/
  6195. c=0;
  6196. loc = strstr(where, "startPeriod");
  6197. memset(sstr ,0, sizeof(sstr) );
  6198. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6199. {
  6200. sstr[c] = loc[strlen("startPeriod")+2+c];
  6201. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6202. c++;
  6203. }
  6204. sstr[c] = '\0';
  6205. startPeriodInt[periodNums] = atoi(sstr);
  6206. //****************limit*******************/
  6207. c=0;
  6208. loc = strstr(where, "limit");
  6209. memset(sstr ,0, sizeof(sstr) );
  6210. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6211. {
  6212. sstr[c] = loc[strlen("limit")+2+c];
  6213. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6214. c++;
  6215. }
  6216. sstr[c] = '\0';
  6217. limitflaot[periodNums] = atof(sstr);
  6218. //****************numberPhases*******************/
  6219. loc = strstr(where, "numberPhases");
  6220. if(loc == NULL)
  6221. {
  6222. numberPhasesIsNULL = TRUE;
  6223. }
  6224. else
  6225. {
  6226. c=0;
  6227. memset(sstr ,0, sizeof(sstr) );
  6228. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6229. {
  6230. sstr[c] = loc[strlen("numberPhases")+2+c];
  6231. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6232. c++;
  6233. }
  6234. sstr[c] = '\0';
  6235. numberPhasesInt[periodNums] = atoi(sstr);
  6236. }
  6237. where = loc;
  6238. }
  6239. }
  6240. }
  6241. /*
  6242. enum _SYSTEM_STATUS
  6243. {
  6244. S_BOOTING = 0,
  6245. S_IDLE, = 1
  6246. S_AUTHORIZING, =2
  6247. S_REASSIGN_CHECK, =3
  6248. S_REASSIGN, =4
  6249. S_PRECHARGE, =5
  6250. S_PREPARING_FOR_EV, =6
  6251. S_PREPARING_FOR_EVSE, =7
  6252. S_CHARGING, =8
  6253. S_TERMINATING, =9
  6254. S_COMPLETE, =10
  6255. S_ALARM, =11
  6256. S_FAULT =12
  6257. }
  6258. */
  6259. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6260. {
  6261. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6262. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6263. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6264. //check Transaction active
  6265. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6266. {
  6267. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6268. {
  6269. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6270. {
  6271. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6272. {
  6273. //Reserved
  6274. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6275. }
  6276. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6277. {
  6278. //Reserved
  6279. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6280. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6281. goto end;
  6282. }
  6283. else
  6284. {
  6285. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6286. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6287. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6288. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6289. {
  6290. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6291. goto end;
  6292. }
  6293. }//END FOR ELSE
  6294. }
  6295. }// END FOR CHAdeMO_QUANTITY
  6296. for (int index = 0; index < CCS_QUANTITY; index++)
  6297. {
  6298. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6299. {
  6300. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6301. {
  6302. //Reserved
  6303. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6304. }
  6305. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6306. {
  6307. //Reserved
  6308. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6309. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6310. goto end;
  6311. }
  6312. else
  6313. {
  6314. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6315. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6316. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6317. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6318. {
  6319. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6320. goto end;
  6321. }
  6322. }// END FOR ELSE
  6323. }
  6324. }// END FOR CCS_QUANTITY
  6325. for (int index = 0; index < GB_QUANTITY; index++)
  6326. {
  6327. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6328. {
  6329. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6330. {
  6331. //Reserved
  6332. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6333. }
  6334. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6335. {
  6336. //Reserved
  6337. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6338. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6339. goto end;
  6340. }
  6341. else
  6342. {
  6343. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6344. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6345. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6346. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6347. {
  6348. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6349. goto end;
  6350. }
  6351. }// END FOR ELSE
  6352. }
  6353. } // END FOR GB_QUANTITY
  6354. }
  6355. else
  6356. {
  6357. for (int index = 0; index < AC_QUANTITY; index++)
  6358. {
  6359. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6360. {
  6361. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6362. {
  6363. //Reserved
  6364. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6365. }
  6366. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6367. {
  6368. //Reserved
  6369. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6370. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6371. goto end;
  6372. }
  6373. else
  6374. {
  6375. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6376. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6377. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6378. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6379. {
  6380. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6381. goto end;
  6382. }
  6383. }//END FOR ELSE
  6384. }
  6385. }// END FOR AC_QUANTITY
  6386. }
  6387. if(chargingProfileIsNULL == FALSE)
  6388. {
  6389. //ChargingProfile
  6390. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6391. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6392. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6393. if(recurrencyKindIsNULL == FALSE) //OPTION
  6394. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6395. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6396. if(transactionIdIsNULL == FALSE) // OPTION
  6397. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6398. if(validFromIsNULL == FALSE) // OPTION
  6399. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6400. if(validToIsNULL == FALSE) //OPTION
  6401. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6402. //ChargingSchedule
  6403. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6404. if(durationIsNULL == FALSE) //OPTION
  6405. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6406. if(minChargingRateIsNULL == FALSE) //OPTION
  6407. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6408. if(startScheduleIsNULL == FALSE) //OPTION
  6409. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6410. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6411. {
  6412. //ChargingSchedulePeriod
  6413. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6414. if(numberPhasesIsNULL == FALSE)
  6415. {
  6416. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6417. }
  6418. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6419. }
  6420. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6421. {
  6422. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6423. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6424. //memset idTag
  6425. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6426. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6427. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6428. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6429. }
  6430. else
  6431. {
  6432. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6433. }
  6434. }
  6435. else
  6436. {
  6437. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6438. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6439. //memset idTag
  6440. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6441. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6442. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6443. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6444. }
  6445. }
  6446. else
  6447. {
  6448. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6449. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6450. }
  6451. end:
  6452. if(connectorIdIsNULL == FALSE)
  6453. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6454. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6455. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6456. //OCPP send RemoteStartConfirmation by first.
  6457. sendRemoteStartConfirmation(uuid, comfirmstr);
  6458. return result;
  6459. }
  6460. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6461. {
  6462. mtrace();
  6463. int result = FAIL;
  6464. int match = FALSE;
  6465. int GunNO = 0;
  6466. int transactionIdInt=0;
  6467. int transactionIdIsNULL= FALSE;
  6468. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6469. int c = 0;
  6470. char *loc;
  6471. char comfirmstr[20];
  6472. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6473. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6474. if(server_pending == TRUE)
  6475. {
  6476. return 0;
  6477. }
  6478. c=0;
  6479. loc = strstr(payload, "transactionId");
  6480. if(loc == NULL)
  6481. {
  6482. transactionIdIsNULL= TRUE;
  6483. }
  6484. else
  6485. {
  6486. memset(sstr ,0, sizeof(sstr) );
  6487. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6488. {
  6489. sstr[c] = loc[strlen("transactionId")+2+c];
  6490. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6491. c++;
  6492. }
  6493. sstr[c] = '\0';
  6494. transactionIdInt = atoi(sstr);
  6495. }
  6496. if(transactionIdIsNULL == FALSE)
  6497. {
  6498. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6499. {
  6500. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6501. {
  6502. //check Transaction active
  6503. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6504. {
  6505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6506. {
  6507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6508. {
  6509. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6510. {
  6511. match = TRUE;
  6512. GunNO = gun_index;
  6513. }
  6514. }
  6515. }// END FOR CHAdeMO_QUANTITY
  6516. for (int index = 0; index < CCS_QUANTITY; index++)
  6517. {
  6518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6519. {
  6520. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6521. {
  6522. match = TRUE;
  6523. GunNO = gun_index;
  6524. }
  6525. }
  6526. }// END FOR CCS_QUANTITY
  6527. for (int index = 0; index < GB_QUANTITY; index++)
  6528. {
  6529. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6530. {
  6531. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6532. {
  6533. match = TRUE;
  6534. GunNO = gun_index;
  6535. }
  6536. }
  6537. }// END FOR GB_QUANTITY
  6538. }
  6539. else
  6540. {
  6541. for (int index = 0; index < AC_QUANTITY; index++)
  6542. {
  6543. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6544. {
  6545. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6546. {
  6547. match = TRUE;
  6548. GunNO = gun_index;
  6549. }
  6550. }
  6551. }// END FOR CHAdeMO_QUANTITY
  6552. }// END FOR AC ELSE
  6553. }// CHECK IF ResponseTransactionId == transactionIdInt
  6554. }//END FOR
  6555. if( match == TRUE)
  6556. {
  6557. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6558. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6559. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6560. }
  6561. else
  6562. {
  6563. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6564. }
  6565. }
  6566. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6567. return result;
  6568. }
  6569. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6570. {
  6571. mtrace();
  6572. int result = FAIL;
  6573. int connectorIdInt=0, reservationIdInt=0;
  6574. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6575. char comfirmstr[20]={0};
  6576. char sstr[180]={ 0 };
  6577. int c = 0;
  6578. char *loc;
  6579. //char *ptr;
  6580. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6581. //***(1)connectorId ****/
  6582. c=0;
  6583. loc = strstr(payload, "connectorId");
  6584. memset(sstr ,0, sizeof(sstr) );
  6585. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6586. {
  6587. sstr[c] = loc[strlen("connectorId")+2+c];
  6588. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6589. c++;
  6590. }
  6591. sstr[c] = '\0';
  6592. connectorIdInt = atoi(sstr);
  6593. //***(2)expiryDate ****/
  6594. loc = strstr(payload, "expiryDate");
  6595. memset(sstr ,0, sizeof(sstr) );
  6596. c = 0;
  6597. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6598. {
  6599. sstr[c] = loc[3+strlen("expiryDate")+c];
  6600. c++;
  6601. }
  6602. sstr[c] = '\0';
  6603. strcpy(expiryDatestr, sstr);
  6604. //***(3)idTag ****/
  6605. loc = strstr(payload, "idTag");
  6606. memset(sstr ,0, sizeof(sstr) );
  6607. c = 0;
  6608. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6609. {
  6610. sstr[c] = loc[3+strlen("idTag")+c];
  6611. c++;
  6612. }
  6613. sstr[c] = '\0';
  6614. strcpy(idTagstr, sstr);
  6615. //***(4)parentIdTag ****/
  6616. loc = strstr(payload, "parentIdTag");
  6617. memset(sstr ,0, sizeof(sstr) );
  6618. c = 0;
  6619. if(loc == NULL)
  6620. {
  6621. strcpy(parentIdTagstr, "");
  6622. }
  6623. else
  6624. {
  6625. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6626. {
  6627. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6628. c++;
  6629. }
  6630. sstr[c] = '\0';
  6631. strcpy(parentIdTagstr, sstr);
  6632. }
  6633. //***(5)reservationId ****/
  6634. c=0;
  6635. loc = strstr(payload, "reservationId");
  6636. memset(sstr ,0, sizeof(sstr) );
  6637. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6638. {
  6639. sstr[c] = loc[strlen("reservationId")+2+c];
  6640. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6641. c++;
  6642. }
  6643. sstr[c] = '\0';
  6644. reservationIdInt = atoi(sstr);
  6645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6646. /*
  6647. enum SYSTEM_STATUS
  6648. {
  6649. SYS_MODE_BOOTING = 0,
  6650. SYS_MODE_IDLE = 1,
  6651. SYS_MODE_AUTHORIZING = 2,
  6652. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6653. SYS_MODE_REASSIGN = 4,
  6654. SYS_MODE_PREPARING = 5,
  6655. SYS_MODE_PREPARE_FOR_EV = 6,
  6656. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6657. SYS_MODE_CHARGING = 8,
  6658. SYS_MODE_TERMINATING = 9,
  6659. SYS_MODE_COMPLETE = 10,
  6660. SYS_MODE_ALARM = 11,
  6661. SYS_MODE_FAULT = 12,
  6662. SYS_MODE_RESERVATION = 13,
  6663. SYS_MODE_BOOKING = 14,
  6664. SYS_MODE_MAINTAIN = 15,
  6665. SYS_MODE_DEBUG = 16,
  6666. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6667. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6668. SYS_MODE_UPDATE = 19
  6669. };
  6670. */
  6671. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6672. {
  6673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6674. goto end;
  6675. }
  6676. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6677. {
  6678. //check Transaction active
  6679. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6680. {
  6681. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6682. {
  6683. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6684. {
  6685. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6686. {
  6687. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6688. {
  6689. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6690. {
  6691. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6693. }
  6694. 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'))
  6695. {
  6696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6697. }
  6698. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6699. {
  6700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6701. }
  6702. else
  6703. {
  6704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6705. }
  6706. }
  6707. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6708. {
  6709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6710. }
  6711. }
  6712. else
  6713. {
  6714. //replace reservation
  6715. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6717. }
  6718. }
  6719. } // END FOR CHAdeMO_QUANTITY
  6720. for (int index = 0; index < CCS_QUANTITY; index++)
  6721. {
  6722. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6723. {
  6724. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6725. {
  6726. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6727. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6728. {
  6729. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6730. {
  6731. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6733. }
  6734. 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'))
  6735. {
  6736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6737. }
  6738. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6739. {
  6740. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6741. }
  6742. else
  6743. {
  6744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6745. }
  6746. }
  6747. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6748. {
  6749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6750. }
  6751. }
  6752. else
  6753. {
  6754. //replace reservation
  6755. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6757. }
  6758. }
  6759. } // END FOR CCS_QUANTITY
  6760. for (int index = 0; index < GB_QUANTITY; index++)
  6761. {
  6762. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6763. {
  6764. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6765. {
  6766. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6767. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6768. {
  6769. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6770. {
  6771. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6773. }
  6774. 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'))
  6775. {
  6776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6777. }
  6778. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6779. {
  6780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6781. }
  6782. else
  6783. {
  6784. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6785. }
  6786. }
  6787. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6788. {
  6789. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6790. }
  6791. }
  6792. else
  6793. {
  6794. //replace reservation
  6795. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6796. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6797. }
  6798. }
  6799. }// END FOR GB_QUANTITY
  6800. }
  6801. else
  6802. {
  6803. for (int index = 0; index < AC_QUANTITY; index++)
  6804. {
  6805. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6806. {
  6807. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6808. {
  6809. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6810. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6811. {
  6812. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6813. {
  6814. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6815. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6816. }
  6817. 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'))
  6818. {
  6819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6820. }
  6821. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6822. {
  6823. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6824. }
  6825. else
  6826. {
  6827. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6828. }
  6829. }
  6830. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6831. {
  6832. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6833. }
  6834. }
  6835. else
  6836. {
  6837. //replace reservation
  6838. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6840. }
  6841. }
  6842. } // END FOR AC_QUANTITY
  6843. }//END FOR AC ELSE
  6844. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6845. }
  6846. else if(connectorIdInt == 0)
  6847. {
  6848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6849. {
  6850. //check Transaction active
  6851. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6852. {
  6853. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6854. {
  6855. 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'))
  6856. {
  6857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6858. goto end;
  6859. }
  6860. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6861. {
  6862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6863. goto end;
  6864. }
  6865. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6866. {
  6867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6868. goto end;
  6869. }
  6870. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6871. {
  6872. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6873. goto end;
  6874. }
  6875. }
  6876. }// END FOR CHAdeMO_QUANTITY
  6877. for (int index = 0; index < CCS_QUANTITY; index++)
  6878. {
  6879. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6880. {
  6881. 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'))
  6882. {
  6883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6884. }
  6885. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6886. {
  6887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6888. }
  6889. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6890. {
  6891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6892. }
  6893. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6894. {
  6895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6896. }
  6897. }
  6898. } // END FOR CCS_QUANTITY
  6899. for (int index = 0; index < GB_QUANTITY; index++)
  6900. {
  6901. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6902. {
  6903. 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'))
  6904. {
  6905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6906. }
  6907. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6908. {
  6909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6910. }
  6911. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6912. {
  6913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6914. }
  6915. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6916. {
  6917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6918. }
  6919. }
  6920. } // END FOR GB_QUANTITY
  6921. }
  6922. else
  6923. {
  6924. for (int index = 0; index < AC_QUANTITY; index++)
  6925. {
  6926. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6927. {
  6928. 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'))
  6929. {
  6930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6931. goto end;
  6932. }
  6933. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6934. {
  6935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6936. goto end;
  6937. }
  6938. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6939. {
  6940. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6941. goto end;
  6942. }
  6943. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6944. {
  6945. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6946. goto end;
  6947. }
  6948. }
  6949. }// END FOR AC_QUANTITY
  6950. }
  6951. //The connectorId is 0
  6952. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6953. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6954. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6955. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6956. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6957. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6958. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6959. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6960. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6961. result = TRUE;
  6962. return result;
  6963. }
  6964. else
  6965. {
  6966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6967. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6968. }
  6969. if(strcmp(comfirmstr,"Accepted") == 0)
  6970. {
  6971. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6972. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6973. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6974. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6975. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6976. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6977. result = TRUE;
  6978. return result;
  6979. }
  6980. end:
  6981. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6982. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6983. return result;
  6984. }
  6985. int handleResetRequest(char *uuid, char *payload)
  6986. {
  6987. mtrace();
  6988. int result = FAIL;
  6989. char sstr[10]={0};
  6990. char typestr[10]={0};
  6991. char comfirmstr[20]={0};
  6992. int c = 0;
  6993. char *loc;
  6994. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6995. DEBUG_INFO("handleResetRequest ...\n");
  6996. loc = strstr(payload, "type");
  6997. memset(sstr ,0, sizeof(sstr) );
  6998. c = 0;
  6999. while (loc[3+strlen("type")+c] != '\"')
  7000. {
  7001. sstr[c] = loc[3+strlen("type")+c];
  7002. c++;
  7003. }
  7004. sstr[c] = '\0';
  7005. strcpy(typestr,sstr);
  7006. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7007. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7008. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7009. {
  7010. //check Transaction active
  7011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7012. {
  7013. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7014. {
  7015. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7016. {
  7017. //0: unplug, 1: Plug-in
  7018. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7019. }
  7020. }
  7021. for (int index = 0; index < CCS_QUANTITY; index++)
  7022. {
  7023. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7024. {
  7025. //0: unplug, 1: Plug-in
  7026. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7027. }
  7028. }
  7029. for (int index = 0; index < GB_QUANTITY; index++)
  7030. {
  7031. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7032. {
  7033. //0: unplug, 1: Plug-in
  7034. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7035. }
  7036. }
  7037. }
  7038. else
  7039. {
  7040. for (int index = 0; index < AC_QUANTITY; index++)
  7041. {
  7042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7043. {
  7044. //0: unplug, 1: Plug-in
  7045. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7046. }
  7047. }
  7048. }// END FOR AC ELSE
  7049. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7050. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7051. result = TRUE;
  7052. return result;
  7053. }
  7054. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7055. {
  7056. //check Transaction active
  7057. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7058. {
  7059. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7060. {
  7061. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7062. {
  7063. //0: unplug, 1: Plug-in
  7064. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7065. }
  7066. }
  7067. for (int index = 0; index < CCS_QUANTITY; index++)
  7068. {
  7069. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7070. {
  7071. //0: unplug, 1: Plug-in
  7072. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7073. }
  7074. }
  7075. for (int index = 0; index < GB_QUANTITY; index++)
  7076. {
  7077. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7078. {
  7079. //0: unplug, 1: Plug-in
  7080. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7081. }
  7082. }
  7083. }
  7084. else
  7085. {
  7086. for (int index = 0; index < AC_QUANTITY; index++)
  7087. {
  7088. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7089. {
  7090. //0: unplug, 1: Plug-in
  7091. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7092. }
  7093. }
  7094. }// END FOR AC ELSE
  7095. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7096. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7097. result = TRUE;
  7098. return result;
  7099. }
  7100. else
  7101. {
  7102. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7103. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7104. goto errorend;
  7105. }
  7106. errorend:
  7107. sendResetConfirmation(uuid, comfirmstr);
  7108. return result;
  7109. }
  7110. int handleSendLocalListRequest(char *uuid, char *payload)
  7111. {
  7112. mtrace();
  7113. int result = FAIL;
  7114. int listVersionInt;
  7115. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7116. char listsearch[]="listVersion";
  7117. char updateTypesearch[]="updateType";
  7118. char localAuthorizationListsearch[]="localAuthorizationList";
  7119. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7120. char CardList[500][160]={0};
  7121. char updateTypestr[15]={0};
  7122. char idTagstr[20]={0};
  7123. char parentIdTag[20]={0};
  7124. char expiryDate[30]={0};
  7125. char idTagstatus[16]={0};
  7126. int c = 0;
  7127. int i = 0;
  7128. char *delim1 = "}";
  7129. char * pch;
  7130. char *loc;
  7131. //char *ptr;
  7132. char comfirmstr[20];
  7133. //int n_localAuthorizations = 0;
  7134. int checkState_Faulted = FALSE;
  7135. DEBUG_INFO("handleSendLocalListRequest\n");
  7136. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7137. {
  7138. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7139. goto end;
  7140. }
  7141. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7142. {
  7143. //check Charge Point state
  7144. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7145. {
  7146. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7147. {
  7148. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7149. }
  7150. }
  7151. for (int index = 0; index < CCS_QUANTITY; index++)
  7152. {
  7153. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7154. {
  7155. checkState_Faulted = TRUE; //OCPP Status
  7156. }
  7157. }
  7158. for (int index = 0; index < GB_QUANTITY; index++)
  7159. {
  7160. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7161. {
  7162. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7163. }
  7164. }
  7165. }
  7166. else
  7167. {
  7168. //check Charge Point state
  7169. for (int index = 0; index < AC_QUANTITY; index++)
  7170. {
  7171. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7172. {
  7173. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7174. }
  7175. }
  7176. }// END FOR AC ELSE
  7177. if(checkState_Faulted == TRUE)
  7178. {
  7179. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7180. goto end;
  7181. }
  7182. //listVersion
  7183. c = 0;
  7184. loc = strstr(payload, listsearch);
  7185. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7186. {
  7187. sstr[c] = loc[strlen("listVersion")+2+c];
  7188. c++;
  7189. }
  7190. sstr[c] = '\0';
  7191. listVersionInt = atoi(sstr);
  7192. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7193. //updateType
  7194. loc = strstr(payload, updateTypesearch);
  7195. c = 0;
  7196. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7197. {
  7198. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7199. c++;
  7200. }
  7201. sstr[c] = '\0';
  7202. strcpy(updateTypestr, sstr);
  7203. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7204. //localAuthorizationList
  7205. memset(sstr ,0, sizeof(sstr) );
  7206. loc = strstr(payload, localAuthorizationListsearch);
  7207. if(loc != NULL) // localAuthorizationList is not NULL
  7208. {
  7209. //Check UpdateType
  7210. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7211. {
  7212. //Local list full update
  7213. printf("Local list full update.\n");
  7214. OCPP_cleanLocalList();
  7215. }
  7216. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7217. {
  7218. //Local list different update
  7219. printf("Local list different update.\n");
  7220. OCPP_getListVerion();
  7221. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7222. {
  7223. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7224. goto end;
  7225. }
  7226. }
  7227. else
  7228. {
  7229. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7230. goto end;
  7231. }
  7232. c = 0;
  7233. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7234. {
  7235. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7236. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7237. c++;
  7238. }
  7239. sstr[c] = '\0';
  7240. //DEBUG_INFO("sstr=%s\n", sstr);
  7241. //parsing strings to words
  7242. i = 0;
  7243. pch = strtok(sstr,delim1);
  7244. while (pch != NULL)
  7245. {
  7246. strcpy(CardList[i], pch);
  7247. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7248. pch = strtok (NULL, delim1);
  7249. i = i + 1;
  7250. }
  7251. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7252. //local Authorizations List Numbers
  7253. //n_localAuthorizations = i;
  7254. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7255. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7256. c= 0;
  7257. while(c < i)
  7258. {
  7259. //Search "IdToken"
  7260. memset(sstr ,0, sizeof(sstr) );
  7261. loc = strstr(CardList[c], "idTag");
  7262. int j = 0;
  7263. while (loc[3+strlen("idTag")+j] != '\"')
  7264. {
  7265. sstr[j] = loc[3+strlen("idTag")+j];
  7266. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7267. j++;
  7268. }
  7269. sstr[j] = '\0';
  7270. strcpy(idTagstr, sstr);
  7271. DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7272. //Search "expiryDate"
  7273. memset(sstr ,0, sizeof(sstr) );
  7274. loc = strstr(CardList[c], "expiryDate");
  7275. j = 0;
  7276. if(loc != NULL)
  7277. {
  7278. while (loc[3+strlen("expiryDate")+j] != '\"')
  7279. {
  7280. sstr[j] = loc[3+strlen("expiryDate")+j];
  7281. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7282. j++;
  7283. }
  7284. sstr[j] = '\0';
  7285. strcpy(expiryDate, sstr);
  7286. }
  7287. else
  7288. {
  7289. strcpy(expiryDate, "");
  7290. }
  7291. DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7292. //Search "parentIdTag"
  7293. memset(sstr ,0, sizeof(sstr) );
  7294. loc = strstr(CardList[c], "parentIdTag");
  7295. j = 0;
  7296. if(loc != NULL)
  7297. {
  7298. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7299. {
  7300. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7301. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7302. j++;
  7303. }
  7304. sstr[j] = '\0';
  7305. strcpy(parentIdTag, sstr);
  7306. }
  7307. else
  7308. {
  7309. strcpy(parentIdTag, "");
  7310. }
  7311. DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7312. //Search "status"
  7313. memset(sstr ,0, sizeof(sstr) );
  7314. loc = strstr(CardList[c], "status");
  7315. j = 0;
  7316. while (loc[3+strlen("status")+j] != '\"')
  7317. {
  7318. sstr[j] = loc[3+strlen("status")+j];
  7319. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7320. j++;
  7321. }
  7322. sstr[j] = '\0';
  7323. strcpy(idTagstatus, sstr);
  7324. DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7325. OCPP_getIdTag(idTagstr);
  7326. //OCPP_getIdTag("test"); For Test
  7327. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7328. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7329. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7330. {
  7331. //Local list full update
  7332. DEBUG_INFO("Local list full update.\n");
  7333. // update list
  7334. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7335. //DEBUG_INFO("Local list full update. 1\n");
  7336. //OCPP_get_TableAuthlocalAllData();
  7337. //DEBUG_INFO("Local list full update. 2\n");
  7338. }
  7339. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7340. {
  7341. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7342. {
  7343. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7344. }
  7345. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7346. {
  7347. OCPP_deleteIdTag(idTagstr);
  7348. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7349. //OCPP_deleteIdTag(idTagstr);
  7350. }
  7351. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7352. {
  7353. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7354. }
  7355. }
  7356. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7357. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7358. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7359. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7360. c++;
  7361. }
  7362. }
  7363. else
  7364. {
  7365. //Check UpdateType
  7366. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7367. {
  7368. //Local list full update
  7369. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7370. OCPP_cleanLocalList();
  7371. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7372. goto end;
  7373. }
  7374. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7375. {
  7376. //Local list different update
  7377. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7378. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7379. goto end;
  7380. }
  7381. }
  7382. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7383. end:
  7384. sendSendLocalListConfirmation(uuid, comfirmstr);
  7385. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7386. return result;
  7387. }
  7388. #define MAX 200
  7389. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7390. {
  7391. mtrace();
  7392. int result = FAIL;
  7393. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7394. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7395. char chargingProfilePurposeStr[30]={0};
  7396. char chargingProfileKindStr[16]={0};
  7397. char recurrencyKindStr[10]={0};
  7398. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7399. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7400. int chargingSchedulePeriodCount = 0;
  7401. //int updateflag = FALSE;
  7402. char comfirmstr[20]={0};
  7403. int meet= FALSE;
  7404. char sstr[10]={0};
  7405. int c = 0;
  7406. char *loc;
  7407. FILE *fptr1;//, *fptr2;
  7408. //int lno=0;//, linectr = 0;
  7409. //int modifyflag = FALSE;
  7410. char filename[MAX]={0};
  7411. char tempfile[] = "/Storage/OCPP/temp.json";
  7412. //int resultRename=0;
  7413. char rmFileCmd[50]={0};
  7414. char tempchargingProfilePurposeStr[30]={0};
  7415. char word[1600]={0};
  7416. int n_chargingProfile = 0;
  7417. //[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}}}]
  7418. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7419. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7420. //*********************connectorId***************************/
  7421. loc = strstr(payload, "connectorId");
  7422. c = 0;
  7423. memset(sstr ,0, sizeof(sstr) );
  7424. while (loc[strlen("connectorId")+2+c] != ',')
  7425. {
  7426. sstr[c] = loc[strlen("connectorId")+2+c];
  7427. c++;
  7428. }
  7429. sstr[c] = '\0';
  7430. connectorIdInt = atoi(sstr);
  7431. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7432. {
  7433. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7434. }
  7435. else
  7436. {
  7437. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7438. }
  7439. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7440. //*********************chargingProfileId***************************/
  7441. loc = strstr(payload, "chargingProfileId");
  7442. c = 0;
  7443. memset(sstr ,0, sizeof(sstr) );
  7444. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7445. {
  7446. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7447. c++;
  7448. }
  7449. sstr[c] = '\0';
  7450. chargingProfileIdInt = atoi(sstr);
  7451. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7452. {
  7453. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7454. }
  7455. else
  7456. {
  7457. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7458. }
  7459. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7460. //*********************transactionId***************************/
  7461. loc = strstr(payload, "transactionId");
  7462. if(loc != NULL)
  7463. {
  7464. c = 0;
  7465. memset(sstr ,0, sizeof(sstr) );
  7466. while (loc[strlen("transactionId")+2+c] != ',')
  7467. {
  7468. sstr[c] = loc[strlen("transactionId")+2+c];
  7469. c++;
  7470. }
  7471. sstr[c] = '\0';
  7472. transactionIdInt = atoi(sstr);
  7473. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7474. {
  7475. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7476. }
  7477. else
  7478. {
  7479. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7480. }
  7481. }
  7482. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7483. //*********************stackLevel***************************/
  7484. loc = strstr(payload, "stackLevel");
  7485. c = 0;
  7486. memset(sstr ,0, sizeof(sstr) );
  7487. while (loc[strlen("stackLevel")+2+c] != ',')
  7488. {
  7489. sstr[c] = loc[strlen("stackLevel")+2+c];
  7490. c++;
  7491. }
  7492. sstr[c] = '\0';
  7493. stackLevelInt = atoi(sstr);
  7494. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7495. {
  7496. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7497. }
  7498. else
  7499. {
  7500. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7501. }
  7502. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7503. //*********************chargingProfilePurpose***************************/
  7504. loc = strstr(payload, "chargingProfilePurpose");
  7505. c = 0;
  7506. memset(sstr ,0, sizeof(sstr) );
  7507. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7508. {
  7509. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7510. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7511. c++;
  7512. }
  7513. sstr[c] = '\0';
  7514. strcpy(chargingProfilePurposeStr,sstr);
  7515. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7516. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7517. {
  7518. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7519. }
  7520. else
  7521. {
  7522. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7523. }
  7524. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7525. //*********************chargingProfileKind***************************/
  7526. loc = strstr(payload, "chargingProfileKind");
  7527. c = 0;
  7528. memset(sstr ,0, sizeof(sstr) );
  7529. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7530. {
  7531. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7532. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7533. c++;
  7534. }
  7535. sstr[c] = '\0';
  7536. strcpy(chargingProfileKindStr,sstr);
  7537. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7538. {
  7539. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7540. }
  7541. else
  7542. {
  7543. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7544. }
  7545. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7546. //*********************recurrencyKind***************************/
  7547. loc = strstr(payload, "recurrencyKind");
  7548. if(loc != NULL)
  7549. {
  7550. c = 0;
  7551. memset(sstr ,0, sizeof(sstr) );
  7552. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7553. {
  7554. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7555. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7556. c++;
  7557. }
  7558. sstr[c] = '\0';
  7559. strcpy(recurrencyKindStr,sstr);
  7560. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7561. {
  7562. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7563. }
  7564. else
  7565. {
  7566. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7567. }
  7568. }
  7569. else
  7570. {
  7571. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7572. {
  7573. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7574. }
  7575. else
  7576. {
  7577. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7578. }
  7579. }
  7580. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7581. //*********************validFrom***************************/
  7582. loc = strstr(payload, "validFrom");
  7583. if(loc != NULL)
  7584. {
  7585. c = 0;
  7586. memset(sstr ,0, sizeof(sstr) );
  7587. while (loc[3+strlen("validFrom")+c] != '\"')
  7588. {
  7589. sstr[c] = loc[3+strlen("validFrom")+c];
  7590. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7591. c++;
  7592. }
  7593. sstr[c] = '\0';
  7594. strcpy(validFromStr,sstr);
  7595. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7596. {
  7597. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7598. }
  7599. else
  7600. {
  7601. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7602. }
  7603. }
  7604. else
  7605. {
  7606. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7607. {
  7608. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7609. }
  7610. else
  7611. {
  7612. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7613. }
  7614. }
  7615. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7616. //*********************validTo***************************/
  7617. loc = strstr(payload, "validTo");
  7618. if(loc != NULL)
  7619. {
  7620. c = 0;
  7621. memset(sstr ,0, sizeof(sstr) );
  7622. while (loc[3+strlen("validTo")+c] != '\"')
  7623. {
  7624. sstr[c] = loc[3+strlen("validTo")+c];
  7625. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7626. c++;
  7627. }
  7628. sstr[c] = '\0';
  7629. strcpy(validToStr,sstr);
  7630. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7631. {
  7632. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7633. }
  7634. else
  7635. {
  7636. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7637. }
  7638. }
  7639. else
  7640. {
  7641. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7642. {
  7643. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7644. }
  7645. else
  7646. {
  7647. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7648. }
  7649. }
  7650. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7651. //*********************duration***************************/
  7652. loc = strstr(payload, "duration");
  7653. if(loc != NULL)
  7654. {
  7655. c = 0;
  7656. memset(sstr ,0, sizeof(sstr) );
  7657. while (loc[strlen("duration")+2+c] != ',')
  7658. {
  7659. sstr[c] = loc[strlen("duration")+2+c];
  7660. c++;
  7661. }
  7662. sstr[c] = '\0';
  7663. durationInt = atoi(sstr);
  7664. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7665. {
  7666. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7667. }
  7668. else
  7669. {
  7670. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7671. }
  7672. }
  7673. else
  7674. {
  7675. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7676. {
  7677. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7678. }
  7679. else
  7680. {
  7681. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7682. }
  7683. }
  7684. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7685. //*********************startSchedule***************************/
  7686. loc = strstr(payload, "startSchedule");
  7687. if(loc != NULL)
  7688. {
  7689. c = 0;
  7690. memset(sstr ,0, sizeof(sstr) );
  7691. while (loc[3+strlen("startSchedule")+c] != '\"')
  7692. {
  7693. sstr[c] = loc[3+strlen("startSchedule")+c];
  7694. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7695. c++;
  7696. }
  7697. sstr[c] = '\0';
  7698. strcpy(startScheduleStr,sstr);
  7699. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7700. {
  7701. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7702. }
  7703. else
  7704. {
  7705. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7706. }
  7707. }
  7708. else
  7709. {
  7710. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7711. {
  7712. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7713. }
  7714. else
  7715. {
  7716. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7717. }
  7718. }
  7719. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7720. //*********************chargingRateUnit***************************/
  7721. loc = strstr(payload, "chargingRateUnit");
  7722. if(loc != NULL)
  7723. {
  7724. c = 0;
  7725. memset(sstr ,0, sizeof(sstr) );
  7726. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7727. {
  7728. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7729. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7730. c++;
  7731. }
  7732. sstr[c] = '\0';
  7733. strcpy(chargingRateUnitStr,sstr);
  7734. #if 0
  7735. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  7736. {
  7737. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7738. goto end;
  7739. }
  7740. #endif
  7741. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7742. {
  7743. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7744. }
  7745. else
  7746. {
  7747. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7748. }
  7749. }
  7750. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7751. //****************chargingSchedulePeriod count start*******************/
  7752. int what_len = strlen("startPeriod");
  7753. char tempChargingProfile[1000]={0};
  7754. strcpy(tempChargingProfile,(const char*)payload);
  7755. char *where = tempChargingProfile;
  7756. if (what_len)
  7757. {
  7758. while ((where = strstr(where, "startPeriod"))) {
  7759. where += what_len;
  7760. chargingSchedulePeriodCount++;
  7761. }
  7762. }
  7763. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  7764. {
  7765. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7766. goto end;
  7767. }
  7768. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7769. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7770. //where = payload;
  7771. int templength = 0;
  7772. //int searchstart = 0;
  7773. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7774. {
  7775. //****************startPeriod*******************/
  7776. c=0;
  7777. loc = strstr(tempChargingProfile + templength, "startPeriod");
  7778. memset(sstr ,0, sizeof(sstr) );
  7779. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7780. {
  7781. sstr[c] = loc[strlen("startPeriod")+2+c];
  7782. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7783. c++;
  7784. }
  7785. sstr[c] = '\0';
  7786. startPeriodInt[periodNums] = atoi(sstr);
  7787. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7788. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7789. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7790. {
  7791. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7792. }
  7793. else
  7794. {
  7795. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7796. }
  7797. templength = strlen("startPeriod")+2+c;
  7798. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7799. //****************limit*******************/
  7800. c=0;
  7801. loc = strstr(tempChargingProfile + templength, "limit");
  7802. memset(sstr ,0, sizeof(sstr) );
  7803. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7804. {
  7805. sstr[c] = loc[strlen("limit")+2+c];
  7806. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7807. c++;
  7808. }
  7809. sstr[c] = '\0';
  7810. limitflaot[periodNums] = atof(sstr);
  7811. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7812. {
  7813. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7814. }
  7815. else
  7816. {
  7817. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7818. }
  7819. templength = templength + strlen("limit")+2+c;
  7820. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7821. //****************numberPhases*******************/
  7822. loc = strstr(tempChargingProfile + templength, "numberPhases");
  7823. if(loc != NULL)
  7824. {
  7825. c=0;
  7826. memset(sstr ,0, sizeof(sstr) );
  7827. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7828. {
  7829. sstr[c] = loc[strlen("numberPhases")+2+c];
  7830. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7831. c++;
  7832. }
  7833. sstr[c] = '\0';
  7834. numberPhasesInt[periodNums] = atoi(sstr);
  7835. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7836. {
  7837. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7838. }
  7839. else
  7840. {
  7841. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7842. }
  7843. templength = templength + strlen("numberPhases")+2+c;
  7844. }
  7845. //where = loc;
  7846. }
  7847. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7848. //****************chargingSchedulePeriod count end*******************/
  7849. //*********************minChargingRate***************************/
  7850. loc = strstr(payload, "minChargingRate");
  7851. if(loc != NULL)
  7852. {
  7853. c = 0;
  7854. memset(sstr ,0, sizeof(sstr) );
  7855. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7856. {
  7857. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7858. c++;
  7859. }
  7860. sstr[c] = '\0';
  7861. minChargingRateFloat = atof(sstr);
  7862. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7863. {
  7864. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7865. }
  7866. else
  7867. {
  7868. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7869. }
  7870. }
  7871. else
  7872. {
  7873. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7874. {
  7875. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7876. }
  7877. else
  7878. {
  7879. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7880. }
  7881. }
  7882. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7883. {
  7884. //printf("set chargingProfile 1-2\n");
  7885. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7886. if(connectorIdInt != 0)
  7887. {
  7888. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7889. goto end;
  7890. }
  7891. strcpy(filename, ChargePointMaxProfile_JSON );
  7892. fptr1 = fopen(filename, "r");
  7893. if (!fptr1)
  7894. {
  7895. //file not exist
  7896. DEBUG_INFO("Unable to open the input file!!\n");
  7897. fptr1 = fopen(filename, "w+");
  7898. }
  7899. else
  7900. {
  7901. //Check Charging Profile Count
  7902. while(fscanf(fptr1, "%s", word) != EOF)
  7903. {
  7904. //DEBUG_INFO("word=%s\n",word);
  7905. if(strstr(word, "chargingProfileId")!= NULL)
  7906. {
  7907. //DEBUG_INFO("test chargingProfileId \n");
  7908. n_chargingProfile = n_chargingProfile + 1;
  7909. //DEBUG_INFO("chargingProfileId Found\n");
  7910. }
  7911. }
  7912. }
  7913. fclose(fptr1);
  7914. }
  7915. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7916. {
  7917. //printf("set chargingProfile 1-3\n");
  7918. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7919. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7920. {
  7921. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7922. goto end;
  7923. }
  7924. switch(connectorIdInt)
  7925. {
  7926. case 0:
  7927. strcpy(filename, TxDefaultProfile_0_JSON );
  7928. break;
  7929. case 1:
  7930. strcpy(filename, TxDefaultProfile_1_JSON );
  7931. break;
  7932. case 2:
  7933. strcpy(filename, TxDefaultProfile_2_JSON );
  7934. break;
  7935. default:
  7936. strcpy(filename, TxDefaultProfile_0_JSON );
  7937. break;
  7938. }
  7939. fptr1 = fopen(filename, "r");
  7940. if (!fptr1)
  7941. {
  7942. //file not exist
  7943. //DEBUG_INFO("Unable to open the input file!!\n");
  7944. fptr1 = fopen(filename, "w+");
  7945. }
  7946. else
  7947. {
  7948. //Check Charging Profile Count
  7949. while(fscanf(fptr1, "%s", word) != EOF)
  7950. {
  7951. //DEBUG_INFO("word=%s\n",word);
  7952. if(strstr(word, "chargingProfileId")!= NULL)
  7953. {
  7954. //DEBUG_INFO("test chargingProfileId \n");
  7955. n_chargingProfile = n_chargingProfile + 1;
  7956. //DEBUG_INFO("chargingProfileId Found\n");
  7957. }
  7958. }
  7959. }
  7960. fclose(fptr1);
  7961. }
  7962. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7963. {
  7964. //printf("set chargingProfile 1-4\n");
  7965. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7966. //check Transaction active
  7967. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7968. {
  7969. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7970. {
  7971. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7972. {
  7973. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7974. {
  7975. meet = TRUE;
  7976. break;
  7977. }
  7978. }
  7979. }
  7980. }
  7981. for (int index = 0; index < CCS_QUANTITY; index++)
  7982. {
  7983. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7984. {
  7985. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7986. {
  7987. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7988. {
  7989. meet = TRUE;
  7990. break;
  7991. }
  7992. }
  7993. }
  7994. }
  7995. for (int index = 0; index < GB_QUANTITY; index++)
  7996. {
  7997. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7998. {
  7999. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8000. {
  8001. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8002. {
  8003. meet = TRUE;
  8004. break;
  8005. }
  8006. }
  8007. }
  8008. }
  8009. if(meet == FALSE)
  8010. {
  8011. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8012. goto end;
  8013. }
  8014. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8015. {
  8016. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8017. goto end;
  8018. }
  8019. switch(connectorIdInt)
  8020. {
  8021. case 0:
  8022. break;
  8023. case 1:
  8024. strcpy(filename, TxProfile_1_JSON);
  8025. break;
  8026. case 2:
  8027. strcpy(filename, TxProfile_2_JSON);
  8028. break;
  8029. default:
  8030. strcpy(filename, TxProfile_1_JSON);
  8031. break;
  8032. }
  8033. fptr1 = fopen(filename, "r");
  8034. if (!fptr1)
  8035. {
  8036. //file not exist
  8037. DEBUG_INFO("Unable to open the input file!!\n");
  8038. fptr1 = fopen(filename, "w+");
  8039. }
  8040. else
  8041. {
  8042. //Check Charging Profile Count
  8043. while(fscanf(fptr1, "%s", word) != EOF)
  8044. {
  8045. //DEBUG_INFO("word=%s\n",word);
  8046. if(strstr(word, "chargingProfileId")!= NULL)
  8047. {
  8048. //DEBUG_INFO("test chargingProfileId \n");
  8049. n_chargingProfile = n_chargingProfile + 1;
  8050. //DEBUG_INFO("chargingProfileId Found\n");
  8051. }
  8052. }
  8053. }
  8054. fclose(fptr1);
  8055. }
  8056. // Check ChargeProfileMaxStackLevel
  8057. if(n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8058. {
  8059. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8060. goto end;
  8061. }
  8062. // Check all Charging Files
  8063. {
  8064. int i = 0;
  8065. char fnametemp[200]={0};
  8066. n_chargingProfile = 0;
  8067. //Check ChargePointMaxProfile.json exit
  8068. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8069. {
  8070. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8071. //Check Charging Profile Count
  8072. while(fscanf(fptr1, "%s", word) != EOF)
  8073. {
  8074. //DEBUG_INFO("word=%s\n",word);
  8075. if(strstr(word, "chargingProfileId")!= NULL)
  8076. {
  8077. //DEBUG_INFO("test chargingProfileId \n");
  8078. n_chargingProfile = n_chargingProfile + 1;
  8079. i = i + 1;
  8080. //DEBUG_INFO("chargingProfileId Found\n");
  8081. }
  8082. memset(word, 0, sizeof word);
  8083. }
  8084. fclose(fptr1);
  8085. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8086. }
  8087. //Check TxDefaultProfile_0.json exit
  8088. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8089. {
  8090. i = 0;
  8091. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8092. //Check Charging Profile Count
  8093. while(fscanf(fptr1, "%s", word) != EOF)
  8094. {
  8095. //DEBUG_INFO("word=%s\n",word);
  8096. if(strstr(word, "chargingProfileId")!= NULL)
  8097. {
  8098. //DEBUG_INFO("test chargingProfileId \n");
  8099. n_chargingProfile = n_chargingProfile + 1;
  8100. i = i + 1;
  8101. //DEBUG_INFO("chargingProfileId Found\n");
  8102. }
  8103. memset(word, 0, sizeof word);
  8104. }
  8105. fclose(fptr1);
  8106. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8107. }
  8108. //Check TxDefaultProfile_%d.json
  8109. for(int j=1; j <= gunTotalNumber; j++)
  8110. {
  8111. memset(fnametemp, 0, sizeof fnametemp);
  8112. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8113. if((access(fnametemp,F_OK))!=-1)
  8114. {
  8115. i = 0;
  8116. fptr1 = fopen(fnametemp, "r");
  8117. //Check Charging Profile Count
  8118. while(fscanf(fptr1, "%s", word) != EOF)
  8119. {
  8120. //DEBUG_INFO("word=%s\n",word);
  8121. if(strstr(word, "chargingProfileId")!= NULL)
  8122. {
  8123. //DEBUG_INFO("test chargingProfileId \n");
  8124. n_chargingProfile = n_chargingProfile + 1;
  8125. i = i + 1;
  8126. //DEBUG_INFO("chargingProfileId Found\n");
  8127. }
  8128. memset(word, 0, sizeof word);
  8129. }
  8130. fclose(fptr1);
  8131. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8132. }
  8133. }
  8134. //Check TxProfile_%d.json
  8135. for(int j=1; j <= gunTotalNumber; j++)
  8136. {
  8137. memset(fnametemp, 0, sizeof fnametemp);
  8138. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8139. if((access(fnametemp,F_OK))!=-1)
  8140. {
  8141. i = 0;
  8142. fptr1 = fopen(fnametemp, "r");
  8143. //Check Charging Profile Count
  8144. while(fscanf(fptr1, "%s", word) != EOF)
  8145. {
  8146. //DEBUG_INFO("word=%s\n",word);
  8147. if(strstr(word, "chargingProfileId")!= NULL)
  8148. {
  8149. //DEBUG_INFO("test chargingProfileId \n");
  8150. n_chargingProfile = n_chargingProfile + 1;
  8151. i = i + 1;
  8152. //DEBUG_INFO("chargingProfileId Found\n");
  8153. }
  8154. memset(word, 0, sizeof word);
  8155. }
  8156. fclose(fptr1);
  8157. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8158. }
  8159. }
  8160. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8161. {
  8162. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8163. goto end;
  8164. }
  8165. }// End connectorIsNULL is TRUE
  8166. //**********************************Write to File********************************************************/
  8167. FILE *infile;
  8168. FILE *outfile;
  8169. // open file for writing
  8170. infile = fopen (filename, "r");
  8171. outfile = fopen (tempfile, "w");
  8172. int d =0;
  8173. d = fgetc(infile);
  8174. //DEBUG_INFO("d:%d\n",d);
  8175. rewind(infile);
  8176. //*检测到文件结束标识返回1,否则返回0。*/
  8177. if(d == EOF)
  8178. {
  8179. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8180. fprintf(outfile,"%s\n",payload);
  8181. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8182. fclose(infile);
  8183. fclose(outfile);
  8184. sprintf(rmFileCmd,"rm -f %s",filename);
  8185. system(rmFileCmd);
  8186. rename(tempfile, filename);
  8187. #if 0
  8188. resultRename = rename(tempfile, filename);
  8189. if(resultRename == 0)
  8190. {
  8191. DEBUG_INFO("File chargingProfile renamed successfully");
  8192. }
  8193. else
  8194. {
  8195. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8196. }
  8197. #endif
  8198. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8199. //system(rmFileCmd);
  8200. }
  8201. else
  8202. {
  8203. char buf[1000]={0};
  8204. int ChargingProfileAdded = FALSE;
  8205. while (fgets(buf, sizeof(buf), infile) != NULL)
  8206. {
  8207. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8208. //*************************tempconnectorIdInt*********************************/
  8209. loc = strstr(buf, "connectorId");
  8210. c = 0;
  8211. memset(sstr ,0, sizeof(sstr) );
  8212. while (loc[strlen("connectorId")+2+c] != ',')
  8213. {
  8214. sstr[c] = loc[strlen("connectorId")+2+c];
  8215. c++;
  8216. }
  8217. sstr[c] = '\0';
  8218. tempconnectorIdInt = atoi(sstr);
  8219. //*************************tempchargingProfileIdInt*********************************/
  8220. loc = strstr(buf, "chargingProfileId");
  8221. c = 0;
  8222. memset(sstr ,0, sizeof(sstr) );
  8223. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8224. {
  8225. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8226. c++;
  8227. }
  8228. sstr[c] = '\0';
  8229. tempchargingProfileIdInt = atoi(sstr);
  8230. //*************************tempstackLevelInt*********************************/
  8231. loc = strstr(buf, "stackLevel");
  8232. c = 0;
  8233. memset(sstr ,0, sizeof(sstr) );
  8234. while (loc[strlen("stackLevel")+2+c] != ',')
  8235. {
  8236. sstr[c] = loc[strlen("stackLevel")+2+c];
  8237. c++;
  8238. }
  8239. sstr[c] = '\0';
  8240. tempstackLevelInt = atoi(sstr);
  8241. //*************************tempchargingProfilePurposeStr*********************************/
  8242. loc = strstr(payload, "chargingProfilePurpose");
  8243. c = 0;
  8244. memset(sstr ,0, sizeof(sstr) );
  8245. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8246. {
  8247. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8248. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8249. c++;
  8250. }
  8251. sstr[c] = '\0';
  8252. strcpy(tempchargingProfilePurposeStr,sstr);
  8253. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8254. {
  8255. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8256. {
  8257. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8258. if(ChargingProfileAdded == FALSE)
  8259. {
  8260. fprintf(outfile,"%s\n",payload);
  8261. ChargingProfileAdded = TRUE;
  8262. }
  8263. }
  8264. else
  8265. {
  8266. if(tempstackLevelInt < stackLevelInt)
  8267. {
  8268. if(ChargingProfileAdded == FALSE)
  8269. {
  8270. fprintf(outfile,"%s\n",payload);
  8271. ChargingProfileAdded = TRUE;
  8272. fprintf(outfile,"%s\n",buf);
  8273. }
  8274. else
  8275. {
  8276. fprintf(outfile,"%s\n",buf);
  8277. }
  8278. }
  8279. else
  8280. {
  8281. if(ChargingProfileAdded == FALSE)
  8282. {
  8283. fprintf(outfile,"%s\n",buf);
  8284. fprintf(outfile,"%s\n",payload);
  8285. ChargingProfileAdded = TRUE;
  8286. }
  8287. else
  8288. {
  8289. fprintf(outfile,"%s\n",buf);
  8290. }
  8291. }
  8292. }
  8293. }
  8294. else
  8295. {
  8296. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8297. {
  8298. if(ChargingProfileAdded == FALSE)
  8299. {
  8300. fprintf(outfile,"%s\n",payload);
  8301. ChargingProfileAdded = TRUE;
  8302. fprintf(outfile,"%s\n",buf);
  8303. }
  8304. else
  8305. {
  8306. fprintf(outfile,"%s\n",buf);
  8307. }
  8308. }
  8309. else if(tempstackLevelInt < stackLevelInt)
  8310. {
  8311. if(ChargingProfileAdded == FALSE)
  8312. {
  8313. fprintf(outfile,"%s\n",payload);
  8314. ChargingProfileAdded = TRUE;
  8315. fprintf(outfile,"%s\n",buf);
  8316. }
  8317. else
  8318. {
  8319. fprintf(outfile,"%s\n",buf);
  8320. }
  8321. }
  8322. else
  8323. {
  8324. if(ChargingProfileAdded == FALSE)
  8325. {
  8326. fprintf(outfile,"%s\n",buf);
  8327. fprintf(outfile,"%s\n",payload);
  8328. ChargingProfileAdded = TRUE;
  8329. }
  8330. else
  8331. {
  8332. fprintf(outfile,"%s\n",buf);
  8333. }
  8334. }
  8335. }
  8336. } // end of while loop
  8337. fclose(infile);
  8338. fclose(outfile);
  8339. sprintf(rmFileCmd,"rm -f %s",filename);
  8340. system(rmFileCmd);
  8341. rename(tempfile, filename);
  8342. #if 0
  8343. resultRename = rename(tempfile, filename);
  8344. if(resultRename == 0)
  8345. {
  8346. DEBUG_INFO("File chargingProfile renamed successfully");
  8347. }
  8348. else
  8349. {
  8350. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8351. }
  8352. #endif
  8353. result = TRUE;
  8354. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8355. }
  8356. end:
  8357. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8358. return result;
  8359. return result;
  8360. }
  8361. int handleTriggerMessageRequest(char *uuid, char *payload)
  8362. {
  8363. mtrace();
  8364. int result = FAIL;
  8365. int connectorIdIsNULL = FALSE;
  8366. int connectorIdInt =0;
  8367. char sstr[40]={0};
  8368. char requestedMessagestr[40]={0};
  8369. char comfirmstr[20]={0};
  8370. int c = 0;
  8371. char *loc;
  8372. DEBUG_INFO("handleTriggerMessageRequest\n");
  8373. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8374. c = 0;
  8375. loc = strstr(payload, "requestedMessage");
  8376. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8377. {
  8378. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8379. c++;
  8380. }
  8381. sstr[c] = '\0';
  8382. strcpy(requestedMessagestr, sstr);
  8383. c = 0;
  8384. loc = strstr(payload, "connectorId");
  8385. if(loc == NULL)
  8386. {
  8387. connectorIdIsNULL = TRUE;
  8388. }
  8389. else
  8390. {
  8391. memset(sstr ,0, sizeof(sstr) );
  8392. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8393. {
  8394. sstr[c] = loc[strlen("connectorId")+2+c];
  8395. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8396. c++;
  8397. }
  8398. sstr[c] = '\0';
  8399. connectorIdInt = atoi(sstr);
  8400. }
  8401. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8402. {
  8403. //connectorIdInt = json_object_get_int(connectorId);
  8404. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8405. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8406. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8407. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8408. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8409. }
  8410. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8411. {
  8412. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8413. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8414. return TRUE;
  8415. }
  8416. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8417. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8418. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8419. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8420. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8421. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8422. {
  8423. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8424. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8425. return TRUE;
  8426. }
  8427. else
  8428. {
  8429. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8430. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8431. }
  8432. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8433. {
  8434. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8435. {
  8436. FirmwareStatusNotificationStatus = 3;
  8437. }
  8438. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8439. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8440. }
  8441. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8442. {
  8443. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8444. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8445. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8446. }
  8447. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8448. {
  8449. sendBootNotificationRequest();
  8450. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8451. }
  8452. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8453. {
  8454. sendHeartbeatRequest(connectorIdInt);
  8455. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8456. }
  8457. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8458. {
  8459. if(connectorIdIsNULL == FALSE)
  8460. {
  8461. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8462. {
  8463. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8464. sendMeterValuesRequest(connectorIdInt -1);
  8465. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8466. }
  8467. }
  8468. else
  8469. {
  8470. for(int idx=0;idx< gunTotalNumber;idx++)
  8471. {
  8472. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8473. sendMeterValuesRequest(idx);
  8474. }
  8475. }
  8476. }
  8477. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8478. {
  8479. if(connectorIdIsNULL == FALSE)
  8480. {
  8481. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8482. {
  8483. sendStatusNotificationRequest(connectorIdInt -1);
  8484. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8485. }
  8486. }
  8487. else
  8488. {
  8489. for(int idx=0;idx< gunTotalNumber;idx++)
  8490. sendStatusNotificationRequest(idx);
  8491. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8492. }
  8493. }
  8494. return result;
  8495. }
  8496. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8497. {
  8498. mtrace();
  8499. int result = FAIL;
  8500. char sstr[6]={0};
  8501. int connectorIdInt =0;
  8502. char comfirmstr[20]={0};
  8503. int c = 0;
  8504. char *loc;
  8505. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8506. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8507. c = 0;
  8508. loc = strstr(payload, "connectorId");
  8509. memset(sstr ,0, sizeof(sstr) );
  8510. while (loc[strlen("connectorId")+2+c] != '}')
  8511. {
  8512. sstr[c] = loc[strlen("connectorId")+2+c];
  8513. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8514. c++;
  8515. }
  8516. sstr[c] = '\0';
  8517. connectorIdInt = atoi(sstr);
  8518. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8519. if(gunTotalNumber == 0)
  8520. {
  8521. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8522. goto end;
  8523. }
  8524. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8525. {
  8526. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8527. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8528. goto end;
  8529. }
  8530. else
  8531. {
  8532. //check Transaction active
  8533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8534. {
  8535. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8536. {
  8537. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8538. {
  8539. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8540. }
  8541. }
  8542. for (int index = 0; index < CCS_QUANTITY; index++)
  8543. {
  8544. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8545. {
  8546. //stop Transaction
  8547. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8548. }
  8549. }
  8550. for (int index = 0; index < GB_QUANTITY; index++)
  8551. {
  8552. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8553. {
  8554. //stop Transaction
  8555. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8556. }
  8557. }
  8558. }
  8559. else
  8560. {
  8561. for (int index = 0; index < AC_QUANTITY; index++)
  8562. {
  8563. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8564. {
  8565. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8566. }
  8567. }
  8568. }// END FOR AC ELSE
  8569. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8570. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8571. result = TRUE;
  8572. return result;
  8573. }
  8574. end:
  8575. //json_object_put(obj); --- remove temporally
  8576. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8577. return result;
  8578. }
  8579. static char UpdateFirmwarepayloadData[300]={0};
  8580. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8581. {
  8582. mtrace();
  8583. int result = FAIL;
  8584. pthread_t t;
  8585. sendUpdateFirmwareConfirmation(uuid);
  8586. memset(UpdateFirmwarepayloadData, 0, 300);
  8587. strcpy(UpdateFirmwarepayloadData, payload);
  8588. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8589. ////pthread_join(t, NULL); //
  8590. //pthread_detach(t);
  8591. //sendUpdateFirmwareConfirmation(uuid);
  8592. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8593. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8594. return result;
  8595. }
  8596. void *UpdateFirmwareProcess(void *data)
  8597. {
  8598. pthread_detach(pthread_self());
  8599. mtrace();
  8600. int retriesInt =0, retryIntervalInt=0;
  8601. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8602. int port=0;
  8603. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8604. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8605. //char comfirmstr[20];
  8606. int isSuccess = 0;
  8607. char ftpbuf[200];
  8608. char temp[100];
  8609. char * pch;
  8610. int retriesISNULL=FALSE;
  8611. int retryInterval=FALSE;
  8612. int c = 0;
  8613. //int i = 0;
  8614. char *loc;
  8615. char sstr[300]={ 0 };
  8616. char str[300]={ 0 };
  8617. //char *str = (char*) data; // ? ?輸入資 ?
  8618. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8619. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8620. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8621. //***************location **************/
  8622. loc = strstr(str, "location");
  8623. memset(sstr ,0, sizeof(sstr) );
  8624. c = 0;
  8625. while (loc[3+strlen("location")+c] != '\"')
  8626. {
  8627. sstr[c] = loc[3+strlen("location")+c];
  8628. c++;
  8629. }
  8630. sstr[c] = '\0';
  8631. strcpy(locationstr, sstr);
  8632. //***************retries**************/
  8633. c = 0;
  8634. loc = strstr(str, "retries");
  8635. if(loc == NULL)
  8636. {
  8637. retriesISNULL=TRUE;
  8638. }
  8639. else
  8640. {
  8641. memset(sstr ,0, sizeof(sstr) );
  8642. while (loc[strlen("retries")+2+c] != ',')
  8643. {
  8644. sstr[c] = loc[strlen("retries")+2+c];
  8645. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8646. c++;
  8647. }
  8648. sstr[c] = '\0';
  8649. }
  8650. if(retriesISNULL == FALSE)
  8651. {
  8652. retriesInt = atoi(sstr);
  8653. }
  8654. //***************retrieveDate **************/
  8655. loc = strstr(str, "retrieveDate");
  8656. memset(sstr ,0, sizeof(sstr) );
  8657. c = 0;
  8658. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8659. {
  8660. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8661. c++;
  8662. }
  8663. sstr[c] = '\0';
  8664. strcpy(retrieveDatestr, sstr);
  8665. //***************retryInterval **************/
  8666. c = 0;
  8667. loc = strstr(str, "retryInterval");
  8668. memset(sstr ,0, sizeof(sstr) );
  8669. if(loc == NULL)
  8670. {
  8671. retryInterval=TRUE;
  8672. }
  8673. else
  8674. {
  8675. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8676. {
  8677. sstr[c] = loc[strlen("retryInterval")+2+c];
  8678. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8679. c++;
  8680. }
  8681. sstr[c] = '\0';
  8682. }
  8683. if(retryInterval==FALSE)
  8684. {
  8685. retryIntervalInt = atoi(sstr);
  8686. }
  8687. memset(ftppath, 0, sizeof(ftppath));
  8688. memset(path, 0, sizeof(path));
  8689. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8690. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8691. if(strncmp(locationstr,"http", 4) == 0)
  8692. {
  8693. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8694. protocol, host, path);
  8695. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8696. // protocol, user, password, host, path);
  8697. sprintf(ftppath,"/%s", path);
  8698. //DEBUG_INFO("protocol =%s\n",protocol);
  8699. //DEBUG_INFO("host =%s\n",host);
  8700. //DEBUG_INFO("path =%s\n",path);
  8701. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8702. int ftppathlen=strlen(ftppath);
  8703. int i=1;
  8704. char filenametemp[50];
  8705. while(i < ftppathlen)
  8706. {
  8707. int len=ftppathlen-i;
  8708. if(ftppath[len]== 47) // '/' ascll code: 47
  8709. {
  8710. DEBUG_INFO("compare '/' all right\n");
  8711. break;
  8712. }
  8713. i=i+1;
  8714. }
  8715. memset(filenametemp, 0, sizeof(filenametemp));
  8716. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8717. filenametemp[i+1] = 0;
  8718. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8719. do{
  8720. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8721. sleep(retryIntervalInt);
  8722. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8723. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8724. if(!isSuccess)
  8725. {
  8726. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8727. }
  8728. else
  8729. {
  8730. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8731. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8732. isUpdateRequest = TRUE;
  8733. }
  8734. }
  8735. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8736. {
  8737. memset(ftpbuf, 0, sizeof(ftpbuf));
  8738. memset(temp, 0, sizeof(temp));
  8739. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8740. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8741. int ftppathlen=strlen(ftpbuf);
  8742. int i=1;
  8743. char filenametemp[50];
  8744. while(i < ftppathlen)
  8745. {
  8746. int len=ftppathlen-i;
  8747. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8748. {
  8749. DEBUG_INFO(" compare '/' all right\n");
  8750. break;
  8751. }
  8752. i=i+1;
  8753. }
  8754. memset(filenametemp, 0, sizeof(filenametemp));
  8755. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8756. filenametemp[i+1] = 0;
  8757. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8758. pch=strchr(temp,'@');
  8759. if(pch==NULL)
  8760. {
  8761. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8762. protocol, host, &port, path);
  8763. strcpy(user,"anonymous");
  8764. strcpy(password,"");
  8765. }
  8766. else
  8767. {
  8768. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8769. protocol, user, password, host, &port, path);
  8770. }
  8771. sscanf(host,"%[^/]%s",host1, path1);
  8772. sprintf(ftppath,"%s", path1);
  8773. //DEBUG_INFO("protocol =%s\n",protocol);
  8774. //DEBUG_INFO("user =%s\n",user);
  8775. //DEBUG_INFO("password =%s\n",password);
  8776. //DEBUG_INFO("host1 =%s\n",host1);
  8777. //DEBUG_INFO("port =%d\n",port);
  8778. //DEBUG_INFO("path1 =%s\n",path1);
  8779. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8780. //ftpFile(host, user, password, port, ftppath, fname);
  8781. //download firmware pthred
  8782. if(port == 0)
  8783. {
  8784. port = 21;
  8785. }
  8786. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8787. do{
  8788. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8789. sleep(retryIntervalInt);
  8790. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8791. if(!isSuccess)
  8792. {
  8793. //BulldogUtil.sleepMs(interval*1000);
  8794. DEBUG_INFO("Update firmware request and download file fail.\n");
  8795. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8796. }
  8797. else
  8798. {
  8799. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8800. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8801. isUpdateRequest = TRUE;
  8802. }
  8803. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8804. }
  8805. else
  8806. {
  8807. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8808. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8809. }
  8810. pthread_exit(NULL);
  8811. }
  8812. //==========================================
  8813. // Handle server response routine
  8814. //==========================================
  8815. void handleAuthorizeResponse(char *payload, int gun_index)
  8816. {
  8817. mtrace();
  8818. char expiryDatestr[30]={0};
  8819. char parentIdTagstr[20]={0};
  8820. char statusstr[20]={0};
  8821. char expiryDatestrtemp[30]={0};
  8822. char parentIdTagstrtemp[20]={0};
  8823. char IdTagstrtemp[20]={0};
  8824. char statusstrtemp[20]={0};
  8825. int expiryDateISNULL=FALSE;
  8826. int parentIdTagISNULL=FALSE;
  8827. char sstr[160]={ 0 };
  8828. char* filename = AuthorizationCache_JSON;
  8829. char tempfile[] = "/Storage/OCPP/temp.json";
  8830. int c = 0;
  8831. char *loc;
  8832. int resultRename=0;
  8833. int responseIdTagInfoAsZero= 0;
  8834. char rmFileCmd[50]={0};
  8835. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8836. //***********expiryDate*************/
  8837. loc = strstr(payload, "expiryDate");
  8838. memset(sstr ,0, sizeof(sstr) );
  8839. c = 0;
  8840. if(loc == NULL)
  8841. {
  8842. expiryDateISNULL = TRUE;
  8843. }
  8844. else
  8845. {
  8846. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8847. {
  8848. sstr[c] = loc[3+strlen("expiryDate")+c];
  8849. c++;
  8850. }
  8851. sstr[c] = '\0';
  8852. strcpy(expiryDatestr, sstr);
  8853. }
  8854. //***********parentIdTag*************/
  8855. loc = strstr(payload, "parentIdTag");
  8856. memset(sstr ,0, sizeof(sstr) );
  8857. c = 0;
  8858. if(loc == NULL)
  8859. {
  8860. parentIdTagISNULL = TRUE;
  8861. }
  8862. else
  8863. {
  8864. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8865. {
  8866. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8867. c++;
  8868. }
  8869. sstr[c] = '\0';
  8870. strcpy(parentIdTagstr, sstr);
  8871. }
  8872. //***********status*************/
  8873. loc = strstr(payload, "status");
  8874. memset(sstr ,0, sizeof(sstr) );
  8875. c = 0;
  8876. while (loc[3+strlen("status")+c] != '\"')
  8877. {
  8878. sstr[c] = loc[3+strlen("status")+c];
  8879. c++;
  8880. }
  8881. sstr[c] = '\0';
  8882. strcpy(statusstr, sstr);
  8883. if(expiryDateISNULL == FALSE)
  8884. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8885. if(parentIdTagISNULL == FALSE)
  8886. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8887. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8888. //Update idTag information to authorization cache if supproted
  8889. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8890. {
  8891. if((access(filename,F_OK))!=-1)
  8892. {
  8893. printf("AuthorizationCache exist.\n");
  8894. }
  8895. else
  8896. {
  8897. printf("AuthorizationCache not exist\n");
  8898. FILE *log = fopen(filename, "w+");
  8899. if(log == NULL)
  8900. {
  8901. printf("log is NULL\n");
  8902. goto out;
  8903. }
  8904. else
  8905. {
  8906. fclose(log);
  8907. }
  8908. }
  8909. FILE *infile;
  8910. FILE *outfile;
  8911. // open file for writing
  8912. infile = fopen (filename, "r");
  8913. outfile = fopen (tempfile, "w");
  8914. //*检测到文件结束标识返回1,否则返回0。*/
  8915. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8916. int c;
  8917. c = fgetc(infile);
  8918. //DEBUG_INFO("c:%d\n",c);
  8919. rewind(infile);
  8920. if(c == EOF)
  8921. {
  8922. DEBUG_INFO("Orignal File is NULL\n");
  8923. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8924. {
  8925. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8926. }
  8927. else
  8928. {
  8929. strcpy(expiryDatestrtemp, "");
  8930. }
  8931. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8932. {
  8933. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8934. }
  8935. else
  8936. {
  8937. //write Authorize IdTag
  8938. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8939. }
  8940. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8941. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8942. fclose(infile);
  8943. fclose(outfile);
  8944. sprintf(rmFileCmd,"rm -f %s",filename);
  8945. system(rmFileCmd);
  8946. resultRename = rename(tempfile, filename);
  8947. if(resultRename == 0)
  8948. {
  8949. printf("File renamed successfully");
  8950. }
  8951. else
  8952. {
  8953. printf("Error: unable to rename the file");
  8954. }
  8955. }
  8956. else
  8957. {
  8958. char buf[160]={0};
  8959. while (fgets(buf, sizeof(buf), infile) != NULL)
  8960. {
  8961. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8962. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8963. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8964. memset(statusstr, 0, sizeof(statusstrtemp));
  8965. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8966. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8967. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8968. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8969. //------------------IdTag-----------------------
  8970. loc = strstr(buf, "idTag");
  8971. memset(sstr ,0, sizeof(sstr) );
  8972. c = 0;
  8973. while (loc[3+strlen("idTag")+c] != '\"')
  8974. {
  8975. sstr[c] = loc[3+strlen("idTag")+c];
  8976. c++;
  8977. }
  8978. sstr[c] = '\0';
  8979. strcpy(IdTagstrtemp,sstr);
  8980. //*********************expiryDate***************/
  8981. loc = strstr(buf, "expiryDate");
  8982. memset(sstr ,0, sizeof(sstr) );
  8983. c = 0;
  8984. while (loc[3+strlen("expiryDate")+c] != '\"')
  8985. {
  8986. sstr[c] = loc[3+strlen("expiryDate")+c];
  8987. c++;
  8988. }
  8989. sstr[c] = '\0';
  8990. strcpy(expiryDatestr,sstr);
  8991. //*********************parentIdTag***************/
  8992. loc = strstr(buf, "parentIdTag");
  8993. memset(sstr ,0, sizeof(sstr) );
  8994. c = 0;
  8995. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8996. {
  8997. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8998. c++;
  8999. }
  9000. sstr[c] = '\0';
  9001. strcpy(parentIdTagstr,sstr);
  9002. //*********************status***************/
  9003. loc = strstr(buf, "status");
  9004. memset(sstr ,0, sizeof(sstr) );
  9005. c = 0;
  9006. while (loc[3+strlen("status")+c] != '\"')
  9007. {
  9008. sstr[c] = loc[3+strlen("status")+c];
  9009. c++;
  9010. }
  9011. sstr[c] = '\0';
  9012. strcpy(statusstr,sstr);
  9013. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9014. {
  9015. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9016. responseIdTagInfoAsZero = 1;
  9017. }
  9018. else
  9019. {
  9020. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9021. }
  9022. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9023. {
  9024. //modify item
  9025. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9026. {
  9027. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9028. }
  9029. else
  9030. {
  9031. strcpy(expiryDatestrtemp, "");
  9032. }
  9033. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9034. {
  9035. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9036. }
  9037. else
  9038. {
  9039. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9040. }
  9041. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9042. }
  9043. else
  9044. {
  9045. //wrie original item
  9046. strcpy(expiryDatestrtemp, expiryDatestr);
  9047. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9048. strcpy(statusstrtemp, statusstr);
  9049. }
  9050. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9051. }
  9052. fclose(infile);
  9053. fclose(outfile);
  9054. sprintf(rmFileCmd,"rm -f %s",filename);
  9055. system(rmFileCmd);
  9056. resultRename = rename(tempfile, filename);
  9057. if(resultRename == 0)
  9058. {
  9059. DEBUG_INFO("File renamed successfully");
  9060. }
  9061. else
  9062. {
  9063. DEBUG_INFO("Error: unable to rename the file");
  9064. }
  9065. }
  9066. }
  9067. out:
  9068. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9069. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9070. authorizeRetryTimes = 0;
  9071. }
  9072. void handleBootNotificationResponse(char *payload, int gun_index)
  9073. {
  9074. mtrace();
  9075. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9076. char statusStr[12]={0};
  9077. char currentTimeStr[30]={0};
  9078. char *loc;
  9079. int intervalInt = 0;
  9080. int c = 0;
  9081. //double diff_t;
  9082. struct tm tp;
  9083. char buf[28]={0};
  9084. char timebuf[50]={0};
  9085. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9086. //*** interval ****/
  9087. c = 0;
  9088. loc = strstr(payload, "interval");
  9089. //printf("loc=%s\n",loc);
  9090. memset(sstr ,0, sizeof(sstr) );
  9091. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9092. {
  9093. sstr[c] = loc[strlen("interval")+2+c];
  9094. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9095. c++;
  9096. }
  9097. sstr[c] = '\0';
  9098. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9099. intervalInt = atoi(sstr);
  9100. //***status ****/
  9101. loc = strstr(payload, "status");
  9102. memset(sstr ,0, sizeof(sstr) );
  9103. c = 0;
  9104. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9105. {
  9106. sstr[c] = loc[3+strlen("status")+c];
  9107. c++;
  9108. }
  9109. sstr[c] = '\0';
  9110. strcpy(statusStr, sstr);
  9111. //***currentTime ****/
  9112. loc = strstr(payload, "currentTime");
  9113. //printf("loc=%s\n",loc);
  9114. memset(sstr ,0, sizeof(sstr) );
  9115. c = 0;
  9116. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9117. {
  9118. sstr[c] = loc[3+strlen("currentTime")+c];
  9119. c++;
  9120. }
  9121. sstr[c] = '\0';
  9122. strcpy(currentTimeStr, sstr);
  9123. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9124. HeartBeatWaitTime = BootNotificationInterval;
  9125. clientTime.Heartbeat=time((time_t*)NULL);
  9126. //write back to ShmOCPP16Data->BootNotification
  9127. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9128. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9129. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9130. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9131. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9132. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9133. {
  9134. server_sign = TRUE;
  9135. server_pending =FALSE;
  9136. }
  9137. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9138. {
  9139. server_pending = TRUE;
  9140. }
  9141. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9142. tp.tm_isdst = -1;
  9143. //time_t utc = mktime(&tp);
  9144. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9145. memset(timebuf, 0, sizeof timebuf);
  9146. sprintf(timebuf,"date -s '%s'",buf);
  9147. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9148. system(timebuf);
  9149. //==============================================
  9150. // RTC sync
  9151. //==============================================
  9152. system("/sbin/hwclock -w --systohc");
  9153. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9154. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9155. }
  9156. void handleDataTransferResponse(char *payload, int gun_index)
  9157. {
  9158. char sstr[160]={0};//sstr[200]={ 0 };
  9159. int c = 0;
  9160. char *loc;
  9161. DEBUG_INFO("handleDataTransferResponse ...\n");
  9162. loc = strstr(payload, "status");
  9163. printf("loc=%s\n",loc);
  9164. c = 0;
  9165. while (loc[3+strlen("status")+c] != '\"')
  9166. {
  9167. sstr[c] = loc[3+strlen("status")+c];
  9168. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9169. c++;
  9170. }
  9171. sstr[c] = '\0';
  9172. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9173. }
  9174. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9175. {
  9176. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9177. //struct json_object *obj;
  9178. // obj = json_tokener_parse(payload);
  9179. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9180. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9181. //No fields are defined.
  9182. }
  9183. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9184. {
  9185. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9186. //struct json_object *obj;
  9187. // obj = json_tokener_parse(payload);
  9188. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9189. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9190. //No fields are defined.
  9191. }
  9192. void handleHeartbeatResponse(char *payload, int gun_index)
  9193. {
  9194. mtrace();
  9195. //double diff_t;
  9196. struct tm tp;
  9197. char buf[28]={0};
  9198. char timebuf[50]={0};
  9199. char sstr[30]={ 0 };
  9200. int c = 0;
  9201. char *loc;
  9202. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9203. c = 0;
  9204. loc = strstr(payload, "currentTime");
  9205. memset(sstr ,0, sizeof(sstr) );
  9206. while (loc[3+strlen("currentTime")+c] != '\"')
  9207. {
  9208. sstr[c] = loc[3+strlen("currentTime")+c];
  9209. c++;
  9210. }
  9211. sstr[c] = '\0';
  9212. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9213. // #ifdef SystemLogMessage
  9214. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9215. // #endif
  9216. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9217. tp.tm_isdst = -1;
  9218. //time_t utc = mktime(&tp);
  9219. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9220. memset(timebuf, 0, sizeof timebuf);
  9221. sprintf(timebuf,"date -s '%s'",buf);
  9222. system(timebuf);
  9223. //==============================================
  9224. // RTC sync
  9225. //==============================================
  9226. system("/sbin/hwclock -w --systohc");
  9227. if(FirstHeartBeat == 0)
  9228. {
  9229. FirstHeartBeat = 1;
  9230. }
  9231. HeartBeatWithNOResponse = 0;
  9232. //--------Print Out HeartBeat log
  9233. {
  9234. double diff_t;
  9235. struct tm tp,tp1;
  9236. // BootNotification Receive Time
  9237. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9238. tp.tm_isdst = -1;
  9239. time_t BootNotificationReceiveTime = mktime(&tp);
  9240. //HeartBeat Receive Time
  9241. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9242. tp1.tm_isdst = -1;
  9243. time_t HeartBeatReceiveTime = mktime(&tp1);
  9244. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9245. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9246. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9247. {
  9248. HeartBeatCountPerHour = (int)diff_t / 3600;
  9249. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9250. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9251. }
  9252. }
  9253. }
  9254. void handleMeterValuesResponse(char *payload, int gun_index)
  9255. {
  9256. mtrace();
  9257. //struct json_object *obj;
  9258. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9259. //No fields are defined.
  9260. }
  9261. void handleStartTransactionResponse(char *payload, int gun_index)
  9262. {
  9263. mtrace();
  9264. char sstr[28]={ 0 };
  9265. int c = 0;
  9266. char *loc;
  9267. int transactionIdInt = 0;
  9268. FILE *outfile;
  9269. char data[100]={0};
  9270. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9271. DEBUG_INFO("handleStartTransactionResponse\n");
  9272. //****************expiryDate********************/
  9273. loc = strstr(payload, "expiryDate");
  9274. if(loc == NULL)
  9275. {
  9276. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9277. }
  9278. else
  9279. {
  9280. c = 0;
  9281. memset(sstr ,0, sizeof(sstr) );
  9282. while (loc[3+strlen("expiryDate")+c] != '\"')
  9283. {
  9284. sstr[c] = loc[3+strlen("expiryDate")+c];
  9285. c++;
  9286. }
  9287. sstr[c] = '\0';
  9288. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9289. }
  9290. //****************parentIdTag********************/
  9291. loc = strstr(payload, "parentIdTag");
  9292. if(loc == NULL)
  9293. {
  9294. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9295. }
  9296. else
  9297. {
  9298. c = 0;
  9299. memset(sstr ,0, sizeof(sstr) );
  9300. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9301. {
  9302. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9303. c++;
  9304. }
  9305. sstr[c] = '\0';
  9306. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9307. }
  9308. //****************status********************/
  9309. loc = strstr(payload, "status");
  9310. if(loc == NULL)
  9311. {
  9312. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9313. }
  9314. else
  9315. {
  9316. c = 0;
  9317. memset(sstr ,0, sizeof(sstr) );
  9318. while (loc[3+strlen("status")+c] != '\"')
  9319. {
  9320. sstr[c] = loc[3+strlen("status")+c];
  9321. c++;
  9322. }
  9323. sstr[c] = '\0';
  9324. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9325. }
  9326. //****************transactionId********************/
  9327. c=0;
  9328. loc = strstr(payload, "transactionId");
  9329. memset(sstr ,0, sizeof(sstr) );
  9330. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9331. {
  9332. sstr[c] = loc[strlen("transactionId")+2+c];
  9333. c++;
  9334. }
  9335. sstr[c] = '\0';
  9336. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9337. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9338. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9339. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9340. //-----------Start : write to the Queue TransactionId file -----------------//
  9341. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9342. {
  9343. //DEBUG_INFO("QueueTransactionId exist.\n");
  9344. }
  9345. else
  9346. {
  9347. //DEBUG_INFO("QueueTransactionId not exist\n");
  9348. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9349. if(log == NULL)
  9350. {
  9351. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9352. return ;
  9353. }
  9354. else
  9355. {
  9356. fclose(log);
  9357. }
  9358. }
  9359. // open file for writing
  9360. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9361. //DEBUG_INFO("data=%s\n",data);
  9362. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9363. fputs(data, outfile);
  9364. //fputs("\n", outfile);
  9365. fclose (outfile);
  9366. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9367. TransactionId[gun_index] = transactionIdInt;
  9368. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9369. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9370. #ifdef SystemLogMessage
  9371. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9372. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9373. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9374. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9375. #endif
  9376. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  9377. {
  9378. //add Charging Record
  9379. SettingChargingRecord(gun_index, transactionIdInt);
  9380. }
  9381. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  9382. }
  9383. void handleStatusNotificationResponse(char *payload, int gun_index)
  9384. {
  9385. mtrace();
  9386. printf("handleStatusNotificationResponse\n");
  9387. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9388. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9389. }
  9390. void handleStopTransactionnResponse(char *payload, int gun_index)
  9391. {
  9392. mtrace();
  9393. char sstr[30]={ 0 };
  9394. int c = 0;
  9395. char *loc;
  9396. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9397. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9398. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9399. loc = strstr(payload, "idTagInfo");
  9400. //***********************idTagInfo************************/
  9401. if(loc != NULL)
  9402. {
  9403. //***********************expiryDate************************/
  9404. loc = strstr(payload, "expiryDate");
  9405. if(loc != NULL)
  9406. {
  9407. memset(sstr ,0, sizeof(sstr) );
  9408. c = 0;
  9409. while (loc[3+strlen("expiryDate")+c] != '\"')
  9410. {
  9411. sstr[c] = loc[3+strlen("expiryDate")+c];
  9412. c++;
  9413. }
  9414. sstr[c] = '\0';
  9415. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9416. }
  9417. //***********************parentIdTag************************/
  9418. loc = strstr(payload, "parentIdTag");
  9419. if(loc != NULL)
  9420. {
  9421. memset(sstr ,0, sizeof(sstr) );
  9422. c = 0;
  9423. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9424. {
  9425. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9426. c++;
  9427. }
  9428. sstr[c] = '\0';
  9429. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9430. }
  9431. //***********************status************************/
  9432. loc = strstr(payload, "status");
  9433. memset(sstr ,0, sizeof(sstr) );
  9434. c = 0;
  9435. while (loc[3+strlen("status")+c] != '\"')
  9436. {
  9437. sstr[c] = loc[3+strlen("status")+c];
  9438. c++;
  9439. }
  9440. sstr[c] = '\0';
  9441. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9442. }
  9443. #ifdef SystemLogMessage
  9444. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9445. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9446. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9447. #endif
  9448. }
  9449. //==========================================
  9450. // Handle Error routine
  9451. //==========================================
  9452. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9453. {
  9454. mtrace();
  9455. #ifdef SystemLogMessage
  9456. DEBUG_INFO("errorCode: %s\n", errorCode);
  9457. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9458. DEBUG_INFO("errorDetails: %s\n", payload);
  9459. #endif
  9460. }
  9461. //===============================================
  9462. // Common routine
  9463. //===============================================
  9464. int initialConfigurationTable(void)
  9465. {
  9466. FILE *fp;
  9467. FILE *outfile;
  9468. char str[200]={0};
  9469. char sstr[100]={0};
  9470. int c = 0;
  9471. char *loc;
  9472. printf("initialConfigurationTable \n");
  9473. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9474. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9475. {
  9476. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9477. if(outfile == NULL) {
  9478. DEBUG_INFO("Error opening file");
  9479. return FALSE;
  9480. }
  9481. /*Core Profile*/
  9482. //AllowOfflineTxForUnknownId
  9483. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9484. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  9488. //AuthorizationCacheEnabled
  9489. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9493. //AuthorizeRemoteTxRequests
  9494. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9498. //BlinkRepeat
  9499. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9503. //ClockAlignedDataInterval
  9504. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9508. //ConnectionTimeOut
  9509. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9513. //GetConfigurationMaxKeys
  9514. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9518. // HeartbeatInterval
  9519. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9523. // LightIntensity
  9524. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9528. // LocalAuthorizeOffline
  9529. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9533. // LocalPreAuthorize
  9534. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9538. // MaxEnergyOnInvalidId
  9539. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9542. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9544. // MeterValuesAlignedData
  9545. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9549. // MeterValuesAlignedDataMaxLength
  9550. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9554. // MeterValuesSampledData
  9555. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9559. // MeterValuesSampledDataMaxLength
  9560. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9564. // MeterValueSampleInterval
  9565. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9569. // MinimumStatusDuration
  9570. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9574. // NumberOfConnectors
  9575. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9577. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9578. {
  9579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9580. }
  9581. else
  9582. {
  9583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9584. }
  9585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9586. // ResetRetries
  9587. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9591. // ConnectorPhaseRotation
  9592. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9596. // ConnectorPhaseRotationMaxLength
  9597. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9601. // StopTransactionOnEVSideDisconnect
  9602. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9606. // StopTransactionOnInvalidId
  9607. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9611. // StopTxnAlignedData
  9612. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9616. // StopTxnAlignedDataMaxLength
  9617. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9621. // StopTxnSampledData
  9622. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9626. // StopTxnSampledDataMaxLength
  9627. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9629. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9630. {
  9631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9632. }
  9633. else
  9634. {
  9635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9636. }
  9637. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9639. // SupportedFeatureProfiles
  9640. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9644. // SupportedFeatureProfilesMaxLength
  9645. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9649. // TransactionMessageAttempts
  9650. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9653. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9655. // TransactionMessageRetryInterval
  9656. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9659. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9661. // UnlockConnectorOnEVSideDisconnect
  9662. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9666. // WebSocketPingInterval
  9667. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9671. //* Local Auth List Management Profile*/
  9672. #if 0
  9673. //For OCTT Test Case
  9674. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9677. #endif
  9678. #if 1
  9679. //LocalAuthListEnabled
  9680. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9684. #endif
  9685. //LocalAuthListMaxLength
  9686. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9690. //SendLocalListMaxLength
  9691. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9695. //ReserveConnectorZeroSupported
  9696. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9700. //* Smart Charging Profile */
  9701. //ChargeProfileMaxStackLevel
  9702. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9706. // ChargingScheduleAllowedChargingRateUnit
  9707. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9711. // ChargingScheduleMaxPeriods
  9712. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9716. // ConnectorSwitch3to1PhaseSupported
  9717. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9721. // MaxChargingProfilesInstalled
  9722. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9726. fclose(outfile);
  9727. }
  9728. else
  9729. {
  9730. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9731. char keystr[60]={0};
  9732. char readonlystr[10]={0};
  9733. char valuestr[100]={0};
  9734. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9735. if(fp == NULL) {
  9736. DEBUG_INFO("Error opening file");
  9737. return FALSE;
  9738. }
  9739. while( fgets (str, sizeof(str), fp)!=NULL )
  9740. {
  9741. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9742. //*************************key*********************************/
  9743. loc = strstr(str, "key");
  9744. c = 0;
  9745. memset(sstr ,0, sizeof(sstr) );
  9746. while (loc[strlen("key")+3+c] != '\"')
  9747. {
  9748. sstr[c] = loc[strlen("key")+3+c];
  9749. c++;
  9750. }
  9751. sstr[c] = '\0';
  9752. strcpy(keystr,sstr);
  9753. //*************************readonly*********************************/
  9754. loc = strstr(str, "readonly");
  9755. c = 0;
  9756. memset(sstr ,0, sizeof(sstr) );
  9757. while (loc[strlen("readonly")+2+c] != ',')
  9758. {
  9759. sstr[c] = loc[strlen("readonly")+2+c];
  9760. c++;
  9761. }
  9762. sstr[c] = '\0';
  9763. strcpy(readonlystr,sstr);
  9764. //*************************value*********************************/
  9765. loc = strstr(str, "value");
  9766. c = 0;
  9767. memset(sstr ,0, sizeof(sstr) );
  9768. while (loc[strlen("value")+3+c] != '\"')
  9769. {
  9770. sstr[c] = loc[strlen("value")+3+c];
  9771. c++;
  9772. }
  9773. sstr[c] = '\0';
  9774. strcpy(valuestr,sstr);
  9775. // DEBUG_INFO("keystr=%s\n",keystr);
  9776. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9777. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9778. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9779. {
  9780. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9781. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9783. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9784. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9785. }
  9786. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9787. {
  9788. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9789. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9791. }
  9792. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9793. {
  9794. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9796. }
  9797. if(strcmp(keystr, "BlinkRepeat") == 0)
  9798. {
  9799. //Charger.BlinkRepeat = Integer.parseInt(value);
  9800. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9802. }
  9803. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9804. {
  9805. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9807. }
  9808. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9809. {
  9810. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9812. }
  9813. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9814. {
  9815. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9817. }
  9818. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9819. {
  9820. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9822. HeartBeatWaitTime = atoi(valuestr);
  9823. }
  9824. if(strcmp(keystr, "LightIntensity") == 0)
  9825. {
  9826. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9828. }
  9829. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9830. {
  9831. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9833. }
  9834. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9835. {
  9836. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9838. }
  9839. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9840. {
  9841. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9843. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9844. }
  9845. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9846. {
  9847. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9849. }
  9850. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9851. {
  9852. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9854. }
  9855. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9856. {
  9857. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9859. }
  9860. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9861. {
  9862. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9864. }
  9865. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9866. {
  9867. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9869. }
  9870. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9871. {
  9872. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9874. }
  9875. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9876. {
  9877. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9879. }
  9880. if(strcmp(keystr, "ResetRetries") == 0)
  9881. {
  9882. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9884. }
  9885. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9886. {
  9887. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9889. }
  9890. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9891. {
  9892. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9894. }
  9895. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  9896. {
  9897. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  9899. }
  9900. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  9901. {
  9902. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  9904. }
  9905. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  9906. {
  9907. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  9909. }
  9910. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  9911. {
  9912. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9914. }
  9915. if(strcmp(keystr, "StopTxnSampledData") == 0)
  9916. {
  9917. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  9919. }
  9920. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  9921. {
  9922. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9924. }
  9925. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  9926. {
  9927. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  9929. }
  9930. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  9931. {
  9932. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  9934. }
  9935. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  9936. {
  9937. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  9939. TransactionMessageAttemptsValue = atoi(valuestr);
  9940. }
  9941. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  9942. {
  9943. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  9945. TransactionMessageRetryIntervalValue = atoi(valuestr);
  9946. }
  9947. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  9948. {
  9949. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  9951. }
  9952. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  9953. {
  9954. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  9956. }
  9957. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  9958. {
  9959. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  9961. }
  9962. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  9963. {
  9964. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  9966. }
  9967. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  9968. {
  9969. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  9971. }
  9972. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  9973. {
  9974. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  9976. }
  9977. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  9978. {
  9979. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  9981. }
  9982. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  9983. {
  9984. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  9986. }
  9987. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  9988. {
  9989. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  9991. }
  9992. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  9993. {
  9994. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  9996. }
  9997. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  9998. {
  9999. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10001. }
  10002. }
  10003. fclose(fp);
  10004. }
  10005. return 0;
  10006. }
  10007. void StoreConfigurationTable(void)
  10008. {
  10009. FILE *outfile;
  10010. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10011. if(outfile == NULL)
  10012. {
  10013. DEBUG_INFO("Error opening file");
  10014. return ;
  10015. }
  10016. /*Core Profile*/
  10017. //AllowOfflineTxForUnknownId
  10018. /*
  10019. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10020. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10023. */
  10024. //DEBUG_INFO("data=%s\n",data);
  10025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10026. //AuthorizationCacheEnabled
  10027. /*
  10028. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10031. */
  10032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10033. //AuthorizeRemoteTxRequests
  10034. /*
  10035. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10038. */
  10039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10040. //BlinkRepeat
  10041. /*
  10042. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10045. */
  10046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10047. //ClockAlignedDataInterval
  10048. /*
  10049. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10052. */
  10053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10054. //ConnectionTimeOut
  10055. /*
  10056. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10059. */
  10060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10061. //GetConfigurationMaxKeys
  10062. /*
  10063. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10066. */
  10067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10068. // HeartbeatInterval
  10069. /*
  10070. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10073. */
  10074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10075. // LightIntensity
  10076. /*
  10077. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10080. */
  10081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10082. // LocalAuthorizeOffline
  10083. /*
  10084. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10087. */
  10088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10089. // LocalPreAuthorize
  10090. /*
  10091. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10094. */
  10095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10096. // MaxEnergyOnInvalidId
  10097. /*
  10098. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10101. */
  10102. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10104. // MeterValuesAlignedData
  10105. /*
  10106. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10109. */
  10110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10111. // MeterValuesAlignedDataMaxLength
  10112. /*
  10113. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10116. */
  10117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10118. // MeterValuesSampledData
  10119. /*
  10120. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10123. */
  10124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10125. // MeterValuesSampledDataMaxLength
  10126. /*
  10127. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10130. */
  10131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10132. // MeterValueSampleInterval
  10133. /*
  10134. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10137. */
  10138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10139. // MinimumStatusDuration
  10140. /*
  10141. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10144. */
  10145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10146. // NumberOfConnectors
  10147. /*
  10148. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10150. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10151. {
  10152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10153. }
  10154. else
  10155. {
  10156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10157. }
  10158. */
  10159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10160. // ResetRetries
  10161. /*
  10162. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10165. */
  10166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10167. // ConnectorPhaseRotation
  10168. /*
  10169. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10172. */
  10173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10174. // ConnectorPhaseRotationMaxLength
  10175. /*
  10176. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10179. */
  10180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10181. // StopTransactionOnEVSideDisconnect
  10182. /*
  10183. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10186. */
  10187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10188. // StopTransactionOnInvalidId
  10189. /*
  10190. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10193. */
  10194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10195. // StopTxnAlignedData
  10196. /*
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10200. */
  10201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10202. // StopTxnAlignedDataMaxLength
  10203. /*
  10204. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10207. */
  10208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10209. // StopTxnSampledData
  10210. /*
  10211. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10214. */
  10215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10216. // StopTxnSampledDataMaxLength
  10217. /*
  10218. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10221. */
  10222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10223. // SupportedFeatureProfiles
  10224. /*
  10225. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10228. */
  10229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10230. // SupportedFeatureProfilesMaxLength
  10231. /*
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10235. */
  10236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10237. // TransactionMessageAttempts
  10238. /*
  10239. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10242. */
  10243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10244. // TransactionMessageRetryInterval
  10245. /*
  10246. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10249. */
  10250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10251. // UnlockConnectorOnEVSideDisconnect
  10252. /*
  10253. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10256. */
  10257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10258. // WebSocketPingInterval
  10259. /*
  10260. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10263. */
  10264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10265. //* Local Auth List Management Profile*/
  10266. //LocalAuthListEnabled
  10267. /*
  10268. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10271. */
  10272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10273. //LocalAuthListMaxLength
  10274. /*
  10275. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10278. */
  10279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10280. //SendLocalListMaxLength
  10281. /*
  10282. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10285. */
  10286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10287. //ReserveConnectorZeroSupported
  10288. /*
  10289. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10292. */
  10293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10294. //* Smart Charging Profile */
  10295. //ChargeProfileMaxStackLevel
  10296. /*
  10297. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10300. */
  10301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10302. // ChargingScheduleAllowedChargingRateUnit
  10303. /*
  10304. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10307. */
  10308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10309. // ChargingScheduleMaxPeriods
  10310. /*
  10311. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10314. */
  10315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10316. // ConnectorSwitch3to1PhaseSupported
  10317. /*
  10318. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10321. */
  10322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10323. // MaxChargingProfilesInstalled
  10324. /*
  10325. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10328. */
  10329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10330. fclose(outfile);
  10331. }
  10332. void getKeyValue(char *keyReq)
  10333. {
  10334. int isEmpty = FALSE;
  10335. int isKnowKey = FALSE;
  10336. //int unKnowIndex = 0;
  10337. DEBUG_INFO("getKeyValue \n");
  10338. DEBUG_INFO("keyReq=%s \n",keyReq);
  10339. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10340. isEmpty = TRUE;
  10341. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10342. {
  10343. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  10344. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10347. {
  10348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10349. }
  10350. else
  10351. {
  10352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10353. }
  10354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10355. isKnowKey = TRUE;
  10356. }
  10357. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10358. {
  10359. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10362. {
  10363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10364. }
  10365. else
  10366. {
  10367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10368. }
  10369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10370. isKnowKey = TRUE;
  10371. }
  10372. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10373. {
  10374. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10377. {
  10378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10379. }
  10380. else
  10381. {
  10382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10383. }
  10384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10385. isKnowKey = TRUE;
  10386. }
  10387. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10388. {
  10389. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10392. {
  10393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10394. }
  10395. else
  10396. {
  10397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10398. }
  10399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10400. isKnowKey = TRUE;
  10401. }
  10402. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10403. {
  10404. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10407. {
  10408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10409. }
  10410. else
  10411. {
  10412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10413. }
  10414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10415. isKnowKey = TRUE;
  10416. }
  10417. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10418. {
  10419. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10422. {
  10423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10424. }
  10425. else
  10426. {
  10427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10428. }
  10429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10430. isKnowKey = TRUE;
  10431. }
  10432. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10433. {
  10434. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10437. {
  10438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10439. }
  10440. else
  10441. {
  10442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10443. }
  10444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10445. isKnowKey = TRUE;
  10446. }
  10447. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10448. {
  10449. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10452. {
  10453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10454. }
  10455. else
  10456. {
  10457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10458. }
  10459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10460. isKnowKey = TRUE;
  10461. }
  10462. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10463. {
  10464. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10466. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10467. {
  10468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10469. }
  10470. else
  10471. {
  10472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10473. }
  10474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10475. isKnowKey = TRUE;
  10476. }
  10477. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10478. {
  10479. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10482. {
  10483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10484. }
  10485. else
  10486. {
  10487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10488. }
  10489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10490. isKnowKey = TRUE;
  10491. }
  10492. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10493. {
  10494. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10497. {
  10498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10499. }
  10500. else
  10501. {
  10502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10503. }
  10504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10505. isKnowKey = TRUE;
  10506. }
  10507. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10508. {
  10509. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10511. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10512. {
  10513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10514. }
  10515. else
  10516. {
  10517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10518. }
  10519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10520. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10521. isKnowKey = TRUE;
  10522. }
  10523. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10524. {
  10525. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10528. {
  10529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10530. }
  10531. else
  10532. {
  10533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10534. }
  10535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10536. isKnowKey = TRUE;
  10537. }
  10538. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10539. {
  10540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10543. {
  10544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10545. }
  10546. else
  10547. {
  10548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10549. }
  10550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10551. isKnowKey = TRUE;
  10552. }
  10553. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10554. {
  10555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10558. {
  10559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10560. }
  10561. else
  10562. {
  10563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10564. }
  10565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10566. isKnowKey = TRUE;
  10567. }
  10568. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10569. {
  10570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10573. {
  10574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10575. }
  10576. else
  10577. {
  10578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10579. }
  10580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10581. isKnowKey = TRUE;
  10582. }
  10583. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10584. {
  10585. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10588. {
  10589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10590. }
  10591. else
  10592. {
  10593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10594. }
  10595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10596. isKnowKey = TRUE;
  10597. }
  10598. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10599. {
  10600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10603. {
  10604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10605. }
  10606. else
  10607. {
  10608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10609. }
  10610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10611. isKnowKey = TRUE;
  10612. }
  10613. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10614. {
  10615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10618. {
  10619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10620. }
  10621. else
  10622. {
  10623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10624. }
  10625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10626. isKnowKey = TRUE;
  10627. }
  10628. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10629. {
  10630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10633. {
  10634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10635. }
  10636. else
  10637. {
  10638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10639. }
  10640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10641. isKnowKey = TRUE;
  10642. }
  10643. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10644. {
  10645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10648. {
  10649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10650. }
  10651. else
  10652. {
  10653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10654. }
  10655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10656. isKnowKey = TRUE;
  10657. }
  10658. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10659. {
  10660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10663. {
  10664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10665. }
  10666. else
  10667. {
  10668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10669. }
  10670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10671. isKnowKey = TRUE;
  10672. }
  10673. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10674. {
  10675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10678. {
  10679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10680. }
  10681. else
  10682. {
  10683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10684. }
  10685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10686. isKnowKey = TRUE;
  10687. }
  10688. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10689. {
  10690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10693. {
  10694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10695. }
  10696. else
  10697. {
  10698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10699. }
  10700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10701. isKnowKey = TRUE;
  10702. }
  10703. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10704. {
  10705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10708. {
  10709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10710. }
  10711. else
  10712. {
  10713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10714. }
  10715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10716. isKnowKey = TRUE;
  10717. }
  10718. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10719. {
  10720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10723. {
  10724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10725. }
  10726. else
  10727. {
  10728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10729. }
  10730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10731. isKnowKey = TRUE;
  10732. }
  10733. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10734. {
  10735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10738. {
  10739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10740. }
  10741. else
  10742. {
  10743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10744. }
  10745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10746. isKnowKey = TRUE;
  10747. }
  10748. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10749. {
  10750. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10753. {
  10754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10755. }
  10756. else
  10757. {
  10758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10759. }
  10760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10761. isKnowKey = TRUE;
  10762. }
  10763. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10764. {
  10765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10768. {
  10769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10770. }
  10771. else
  10772. {
  10773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10774. }
  10775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10776. isKnowKey = TRUE;
  10777. }
  10778. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10779. {
  10780. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10783. {
  10784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10785. }
  10786. else
  10787. {
  10788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10789. }
  10790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10791. isKnowKey = TRUE;
  10792. }
  10793. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10794. {
  10795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10798. {
  10799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10800. }
  10801. else
  10802. {
  10803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10804. }
  10805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10806. isKnowKey = TRUE;
  10807. }
  10808. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10809. {
  10810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10813. {
  10814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10815. }
  10816. else
  10817. {
  10818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10819. }
  10820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10821. isKnowKey = TRUE;
  10822. }
  10823. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10824. {
  10825. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10828. {
  10829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10830. }
  10831. else
  10832. {
  10833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10834. }
  10835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10836. isKnowKey = TRUE;
  10837. }
  10838. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10839. {
  10840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10843. {
  10844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10845. }
  10846. else
  10847. {
  10848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10849. }
  10850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10851. isKnowKey = TRUE;
  10852. }
  10853. #if 0
  10854. //For OCTT Test Case
  10855. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10856. {
  10857. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10859. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10860. {
  10861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10862. }
  10863. else
  10864. {
  10865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10866. }
  10867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10868. isKnowKey = TRUE;
  10869. }
  10870. #endif
  10871. #if 1
  10872. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10873. {
  10874. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10876. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10877. {
  10878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10879. }
  10880. else
  10881. {
  10882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10883. }
  10884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10885. isKnowKey = TRUE;
  10886. }
  10887. #endif
  10888. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10889. {
  10890. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10892. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10893. {
  10894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10895. }
  10896. else
  10897. {
  10898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10899. }
  10900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  10901. isKnowKey = TRUE;
  10902. }
  10903. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  10904. {
  10905. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  10906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  10907. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  10908. {
  10909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10910. }
  10911. else
  10912. {
  10913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10914. }
  10915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  10916. isKnowKey = TRUE;
  10917. }
  10918. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  10919. {
  10920. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  10921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  10922. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  10923. {
  10924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  10925. }
  10926. else
  10927. {
  10928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  10929. }
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10931. isKnowKey = TRUE;
  10932. }
  10933. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  10934. {
  10935. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  10936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  10937. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  10938. {
  10939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  10940. }
  10941. else
  10942. {
  10943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  10944. }
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10946. isKnowKey = TRUE;
  10947. }
  10948. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  10949. {
  10950. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  10951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  10952. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  10953. {
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  10955. }
  10956. else
  10957. {
  10958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  10959. }
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10961. isKnowKey = TRUE;
  10962. }
  10963. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  10964. {
  10965. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  10966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  10967. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  10968. {
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  10970. }
  10971. else
  10972. {
  10973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  10974. }
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10976. isKnowKey = TRUE;
  10977. }
  10978. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  10979. {
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  10981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  10982. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  10983. {
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  10985. }
  10986. else
  10987. {
  10988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  10989. }
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10991. isKnowKey = TRUE;
  10992. }
  10993. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  10994. {
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  10997. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  10998. {
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11000. }
  11001. else
  11002. {
  11003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11004. }
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11006. isKnowKey = TRUE;
  11007. }
  11008. //=========================================================
  11009. if(!isEmpty && !isKnowKey)
  11010. {
  11011. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11012. strcpy(unknownkey[UnknownKeynum], keyReq);
  11013. UnknownKeynum = UnknownKeynum + 1;
  11014. }
  11015. }
  11016. void processUnkownKey(void)
  11017. {
  11018. DEBUG_INFO("processUnkownKey\n");
  11019. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11020. for(int index=0; index < UnknownKeynum; index++)
  11021. {
  11022. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11023. {
  11024. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11025. }
  11026. }
  11027. }
  11028. int setKeyValue(char *key, char *value)
  11029. {
  11030. int isSuccess = NotSupported;
  11031. int check_ascii=0;
  11032. char str[10]={0};
  11033. #ifdef Debug
  11034. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11035. #endif
  11036. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11037. {
  11038. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11039. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11040. {
  11041. strcpy(str, (const char*)value);
  11042. for(int i = 0; str[i]; i++){
  11043. str[i] = tolower(str[i]);
  11044. }
  11045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11046. isSuccess = ConfigurationStatus_Accepted;
  11047. }
  11048. else
  11049. {
  11050. isSuccess = ConfigurationStatus_Rejected;
  11051. }
  11052. }
  11053. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11054. {
  11055. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11057. {
  11058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  11059. isSuccess = ConfigurationStatus_Accepted;
  11060. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11061. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11062. }
  11063. else
  11064. {
  11065. isSuccess = ConfigurationStatus_Rejected;
  11066. }
  11067. }
  11068. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11069. {
  11070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11071. {
  11072. strcpy(str, (const char*)value);
  11073. for(int i = 0; str[i]; i++)
  11074. {
  11075. str[i] = tolower(str[i]);
  11076. }
  11077. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11079. isSuccess = ConfigurationStatus_Accepted;
  11080. }
  11081. else
  11082. {
  11083. isSuccess = ConfigurationStatus_Rejected;
  11084. }
  11085. }
  11086. if(strcmp(key, "BlinkRepeat") == 0)
  11087. {
  11088. //Charger.BlinkRepeat = Integer.parseInt(value);
  11089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11090. {
  11091. check_ascii = value[0];
  11092. if( (check_ascii < 48) || (check_ascii > 57) )
  11093. {
  11094. isSuccess = ConfigurationStatus_Rejected;
  11095. }
  11096. else
  11097. {
  11098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11099. isSuccess = ConfigurationStatus_Accepted;
  11100. }
  11101. }
  11102. else
  11103. {
  11104. isSuccess = ConfigurationStatus_Rejected;
  11105. }
  11106. }
  11107. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11108. {
  11109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].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.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11120. isSuccess = ConfigurationStatus_Accepted;
  11121. }
  11122. }
  11123. else
  11124. {
  11125. isSuccess = ConfigurationStatus_Rejected;
  11126. }
  11127. }
  11128. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11129. {
  11130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11131. {
  11132. check_ascii = value[0];
  11133. if( (check_ascii < 48) || (check_ascii > 57) )
  11134. {
  11135. isSuccess = ConfigurationStatus_Rejected;
  11136. }
  11137. else
  11138. {
  11139. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11141. isSuccess = ConfigurationStatus_Accepted;
  11142. }
  11143. }
  11144. else
  11145. {
  11146. isSuccess = ConfigurationStatus_Rejected;
  11147. }
  11148. }
  11149. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11150. {
  11151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11152. {
  11153. check_ascii = value[0];
  11154. if( (check_ascii < 48) || (check_ascii > 57) )
  11155. {
  11156. isSuccess = ConfigurationStatus_Rejected;
  11157. }
  11158. else
  11159. {
  11160. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11162. isSuccess = ConfigurationStatus_Accepted;
  11163. }
  11164. }
  11165. else
  11166. {
  11167. isSuccess = ConfigurationStatus_Rejected;
  11168. }
  11169. }
  11170. if(strcmp(key, "HeartbeatInterval") == 0)
  11171. {
  11172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11173. {
  11174. check_ascii = value[0];
  11175. if( (check_ascii < 48) || (check_ascii > 57) )
  11176. {
  11177. isSuccess = ConfigurationStatus_Rejected;
  11178. }
  11179. else
  11180. {
  11181. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11183. HeartBeatWaitTime = atoi(value);
  11184. isSuccess = ConfigurationStatus_Accepted;
  11185. }
  11186. }
  11187. else
  11188. {
  11189. isSuccess = ConfigurationStatus_Rejected;
  11190. }
  11191. }
  11192. if(strcmp(key, "LightIntensity") == 0)
  11193. {
  11194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11195. {
  11196. check_ascii = value[0];
  11197. if( (check_ascii < 48) || (check_ascii > 57) )
  11198. {
  11199. isSuccess = ConfigurationStatus_Rejected;
  11200. }
  11201. else
  11202. {
  11203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11204. isSuccess = ConfigurationStatus_Accepted;
  11205. }
  11206. }
  11207. else
  11208. {
  11209. isSuccess = ConfigurationStatus_Rejected;
  11210. }
  11211. }
  11212. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11213. {
  11214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11215. {
  11216. strcpy(str, (const char*)value);
  11217. for(int i = 0; str[i]; i++)
  11218. {
  11219. str[i] = tolower(str[i]);
  11220. }
  11221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11222. isSuccess = ConfigurationStatus_Accepted;
  11223. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11224. }
  11225. else
  11226. {
  11227. isSuccess = ConfigurationStatus_Rejected;
  11228. }
  11229. }
  11230. if(strcmp(key, "LocalPreAuthorize") == 0)
  11231. {
  11232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11233. {
  11234. strcpy(str, (const char*)value);
  11235. for(int i = 0; str[i]; i++)
  11236. {
  11237. str[i] = tolower(str[i]);
  11238. }
  11239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11240. isSuccess = ConfigurationStatus_Accepted;
  11241. }
  11242. else
  11243. {
  11244. isSuccess = ConfigurationStatus_Rejected;
  11245. }
  11246. }
  11247. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11248. {
  11249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11250. {
  11251. check_ascii = value[0];
  11252. if( (check_ascii < 48) || (check_ascii > 57) )
  11253. {
  11254. isSuccess = ConfigurationStatus_Rejected;
  11255. }
  11256. else
  11257. {
  11258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11259. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11260. isSuccess = ConfigurationStatus_Accepted;
  11261. }
  11262. }
  11263. else
  11264. {
  11265. isSuccess = ConfigurationStatus_Rejected;
  11266. }
  11267. }
  11268. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11269. {
  11270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11271. {
  11272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11273. isSuccess = ConfigurationStatus_Accepted;
  11274. }
  11275. else
  11276. {
  11277. isSuccess = ConfigurationStatus_Rejected;
  11278. }
  11279. }
  11280. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11281. {
  11282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11283. {
  11284. check_ascii = value[0];
  11285. if( (check_ascii < 48) || (check_ascii > 57) )
  11286. {
  11287. isSuccess = ConfigurationStatus_Rejected;
  11288. }
  11289. else
  11290. {
  11291. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11293. isSuccess = ConfigurationStatus_Accepted;
  11294. }
  11295. }
  11296. else
  11297. {
  11298. isSuccess = ConfigurationStatus_Rejected;
  11299. }
  11300. }
  11301. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11302. {
  11303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11304. {
  11305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11306. isSuccess = ConfigurationStatus_Accepted;
  11307. }
  11308. else
  11309. {
  11310. isSuccess = ConfigurationStatus_Rejected;
  11311. }
  11312. }
  11313. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11314. {
  11315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11316. {
  11317. check_ascii = value[0];
  11318. if( (check_ascii < 48) || (check_ascii > 57) )
  11319. {
  11320. isSuccess = ConfigurationStatus_Rejected;
  11321. }
  11322. else
  11323. {
  11324. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11326. isSuccess = ConfigurationStatus_Accepted;
  11327. }
  11328. }
  11329. else
  11330. {
  11331. isSuccess = ConfigurationStatus_Rejected;
  11332. }
  11333. }
  11334. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11335. {
  11336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11337. {
  11338. check_ascii = value[0];
  11339. if( (check_ascii < 48) || (check_ascii > 57) )
  11340. {
  11341. isSuccess = ConfigurationStatus_Rejected;
  11342. }
  11343. else
  11344. {
  11345. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11347. isSuccess = ConfigurationStatus_Accepted;
  11348. }
  11349. }
  11350. else
  11351. {
  11352. isSuccess = ConfigurationStatus_Rejected;
  11353. }
  11354. }
  11355. if(strcmp(key, "MinimumStatusDuration") == 0)
  11356. {
  11357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11358. {
  11359. check_ascii = value[0];
  11360. if( (check_ascii < 48) || (check_ascii > 57) )
  11361. {
  11362. isSuccess = ConfigurationStatus_Rejected;
  11363. }
  11364. else
  11365. {
  11366. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11368. isSuccess = ConfigurationStatus_Accepted;
  11369. }
  11370. }
  11371. else
  11372. {
  11373. isSuccess = ConfigurationStatus_Rejected;
  11374. }
  11375. }
  11376. if(strcmp(key, "NumberOfConnectors") == 0)
  11377. {
  11378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11379. {
  11380. check_ascii = value[0];
  11381. if( (check_ascii < 48) || (check_ascii > 57) )
  11382. {
  11383. isSuccess = ConfigurationStatus_Rejected;
  11384. }
  11385. else
  11386. {
  11387. //Charger.ResetRetries = Integer.parseInt(value);
  11388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11389. isSuccess = ConfigurationStatus_Accepted;
  11390. }
  11391. }
  11392. else
  11393. {
  11394. isSuccess = ConfigurationStatus_Rejected;
  11395. }
  11396. }
  11397. if(strcmp(key, "ResetRetries") == 0)
  11398. {
  11399. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11400. {
  11401. check_ascii = value[0];
  11402. if( (check_ascii < 48) || (check_ascii > 57) )
  11403. {
  11404. isSuccess = ConfigurationStatus_Rejected;
  11405. }
  11406. else
  11407. {
  11408. //Charger.ResetRetries = Integer.parseInt(value);
  11409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11410. isSuccess = ConfigurationStatus_Accepted;
  11411. }
  11412. }
  11413. else
  11414. {
  11415. isSuccess = ConfigurationStatus_Rejected;
  11416. }
  11417. }
  11418. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11419. {
  11420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11421. {
  11422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  11423. isSuccess = ConfigurationStatus_Accepted;
  11424. }
  11425. else
  11426. {
  11427. isSuccess = ConfigurationStatus_Rejected;
  11428. }
  11429. }
  11430. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11431. {
  11432. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11433. {
  11434. check_ascii = value[0];
  11435. if( (check_ascii < 48) || (check_ascii > 57) )
  11436. {
  11437. isSuccess = ConfigurationStatus_Rejected;
  11438. }
  11439. else
  11440. {
  11441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11442. isSuccess = ConfigurationStatus_Accepted;
  11443. }
  11444. }
  11445. else
  11446. {
  11447. isSuccess = ConfigurationStatus_Rejected;
  11448. }
  11449. }
  11450. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11451. {
  11452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11453. {
  11454. strcpy(str, (const char*)value);
  11455. for(int i = 0; str[i]; i++)
  11456. {
  11457. str[i] = tolower(str[i]);
  11458. }
  11459. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11461. isSuccess = ConfigurationStatus_Accepted;
  11462. }
  11463. else
  11464. {
  11465. isSuccess = ConfigurationStatus_Rejected;
  11466. }
  11467. }
  11468. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11469. {
  11470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11471. {
  11472. strcpy(str, (const char*)value);
  11473. for(int i = 0; str[i]; i++)
  11474. {
  11475. str[i] = tolower(str[i]);
  11476. }
  11477. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11479. isSuccess = ConfigurationStatus_Accepted;
  11480. }
  11481. else
  11482. {
  11483. isSuccess = ConfigurationStatus_Rejected;
  11484. }
  11485. }
  11486. if(strcmp(key, "StopTxnAlignedData") == 0)
  11487. {
  11488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11489. {
  11490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11491. isSuccess = ConfigurationStatus_Accepted;
  11492. }
  11493. else
  11494. {
  11495. isSuccess = ConfigurationStatus_Rejected;
  11496. }
  11497. }
  11498. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11499. {
  11500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11501. {
  11502. check_ascii = value[0];
  11503. if( (check_ascii < 48) || (check_ascii > 57) )
  11504. {
  11505. isSuccess = ConfigurationStatus_Rejected;
  11506. }
  11507. else
  11508. {
  11509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11510. isSuccess = ConfigurationStatus_Accepted;
  11511. }
  11512. }
  11513. else
  11514. {
  11515. isSuccess = ConfigurationStatus_Rejected;
  11516. }
  11517. }
  11518. if(strcmp(key, "StopTxnSampledData") == 0)
  11519. {
  11520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11521. {
  11522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11523. isSuccess = ConfigurationStatus_Accepted;
  11524. }
  11525. else
  11526. {
  11527. isSuccess = ConfigurationStatus_Rejected;
  11528. }
  11529. }
  11530. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11531. {
  11532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11533. {
  11534. check_ascii = value[0];
  11535. if( (check_ascii < 48) || (check_ascii > 57) )
  11536. {
  11537. isSuccess = ConfigurationStatus_Rejected;
  11538. }
  11539. else
  11540. {
  11541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11542. isSuccess = ConfigurationStatus_Accepted;
  11543. }
  11544. }
  11545. else
  11546. {
  11547. isSuccess = ConfigurationStatus_Rejected;
  11548. }
  11549. }
  11550. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11551. {
  11552. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11553. {
  11554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11555. isSuccess = ConfigurationStatus_Accepted;
  11556. }
  11557. else
  11558. {
  11559. isSuccess = ConfigurationStatus_Rejected;
  11560. }
  11561. }
  11562. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11563. {
  11564. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11565. {
  11566. check_ascii = value[0];
  11567. if( (check_ascii < 48) || (check_ascii > 57) )
  11568. {
  11569. isSuccess = ConfigurationStatus_Rejected;
  11570. }
  11571. else
  11572. {
  11573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11574. isSuccess = ConfigurationStatus_Accepted;
  11575. }
  11576. }
  11577. else
  11578. {
  11579. isSuccess = ConfigurationStatus_Rejected;
  11580. }
  11581. }
  11582. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11583. {
  11584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11585. {
  11586. check_ascii = value[0];
  11587. if( (check_ascii < 48) || (check_ascii > 57) )
  11588. {
  11589. isSuccess = ConfigurationStatus_Rejected;
  11590. }
  11591. else
  11592. {
  11593. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11595. TransactionMessageAttemptsValue = atoi(value);
  11596. isSuccess = ConfigurationStatus_Accepted;
  11597. }
  11598. }
  11599. else
  11600. {
  11601. isSuccess = ConfigurationStatus_Rejected;
  11602. }
  11603. }
  11604. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11605. {
  11606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11607. {
  11608. check_ascii = value[0];
  11609. if( (check_ascii < 48) || (check_ascii > 57) )
  11610. {
  11611. isSuccess = ConfigurationStatus_Rejected;
  11612. }
  11613. else
  11614. {
  11615. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11617. TransactionMessageRetryIntervalValue = atoi(value);
  11618. isSuccess = ConfigurationStatus_Accepted;
  11619. }
  11620. }
  11621. else
  11622. {
  11623. isSuccess = ConfigurationStatus_Rejected;
  11624. }
  11625. }
  11626. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11627. {
  11628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11629. {
  11630. strcpy(str, (const char*)value);
  11631. for(int i = 0; str[i]; i++)
  11632. {
  11633. str[i] = tolower(str[i]);
  11634. }
  11635. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11637. isSuccess = ConfigurationStatus_Accepted;
  11638. }
  11639. else
  11640. {
  11641. isSuccess = ConfigurationStatus_Rejected;
  11642. }
  11643. }
  11644. if(strcmp(key, "WebSocketPingInterval") == 0)
  11645. {
  11646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11647. {
  11648. check_ascii = value[0];
  11649. if( (check_ascii < 48) || (check_ascii > 57) )
  11650. {
  11651. isSuccess = ConfigurationStatus_Rejected;
  11652. }
  11653. else
  11654. {
  11655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11656. isSuccess = ConfigurationStatus_Accepted;
  11657. }
  11658. }
  11659. else
  11660. {
  11661. isSuccess = ConfigurationStatus_Rejected;
  11662. }
  11663. }
  11664. #if 0
  11665. //For OCPP Test Case
  11666. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11667. {
  11668. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11669. {
  11670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11671. isSuccess = ConfigurationStatus_Accepted;
  11672. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11673. }
  11674. else
  11675. {
  11676. isSuccess = ConfigurationStatus_Rejected;
  11677. }
  11678. }
  11679. #endif
  11680. #if 1
  11681. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11682. {
  11683. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11684. {
  11685. strcpy(str, (const char*)value);
  11686. for(int i = 0; str[i]; i++)
  11687. {
  11688. str[i] = tolower(str[i]);
  11689. }
  11690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11691. isSuccess = ConfigurationStatus_Accepted;
  11692. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11693. }
  11694. else
  11695. {
  11696. isSuccess = ConfigurationStatus_Rejected;
  11697. }
  11698. }
  11699. #endif
  11700. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11701. {
  11702. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11703. {
  11704. check_ascii = value[0];
  11705. if( (check_ascii < 48) || (check_ascii > 57) )
  11706. {
  11707. isSuccess = ConfigurationStatus_Rejected;
  11708. }
  11709. else
  11710. {
  11711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11712. isSuccess = ConfigurationStatus_Accepted;
  11713. }
  11714. }
  11715. else
  11716. {
  11717. isSuccess = ConfigurationStatus_Rejected;
  11718. }
  11719. }
  11720. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11721. {
  11722. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11723. {
  11724. check_ascii = value[0];
  11725. if( (check_ascii < 48) || (check_ascii > 57) )
  11726. {
  11727. isSuccess = ConfigurationStatus_Rejected;
  11728. }
  11729. else
  11730. {
  11731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11732. isSuccess = ConfigurationStatus_Accepted;
  11733. }
  11734. }
  11735. else
  11736. {
  11737. isSuccess = ConfigurationStatus_Rejected;
  11738. }
  11739. }
  11740. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11741. {
  11742. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11743. {
  11744. strcpy(str, (const char*)value);
  11745. for(int i = 0; str[i]; i++)
  11746. {
  11747. str[i] = tolower(str[i]);
  11748. }
  11749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11750. isSuccess = ConfigurationStatus_Accepted;
  11751. }
  11752. else
  11753. {
  11754. isSuccess = ConfigurationStatus_Rejected;
  11755. }
  11756. }
  11757. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11758. {
  11759. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11760. {
  11761. check_ascii = value[0];
  11762. if( (check_ascii < 48) || (check_ascii > 57) )
  11763. {
  11764. isSuccess = ConfigurationStatus_Rejected;
  11765. }
  11766. else
  11767. {
  11768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11769. isSuccess = ConfigurationStatus_Accepted;
  11770. }
  11771. }
  11772. else
  11773. {
  11774. isSuccess = ConfigurationStatus_Rejected;
  11775. }
  11776. }
  11777. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11778. {
  11779. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11780. {
  11781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11782. isSuccess = ConfigurationStatus_Accepted;
  11783. }
  11784. else
  11785. {
  11786. isSuccess = ConfigurationStatus_Rejected;
  11787. }
  11788. }
  11789. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11790. {
  11791. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11792. {
  11793. check_ascii = value[0];
  11794. if( (check_ascii < 48) || (check_ascii > 57) )
  11795. {
  11796. isSuccess = ConfigurationStatus_Rejected;
  11797. }
  11798. else
  11799. {
  11800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11801. isSuccess = ConfigurationStatus_Accepted;
  11802. }
  11803. }
  11804. else
  11805. {
  11806. isSuccess = ConfigurationStatus_Rejected;
  11807. }
  11808. }
  11809. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11810. {
  11811. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11812. {
  11813. strcpy(str, (const char*)value);
  11814. for(int i = 0; str[i]; i++)
  11815. {
  11816. str[i] = tolower(str[i]);
  11817. }
  11818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11819. isSuccess = ConfigurationStatus_Accepted;
  11820. }
  11821. else
  11822. {
  11823. isSuccess = ConfigurationStatus_Rejected;
  11824. }
  11825. }
  11826. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11827. {
  11828. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11829. {
  11830. check_ascii = value[0];
  11831. if( (check_ascii < 48) || (check_ascii > 57) )
  11832. {
  11833. isSuccess = ConfigurationStatus_Rejected;
  11834. }
  11835. else
  11836. {
  11837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11838. isSuccess = ConfigurationStatus_Accepted;
  11839. }
  11840. }
  11841. else
  11842. {
  11843. isSuccess = ConfigurationStatus_Rejected;
  11844. }
  11845. }
  11846. return isSuccess;
  11847. }
  11848. int updateSetting(char *key, char *value)
  11849. {
  11850. mtrace();
  11851. int isSuccess = FALSE;
  11852. char string[1000]={0}, buffer[1000]={0};
  11853. char strtemp[50]={0};
  11854. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11855. int pos, c = 0;
  11856. char *loc;
  11857. int pos1=0;
  11858. FILE *f = fopen("/var/www/settings1", "r");
  11859. if(f == NULL)
  11860. {
  11861. #ifdef Debug
  11862. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11863. #endif
  11864. return isSuccess;
  11865. }
  11866. fseek(f, 0, SEEK_END);
  11867. long fsize = ftell(f);
  11868. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11869. fread(string, 1, fsize, f);
  11870. fclose(f);
  11871. string[fsize] = 0;
  11872. loc = strstr(string, key);
  11873. if(loc != NULL)
  11874. {
  11875. DEBUG_INFO("key exist!\n");
  11876. pos = loc - string-1;
  11877. f = fopen("/var/www/settings1", "w");
  11878. strncpy(buffer, string, pos);
  11879. fprintf(f, "%s", buffer);
  11880. memset(sstr ,0, sizeof(sstr) );
  11881. c = 0;
  11882. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11883. {
  11884. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11885. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11886. c++;
  11887. }
  11888. sstr[c] = '\0';
  11889. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11890. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11891. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11892. memset(buffer ,0, sizeof(buffer) );
  11893. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11894. //printf("buffer=%s",buffer);
  11895. fprintf(f, "%s", buffer);
  11896. fclose(f);
  11897. }
  11898. else
  11899. {
  11900. printf("key not exist!\n");
  11901. f = fopen("/var/www/settings1", "w+");
  11902. fputs(string, f);
  11903. fseek(f, -1, SEEK_CUR);
  11904. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  11905. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  11906. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  11907. fclose(f);
  11908. }
  11909. isSuccess = TRUE;
  11910. return isSuccess;
  11911. }
  11912. int TransactionMessageAttemptsGet(void)
  11913. {
  11914. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11915. }
  11916. int FirstHeartBeatResponse(void)
  11917. {
  11918. return FirstHeartBeat;
  11919. }
  11920. int TransactionMessageRetryIntervalGet(void)
  11921. {
  11922. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11923. }
  11924. #define SA struct sockaddr
  11925. #define MAXBUF 1024
  11926. //static int m_socket_data;
  11927. //static int sockfd;
  11928. int ReadHttpStatus(int sock){
  11929. //char c;
  11930. char buff[1024]="",*ptr=buff+1;
  11931. int bytes_received, status;
  11932. DEBUG_INFO("Begin Response ..\n");
  11933. while((bytes_received = recv(sock, ptr, 1, 0))){
  11934. if(bytes_received==-1){
  11935. perror("ReadHttpStatus");
  11936. exit(1);
  11937. }
  11938. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  11939. ptr++;
  11940. }
  11941. *ptr=0;
  11942. ptr=buff+1;
  11943. sscanf(ptr,"%*s %d ", &status);
  11944. DEBUG_INFO("%s\n",ptr);
  11945. DEBUG_INFO("status=%d\n",status);
  11946. DEBUG_INFO("End Response ..\n");
  11947. return (bytes_received>0)?status:0;
  11948. }
  11949. //the only filed that it parsed is 'Content-Length'
  11950. int ParseHeader(int sock){
  11951. //char c;
  11952. char buff[1024]="",*ptr=buff+4;
  11953. int bytes_received;
  11954. DEBUG_INFO("Begin HEADER ..\n");
  11955. while((bytes_received = recv(sock, ptr, 1, 0))){
  11956. if(bytes_received==-1){
  11957. perror("Parse Header");
  11958. exit(1);
  11959. }
  11960. if(
  11961. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  11962. (ptr[-1]=='\r') && (*ptr=='\n' )
  11963. ) break;
  11964. ptr++;
  11965. }
  11966. *ptr=0;
  11967. ptr=buff+4;
  11968. //printf("%s",ptr);
  11969. if(bytes_received){
  11970. ptr=strstr(ptr,"Content-Length:");
  11971. if(ptr){
  11972. sscanf(ptr,"%*s %d",&bytes_received);
  11973. }else
  11974. bytes_received=-1; //unknown size
  11975. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  11976. }
  11977. DEBUG_INFO("End HEADER ..\n");
  11978. return bytes_received ;
  11979. }
  11980. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  11981. {
  11982. char rmFileCmd[100]={0};
  11983. char FilePath[100]={0};
  11984. char ftpbuf[200];
  11985. int systemresult;
  11986. //DEBUG_INFO("filename=%s\n",filename);
  11987. //DEBUG_INFO("url=%s\n",url);
  11988. sprintf(FilePath,"/mnt/%s",filename);
  11989. if((access(FilePath,F_OK))!=-1)
  11990. {
  11991. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11992. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11993. system(rmFileCmd);
  11994. }
  11995. memset(ftpbuf, 0, sizeof(ftpbuf));
  11996. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  11997. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11998. systemresult = system(ftpbuf);
  11999. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12000. if(systemresult != 0)
  12001. {
  12002. DEBUG_INFO("http DownLoad error!\n");
  12003. return FALSE;
  12004. }
  12005. return TRUE;
  12006. }
  12007. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12008. {
  12009. char rmFileCmd[100]={0};
  12010. char FilePath[100]={0};
  12011. char ftpbuf[200];
  12012. int systemresult;
  12013. //char temp[100];
  12014. #if 0
  12015. struct hostent* server;
  12016. char *IPbuffer;
  12017. server = gethostbyname(location);
  12018. // To convert an Internet network
  12019. // address into ASCII string
  12020. IPbuffer = inet_ntoa(*((struct in_addr*)
  12021. server->h_addr_list[0]));
  12022. #endif
  12023. sprintf(FilePath,"/mnt/%s",filename);
  12024. if((access(FilePath,F_OK))!=-1)
  12025. {
  12026. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12027. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12028. system(rmFileCmd);
  12029. }
  12030. memset(ftpbuf, 0, sizeof(ftpbuf));
  12031. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12032. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12033. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12034. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12035. systemresult = system(ftpbuf);
  12036. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12037. if(systemresult != 0)
  12038. {
  12039. printf("wget error!\n");
  12040. return FALSE;
  12041. }
  12042. return TRUE;
  12043. }
  12044. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12045. {
  12046. char rmFileCmd[100]={0};
  12047. char FilePath[100]={0};
  12048. char ftpbuf[200];
  12049. char filenametemp[60]={0};
  12050. int systemresult;
  12051. //DEBUG_INFO("filename=%s\n",filename);
  12052. //DEBUG_INFO("url=%s\n",url);
  12053. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12054. if((access(FilePath,F_OK))!=-1)
  12055. {
  12056. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12057. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12058. system(rmFileCmd);
  12059. }
  12060. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12061. if(fp == NULL)
  12062. {
  12063. DEBUG_INFO("log is NULL\n");
  12064. return FALSE;
  12065. }
  12066. else
  12067. {
  12068. fprintf(fp, "%s\n", url);
  12069. sscanf(filename, "%*2[.]%s", filenametemp);
  12070. fprintf(fp, "%s\n", filenametemp);
  12071. fclose(fp);
  12072. }
  12073. memset(ftpbuf, 0, sizeof(ftpbuf));
  12074. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12075. systemresult = system(ftpbuf);
  12076. DEBUG_INFO("systemresult=%d\n",systemresult);
  12077. if(systemresult != 0)
  12078. {
  12079. DEBUG_INFO("http upload error!\n");
  12080. return FALSE;
  12081. }
  12082. return TRUE;
  12083. }
  12084. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12085. {
  12086. struct hostent* server;
  12087. char *IPbuffer;
  12088. char ftpbuf[200];
  12089. int systemresult;
  12090. // To retrieve host information
  12091. server = gethostbyname(location);
  12092. // To convert an Internet network
  12093. // address into ASCII string
  12094. IPbuffer = inet_ntoa(*((struct in_addr*)
  12095. server->h_addr_list[0]));
  12096. memset(ftpbuf, 0, sizeof(ftpbuf));
  12097. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12098. /* format : ftpput -u username -p passwd IP target source*/
  12099. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12100. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12101. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12102. systemresult = system(ftpbuf);
  12103. DEBUG_INFO("systemresult=%d\n",systemresult);
  12104. if(systemresult != 0)
  12105. {
  12106. DEBUG_INFO("ftpput error!\n");
  12107. return FALSE;
  12108. }
  12109. return TRUE;
  12110. }
  12111. int SettingChargingRecord(int target, int transactionId)
  12112. {
  12113. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12114. {
  12115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12116. {
  12117. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12118. {
  12119. addBuff(target, transactionId, 0);
  12120. return TRUE;
  12121. }
  12122. }
  12123. for (int index = 0; index < CCS_QUANTITY; index++)
  12124. {
  12125. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12126. {
  12127. addBuff(target, transactionId, 0);
  12128. return TRUE;
  12129. }
  12130. }
  12131. for (int index = 0; index < GB_QUANTITY; index++)
  12132. {
  12133. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12134. {
  12135. addBuff(target, transactionId, 0);
  12136. return TRUE;
  12137. }
  12138. }
  12139. }
  12140. else
  12141. {
  12142. for (int index = 0; index < AC_QUANTITY; index++)
  12143. {
  12144. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12145. {
  12146. addBuff(target, transactionId, 0);
  12147. return TRUE;
  12148. }
  12149. }
  12150. }
  12151. return FALSE;
  12152. }
  12153. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12154. {
  12155. int isSuccess = FALSE;
  12156. //char *query = NULL;
  12157. sqlite3_stmt *stmt;
  12158. int rc; // return code
  12159. char str[20];
  12160. sprintf(str,"%d",user_id);
  12161. 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 */
  12162. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12163. rc = sqlite3_step(stmt); /* 3 */
  12164. if (rc != SQLITE_DONE) {
  12165. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12166. goto out;
  12167. }
  12168. sqlite3_finalize(stmt);
  12169. // free(query);
  12170. out:
  12171. //----------------------
  12172. // close SQLite database
  12173. //----------------------
  12174. sqlite3_close(db);
  12175. printf("database closed.\n");
  12176. return isSuccess;
  12177. }
  12178. /**
  12179. * Place the contents of the specified file into a memory buffer
  12180. *
  12181. * @param[in] filename The path and name of the file to read
  12182. * @param[out] filebuffer A pointer to the contents in memory
  12183. * @return status 0 success, 1 on failure
  12184. */
  12185. int get_file_contents(const char* filename, char** outbuffer) {
  12186. FILE* file = NULL;
  12187. long filesize;
  12188. const int blocksize = 1;
  12189. size_t readsize;
  12190. char* filebuffer;
  12191. // Open the file
  12192. file = fopen(filename, "r");
  12193. if (NULL == file)
  12194. {
  12195. printf("'%s' not opened\n", filename);
  12196. exit(EXIT_FAILURE);
  12197. }
  12198. // Determine the file size
  12199. fseek(file, 0, SEEK_END);
  12200. filesize = ftell(file);
  12201. rewind (file);
  12202. // Allocate memory for the file contents
  12203. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12204. *outbuffer = filebuffer;
  12205. if (filebuffer == NULL)
  12206. {
  12207. fputs ("malloc out-of-memory", stderr);
  12208. exit(EXIT_FAILURE);
  12209. }
  12210. // Read in the file
  12211. readsize = fread(filebuffer, blocksize, filesize, file);
  12212. if (readsize != filesize)
  12213. {
  12214. fputs ("didn't read file completely",stderr);
  12215. exit(EXIT_FAILURE);
  12216. }
  12217. // Clean exit
  12218. fclose(file);
  12219. return EXIT_SUCCESS;
  12220. }
  12221. static int selectSqlCount = 0;
  12222. static int callback(void *data, int argc, char **argv, char **azColName){
  12223. int i;
  12224. printf("%s: ", (const char*)data);
  12225. selectSqlCount = argc;
  12226. for(i = 0; i<argc; i++){
  12227. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12228. }
  12229. printf("\n");
  12230. return 0;
  12231. }
  12232. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12233. //int i;
  12234. //printf("%s:\n", (const char*)data);
  12235. localversion = argv[5] ? atoi(argv[5]) : 0;
  12236. printf("localversion=%d\n", localversion);
  12237. return 0;
  12238. }
  12239. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12240. //int i;
  12241. //printf("%s:\n", (const char*)data);
  12242. //idTag
  12243. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12244. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12245. //parentIdTag
  12246. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12247. //expir_date
  12248. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12249. //status
  12250. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12251. //version
  12252. idTagQuery.listVersionInt = atoi(argv[5]);
  12253. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12254. return 0;
  12255. }
  12256. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12257. int i;
  12258. //printf("%s:\n", (const char*)data);
  12259. #if 1
  12260. for(i=0; i<argc; i++){
  12261. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12262. }
  12263. //printf("");
  12264. #endif
  12265. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12266. // printf("localversion=%d\n", localversion);
  12267. return 0;
  12268. }
  12269. /** sqlite3_exec的回调。
  12270. *
  12271. * 向控制台打印查询的结果。
  12272. *
  12273. * @param in data 传递给回调函数的数据。
  12274. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12275. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12276. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12277. * @return 状态码。
  12278. */
  12279. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12280. {
  12281. for (int i = 0; i < n_columns; i++)
  12282. {
  12283. DEBUG_INFO("%s/t", col_values[i]);
  12284. }
  12285. DEBUG_INFO("/n");
  12286. return 0;
  12287. }
  12288. void OCPP_getListVerion()
  12289. {
  12290. int rc = 0;
  12291. // const char* data = "Callback function called";
  12292. char sql[100];
  12293. char zErrMsg[100];
  12294. memset(sql, 0, 100);
  12295. memset(zErrMsg, 0, 100);
  12296. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12297. /* Execute SQL statement */
  12298. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12299. DEBUG_INFO("rc=%d\n",rc);
  12300. if( rc != SQLITE_OK ){
  12301. DEBUG_INFO("SQL error: %s", zErrMsg);
  12302. //sqlite3_free(zErrMsg);
  12303. }else{
  12304. DEBUG_INFO("Operation done successfully");
  12305. }
  12306. }
  12307. void OCPP_getIdTag(char idTag[])
  12308. {
  12309. int rc = 0;
  12310. // const char* data = "Callback function called";
  12311. char sql[100];
  12312. char zErrMsg[100];
  12313. memset(sql, 0, 100);
  12314. memset(zErrMsg, 0, 100);
  12315. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12316. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12317. DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12318. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12319. /* Execute SQL statement */
  12320. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12321. if( rc != SQLITE_OK ){
  12322. DEBUG_INFO("SQL error: %s", zErrMsg);
  12323. //sqlite3_free(zErrMsg);
  12324. }else{
  12325. printf("Operation done successfully");
  12326. }
  12327. //return ver;
  12328. }
  12329. void OCPP_get_TableAuthlocalAllData(void)
  12330. {
  12331. int rc = 0;
  12332. // const char* data = "Callback function called";
  12333. char sql[100];
  12334. char zErrMsg[100];
  12335. memset(sql, 0, 100);
  12336. memset(zErrMsg, 0, 100);
  12337. sprintf(sql,"select * from ocpp_auth_local ");
  12338. /* Execute SQL statement */
  12339. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12340. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12341. if( rc != SQLITE_OK ){
  12342. DEBUG_INFO("SQL error: %s", zErrMsg);
  12343. //sqlite3_free(zErrMsg);
  12344. }else{
  12345. DEBUG_INFO("Operation done successfully");
  12346. }
  12347. //return ver;
  12348. }
  12349. int OCPP_cleanLocalList()
  12350. {
  12351. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12352. char *errMsg = 0;
  12353. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12354. if (SQLITE_OK != rc)
  12355. {
  12356. DEBUG_INFO("%s\n",errMsg);
  12357. return FALSE;
  12358. }
  12359. else
  12360. {
  12361. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12362. }
  12363. return TRUE;
  12364. }
  12365. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12366. {
  12367. int isSuccess = FALSE;
  12368. int ret = 0;
  12369. //const char* data = "Callback function called";
  12370. char sql[300];
  12371. char zErrMsg[200];
  12372. memset(sql, 0, 300);
  12373. memset(zErrMsg, 0, 200);
  12374. 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);
  12375. //* Execute SQL statement */
  12376. //zErrMsg = 0;
  12377. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12378. if( ret != SQLITE_OK ){
  12379. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12380. // free(zErrMsg);
  12381. // free(sql);
  12382. return isSuccess;
  12383. }
  12384. DEBUG_INFO("successfully Insert records created\n");
  12385. isSuccess = TRUE;
  12386. return isSuccess;
  12387. }
  12388. void OCPP_deleteIdTag(char idTag[])
  12389. {
  12390. //int ver = 0;
  12391. //int isSuccess = FALSE;
  12392. int rc = 0;
  12393. char sql[100];
  12394. char zErrMsg[100];
  12395. memset(sql, 0, 100);
  12396. memset(zErrMsg, 0, 100);
  12397. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12398. //* Execute SQL statement */
  12399. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12400. if( rc != SQLITE_OK ){
  12401. DEBUG_INFO("SQL error: %s", zErrMsg);
  12402. //sqlite3_free(zErrMsg);
  12403. }else{
  12404. DEBUG_INFO("Operation done successfully");
  12405. }
  12406. }
  12407. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12408. {
  12409. int isSuccess = FALSE;
  12410. int ret = 0;
  12411. const char* data = "Callback function called";
  12412. char sql[200];
  12413. char zErrMsg[100];
  12414. memset(sql, 0, 200);
  12415. memset(zErrMsg, 0, 100);
  12416. //* selectFromTable */
  12417. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12418. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12419. //* Execute SQL statement */
  12420. selectSqlCount = 0;
  12421. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12422. if( ret != SQLITE_OK ){
  12423. printf("Error SQL: %s\n", zErrMsg);
  12424. }
  12425. printf("successfully select operation done\n");
  12426. memset(sql, 0, 200);
  12427. memset(zErrMsg, 0, 100);
  12428. if(selectSqlCount == 0)
  12429. {
  12430. //Insert
  12431. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12432. 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);
  12433. DEBUG_INFO("sql:%s\n", sql);
  12434. //* Execute SQL statement */
  12435. //zErrMsg = 0;
  12436. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12437. if( ret != SQLITE_OK ){
  12438. printf("SQL error: %s\n", zErrMsg);
  12439. return isSuccess;
  12440. }
  12441. DEBUG_INFO("successfully Insert records created\n");
  12442. isSuccess = TRUE;
  12443. }
  12444. else
  12445. {
  12446. //Update
  12447. //* Create merged SQL statement */
  12448. 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);
  12449. /* Execute SQL statement */
  12450. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12451. if( ret != SQLITE_OK ){
  12452. printf("SQL error: %s\n", zErrMsg);
  12453. //sqlite3_free(zErrMsg);
  12454. //sqlite3_free(sql);
  12455. return isSuccess;
  12456. }
  12457. DEBUG_INFO("Successfully operation done \n");
  12458. isSuccess = TRUE;
  12459. }
  12460. return isSuccess;
  12461. }
  12462. int GetOcppServerURL()
  12463. {
  12464. int result = FALSE;
  12465. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12466. memset(OcppHost, 0, sizeof(OcppHost));
  12467. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12468. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12469. {
  12470. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12471. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12472. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12473. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12474. result = TRUE;
  12475. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12476. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12477. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12478. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12479. goto End;
  12480. }
  12481. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12482. {
  12483. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12484. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12485. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12486. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12487. result = TRUE;
  12488. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12489. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12490. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12491. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12492. goto End;
  12493. }
  12494. else
  12495. {
  12496. strcpy(OcppHost,"");
  12497. }
  12498. End:
  12499. return result;
  12500. }
  12501. int GetOcppPath()
  12502. {
  12503. int result = FALSE;
  12504. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12505. {
  12506. if(OcppTempPath == NULL)
  12507. {
  12508. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12509. }
  12510. else
  12511. {
  12512. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12513. }
  12514. result = TRUE;
  12515. goto End;
  12516. }
  12517. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12518. {
  12519. if(OcppTempPath == NULL)
  12520. {
  12521. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12522. }
  12523. else
  12524. {
  12525. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12526. }
  12527. result = TRUE;
  12528. goto End;
  12529. }
  12530. else
  12531. {
  12532. strcpy(OcppPath,"");
  12533. }
  12534. End:
  12535. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12536. return result;
  12537. }
  12538. int GetOcppPort()
  12539. {
  12540. return OcppPort;
  12541. }
  12542. int GetOcppConnStatus(void)
  12543. {
  12544. return ShmOCPP16Data->OcppConnStatus;
  12545. }
  12546. void SetOcppConnStatus(uint8_t status)
  12547. {
  12548. ShmOCPP16Data->OcppConnStatus = status;
  12549. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12550. if(status == FALSE)
  12551. {
  12552. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12553. {
  12554. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12555. }
  12556. else
  12557. {
  12558. SystemInitial = AC_QUANTITY;
  12559. }
  12560. }
  12561. }
  12562. int GetHeartBeatWithNOResponse(void)
  12563. {
  12564. return HeartBeatWithNOResponse;
  12565. }
  12566. void SetHeartBeatWithNOResponse(void)
  12567. {
  12568. HeartBeatWithNOResponse = 0;
  12569. }
  12570. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12571. /*
  12572. src 源字串的首地址(buf的地址)
  12573. separator 指定的分割字元
  12574. dest 接收子字串的陣列
  12575. num 分割後子字串的個數
  12576. */
  12577. char *pNext;
  12578. int count = 0;
  12579. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12580. return;
  12581. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12582. return;
  12583. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12584. while(pNext != NULL) {
  12585. *dest++ = pNext;
  12586. ++count;
  12587. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12588. }
  12589. *num = count;
  12590. }
  12591. int GetTransactionId(int gunindex, unsigned char idTag[])
  12592. {
  12593. char ch;
  12594. FILE *fptr1;
  12595. int temptransactionId;
  12596. char str[100]={0};
  12597. temptransactionId = 0;
  12598. /*------ Read the file ----------------*/
  12599. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12600. ch=fgetc(fptr1);
  12601. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12602. rewind(fptr1);
  12603. if(ch!=EOF)
  12604. {
  12605. // printf("%c",ch);
  12606. while (fgets(str, 100, fptr1) != NULL)
  12607. {
  12608. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12609. if(str[0]=='\0')
  12610. {
  12611. break;
  12612. }
  12613. char *revbuf[8] = {0}; //存放分割後的子字串
  12614. int num = 0;//分割後子字串的個數
  12615. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12616. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12617. {
  12618. temptransactionId = atoi(revbuf[2]);
  12619. break;
  12620. }
  12621. }
  12622. }
  12623. fclose(fptr1);
  12624. /*------- End of reading ---------------*/
  12625. return temptransactionId;
  12626. }
  12627. void SetTransactionIdZero(int transactionId)
  12628. {
  12629. //TransactionId[gunindex] = 0;
  12630. char ch;
  12631. FILE *fptr1, *fptr2;
  12632. int temptransactionId;
  12633. char str[100]={0}, temp[] = "/Storage/OCPP/temp.txt";
  12634. printf("\n\n Delete a specific line from a file :\n");
  12635. printf("-----------------------------------------\n");
  12636. //scanf("%s",fname);
  12637. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12638. if (!fptr1)
  12639. {
  12640. printf(" File not found or unable to open the input file!!\n");
  12641. return ;
  12642. }
  12643. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12644. if (!fptr2)
  12645. {
  12646. printf("Unable to open a temporary file to write!!\n");
  12647. fclose(fptr1);
  12648. return ;
  12649. }
  12650. ch=fgetc(fptr1);
  12651. //printf(" Now the content of the file %s is : \n",fname);
  12652. rewind(fptr1);
  12653. if(ch!=EOF)
  12654. {
  12655. // copy all contents to the temporary file except the specific line
  12656. while (fgets(str, 100, fptr1) != NULL)
  12657. {
  12658. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12659. if(str[0]=='\0')
  12660. {
  12661. break;
  12662. }
  12663. char *revbuf[8] = {0}; //存放分割後的子字串
  12664. int num = 0;//分割後子字串的個數
  12665. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12666. temptransactionId = atoi(revbuf[2]);
  12667. if(transactionId != temptransactionId)
  12668. {
  12669. fprintf(fptr2, "%s", str);
  12670. }
  12671. }
  12672. }
  12673. fclose(fptr1);
  12674. fclose(fptr2);
  12675. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12676. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12677. /*------ Read the file ----------------*/
  12678. }
  12679. int InternetDisconnect(void)
  12680. {
  12681. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12682. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12683. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12684. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12685. }
  12686. void GetChargingProfileRequest(int gunindex)
  12687. {
  12688. mtrace();
  12689. //int connectorIdInt, durationInt;
  12690. //char chargingRateUnitStr[4]={0};
  12691. int tempdurationInt = 0;
  12692. int tempchargingProfileId = 0;
  12693. int tempstackLevel = 0;
  12694. int temptransactionId = 0;
  12695. float tempminChargingRateFloat = 0.0;
  12696. char tempchargingProfilePurposeStr[24]={0};
  12697. char tempchargingProfileKindStr[12]={0};
  12698. char temprecurrencyKindStr[8]={0};
  12699. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12700. char tempvalidToStr[28]={0};
  12701. int tempStartPeriodInt = 0;
  12702. float tempLimitInt = 0.0;//0.1;
  12703. int tempNumberPhasesInt=0;
  12704. char fname[200];
  12705. //char comfirmstr[20];
  12706. float MinChargingRate =0.0;
  12707. double diff_t;
  12708. struct tm tp;
  12709. FILE *fptr1;//, *fptr2;
  12710. int c = 0;
  12711. char * pch;
  12712. char *loc;
  12713. char sstr[200]={ 0 };
  12714. int n_chargingProfile = 0;
  12715. int n_SchedulePeriods = 0;
  12716. char SchedulePeriodList[10][200]={0};
  12717. char sLineWord[1600]={0};
  12718. char word[1000]={0};
  12719. int confirmPeriods = 0;
  12720. struct StructProfile ChargePointMaxProfile;
  12721. struct StructProfile TxDefaultProfile;
  12722. struct StructProfile TxProfile;
  12723. struct StructProfile TxDefaultProfiletemp[2]={0};
  12724. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12725. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12726. struct StructChargingProfile TxProfile_TEMP={0};
  12727. int TxDefaultProfileFileIsNull=FALSE;
  12728. int ChargePointMaxProfileIsNull=FALSE;
  12729. int TxProfileIsNull=FALSE;
  12730. // int CompositeSceduleIndex = 0;
  12731. char ChargePointMaxProfileScheduleStr[30]={0};
  12732. char TxDefaultProfileScheduleStr[30]={0};
  12733. char TxProfileScheduleStr[30]={0};
  12734. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12735. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12736. memset(&TxProfile,0,sizeof(struct StructProfile));
  12737. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  12738. DEBUG_INFO("GetChargingProfileRequest\n");
  12739. //*****************************ChargePointMaxProfile******************************************/
  12740. strcpy(fname, ChargePointMaxProfile_JSON);
  12741. ChargePointMaxProfileIsNull=TRUE;
  12742. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12743. {
  12744. fptr1 = fopen(fname, "r");
  12745. int c;
  12746. c = fgetc(fptr1);
  12747. //DEBUG_INFO("c:%d\n",c);
  12748. rewind(fptr1);
  12749. if(c == EOF)
  12750. {
  12751. DEBUG_INFO("\n End of file reached.");
  12752. ChargePointMaxProfileIsNull=TRUE;
  12753. fclose(fptr1);
  12754. }
  12755. else
  12756. {
  12757. ChargePointMaxProfileIsNull=FALSE;
  12758. while(fscanf(fptr1, "%s", word) != EOF)
  12759. {
  12760. if(strcmp(word, "chargingProfileId") == 0)
  12761. {
  12762. n_chargingProfile = n_chargingProfile + 1;
  12763. }
  12764. }
  12765. rewind(fptr1);
  12766. //search Charging Profile Element
  12767. int i = 0;
  12768. int j = 0;
  12769. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12770. //***********chargingProfileId**************/
  12771. c = 0;
  12772. loc = strstr(sLineWord, "chargingProfileId");
  12773. //DEBUG_INFO("loc=%s\n",loc);
  12774. memset(sstr ,0, sizeof(sstr) );
  12775. if(loc != NULL)
  12776. {
  12777. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12778. {
  12779. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12780. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12781. c++;
  12782. }
  12783. sstr[c] = '\0';
  12784. tempchargingProfileId = atoi(sstr);
  12785. }
  12786. else
  12787. {
  12788. tempchargingProfileId = 0;
  12789. }
  12790. //***********stackLevel**************/
  12791. c = 0;
  12792. loc = strstr(sLineWord, "stackLevel");
  12793. //DEBUG_INFO("loc=%s\n",loc);
  12794. memset(sstr ,0, sizeof(sstr) );
  12795. if(loc != NULL)
  12796. {
  12797. while (loc[2+strlen("stackLevel")+c] != '\"')
  12798. {
  12799. sstr[c] = loc[2+strlen("stackLevel")+c];
  12800. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12801. c++;
  12802. }
  12803. sstr[c] = '\0';
  12804. tempstackLevel = atoi(sstr);
  12805. }
  12806. else
  12807. {
  12808. tempstackLevel = 0;
  12809. }
  12810. //***********chargingProfilePurpose **************/
  12811. c = 0;
  12812. loc = strstr(sLineWord, "chargingProfilePurpose");
  12813. //DEBUG_INFO("loc=%s\n",loc);
  12814. memset(sstr ,0, sizeof(sstr) );
  12815. if(loc != NULL)
  12816. {
  12817. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12818. {
  12819. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12820. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12821. c++;
  12822. }
  12823. sstr[c] = '\0';
  12824. strcpy(tempchargingProfilePurposeStr,sstr);
  12825. }
  12826. else
  12827. {
  12828. strcpy(tempchargingProfilePurposeStr,"");
  12829. }
  12830. //***********chargingProfileKind **************/
  12831. c = 0;
  12832. loc = strstr(sLineWord, "chargingProfileKind");
  12833. //DEBUG_INFO("loc=%s\n",loc);
  12834. memset(sstr ,0, sizeof(sstr) );
  12835. if(loc != NULL)
  12836. {
  12837. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12838. {
  12839. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12840. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12841. c++;
  12842. }
  12843. sstr[c] = '\0';
  12844. strcpy(tempchargingProfileKindStr,sstr);
  12845. }
  12846. else
  12847. {
  12848. strcpy(tempchargingProfileKindStr,"");
  12849. }
  12850. //***********recurrencyKind **************/
  12851. c = 0;
  12852. loc = strstr(sLineWord, "recurrencyKind");
  12853. //DEBUG_INFO("loc=%s\n",loc);
  12854. memset(sstr ,0, sizeof(sstr) );
  12855. if(loc != NULL)
  12856. {
  12857. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12858. {
  12859. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12860. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12861. c++;
  12862. }
  12863. sstr[c] = '\0';
  12864. strcpy(temprecurrencyKindStr,sstr);
  12865. }
  12866. else
  12867. {
  12868. strcpy(temprecurrencyKindStr,"");
  12869. }
  12870. //***********validFrom**************/
  12871. c = 0;
  12872. loc = strstr(sLineWord, "validFrom");
  12873. //DEBUG_INFO("loc=%s\n",loc);
  12874. memset(sstr ,0, sizeof(sstr) );
  12875. if(loc != NULL)
  12876. {
  12877. while (loc[3+strlen("validFrom")+c] != '\"')
  12878. {
  12879. sstr[c] = loc[3+strlen("validFrom")+c];
  12880. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12881. c++;
  12882. }
  12883. sstr[c] = '\0';
  12884. strcpy(tempvalidFromStr,sstr);
  12885. }
  12886. else
  12887. {
  12888. strcpy(tempvalidFromStr,"");
  12889. }
  12890. //***********validTo **************/
  12891. c = 0;
  12892. loc = strstr(sLineWord, "validTo");
  12893. //DEBUG_INFO("loc=%s\n",loc);
  12894. memset(sstr ,0, sizeof(sstr) );
  12895. if(loc != NULL)
  12896. {
  12897. while (loc[3+strlen("validTo")+c] != '\"')
  12898. {
  12899. sstr[c] = loc[3+strlen("validTo")+c];
  12900. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12901. c++;
  12902. }
  12903. sstr[c] = '\0';
  12904. strcpy(tempvalidToStr,sstr);
  12905. }
  12906. else
  12907. {
  12908. strcpy(tempvalidToStr,"");
  12909. }
  12910. //***********validFrom**************/
  12911. c = 0;
  12912. loc = strstr(sLineWord, "validFrom");
  12913. if(loc != NULL)
  12914. {
  12915. memset(sstr ,0, sizeof(sstr) );
  12916. while (loc[3+strlen("validFrom")+c] != '\"')
  12917. {
  12918. sstr[c] = loc[3+strlen("validFrom")+c];
  12919. c++;
  12920. }
  12921. sstr[c] = '\0';
  12922. strcpy(tempvalidFromStr,sstr);
  12923. }
  12924. else
  12925. {
  12926. strcpy(tempvalidFromStr,"");
  12927. }
  12928. //***********validTo **************/
  12929. c = 0;
  12930. loc = strstr(sLineWord, "validTo");
  12931. if(loc != NULL)
  12932. {
  12933. memset(sstr ,0, sizeof(sstr) );
  12934. while (loc[3+strlen("validTo")+c] != '\"')
  12935. {
  12936. sstr[c] = loc[3+strlen("validTo")+c];
  12937. c++;
  12938. }
  12939. sstr[c] = '\0';
  12940. strcpy(tempvalidToStr,sstr);
  12941. }
  12942. else
  12943. {
  12944. strcpy(tempvalidToStr,"");
  12945. }
  12946. //***********duration**************/
  12947. c = 0;
  12948. loc = strstr(sLineWord, "duration");
  12949. if(loc != NULL)
  12950. {
  12951. memset(sstr ,0, sizeof(sstr) );
  12952. while (loc[2+strlen("duration")+c] != ',')
  12953. {
  12954. sstr[c] = loc[2+strlen("duration")+c];
  12955. c++;
  12956. }
  12957. sstr[c] = '\0';
  12958. tempdurationInt = atoi(sstr);
  12959. }
  12960. else
  12961. {
  12962. tempdurationInt = 0;
  12963. }
  12964. //**********startSchedule**********/
  12965. c = 0;
  12966. loc = strstr(sLineWord, "startSchedule");
  12967. memset(sstr ,0, sizeof(sstr) );
  12968. while (loc[3+strlen("startSchedule")+c] != '\"')
  12969. {
  12970. sstr[c] = loc[3+strlen("startSchedule")+c];
  12971. c++;
  12972. }
  12973. sstr[c] = '\0';
  12974. strcpy(tempstartScheduleStr, sstr);
  12975. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  12976. //**********chargingRateUnit**********/
  12977. c = 0;
  12978. loc = strstr(sLineWord, "chargingRateUnit");
  12979. memset(sstr ,0, sizeof(sstr) );
  12980. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12981. {
  12982. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12983. c++;
  12984. }
  12985. sstr[c] = '\0';
  12986. strcpy(tempchargingRateUnitStr, sstr);
  12987. //**********minChargingRate*******/
  12988. c = 0;
  12989. loc = strstr(sLineWord, "minChargingRate");
  12990. if(loc != NULL)
  12991. {
  12992. memset(sstr ,0, sizeof(sstr) );
  12993. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12994. {
  12995. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12996. c++;
  12997. }
  12998. sstr[c] = '\0';
  12999. tempminChargingRateFloat = atof(sstr);
  13000. }
  13001. else
  13002. {
  13003. tempminChargingRateFloat = 0.0;
  13004. }
  13005. //
  13006. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13007. tp.tm_isdst = -1;
  13008. time_t utc = mktime(&tp);
  13009. time_t t = time(NULL);
  13010. diff_t = difftime(t, utc);
  13011. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13012. //parsing strings to words
  13013. i = 0;
  13014. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13015. loc = loc+3+strlen("chargingSchedulePeriod");
  13016. pch = strtok(loc ,"{");
  13017. while (pch != NULL)
  13018. {
  13019. strcpy(SchedulePeriodList[i], pch);
  13020. pch = strtok (NULL, "{");
  13021. i = i + 1;
  13022. }
  13023. n_SchedulePeriods = i;
  13024. for(int i=0;i<n_SchedulePeriods;i++)
  13025. {
  13026. //*************startPeriod****************/
  13027. c = 0;
  13028. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13029. memset(sstr ,0, sizeof(sstr) );
  13030. while (loc[strlen("startPeriod")+2+c] != ',')
  13031. {
  13032. sstr[c] = loc[strlen("startPeriod")+2+c];
  13033. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13034. c++;
  13035. }
  13036. sstr[c] = '\0';
  13037. tempStartPeriodInt = atoi(sstr);
  13038. //*************limit****************/
  13039. c = 0;
  13040. loc = strstr(SchedulePeriodList[i], "limit");
  13041. memset(sstr ,0, sizeof(sstr) );
  13042. while (loc[strlen("limit")+2+c] != ',')
  13043. {
  13044. sstr[c] = loc[strlen("limit")+2+c];
  13045. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13046. c++;
  13047. }
  13048. sstr[c] = '\0';
  13049. tempLimitInt = atof(sstr);
  13050. //*************numberPhases****************/
  13051. c = 0;
  13052. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13053. memset(sstr ,0, sizeof(sstr) );
  13054. while (loc[strlen("numberPhases")+2+c] != '}')
  13055. {
  13056. sstr[c] = loc[strlen("numberPhases")+2+c];
  13057. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13058. c++;
  13059. }
  13060. sstr[c] = '\0';
  13061. tempNumberPhasesInt = atoi(sstr);
  13062. if(j == 0)
  13063. {
  13064. ChargePointMaxProfile.Duration = tempdurationInt;
  13065. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13066. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13067. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13068. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13069. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13070. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13071. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13072. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13073. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13074. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13075. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13076. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13077. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13078. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13079. }
  13080. }
  13081. if(MinChargingRate < tempminChargingRateFloat)
  13082. {
  13083. MinChargingRate = tempminChargingRateFloat;
  13084. }
  13085. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13086. if(confirmPeriods < n_SchedulePeriods)
  13087. {
  13088. confirmPeriods = n_SchedulePeriods;
  13089. }
  13090. j = j + 1;
  13091. }
  13092. fclose(fptr1);
  13093. }
  13094. }// the end of access file ChargePointMaxProfile
  13095. //****************************TxDefaultProfile************************************************/
  13096. switch(gunindex + 1)
  13097. {
  13098. case 0:
  13099. strcpy(fname, TxDefaultProfile_0_JSON );
  13100. break;
  13101. case 1:
  13102. strcpy(fname, TxDefaultProfile_1_JSON );
  13103. break;
  13104. case 2:
  13105. strcpy(fname, TxDefaultProfile_2_JSON );
  13106. break;
  13107. default:
  13108. strcpy(fname, TxDefaultProfile_1_JSON );
  13109. break;
  13110. }
  13111. TxDefaultProfileFileIsNull=TRUE;
  13112. if((access(fname,F_OK))!=-1)
  13113. {
  13114. fptr1 = fopen(fname, "r");
  13115. c = 0;
  13116. c = fgetc(fptr1);
  13117. //DEBUG_INFO("c:%d\n",c);
  13118. rewind(fptr1);
  13119. if(c == EOF)
  13120. {
  13121. DEBUG_INFO("\n End of file reached.");
  13122. TxDefaultProfileFileIsNull=TRUE;
  13123. fclose(fptr1);
  13124. }
  13125. else
  13126. {
  13127. TxDefaultProfileFileIsNull=FALSE;
  13128. while(fscanf(fptr1, "%s", word) != EOF)
  13129. {
  13130. if(strcmp(word, "chargingProfileId") == 0)
  13131. {
  13132. n_chargingProfile = n_chargingProfile + 1;
  13133. }
  13134. }
  13135. rewind(fptr1);
  13136. //search Charging Profile Element
  13137. int i = 0;
  13138. int j = 0;
  13139. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13140. #if 0
  13141. /***********connectorId****************/
  13142. c = 0;
  13143. loc = strstr(sLineWord, "connectorId");
  13144. memset(sstr ,0, sizeof(sstr) );
  13145. while (loc[strlen("connectorId")+2+c] != ',')
  13146. {
  13147. sstr[c] = loc[strlen("connectorId")+2+c];
  13148. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13149. c++;
  13150. }
  13151. sstr[c] = '\0';
  13152. tempconnectorIdInt = atoi(sstr);
  13153. #endif
  13154. //***********chargingProfileId**************/
  13155. c = 0;
  13156. loc = strstr(sLineWord, "chargingProfileId");
  13157. //DEBUG_INFO("loc=%s\n",loc);
  13158. memset(sstr ,0, sizeof(sstr) );
  13159. if(loc != NULL)
  13160. {
  13161. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13162. {
  13163. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13164. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13165. c++;
  13166. }
  13167. sstr[c] = '\0';
  13168. tempchargingProfileId = atoi(sstr);
  13169. }
  13170. else
  13171. {
  13172. tempchargingProfileId = 0;
  13173. }
  13174. //***********stackLevel**************/
  13175. c = 0;
  13176. loc = strstr(sLineWord, "stackLevel");
  13177. //DEBUG_INFO("loc=%s\n",loc);
  13178. memset(sstr ,0, sizeof(sstr) );
  13179. if(loc != NULL)
  13180. {
  13181. while (loc[2+strlen("stackLevel")+c] != '\"')
  13182. {
  13183. sstr[c] = loc[2+strlen("stackLevel")+c];
  13184. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13185. c++;
  13186. }
  13187. sstr[c] = '\0';
  13188. tempstackLevel = atoi(sstr);
  13189. }
  13190. else
  13191. {
  13192. tempstackLevel = 0;
  13193. }
  13194. //***********chargingProfilePurpose **************/
  13195. c = 0;
  13196. loc = strstr(sLineWord, "chargingProfilePurpose");
  13197. //DEBUG_INFO("loc=%s\n",loc);
  13198. memset(sstr ,0, sizeof(sstr) );
  13199. if(loc != NULL)
  13200. {
  13201. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13202. {
  13203. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13204. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13205. c++;
  13206. }
  13207. sstr[c] = '\0';
  13208. strcpy(tempchargingProfilePurposeStr,sstr);
  13209. }
  13210. else
  13211. {
  13212. strcpy(tempchargingProfilePurposeStr,"");
  13213. }
  13214. //***********chargingProfileKind **************/
  13215. c = 0;
  13216. loc = strstr(sLineWord, "chargingProfileKind");
  13217. //DEBUG_INFO("loc=%s\n",loc);
  13218. memset(sstr ,0, sizeof(sstr) );
  13219. if(loc != NULL)
  13220. {
  13221. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13222. {
  13223. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13224. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13225. c++;
  13226. }
  13227. sstr[c] = '\0';
  13228. strcpy(tempchargingProfileKindStr,sstr);
  13229. }
  13230. else
  13231. {
  13232. strcpy(tempchargingProfileKindStr,"");
  13233. }
  13234. //***********recurrencyKind **************/
  13235. c = 0;
  13236. loc = strstr(sLineWord, "recurrencyKind");
  13237. //DEBUG_INFO("loc=%s\n",loc);
  13238. memset(sstr ,0, sizeof(sstr) );
  13239. if(loc != NULL)
  13240. {
  13241. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13242. {
  13243. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13244. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13245. c++;
  13246. }
  13247. sstr[c] = '\0';
  13248. strcpy(temprecurrencyKindStr,sstr);
  13249. }
  13250. else
  13251. {
  13252. strcpy(temprecurrencyKindStr,"");
  13253. }
  13254. //***********validFrom**************/
  13255. c = 0;
  13256. loc = strstr(sLineWord, "validFrom");
  13257. if(loc != NULL)
  13258. {
  13259. memset(sstr ,0, sizeof(sstr) );
  13260. while (loc[3+strlen("validFrom")+c] != '\"')
  13261. {
  13262. sstr[c] = loc[3+strlen("validFrom")+c];
  13263. c++;
  13264. }
  13265. sstr[c] = '\0';
  13266. strcpy(tempvalidFromStr,sstr);
  13267. }
  13268. else
  13269. {
  13270. strcpy(tempvalidFromStr,"");
  13271. }
  13272. //***********validTo **************/
  13273. c = 0;
  13274. loc = strstr(sLineWord, "validTo");
  13275. if(loc != NULL)
  13276. {
  13277. memset(sstr ,0, sizeof(sstr) );
  13278. while (loc[3+strlen("validTo")+c] != '\"')
  13279. {
  13280. sstr[c] = loc[3+strlen("validTo")+c];
  13281. c++;
  13282. }
  13283. sstr[c] = '\0';
  13284. strcpy(tempvalidToStr,sstr);
  13285. }
  13286. else
  13287. {
  13288. strcpy(tempvalidToStr,"");
  13289. }
  13290. //***********duration**************/
  13291. c = 0;
  13292. loc = strstr(sLineWord, "duration");
  13293. if(loc != NULL)
  13294. {
  13295. memset(sstr ,0, sizeof(sstr) );
  13296. while (loc[2+strlen("duration")+c] != ',')
  13297. {
  13298. sstr[c] = loc[2+strlen("duration")+c];
  13299. c++;
  13300. }
  13301. sstr[c] = '\0';
  13302. tempdurationInt = atoi(sstr);
  13303. }
  13304. else
  13305. {
  13306. tempdurationInt = 0;
  13307. }
  13308. //**********startSchedule**********/
  13309. c = 0;
  13310. loc = strstr(sLineWord, "startSchedule");
  13311. memset(sstr ,0, sizeof(sstr) );
  13312. while (loc[3+strlen("startSchedule")+c] != '\"')
  13313. {
  13314. sstr[c] = loc[3+strlen("startSchedule")+c];
  13315. c++;
  13316. }
  13317. sstr[c] = '\0';
  13318. strcpy(tempstartScheduleStr, sstr);
  13319. strcpy(TxDefaultProfileScheduleStr, sstr);
  13320. //**********chargingRateUnit**********/
  13321. c = 0;
  13322. loc = strstr(sLineWord, "chargingRateUnit");
  13323. memset(sstr ,0, sizeof(sstr) );
  13324. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13325. {
  13326. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13327. c++;
  13328. }
  13329. sstr[c] = '\0';
  13330. strcpy(tempchargingRateUnitStr, sstr);
  13331. //**********minChargingRate*******/
  13332. c = 0;
  13333. loc = strstr(sLineWord, "minChargingRate");
  13334. if(loc != NULL)
  13335. {
  13336. memset(sstr ,0, sizeof(sstr) );
  13337. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13338. {
  13339. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13340. c++;
  13341. }
  13342. sstr[c] = '\0';
  13343. tempminChargingRateFloat = atof(sstr);
  13344. }
  13345. else
  13346. {
  13347. tempminChargingRateFloat = 0.0;
  13348. }
  13349. //
  13350. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13351. tp.tm_isdst = -1;
  13352. time_t utc = mktime(&tp);
  13353. time_t t = time(NULL);
  13354. diff_t = difftime(t, utc);
  13355. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13356. //parsing strings to words
  13357. i = 0;
  13358. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13359. loc = loc+3+strlen("chargingSchedulePeriod");
  13360. pch = strtok(loc ,"{");
  13361. while (pch != NULL)
  13362. {
  13363. strcpy(SchedulePeriodList[i], pch);
  13364. pch = strtok (NULL, "{");
  13365. i = i + 1;
  13366. }
  13367. n_SchedulePeriods = i;
  13368. for(int i=0;i<n_SchedulePeriods;i++)
  13369. {
  13370. //*************startPeriod****************/
  13371. c = 0;
  13372. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13373. memset(sstr ,0, sizeof(sstr) );
  13374. while (loc[strlen("startPeriod")+2+c] != ',')
  13375. {
  13376. sstr[c] = loc[strlen("startPeriod")+2+c];
  13377. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13378. c++;
  13379. }
  13380. sstr[c] = '\0';
  13381. tempStartPeriodInt = atoi(sstr);
  13382. //*************limit****************/
  13383. c = 0;
  13384. loc = strstr(SchedulePeriodList[i], "limit");
  13385. memset(sstr ,0, sizeof(sstr) );
  13386. while (loc[strlen("limit")+2+c] != ',')
  13387. {
  13388. sstr[c] = loc[strlen("limit")+2+c];
  13389. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13390. c++;
  13391. }
  13392. sstr[c] = '\0';
  13393. tempLimitInt = atof(sstr);
  13394. //*************numberPhases****************/
  13395. c = 0;
  13396. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13397. memset(sstr ,0, sizeof(sstr) );
  13398. while (loc[strlen("numberPhases")+2+c] != '}')
  13399. {
  13400. sstr[c] = loc[strlen("numberPhases")+2+c];
  13401. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13402. c++;
  13403. }
  13404. sstr[c] = '\0';
  13405. tempNumberPhasesInt = atoi(sstr);
  13406. if(j == 0)
  13407. {
  13408. TxDefaultProfile.Duration = tempdurationInt;
  13409. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13410. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13411. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13412. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13413. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13414. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13415. TxDefaultProfile_TEMP.TransactionId = 0;
  13416. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13417. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13418. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13419. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13420. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13421. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13422. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13423. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13424. }
  13425. else
  13426. {
  13427. //other stack level charging Profile
  13428. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13429. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13430. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13431. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13432. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13433. }
  13434. }
  13435. if(MinChargingRate < tempminChargingRateFloat)
  13436. {
  13437. MinChargingRate = tempminChargingRateFloat;
  13438. }
  13439. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13440. if(confirmPeriods < n_SchedulePeriods)
  13441. confirmPeriods = n_SchedulePeriods;
  13442. j = j + 1;
  13443. }
  13444. fclose(fptr1);
  13445. //Stacking Charging Profiles
  13446. for(int l=0; l <(j-1) ;l++)
  13447. {
  13448. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13449. {
  13450. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13451. {
  13452. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13453. {
  13454. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13455. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13456. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13457. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13458. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13459. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13460. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13461. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13462. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13463. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13464. }
  13465. else
  13466. {
  13467. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13468. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13469. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13470. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13471. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13472. }
  13473. }
  13474. }
  13475. }
  13476. //end of Stacking Charging Profiles
  13477. }
  13478. }// the end of ACCESS TxDefaultProfile
  13479. //****************************TxProfile************************************************/
  13480. switch(gunindex + 1)
  13481. {
  13482. case 0:
  13483. break;
  13484. case 1:
  13485. strcpy(fname, TxProfile_1_JSON );
  13486. break;
  13487. case 2:
  13488. strcpy(fname, TxProfile_2_JSON );
  13489. break;
  13490. default:
  13491. strcpy(fname, TxProfile_1_JSON );
  13492. break;
  13493. }
  13494. TxProfileIsNull=TRUE;
  13495. if((access(fname,F_OK))!=-1)
  13496. {
  13497. fptr1 = fopen(fname, "r");
  13498. c = 0;
  13499. c = fgetc(fptr1);
  13500. //DEBUG_INFO("c:%d\n",c);
  13501. rewind(fptr1);
  13502. if(c == EOF)
  13503. {
  13504. DEBUG_INFO("\n End of file reached.");
  13505. TxProfileIsNull=TRUE;
  13506. fclose(fptr1);
  13507. }
  13508. else
  13509. {
  13510. TxProfileIsNull=FALSE;
  13511. while(fscanf(fptr1, "%s", word) != EOF)
  13512. {
  13513. if(strcmp(word, "chargingProfileId") == 0)
  13514. {
  13515. n_chargingProfile = n_chargingProfile + 1;
  13516. }
  13517. }
  13518. rewind(fptr1);
  13519. //search Charging Profile Element
  13520. int i= 0;
  13521. int j= 0;
  13522. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13523. #if 0
  13524. /***********connectorId****************/
  13525. c = 0;
  13526. loc = strstr(sLineWord, "connectorId");
  13527. memset(sstr ,0, sizeof(sstr) );
  13528. while (loc[strlen("connectorId")+2+c] != ',')
  13529. {
  13530. sstr[c] = loc[strlen("connectorId")+2+c];
  13531. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13532. c++;
  13533. }
  13534. sstr[c] = '\0';
  13535. tempconnectorIdInt = atoi(sstr);
  13536. #endif
  13537. //***********chargingProfileId**************/
  13538. c = 0;
  13539. loc = strstr(sLineWord, "chargingProfileId");
  13540. memset(sstr ,0, sizeof(sstr) );
  13541. if(loc != NULL)
  13542. {
  13543. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13544. {
  13545. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13546. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13547. c++;
  13548. }
  13549. sstr[c] = '\0';
  13550. tempchargingProfileId = atoi(sstr);
  13551. }
  13552. else
  13553. {
  13554. tempchargingProfileId = 0;
  13555. }
  13556. //***********transactionId **************/
  13557. c = 0;
  13558. loc = strstr(sLineWord, "transactionId");
  13559. //DEBUG_INFO("loc=%s\n",loc);
  13560. memset(sstr ,0, sizeof(sstr) );
  13561. if(loc != NULL)
  13562. {
  13563. while (loc[2+strlen("transactionId")+c] != '\"')
  13564. {
  13565. sstr[c] = loc[2+strlen("transactionId")+c];
  13566. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13567. c++;
  13568. }
  13569. sstr[c] = '\0';
  13570. temptransactionId = atoi(sstr);
  13571. }
  13572. else
  13573. {
  13574. temptransactionId = 0;
  13575. }
  13576. //***********stackLevel**************/
  13577. c = 0;
  13578. loc = strstr(sLineWord, "stackLevel");
  13579. //DEBUG_INFO("loc=%s\n",loc);
  13580. memset(sstr ,0, sizeof(sstr) );
  13581. if(loc != NULL)
  13582. {
  13583. while (loc[2+strlen("stackLevel")+c] != '\"')
  13584. {
  13585. sstr[c] = loc[2+strlen("stackLevel")+c];
  13586. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13587. c++;
  13588. }
  13589. sstr[c] = '\0';
  13590. tempstackLevel = atoi(sstr);
  13591. }
  13592. else
  13593. {
  13594. tempstackLevel = 0;
  13595. }
  13596. //***********chargingProfilePurpose **************/
  13597. c = 0;
  13598. loc = strstr(sLineWord, "chargingProfilePurpose");
  13599. //DEBUG_INFO("loc=%s\n",loc);
  13600. memset(sstr ,0, sizeof(sstr) );
  13601. if(loc != NULL)
  13602. {
  13603. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13604. {
  13605. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13606. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13607. c++;
  13608. }
  13609. sstr[c] = '\0';
  13610. strcpy(tempchargingProfilePurposeStr,sstr);
  13611. }
  13612. else
  13613. {
  13614. strcpy(tempchargingProfilePurposeStr,"");
  13615. }
  13616. //***********chargingProfileKind **************/
  13617. c = 0;
  13618. loc = strstr(sLineWord, "chargingProfileKind");
  13619. //DEBUG_INFO("loc=%s\n",loc);
  13620. memset(sstr ,0, sizeof(sstr) );
  13621. if(loc != NULL)
  13622. {
  13623. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13624. {
  13625. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13626. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13627. c++;
  13628. }
  13629. sstr[c] = '\0';
  13630. strcpy(tempchargingProfileKindStr,sstr);
  13631. }
  13632. else
  13633. {
  13634. strcpy(tempchargingProfileKindStr,"");
  13635. }
  13636. //***********recurrencyKind **************/
  13637. c = 0;
  13638. loc = strstr(sLineWord, "recurrencyKind");
  13639. //DEBUG_INFO("loc=%s\n",loc);
  13640. memset(sstr ,0, sizeof(sstr) );
  13641. if(loc != NULL)
  13642. {
  13643. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13644. {
  13645. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13646. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13647. c++;
  13648. }
  13649. sstr[c] = '\0';
  13650. strcpy(temprecurrencyKindStr,sstr);
  13651. }
  13652. else
  13653. {
  13654. strcpy(temprecurrencyKindStr,"");
  13655. }
  13656. //***********validFrom**************/
  13657. c = 0;
  13658. loc = strstr(sLineWord, "validFrom");
  13659. if(loc != NULL)
  13660. {
  13661. memset(sstr ,0, sizeof(sstr) );
  13662. while (loc[3+strlen("validFrom")+c] != '\"')
  13663. {
  13664. sstr[c] = loc[3+strlen("validFrom")+c];
  13665. c++;
  13666. }
  13667. sstr[c] = '\0';
  13668. strcpy(tempvalidFromStr,sstr);
  13669. }
  13670. else
  13671. {
  13672. strcpy(tempvalidFromStr,"");
  13673. }
  13674. //***********validTo**************/
  13675. c = 0;
  13676. loc = strstr(sLineWord, "validTo");
  13677. if(loc != NULL)
  13678. {
  13679. memset(sstr ,0, sizeof(sstr) );
  13680. while (loc[3+strlen("validTo")+c] != '\"')
  13681. {
  13682. sstr[c] = loc[3+strlen("validTo")+c];
  13683. c++;
  13684. }
  13685. sstr[c] = '\0';
  13686. strcpy(tempvalidToStr,sstr);
  13687. }
  13688. else
  13689. {
  13690. strcpy(tempvalidToStr,"");
  13691. }
  13692. //***********duration**************/
  13693. c = 0;
  13694. loc = strstr(sLineWord, "duration");
  13695. //DEBUG_INFO("loc=%s\n",loc);
  13696. memset(sstr ,0, sizeof(sstr) );
  13697. if(loc != NULL)
  13698. {
  13699. while (loc[2+strlen("duration")+c] != '\"')
  13700. {
  13701. sstr[c] = loc[2+strlen("duration")+c];
  13702. c++;
  13703. }
  13704. sstr[c] = '\0';
  13705. tempdurationInt = atoi(sstr);
  13706. }
  13707. else
  13708. {
  13709. tempdurationInt = 0;
  13710. }
  13711. //**********startSchedule**********/
  13712. c = 0;
  13713. loc = strstr(sLineWord, "startSchedule");
  13714. memset(sstr ,0, sizeof(sstr) );
  13715. while (loc[3+strlen("startSchedule")+c] != '\"')
  13716. {
  13717. sstr[c] = loc[3+strlen("startSchedule")+c];
  13718. c++;
  13719. }
  13720. sstr[c] = '\0';
  13721. strcpy(tempstartScheduleStr, sstr);
  13722. strcpy(TxProfileScheduleStr, sstr);
  13723. //**********chargingRateUnit**********/
  13724. c = 0;
  13725. loc = strstr(sLineWord, "chargingRateUnit");
  13726. memset(sstr ,0, sizeof(sstr) );
  13727. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13728. {
  13729. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13730. c++;
  13731. }
  13732. sstr[c] = '\0';
  13733. strcpy(tempchargingRateUnitStr, sstr);
  13734. //**********minChargingRate*******/
  13735. c = 0;
  13736. loc = strstr(sLineWord, "minChargingRate");
  13737. if(loc != NULL)
  13738. {
  13739. memset(sstr ,0, sizeof(sstr) );
  13740. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13741. {
  13742. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13743. c++;
  13744. }
  13745. sstr[c] = '\0';
  13746. tempminChargingRateFloat = atof(sstr);
  13747. }
  13748. else
  13749. {
  13750. tempminChargingRateFloat = 0.0;
  13751. }
  13752. //
  13753. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13754. tp.tm_isdst = -1;
  13755. time_t utc = mktime(&tp);
  13756. time_t t = time(NULL);
  13757. diff_t = difftime(t, utc);
  13758. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13759. //parsing strings to words
  13760. i = 0;
  13761. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13762. loc = loc+3+strlen("chargingSchedulePeriod");
  13763. pch = strtok(loc ,"{");
  13764. while (pch != NULL)
  13765. {
  13766. strcpy(SchedulePeriodList[i], pch);
  13767. pch = strtok (NULL, "{");
  13768. i = i + 1;
  13769. }
  13770. n_SchedulePeriods = i;
  13771. for(int i=0;i<n_SchedulePeriods;i++)
  13772. {
  13773. //*************startPeriod****************/
  13774. c = 0;
  13775. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13776. memset(sstr ,0, sizeof(sstr) );
  13777. while (loc[strlen("startPeriod")+2+c] != ',')
  13778. {
  13779. sstr[c] = loc[strlen("startPeriod")+2+c];
  13780. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13781. c++;
  13782. }
  13783. sstr[c] = '\0';
  13784. tempStartPeriodInt = atoi(sstr);
  13785. //*************limit****************/
  13786. c = 0;
  13787. loc = strstr(SchedulePeriodList[i], "limit");
  13788. memset(sstr ,0, sizeof(sstr) );
  13789. while (loc[strlen("limit")+2+c] != ',')
  13790. {
  13791. sstr[c] = loc[strlen("limit")+2+c];
  13792. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13793. c++;
  13794. }
  13795. sstr[c] = '\0';
  13796. tempLimitInt = atof(sstr);
  13797. //*************numberPhases****************/
  13798. c = 0;
  13799. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13800. memset(sstr ,0, sizeof(sstr) );
  13801. while (loc[strlen("numberPhases")+2+c] != '}')
  13802. {
  13803. sstr[c] = loc[strlen("numberPhases")+2+c];
  13804. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13805. c++;
  13806. }
  13807. sstr[c] = '\0';
  13808. tempNumberPhasesInt = atoi(sstr);
  13809. //TxProfile.Duration = durationInt;
  13810. TxProfile.TotalPeriod = n_SchedulePeriods;
  13811. TxProfile.Period[i].Limit = tempLimitInt;
  13812. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13813. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13814. }
  13815. if(MinChargingRate < tempminChargingRateFloat)
  13816. {
  13817. MinChargingRate = tempminChargingRateFloat;
  13818. }
  13819. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13820. if(confirmPeriods < n_SchedulePeriods)
  13821. confirmPeriods = n_SchedulePeriods;
  13822. if(j == 0)
  13823. {
  13824. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13825. TxProfile_TEMP.StackLevel = tempstackLevel;
  13826. TxProfile_TEMP.TransactionId = 0;
  13827. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13828. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13829. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13830. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13831. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13832. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13833. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13834. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13835. }
  13836. }
  13837. fclose(fptr1);
  13838. }
  13839. }// the end of ACCESS TxProfile
  13840. //CompositeSchedule
  13841. int period=0;
  13842. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13843. {
  13844. //TxProfile
  13845. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13846. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13847. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13848. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13849. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13850. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13851. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13852. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13853. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13854. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13855. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13856. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13857. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13858. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13859. {
  13860. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13861. {
  13862. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13863. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13864. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13865. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13866. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13867. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13868. period = period + 1;
  13869. }
  13870. else
  13871. {
  13872. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13873. {
  13874. }
  13875. else
  13876. {
  13877. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13878. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13879. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13880. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13881. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13882. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13883. period = period + 1;
  13884. }
  13885. }
  13886. }
  13887. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13888. {
  13889. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  13890. {
  13891. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13892. {
  13893. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13894. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13895. }
  13896. else
  13897. {
  13898. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13899. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13900. }
  13901. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13902. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13903. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13904. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13905. period = period + 1;
  13906. }
  13907. }
  13908. }
  13909. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13910. {
  13911. //TxDefaultProfile
  13912. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13913. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13914. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13915. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13916. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  13917. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13918. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13919. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13920. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13921. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13922. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13923. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13924. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13925. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13926. {
  13927. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13928. {
  13929. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13930. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13931. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13932. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13933. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13934. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13935. period = period + 1;
  13936. }
  13937. else
  13938. {
  13939. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13940. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13941. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13942. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13943. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13944. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13945. period = period + 1;
  13946. }
  13947. }
  13948. }
  13949. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  13950. {
  13951. //TxDefaultProfile
  13952. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13953. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13954. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13955. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13956. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  13957. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13958. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13959. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13960. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13961. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13962. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13963. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13964. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13965. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13966. {
  13967. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13968. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13969. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13970. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13971. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13972. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13973. period = period + 1;
  13974. }
  13975. }
  13976. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13977. {
  13978. //ChargePointMaxProfile
  13979. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  13980. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  13981. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13982. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  13983. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  13984. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13985. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13986. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  13987. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  13988. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  13989. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  13990. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  13991. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  13992. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  13993. {
  13994. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  13995. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  13996. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  13997. period = period + 1;
  13998. }
  13999. }
  14000. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14001. {
  14002. //TxProfile
  14003. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14004. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14005. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14006. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14007. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14008. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14009. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14010. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14011. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14012. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14013. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14014. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14015. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14016. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14017. {
  14018. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  14019. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  14020. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  14021. }
  14022. }
  14023. confirmPeriods = period;
  14024. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14025. 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,"
  14026. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14027. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14028. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14029. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14030. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14031. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14032. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14033. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14034. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14035. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14036. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14037. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14038. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14039. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14040. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14041. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14042. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14043. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14044. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14045. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14046. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14047. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14048. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14049. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14050. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14051. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14052. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14053. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14054. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14055. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14056. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14057. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14058. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14059. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14060. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14061. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14062. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14063. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14064. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14065. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14066. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14067. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14068. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14069. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14070. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14071. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14072. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14073. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14074. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14075. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14076. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14077. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14078. }
  14079. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14080. {
  14081. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14082. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14083. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14084. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14085. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14086. }
  14087. int GetWebSocketPingInterval(void)
  14088. {
  14089. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14090. }
  14091. void LWS_Send(char * str)
  14092. {
  14093. //=====================================================
  14094. // Check InternetConn 0: disconnected, 1: connected
  14095. //====================================================
  14096. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14097. {
  14098. DEBUG_INFO("\n offline now !!!\n");
  14099. return;
  14100. }
  14101. pthread_mutex_lock(&lock);
  14102. memset(SendBuffer,0,SendBufLen);
  14103. sprintf((char *)SendBuffer, "%s", str);
  14104. pthread_mutex_unlock(&lock);
  14105. lws_callback_on_writable(wsi_client);
  14106. lws_service(context, 10000);//timeout_ms
  14107. }