MessageHandler.c 612 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "define.h"
  21. #include <sys/socket.h>
  22. #include <netinet/in.h>
  23. #include <stdlib.h>
  24. /*for sendfile()*/
  25. #include <sys/sendfile.h>
  26. /*for O_RDONLY*/
  27. #include <fcntl.h>
  28. #include "sqlite3.h"
  29. #include <arpa/inet.h>
  30. #include <time.h>
  31. #include <assert.h>
  32. #include <pthread.h>
  33. #include <mcheck.h>
  34. #include "MessageHandler.h"
  35. #include "SystemLogMessage.h"
  36. #include "hashmap.h"
  37. #include "ShareMemory.h"
  38. #include "TransactionQueue.h"
  39. #define PASS 1
  40. #define FAIL -1
  41. #define FALSE 0
  42. #define TRUE 1 // Option 1
  43. //ChargePointMaxProfile
  44. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  45. //TxDefaultProfile
  46. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  47. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  48. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  49. //TxProfile
  50. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  51. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  52. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  53. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  54. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  55. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  56. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  57. //===================================
  58. // Define CP State constant
  59. //===================================
  60. #define CP_STATE_UNKNOWN 0
  61. #define CP_STATE_A 1
  62. #define CP_STATE_B 2
  63. #define CP_STATE_C 3
  64. #define CP_STATE_D 4
  65. #define CP_STATE_E 5
  66. #define CP_STATE_F 6
  67. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  68. struct StatusCodeData *ShmStatusCodeData;
  69. struct PsuData *ShmPsuData ;
  70. struct OCPP16Data *ShmOCPP16Data;
  71. // define Macro
  72. #define SystemLogMessage
  73. // OCPP Message Type
  74. #define MESSAGE_TYPE_CALL 2
  75. #define MESSAGE_TYPE_CALLRESULT 3
  76. #define MESSAGE_TYPE_CALLERROR 4
  77. //
  78. //#define server_cycle_Status 120
  79. #define MACROSTR(k) #k
  80. //ConfigurationMaxKeys
  81. #define GetConfigurationMaxKeysNUM 43
  82. //char guid[37];
  83. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  84. char queuedata[2600]={0};
  85. //=================================
  86. // StatusNotification cycle
  87. //=================================
  88. static int server_cycle_Status = 120;
  89. //===============================
  90. // Configuration: unknownkey
  91. //===============================
  92. static char unknownkey[10][20]={0};
  93. static int UnknownKeynum = 0;
  94. //===============================
  95. // Gun Total Numbers
  96. //===============================
  97. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  98. static int gunTotalNumber=0;
  99. //===============================
  100. // Local List Version
  101. //===============================
  102. static int localversion=0;
  103. static char idTagAuthorization[32]={0};
  104. //===============================
  105. // OCPP Path
  106. //===============================
  107. extern char OcppPath[160];
  108. extern char OcppProtocol[10];
  109. extern char OcppHost[50];
  110. extern char OcppTempPath[50];
  111. int OcppPort=0;
  112. //===============================
  113. // OCPP sign variable
  114. //===============================
  115. int server_sign = FALSE;
  116. int server_pending = FALSE;
  117. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  118. int BootNotificationInterval = 0;
  119. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  120. //===============================
  121. // OCPP auth variable
  122. //===============================
  123. int authenrequest = FALSE;
  124. int authorizeRetryTimes = 0; //number of Retry times
  125. //===============================
  126. // OCPP StartTransaction transactionId variables
  127. //===============================
  128. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  129. //===============================
  130. // OCPP other variables
  131. //===============================
  132. int isUpdateRequest = FALSE;
  133. static int HeartBeatWaitTime = 10;
  134. static int FirstHeartBeat = 0;
  135. static int FirmwareStatusNotificationStatus = 3; // Idle
  136. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  137. static char CurrentChargingProfileScheduleStr[30]={0};
  138. //========================================
  139. // OCPP status/previous related variables
  140. //========================================
  141. static int GunStatusInterval = 10;
  142. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  143. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  144. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  145. static int GbPreviousSystemStatus[GB_QUANTITY];
  146. static int AcPreviousSystemStatus[AC_QUANTITY];
  147. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  148. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  149. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  150. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  151. int TransactionMessageAttemptsValue = 0;
  152. int TransactionMessageRetryIntervalValue = 0;
  153. static struct OCPPAuthLocalElemet
  154. {
  155. int listVersionInt;
  156. char idTagstr[20];
  157. char parentIdTag[20];
  158. char expiryDate[30];
  159. char idTagstatus[16];
  160. }idTagQuery;
  161. //=============================================
  162. // OCPP HeartBeat Response Not Receive Counts
  163. //============================================
  164. static int HeartBeatWithNOResponse = 0;
  165. static int HeartBeatCountPerHour = 0;
  166. extern struct lws *wsi_client;
  167. extern struct lws_context *context;
  168. extern unsigned char SendBuffer[4096];
  169. extern int SendBufLen;
  170. extern char *random_uuid( char buf[37] );
  171. extern void split(char **arr, char *str, const char *del);
  172. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  173. extern int GetTransactionQueueNum(void);
  174. extern pthread_mutex_t mutex1;
  175. extern struct Charger_Info Charger;
  176. extern sqlite3 *db;
  177. int TransactionMessageAttemptsGet(void);
  178. int TransactionMessageRetryIntervalGet(void);
  179. int GetOcppConnStatus(void);
  180. void SetOcppConnStatus(uint8_t status);
  181. int updateSetting(char *key, char *value);
  182. int setKeyValue(char *key, char *value);
  183. void OCPP_get_TableAuthlocalAllData(void);
  184. void processUnkownKey(void);
  185. struct StructOCPPMeterValue
  186. {
  187. unsigned char TimeStamp[28];
  188. struct StructSampledValue SampledValue[10];
  189. };
  190. struct ClientTime
  191. {
  192. unsigned int Heartbeat;
  193. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  194. unsigned int StartTransaction;
  195. unsigned int StopTransaction;
  196. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  197. }clientTime;
  198. typedef union
  199. {
  200. //Operations Initiated by Central System
  201. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  202. struct
  203. {
  204. //CsMsgValue[0]
  205. unsigned char StatusNotificationReq :1; //bit 0,
  206. unsigned char StatusNotificationConf :1; //bit 0,
  207. unsigned char :6; //bit 2~7
  208. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  209. }CpinitiateMsg;
  210. CpinitiateMsg cpinitateMsg;
  211. //==========================================
  212. // Init all Enumeration & Mapping String
  213. //==========================================
  214. /*ChargePointErrorCode*/
  215. typedef enum {
  216. ConnectorLockFailure,
  217. EVCommunicationError,
  218. GroundFailure,
  219. HighTemperature,
  220. InternalError,
  221. LocalListConflict,
  222. NoError,
  223. OtherError,
  224. OverCurrentFailure,
  225. OverVoltage,
  226. PowerMeterFailure,
  227. PowerSwitchFailure,
  228. ReaderFailure,
  229. ResetFailure,
  230. UnderVoltage,
  231. WeakSignal
  232. } ChargePointErrorCode;
  233. #if 0
  234. static char *ChargePointErrorCodeStr[] = {
  235. MACROSTR(ConnectorLockFailure),
  236. MACROSTR(EVCommunicationError),
  237. MACROSTR(GroundFailure),
  238. MACROSTR(HighTemperature),
  239. MACROSTR(InternalError),
  240. MACROSTR(LocalListConflict),
  241. MACROSTR(NoError),
  242. MACROSTR(OtherError),
  243. MACROSTR(OverCurrentFailure),
  244. MACROSTR(OverVoltage),
  245. MACROSTR(PowerMeterFailure),
  246. MACROSTR(PowerSwitchFailure),
  247. MACROSTR(ReaderFailure),
  248. MACROSTR(ResetFailure),
  249. MACROSTR(UnderVoltage),
  250. MACROSTR(WeakSignal)
  251. };
  252. #endif
  253. /*ChargePointStatus*/
  254. typedef enum {
  255. Available =0,
  256. Preparing,
  257. Charging,
  258. SuspendedEVSE,
  259. SuspendedEV,
  260. Finishing,
  261. Reserved,
  262. Unavailable,
  263. Faulted
  264. } ChargePointStatus;
  265. static char * ChargePointStatusStr[] = {
  266. MACROSTR(Available),
  267. MACROSTR(Preparing),
  268. MACROSTR(Charging),
  269. MACROSTR(SuspendedEVSE),
  270. MACROSTR(SuspendedEV),
  271. MACROSTR(Finishing),
  272. MACROSTR(Reserved),
  273. MACROSTR(Unavailable),
  274. MACROSTR(Faulted)
  275. };
  276. /*AvailabilityType*/
  277. typedef enum {
  278. RegistrationStatus_Accepted,
  279. RegistrationStatus_Pending,
  280. RegistrationStatus_Rejected
  281. } RegistrationStatus;
  282. static char *RegistrationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Pending),
  285. MACROSTR(Rejected)
  286. };
  287. /*AvailabilityType*/
  288. typedef enum {
  289. Inoperative,
  290. Operative
  291. } AvailabilityType;
  292. static char *AvailabilityTypeStr[] = {
  293. MACROSTR(Inoperative),
  294. MACROSTR(Operative)
  295. };
  296. /*AvailabilityStatus*/
  297. typedef enum {
  298. Accepted,
  299. Rejected,
  300. Scheduled
  301. } AvailabilityStatus;
  302. static char *AvailabilityStatusStr[] = {
  303. MACROSTR(Accepted),
  304. MACROSTR(Rejected),
  305. MACROSTR(Scheduled)
  306. };
  307. /*ConfigurationStatus*/
  308. typedef enum {
  309. ConfigurationStatus_Accepted,
  310. ConfigurationStatus_Rejected,
  311. RebootRequired,
  312. NotSupported
  313. } ConfigurationStatus;
  314. static char *ConfigurationStatusStr[] = {
  315. MACROSTR(Accepted),
  316. MACROSTR(Rejected),
  317. MACROSTR(RebootRequired),
  318. MACROSTR(NotSupported)
  319. };
  320. /*ClearCacheStatus*/
  321. typedef enum {
  322. ClearCacheStatus_Accepted,
  323. ClearCacheStatus_Rejected
  324. } ClearCacheStatus;
  325. static char *ClearCacheStatusStr[] = {
  326. MACROSTR(Accepted),
  327. MACROSTR(Rejected)
  328. };
  329. /*ChargingProfilePurposeType*/
  330. typedef enum {
  331. ChargePointMaxProfile,
  332. TxDefaultProfile,
  333. TxProfile
  334. } ChargingProfilePurposeType;
  335. static char *ChargingProfilePurposeTypeStr[] = {
  336. MACROSTR(ChargePointMaxProfile),
  337. MACROSTR(TxDefaultProfile),
  338. MACROSTR(TxProfile)
  339. };
  340. /*ChargingProfileStatus*/
  341. typedef enum {
  342. ChargingProfileStatus_Accepted,
  343. ChargingProfileStatus_Rejected,
  344. ChargingProfileStatus_NotSupported
  345. } ChargingProfileStatus;
  346. static char *ChargingProfileStatusStr[] = {
  347. MACROSTR(Accepted),
  348. MACROSTR(Rejected),
  349. MACROSTR(NotSupported)
  350. };
  351. /*ClearChargingProfileStatus*/
  352. typedef enum {
  353. ClearChargingProfileStatus_Accepted,
  354. ClearChargingProfileStatus_Unknown
  355. } ClearChargingProfileStatus;
  356. static char *ClearChargingProfileStatusStr[] = {
  357. MACROSTR(Accepted),
  358. MACROSTR(Unknown)
  359. };
  360. /*GetCompositeScheduleStatus*/
  361. typedef enum {
  362. GetCompositeScheduleStatus_Accepted,
  363. GetCompositeScheduleStatus_Rejected
  364. } GetCompositeScheduleStatus;
  365. static char *GetCompositeScheduleStatusStr[] = {
  366. MACROSTR(Accepted),
  367. MACROSTR(Rejected)
  368. };
  369. /*ChargingRateUnitType*/
  370. typedef enum {
  371. ChargingRateUnitType_W,
  372. ChargingRateUnitType_A
  373. } ChargingRateUnitType;
  374. /*AuthorizationStatus*/
  375. typedef enum {
  376. AuthorizationStatus_Accepted ,
  377. AuthorizationStatus_Blocked ,
  378. AuthorizationStatus_Expired ,
  379. AuthorizationStatus_Invalid ,
  380. AuthorizationStatus_ConcurrentTx
  381. } AuthorizationStatus;
  382. /*UpdateType*/
  383. typedef enum {
  384. Differential ,
  385. Full
  386. } UpdateType;
  387. static char *UpdateTypeStr[] = {
  388. MACROSTR(Differential),
  389. MACROSTR(Full)
  390. };
  391. /*UpdateStatus*/
  392. typedef enum {
  393. UpdateStatus_Accepted ,
  394. UpdateStatus_Failed ,
  395. UpdateStatus_NotSupported ,
  396. UpdateStatus_VersionMismatch
  397. } UpdateStatus;
  398. static char *UpdateStatusStr[] = {
  399. MACROSTR(Accepted),
  400. MACROSTR(Failed),
  401. MACROSTR(NotSupported),
  402. MACROSTR(VersionMismatch)
  403. };
  404. /*RemoteStartStopStatus*/
  405. typedef enum {
  406. RemoteStartStopStatus_Accepted,
  407. RemoteStartStopStatus_Rejected
  408. } RemoteStartStopStatus;
  409. static char *RemoteStartStopStatusStr[] = {
  410. MACROSTR(Accepted),
  411. MACROSTR(Rejected)
  412. };
  413. /*ReservationStatus*/
  414. typedef enum {
  415. ReservationStatus_Accepted,
  416. ReservationStatus_Faulted,
  417. ReservationStatus_Occupied,
  418. ReservationStatus_Rejected,
  419. ReservationStatus_Unavailable
  420. } ReservationStatus;
  421. static char *ReservationStatusStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Faulted),
  424. MACROSTR(Occupied),
  425. MACROSTR(Rejected),
  426. MACROSTR(Unavailable)
  427. };
  428. /*ResetType*/
  429. typedef enum {
  430. Hard,
  431. Soft
  432. } ResetType;
  433. static char *ResetTypeStr[] = {
  434. MACROSTR(Hard),
  435. MACROSTR(Soft)
  436. };
  437. /*ResetStatus*/
  438. typedef enum {
  439. ResetStatus_Accepted,
  440. ResetStatus_Rejected
  441. } ResetStatus;
  442. static char *ResetStatusStr[] = {
  443. MACROSTR(Accepted),
  444. MACROSTR(Rejected)
  445. };
  446. /*DiagnosticsStatus*/
  447. typedef enum {
  448. DiagnosticsStatus_Idle,
  449. DiagnosticsStatus_Uploaded,
  450. DiagnosticsStatus_UploadFailed,
  451. DiagnosticsStatus_Uploading
  452. } DiagnosticsStatus;
  453. static char * DiagnosticsStatusStr[] = {
  454. MACROSTR(Idle),
  455. MACROSTR(Uploaded),
  456. MACROSTR(UploadFailed),
  457. MACROSTR(Uploading)
  458. };
  459. /*FirmwareStatus*/
  460. typedef enum {
  461. FirmwareStatus_Downloaded,
  462. FirmwareStatus_DownloadFailed,
  463. FirmwareStatus_Downloading,
  464. FirmwareStatus_Idle,
  465. FirmwareStatus_InstallationFailed,
  466. FirmwareStatus_Installing,
  467. FirmwareStatus_Installed
  468. } FirmwareStatus;
  469. static char * FirmwareStatusStr[] = {
  470. MACROSTR(Downloaded),
  471. MACROSTR(DownloadFailed),
  472. MACROSTR(Downloading),
  473. MACROSTR(Idle),
  474. MACROSTR(InstallationFailed),
  475. MACROSTR(Installing),
  476. MACROSTR(Installed)
  477. };
  478. /*MessageTrigger*/
  479. typedef enum {
  480. BootNotification,
  481. DiagnosticsStatusNotification,
  482. FirmwareStatusNotification,
  483. Heartbeat,
  484. MeterValues,
  485. StatusNotification
  486. } MessageTrigger;
  487. static char * MessageTriggerStr[] = {
  488. MACROSTR(BootNotification),
  489. MACROSTR(DiagnosticsStatusNotification),
  490. MACROSTR(FirmwareStatusNotification),
  491. MACROSTR(Heartbeat),
  492. MACROSTR(MeterValues),
  493. MACROSTR(StatusNotification)
  494. };
  495. /*TriggerMessageStatus*/
  496. typedef enum {
  497. TriggerMessageStatus_Accepted ,
  498. TriggerMessageStatus_Rejected ,
  499. TriggerMessageStatus_NotImplemented
  500. } TriggerMessageStatus;
  501. static char * TriggerMessageStatusStr[] = {
  502. MACROSTR(Accepted),
  503. MACROSTR(Rejected),
  504. MACROSTR(NotImplemented)
  505. };
  506. /*UnlockStatus*/
  507. typedef enum {
  508. Unlocked,
  509. UnlockFailed,
  510. UnlockStatus_NotSupported
  511. } UnlockStatus;
  512. static char * UnlockStatusStr[] = {
  513. MACROSTR(Unlocked),
  514. MACROSTR(UnlockFailed),
  515. MACROSTR(NotSupported)
  516. };
  517. /*StopTransactionReason*/
  518. typedef enum {
  519. EmergencyStop,
  520. EVDisconnected,
  521. HardReset,
  522. Local,
  523. Other,
  524. PowerLoss,
  525. Reboot,
  526. Remote,
  527. SoftReset,
  528. UnlockCommand,
  529. DeAuthorized
  530. } StopTransactionReason;
  531. #if 0
  532. static char * StopTransactionReasonStr[] = {
  533. MACROSTR(EmergencyStop),
  534. MACROSTR(EVDisconnected),
  535. MACROSTR(HardReset),
  536. MACROSTR(Local),
  537. MACROSTR(Other),
  538. MACROSTR(PowerLoss),
  539. MACROSTR(Reboot),
  540. MACROSTR(Remote),
  541. MACROSTR(SoftReset),
  542. MACROSTR(UnlockCommand),
  543. MACROSTR(DeAuthorized)
  544. };
  545. #endif
  546. /*CancelReservationStatus*/
  547. typedef enum {
  548. CancelReservationStatus_Accepted,
  549. CancelReservationStatus_Rejected
  550. } CancelReservationStatus;
  551. static char * CancelReservationStatusStr[] = {
  552. MACROSTR(Accepted),
  553. MACROSTR(Rejected)
  554. };
  555. /*ReadingContext*/
  556. typedef enum {
  557. ReadingContext_Interruption_Begin,
  558. ReadingContext_Interruption_End,
  559. ReadingContext_Other,
  560. ReadingContext_Sample_Clock,
  561. ReadingContext_Sample_Periodic ,
  562. ReadingContext_Transaction_Begin ,
  563. ReadingContext_Transaction_End,
  564. ReadingContext_Trigger
  565. } ReadingContext;
  566. static char * ReadingContextStr[] = {
  567. MACROSTR(Interruption.Begin),
  568. MACROSTR(Interruption.End),
  569. MACROSTR(Other),
  570. MACROSTR(Sample.Clock),
  571. MACROSTR(Sample.Periodic),
  572. MACROSTR(Transaction.Begin),
  573. MACROSTR(Transaction.End),
  574. MACROSTR(Trigger)
  575. };
  576. /*ValueFormat*/
  577. typedef enum {
  578. Raw,
  579. SignedData
  580. } ValueFormat;
  581. static char * ValueFormatStr[] = {
  582. MACROSTR(Raw),
  583. MACROSTR(SignedData)
  584. };
  585. /*Measurand*/
  586. typedef enum {
  587. Current_Export ,
  588. Current_Import,
  589. Current_Offered,
  590. Energy_Active_Export_Register,
  591. Energy_Active_Import_Register,
  592. Energy_Reactive_Export_Register,
  593. Energy_Reactive_Import_Register,
  594. Energy_Active_Export_Interval,
  595. Energy_Active_Import_Interval,
  596. Energy_Reactive_Export_Interval,
  597. Energy_Reactive_Import_Interval,
  598. Frequency,
  599. Power_Active_Export ,
  600. Power_Active_Import,
  601. Power_Factor,
  602. Power_Offered,
  603. Power_Reactive_Export,
  604. Power_Reactive_Import,
  605. RPM,
  606. SoC,
  607. Temperature ,
  608. Voltage
  609. } Measurand;
  610. static char * MeasurandStr[] = {
  611. MACROSTR(Current.Export),
  612. MACROSTR(Current.Import),
  613. MACROSTR(Current.Offered),
  614. MACROSTR(Energy.Active.Export.Register),
  615. MACROSTR(Energy.Active.Import.Register),
  616. MACROSTR(Energy.Reactive.Export.Register),
  617. MACROSTR(Energy.Reactive.Import.Register),
  618. MACROSTR(Energy.Active.Export.Interval),
  619. MACROSTR(Energy.Active.Import.Interval),
  620. MACROSTR(Energy.Reactive.Export.Interval),
  621. MACROSTR(Energy.Reactive.Import.Interval),
  622. MACROSTR(Frequency),
  623. MACROSTR(Power.Active.Export),
  624. MACROSTR(Power.Active.Import),
  625. MACROSTR(Power.Factor),
  626. MACROSTR(Power.Offered),
  627. MACROSTR(Power.Reactive.ExportMACROSTR),
  628. MACROSTR(Power.Reactive.Import),
  629. MACROSTR(RPM),
  630. MACROSTR(SoC),
  631. MACROSTR(Temperature),
  632. MACROSTR(Voltage)
  633. };
  634. /*Location*/
  635. typedef enum {
  636. Location_Body,
  637. Location_Cable,
  638. Location_EV,
  639. Location_Inlet ,
  640. Location_Outlet
  641. } Location;
  642. static char * LocationStr[] = {
  643. MACROSTR(Body),
  644. MACROSTR(Cable),
  645. MACROSTR(EV),
  646. MACROSTR(Inlet),
  647. MACROSTR(Outlet)
  648. };
  649. /*Phase*/
  650. typedef enum {
  651. L1,
  652. L2,
  653. L3,
  654. N,
  655. L1_N,
  656. L2_N,
  657. L3_N,
  658. L1_L2,
  659. L2_L3,
  660. L3_L1
  661. } Phase;
  662. static char * PhaseStr[] = {
  663. MACROSTR(L1),
  664. MACROSTR(L2),
  665. MACROSTR(L3),
  666. MACROSTR(N),
  667. MACROSTR(L1-N),
  668. MACROSTR(L2-N),
  669. MACROSTR(L3-N),
  670. MACROSTR(L1-L2),
  671. MACROSTR(L2-L3),
  672. MACROSTR(L3-L1)
  673. };
  674. /*UnitOfMeasure*/
  675. typedef enum {
  676. UnitOfMeasure_Wh,
  677. UnitOfMeasure_kWh ,
  678. UnitOfMeasure_varh ,
  679. UnitOfMeasure_kvarh ,
  680. UnitOfMeasure_W ,
  681. UnitOfMeasure_kW ,
  682. UnitOfMeasure_VA ,
  683. UnitOfMeasure_kVA ,
  684. UnitOfMeasure_var ,
  685. UnitOfMeasure_kvar ,
  686. UnitOfMeasure_A ,
  687. UnitOfMeasure_V ,
  688. UnitOfMeasure_Celsius ,
  689. UnitOfMeasure_Fahrenheit ,
  690. UnitOfMeasure_K ,
  691. UnitOfMeasure_Percent
  692. } UnitOfMeasure;
  693. static char * UnitOfMeasureStr[] = {
  694. MACROSTR(Wh),
  695. MACROSTR(kWh),
  696. MACROSTR(varh),
  697. MACROSTR(kvarh),
  698. MACROSTR(W),
  699. MACROSTR(kW),
  700. MACROSTR(VA),
  701. MACROSTR(kVA),
  702. MACROSTR(var),
  703. MACROSTR(kvar),
  704. MACROSTR(A),
  705. MACROSTR(V),
  706. MACROSTR(Celsius),
  707. MACROSTR(Fahrenheit),
  708. MACROSTR(K),
  709. MACROSTR(Percent)
  710. };
  711. #if 0
  712. /*Configuration enum*/
  713. enum CoreProfile {
  714. AllowOfflineTxForUnknownId=0,
  715. AuthorizationCacheEnabled,
  716. AuthorizeRemoteTxRequests,
  717. BlinkRepeat,
  718. ClockAlignedDataInterval,
  719. ConnectionTimeOut,
  720. GetConfigurationMaxKeys,
  721. HeartbeatInterval,
  722. LightIntensity,
  723. LocalAuthorizeOffline,
  724. LocalPreAuthorize,
  725. MaxEnergyOnInvalidId,
  726. MeterValuesAlignedData,
  727. MeterValuesAlignedDataMaxLength,
  728. MeterValuesSampledData,
  729. MeterValuesSampledDataMaxLength,
  730. MeterValueSampleInterval,
  731. MinimumStatusDuration,
  732. NumberOfConnectors,
  733. ResetRetries,
  734. ConnectorPhaseRotation,
  735. ConnectorPhaseRotationMaxLength,
  736. StopTransactionOnEVSideDisconnect,
  737. StopTransactionOnInvalidId,
  738. StopTxnAlignedData,
  739. StopTxnAlignedDataMaxLength,
  740. StopTxnSampledData,
  741. StopTxnSampledDataMaxLength,
  742. SupportedFeatureProfiles,
  743. SupportedFeatureProfilesMaxLength,
  744. TransactionMessageAttempts,
  745. TransactionMessageRetryInterval,
  746. UnlockConnectorOnEVSideDisconnect,
  747. WebSocketPingInterval,
  748. _CoreProfile_CNT
  749. };
  750. #endif
  751. enum LocalAuthListManagementProfile{
  752. LocalAuthListEnabled=0,
  753. LocalAuthListMaxLength,
  754. SendLocalListMaxLength,
  755. _LocalAuthListManagementProfile_CNT
  756. };
  757. enum ReservationProfile{
  758. ReserveConnectorZeroSupported
  759. };
  760. enum SmartChargingProfile{
  761. ChargeProfileMaxStackLevel,
  762. ChargingScheduleAllowedChargingRateUnit,
  763. ChargingScheduleMaxPeriods,
  764. ConnectorSwitch3to1PhaseSupported,
  765. MaxChargingProfilesInstalled
  766. };
  767. enum ChargerSystemStatus{
  768. ChargerSystemStatus_Booting,
  769. ChargerSystemStatus_Idle,
  770. ChargerSystemStatus_Authorizing,
  771. ChargerSystemStatus_Preparing,
  772. ChargerSystemStatus_Charging,
  773. ChargerSystemStatus_Terminating,
  774. ChargerSystemStatus_Alarm,
  775. ChargerSystemStatus_Fault
  776. };
  777. enum GetConfigurationKey {
  778. GetConfiguration_AllowOfflineTxForUnknownId=0,
  779. GetConfiguration_AuthorizationCacheEnabled,
  780. GetConfiguration_AuthorizeRemoteTxRequests,
  781. GetConfiguration_BlinkRepeat,
  782. GetConfiguration_ClockAlignedDataInterval,
  783. GetConfiguration_ConnectionTimeOut,
  784. GetConfiguration_GetConfigurationMaxKeys,
  785. GetConfiguration_HeartbeatInterval,
  786. GetConfiguration_LightIntensity,
  787. GetConfiguration_LocalAuthorizeOffline,
  788. GetConfiguration_LocalPreAuthorize,
  789. GetConfiguration_MaxEnergyOnInvalidId,
  790. GetConfiguration_MeterValuesAlignedData,
  791. GetConfiguration_MeterValuesAlignedDataMaxLength,
  792. GetConfiguration_MeterValuesSampledData,
  793. GetConfiguration_MeterValuesSampledDataMaxLength,
  794. GetConfiguration_MeterValueSampleInterval,
  795. GetConfiguration_MinimumStatusDuration,
  796. GetConfiguration_NumberOfConnectors,
  797. GetConfiguration_ResetRetries,
  798. GetConfiguration_ConnectorPhaseRotation,
  799. GetConfiguration_ConnectorPhaseRotationMaxLength,
  800. GetConfiguration_StopTransactionOnEVSideDisconnect,
  801. GetConfiguration_StopTransactionOnInvalidId,
  802. GetConfiguration_StopTxnAlignedData,
  803. GetConfiguration_StopTxnAlignedDataMaxLength,
  804. GetConfiguration_StopTxnSampledData,
  805. GetConfiguration_StopTxnSampledDataMaxLength,
  806. GetConfiguration_SupportedFeatureProfiles,
  807. GetConfiguration_SupportedFeatureProfilesMaxLength,
  808. GetConfiguration_TransactionMessageAttempts,
  809. GetConfiguration_TransactionMessageRetryInterval,
  810. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  811. GetConfiguration_WebSocketPingInterval,
  812. GetConfiguration_LocalAuthListEnabled,
  813. GetConfiguration_LocalAuthListMaxLength,
  814. GetConfiguration_SendLocalListMaxLength,
  815. GetConfiguration_ReserveConnectorZeroSupported,
  816. GetConfiguration_ChargeProfileMaxStackLevel,
  817. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  818. GetConfiguration_ChargingScheduleMaxPeriods,
  819. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  820. GetConfiguration_MaxChargingProfilesInstalled,
  821. };
  822. //GetConfiguration Array
  823. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  824. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  825. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  826. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  827. //==========================================
  828. // Init all share memory
  829. //==========================================
  830. int InitShareMemory()
  831. {
  832. int result = PASS;
  833. int MeterSMId;
  834. //creat ShmSysConfigAndInfo
  835. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  836. {
  837. #ifdef SystemLogMessage
  838. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  839. #endif
  840. result = FAIL;
  841. }
  842. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  843. {
  844. #ifdef SystemLogMessage
  845. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  846. #endif
  847. result = FAIL;
  848. }
  849. else
  850. {}
  851. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  852. {
  853. #ifdef SystemLogMessage
  854. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  855. #endif
  856. result = FAIL;
  857. }
  858. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  859. {
  860. #ifdef SystemLogMessage
  861. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  862. #endif
  863. result = FAIL;
  864. }
  865. else
  866. {}
  867. //creat ShmPsuData
  868. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmget ShmPsuData NG\n");
  872. #endif
  873. result = FAIL;
  874. }
  875. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  876. {
  877. #ifdef SystemLogMessage
  878. DEBUG_ERROR("shmat ShmPsuData NG\n");
  879. #endif
  880. result = FAIL;
  881. }
  882. else
  883. {}
  884. //creat ShmOCPP16Data
  885. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  886. {
  887. #ifdef SystemLogMessage
  888. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  889. #endif
  890. result = FAIL;
  891. }
  892. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  893. {
  894. #ifdef SystemLogMessage
  895. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  896. #endif
  897. result = FAIL;
  898. }
  899. else
  900. {}
  901. /****************************** For Initial Settings************************************************/
  902. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  903. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  904. {
  905. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  906. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  907. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  908. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  909. }
  910. // Charger PRE_SYS_MODE
  911. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  912. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  913. clientTime.Heartbeat=time((time_t*)NULL);
  914. #if 0
  915. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  916. {
  917. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  918. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  919. }
  920. #endif
  921. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  922. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  923. // allocate Configuration memory address
  924. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  925. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  926. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  927. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  928. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  929. {
  930. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  931. DEBUG_INFO("DC ...\n");
  932. }
  933. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  934. {
  935. SystemInitial = AC_QUANTITY;
  936. DEBUG_INFO("AC ...\n");
  937. }
  938. //Status / ConnectorPlugIn Setting
  939. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  940. {
  941. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  942. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  943. }
  944. for (int index = 0; index < CCS_QUANTITY; index++)
  945. {
  946. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  947. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  948. }
  949. for (int index = 0; index < GB_QUANTITY; index++)
  950. {
  951. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  952. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  953. }
  954. for (int index = 0; index < AC_QUANTITY; index++)
  955. {
  956. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  957. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  958. }
  959. return result;
  960. }
  961. int ProcessShareMemory()
  962. {
  963. if(InitShareMemory() == FAIL)
  964. {
  965. #ifdef SystemLogMessage
  966. DEBUG_ERROR("InitShareMemory NG\n");
  967. #endif
  968. if(ShmStatusCodeData!=NULL)
  969. {
  970. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  971. }
  972. sleep(5);
  973. return FAIL;
  974. }
  975. return PASS;
  976. }
  977. //---------------------------------------------
  978. // new:
  979. // enum SYSTEM_STATUS
  980. // {
  981. // SYS_MODE_BOOTING = 0,
  982. // SYS_MODE_IDLE = 1,
  983. // SYS_MODE_AUTHORIZING = 2,
  984. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  985. // SYS_MODE_REASSIGN = 4,
  986. // SYS_MODE_PREPARING = 5,
  987. // SYS_MODE_PREPARE_FOR_EV = 6,
  988. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  989. // SYS_MODE_CHARGING = 8,
  990. // SYS_MODE_TERMINATING = 9,
  991. // SYS_MODE_COMPLETE = 10,
  992. // SYS_MODE_ALARM = 11,
  993. // SYS_MODE_FAULT = 12,
  994. // SYS_MODE_RESERVATION = 13,
  995. // SYS_MODE_BOOKING = 14,
  996. // SYS_MODE_MAINTAIN = 15,
  997. // SYS_MODE_DEBUG = 16,
  998. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  999. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1000. // SYS_MODE_UPDATE = 19
  1001. // };
  1002. //
  1003. //
  1004. //-----------------------------------------
  1005. void CheckSystemValue(void)
  1006. {
  1007. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1008. //int IdleModeCnt = 0;
  1009. char filenmae[100]={0};
  1010. char str[100]={0};
  1011. //===============================
  1012. // send Heartbeat
  1013. //===============================
  1014. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1015. {
  1016. printf("Heartbeat !!!\n");
  1017. //parameter for test
  1018. sendHeartbeatRequest(0);
  1019. //==============================================
  1020. // Reset Waiting Time
  1021. //==============================================
  1022. clientTime.Heartbeat=time((time_t*)NULL);
  1023. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1024. }
  1025. #if 0
  1026. //==============================================
  1027. // Update firmware request
  1028. //==============================================
  1029. if(isUpdateRequest == TRUE )
  1030. {
  1031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1032. {
  1033. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1034. {
  1035. //check SystemStatus
  1036. /*************************DC*******************************/
  1037. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1038. {
  1039. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1040. {
  1041. IdleModeCnt = IdleModeCnt + 1;
  1042. }
  1043. }
  1044. for (int index = 0; index < CCS_QUANTITY; index++)
  1045. {
  1046. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1047. {
  1048. IdleModeCnt = IdleModeCnt + 1;
  1049. }
  1050. }
  1051. for (int index = 0; index < GB_QUANTITY; index++)
  1052. {
  1053. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1054. {
  1055. IdleModeCnt = IdleModeCnt + 1;
  1056. }
  1057. }
  1058. }
  1059. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1060. {
  1061. isUpdateRequest = FALSE;
  1062. }
  1063. }
  1064. else
  1065. {
  1066. /*************************AC*******************************/
  1067. for (int index = 0; index < AC_QUANTITY; index++)
  1068. {
  1069. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1070. {
  1071. IdleModeCnt = IdleModeCnt + 1;
  1072. }
  1073. }
  1074. if(IdleModeCnt == AC_QUANTITY)
  1075. {
  1076. isUpdateRequest = FALSE;
  1077. }
  1078. }
  1079. }
  1080. #endif
  1081. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1082. {
  1083. //===============================
  1084. // CSU Trigger Reset Conf
  1085. //===============================
  1086. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1087. {
  1088. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1089. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1090. {
  1091. server_sign = FALSE;
  1092. }
  1093. }
  1094. //===============================
  1095. // CSU Trigger Authorize Request
  1096. //===============================
  1097. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1098. {
  1099. sendAuthorizeRequest(0);
  1100. authorizeRetryTimes = authorizeRetryTimes + 1;
  1101. if(authorizeRetryTimes < 3)
  1102. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1103. }
  1104. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1105. {
  1106. authorizeRetryTimes = 0;
  1107. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1108. server_sign = FALSE;
  1109. }
  1110. 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))
  1111. {
  1112. sendAuthorizeRequest(0);
  1113. }
  1114. //===============================
  1115. // CSU Trigger Smart Charging Profilw
  1116. //===============================
  1117. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1118. {
  1119. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1120. GetChargingProfileRequest(gun_index);
  1121. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1122. }
  1123. //==============================================
  1124. // Charger start transaction
  1125. //==============================================
  1126. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1127. {
  1128. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1129. sendStartTransactionRequest(gun_index);
  1130. clientTime.StartTransaction = time((time_t*)NULL);
  1131. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1132. }
  1133. //==============================================
  1134. // Charger stop transaction
  1135. //==============================================
  1136. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1137. {
  1138. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1139. sendStopTransactionRequest(gun_index);
  1140. clientTime.StopTransaction = time((time_t*)NULL);
  1141. }
  1142. //==============================================
  1143. // Charger status report
  1144. //==============================================
  1145. /* Check Mode Change */
  1146. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1147. {
  1148. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1149. {
  1150. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1151. {
  1152. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1153. {
  1154. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1155. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1156. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1157. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1158. statusModeChage[gun_index] = TRUE;
  1159. }
  1160. }
  1161. }
  1162. for (int index = 0; index < CCS_QUANTITY; index++)
  1163. {
  1164. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1165. {
  1166. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1167. {
  1168. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1169. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1170. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1171. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1172. statusModeChage[gun_index] = TRUE;
  1173. }
  1174. }
  1175. }
  1176. for (int index = 0; index < GB_QUANTITY; index++)
  1177. {
  1178. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1179. {
  1180. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1181. {
  1182. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1183. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1184. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1185. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1186. statusModeChage[gun_index] = TRUE;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. else //AC
  1192. {
  1193. for (int index = 0; index < AC_QUANTITY; index++)
  1194. {
  1195. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1196. {
  1197. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1198. {
  1199. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1200. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1201. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1202. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1203. statusModeChage[gun_index] = TRUE;
  1204. }
  1205. }
  1206. }// END OF FOR
  1207. }// END OF ELSE
  1208. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1209. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1210. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1211. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1212. {
  1213. if(SystemInitial != 0)
  1214. SystemInitial = SystemInitial -1;
  1215. sendStatusNotificationRequest(gun_index);
  1216. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1217. statusModeChage[gun_index] = FALSE;
  1218. }
  1219. //==============================================
  1220. // Meter report
  1221. //==============================================
  1222. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1223. {
  1224. //check Transaction active
  1225. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1226. {
  1227. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1228. {
  1229. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1230. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1231. {
  1232. meterValueSend[gun_index] =1;
  1233. }
  1234. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1235. {
  1236. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1237. if((access(filenmae,F_OK))!=-1)
  1238. {
  1239. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1240. sprintf(str,"rm -f %s",filenmae);
  1241. system(str);
  1242. }
  1243. }
  1244. }// End for CHAdeMO
  1245. for (int index = 0; index < CCS_QUANTITY; index++)
  1246. {
  1247. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1248. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1249. {
  1250. meterValueSend[gun_index] =1;
  1251. }
  1252. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1253. {
  1254. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1255. if((access(filenmae,F_OK))!=-1)
  1256. {
  1257. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1258. sprintf(str,"rm -f %s",filenmae);
  1259. system(str);
  1260. }
  1261. }
  1262. } // End for CCS
  1263. for (int index = 0; index < GB_QUANTITY; index++)
  1264. {
  1265. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1266. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1267. {
  1268. meterValueSend[gun_index] =1;
  1269. }
  1270. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1271. {
  1272. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1273. if((access(filenmae,F_OK))!=-1)
  1274. {
  1275. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1276. sprintf(str,"rm -f %s",filenmae);
  1277. system(str);
  1278. }
  1279. }
  1280. }// End for GB
  1281. }
  1282. else
  1283. {
  1284. for (int index = 0; index < AC_QUANTITY; index++)
  1285. {
  1286. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1287. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1288. {
  1289. meterValueSend[gun_index] =1;
  1290. }
  1291. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1292. {
  1293. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1294. if((access(filenmae,F_OK))!=-1)
  1295. {
  1296. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1297. sprintf(str,"rm -f %s",filenmae);
  1298. system(str);
  1299. }
  1300. }
  1301. }//End for AC
  1302. }//END OF ELSE
  1303. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1304. if(meterValueSend[gun_index] == 1)
  1305. sendMeterValuesRequest(gun_index);
  1306. }
  1307. //==============================================
  1308. // Check Connector reserved
  1309. //==============================================
  1310. //===============================
  1311. // Check if Reserve is expired
  1312. //===============================
  1313. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1314. {
  1315. double diff_t;
  1316. struct tm tp;
  1317. // current time
  1318. time_t t = time(NULL);
  1319. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1320. tp.tm_isdst = -1;
  1321. time_t utc = mktime(&tp);
  1322. diff_t = difftime(utc, t);
  1323. if(diff_t <= 0)
  1324. {
  1325. DEBUG_INFO("reserve expired !!! \n");
  1326. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1327. }
  1328. }//END OF Check if Reserve is expired
  1329. //==========================================
  1330. // csu trigger FirmwareStatusNotificationReq
  1331. //==========================================
  1332. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1333. {
  1334. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1335. }
  1336. //==========================================
  1337. // csu trigger CancelReservationConf
  1338. //==========================================
  1339. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1340. {
  1341. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1342. }
  1343. //==========================================
  1344. // csu trigger ChangeAvailabilityConf
  1345. //==========================================
  1346. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1347. {
  1348. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1349. }
  1350. //==========================================
  1351. // csu trigger UnlockConnectorConf
  1352. //==========================================
  1353. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1354. {
  1355. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1356. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1357. }
  1358. //==========================================
  1359. // csu trigger ReserveNowConf
  1360. //==========================================
  1361. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1362. {
  1363. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1364. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1365. }
  1366. //==========================================
  1367. // csu trigger DataTransferReq
  1368. //==========================================
  1369. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1370. {
  1371. sendDataTransferRequest(gun_index);
  1372. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1373. }
  1374. }
  1375. }
  1376. //==========================================
  1377. // send request routine
  1378. //==========================================
  1379. int sendAuthorizeRequest(int gun_index)
  1380. {
  1381. mtrace();
  1382. int result = FAIL;
  1383. char message[100]={0};
  1384. char guid[37];
  1385. char tempdata[65]={0};
  1386. DEBUG_INFO("sendAuthorizeRequest \n");
  1387. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1388. //Local Authorize
  1389. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1390. {
  1391. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1392. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1393. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1394. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1395. result = PASS;
  1396. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1397. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1398. authorizeRetryTimes = 0;
  1399. return result;
  1400. }
  1401. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  1402. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1403. {
  1404. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1405. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1406. {
  1407. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1408. {
  1409. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1410. }
  1411. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1412. {
  1413. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1414. }
  1415. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1416. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1417. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1418. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1419. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1420. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1421. authorizeRetryTimes = 0;
  1422. return result;
  1423. }
  1424. else
  1425. {
  1426. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1427. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1428. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1429. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1430. result = PASS;
  1431. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1432. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1433. authorizeRetryTimes = 0;
  1434. return result;
  1435. }
  1436. }
  1437. //initailize struct Authorize
  1438. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1439. //get data from shared memory
  1440. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1441. random_uuid(guid);
  1442. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1443. LWS_Send(message);
  1444. sprintf(tempdata, "Authorize,%d", gun_index);
  1445. if(hashmap_operation(0, guid, tempdata) == 1)
  1446. {
  1447. result = PASS;
  1448. DEBUG_ERROR("Authorize mapItem pass\n");
  1449. }
  1450. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1451. return result;
  1452. }
  1453. int sendBootNotificationRequest(void)
  1454. {
  1455. mtrace();
  1456. int result = FAIL;
  1457. char message[500]={0}, payload[700]={0};
  1458. char guid[37]={0};
  1459. char tempdata[65]={0};
  1460. int IsGunCharging = FALSE;
  1461. //check Transaction active
  1462. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1463. {
  1464. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1465. {
  1466. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1467. {
  1468. IsGunCharging = TRUE;
  1469. }
  1470. }
  1471. for (int index = 0; index < CCS_QUANTITY; index++)
  1472. {
  1473. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1474. {
  1475. IsGunCharging = TRUE;
  1476. }
  1477. }
  1478. for (int index = 0; index < GB_QUANTITY; index++)
  1479. {
  1480. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1481. {
  1482. IsGunCharging = TRUE;
  1483. }
  1484. }
  1485. }
  1486. else
  1487. {
  1488. for (int index = 0; index < AC_QUANTITY; index++)
  1489. {
  1490. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1491. {
  1492. IsGunCharging = TRUE;
  1493. }
  1494. }
  1495. }
  1496. if(IsGunCharging == TRUE)
  1497. {
  1498. server_sign = TRUE;
  1499. return result;
  1500. }
  1501. // Fill BootNotification fields
  1502. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1503. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1504. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1505. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1506. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1507. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1508. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1509. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1510. ShmOCPP16Data->ChargeBoxId
  1511. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1512. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1513. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1514. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1515. ,ShmOCPP16Data->BootNotification.CpIccid
  1516. ,ShmOCPP16Data->BootNotification.CpImsi
  1517. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1518. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1519. random_uuid(guid);
  1520. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1521. LWS_Send(message);
  1522. sprintf(tempdata, "BootNotification,0");
  1523. 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*/)
  1524. {
  1525. result = PASS;
  1526. }
  1527. memset(queuedata, 0, sizeof(queuedata));
  1528. strcpy(queuedata,message);
  1529. return result;
  1530. }
  1531. int sendDataTransferRequest(int gun_index)
  1532. {
  1533. mtrace();
  1534. char message[1000]={0};
  1535. char guid[37]={0};
  1536. char tempdata[65]={0};
  1537. int result = FAIL;
  1538. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1539. random_uuid(guid);
  1540. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1541. MESSAGE_TYPE_CALL,
  1542. guid,
  1543. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1544. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1545. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1546. LWS_Send(message);
  1547. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1548. 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*/)
  1549. {
  1550. result = PASS;
  1551. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1552. }
  1553. return result;
  1554. }
  1555. int sendDiagnosticsStatusNotificationRequest(char *status)
  1556. {
  1557. mtrace();
  1558. int result = FAIL;
  1559. char message[110]={0};
  1560. char guid[37]={0};
  1561. char tempdata[65]={0};
  1562. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1563. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1564. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1565. random_uuid(guid);
  1566. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1567. LWS_Send(message);
  1568. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1569. if(hashmap_operation(0, guid, tempdata) == 1)
  1570. {
  1571. result = PASS;
  1572. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1573. }
  1574. //#ifdef SystemLogMessage
  1575. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1576. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1577. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1578. //#endif
  1579. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1580. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1581. //record status
  1582. if(strcmp(status,"Idle")==0)
  1583. {
  1584. DiagnosticsStatusNotificationStatus = 0;
  1585. }
  1586. else if(strcmp(status,"Uploaded")==0)
  1587. {
  1588. DiagnosticsStatusNotificationStatus = 1;
  1589. }
  1590. else if(strcmp(status,"UploadFailed")==0)
  1591. {
  1592. DiagnosticsStatusNotificationStatus = 2;
  1593. }
  1594. else if(strcmp(status,"Uploading")==0)
  1595. {
  1596. DiagnosticsStatusNotificationStatus = 3;
  1597. }
  1598. return result;
  1599. }
  1600. int sendFirmwareStatusNotificationRequest(char *status)
  1601. {
  1602. mtrace();
  1603. int result = FAIL;
  1604. char message[110]={0};
  1605. char guid[37]={0};
  1606. char tempdata[65]={0};
  1607. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1608. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1609. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1610. random_uuid(guid);
  1611. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1612. LWS_Send(message);
  1613. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1614. 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*/)
  1615. {
  1616. result = PASS;
  1617. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1618. }
  1619. //#ifdef SystemLogMessage
  1620. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1621. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1622. //#endif
  1623. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1624. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1625. //record status
  1626. if(strcmp(status,"Downloaded")==0)
  1627. {
  1628. FirmwareStatusNotificationStatus = 0;
  1629. }
  1630. else if(strcmp(status,"DownloadFailed")==0)
  1631. {
  1632. FirmwareStatusNotificationStatus = 1;
  1633. }
  1634. else if(strcmp(status,"Downloading")==0)
  1635. {
  1636. FirmwareStatusNotificationStatus = 2;
  1637. }
  1638. else if(strcmp(status,"Idle")==0)
  1639. {
  1640. FirmwareStatusNotificationStatus = 3;
  1641. }
  1642. else if(strcmp(status,"InstallationFailed")==0)
  1643. {
  1644. FirmwareStatusNotificationStatus = 4;
  1645. }
  1646. else if(strcmp(status,"Installing")==0)
  1647. {
  1648. FirmwareStatusNotificationStatus = 5;
  1649. }
  1650. else if(strcmp(status,"Installed")==0)
  1651. {
  1652. FirmwareStatusNotificationStatus = 6;
  1653. }
  1654. return result;
  1655. }
  1656. int sendHeartbeatRequest(int gun_index)
  1657. {
  1658. mtrace();
  1659. int result = FAIL;
  1660. char message[80]={0};
  1661. char guid[37]={0};
  1662. char tempdata[65]={0};
  1663. random_uuid(guid);
  1664. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1665. , MESSAGE_TYPE_CALL
  1666. , guid );
  1667. LWS_Send(message);
  1668. sprintf(tempdata, "Heartbeat,%d", 0);
  1669. 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*/)
  1670. {
  1671. result = PASS;
  1672. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1673. }
  1674. return result;
  1675. }
  1676. int sendStartTransactionRequest(int gun_index)
  1677. {
  1678. mtrace();
  1679. int result = FAIL;
  1680. char message[250]={0};
  1681. char guid[37]={0};
  1682. struct timeval tmnow;
  1683. struct tm *tm;
  1684. char buf[28];//, usec_buf[6];
  1685. char tempdata[65]={0};
  1686. DEBUG_INFO("sendStartTransactionRequest...");
  1687. gettimeofday(&tmnow, NULL);
  1688. time_t t;
  1689. t = time(NULL);
  1690. /*UTC time and date*/
  1691. tm = gmtime(&t);
  1692. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1693. #if 0 // remove temporally
  1694. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1695. strcat(buf,".");
  1696. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1697. strcat(buf,usec_buf);
  1698. #endif
  1699. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1700. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1701. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1702. // clear StartTransaction Response
  1703. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1704. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1705. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1706. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1707. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1708. {
  1709. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1710. {
  1711. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1712. {
  1713. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1714. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1715. }
  1716. }
  1717. for (int index = 0; index < CCS_QUANTITY; index++)
  1718. {
  1719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1720. {
  1721. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1722. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1723. }
  1724. }
  1725. for (int index = 0; index < GB_QUANTITY; index++)
  1726. {
  1727. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1728. {
  1729. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1730. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1731. }
  1732. }
  1733. }
  1734. else
  1735. {
  1736. for (int index = 0; index < AC_QUANTITY; index++)
  1737. {
  1738. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1739. {
  1740. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1741. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1742. }
  1743. }
  1744. }//END OF ELSE
  1745. random_uuid(guid);
  1746. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1747. , MESSAGE_TYPE_CALL
  1748. , guid
  1749. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1750. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1751. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1752. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1753. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1754. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1755. 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*/)
  1756. {
  1757. result = PASS;
  1758. }
  1759. strcpy(queuedata, message);
  1760. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1761. if(GetTransactionQueueNum() == 1)
  1762. {
  1763. LWS_Send(message);
  1764. }
  1765. #if 0
  1766. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1767. 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*/)
  1768. {
  1769. result = PASS;
  1770. }
  1771. strcpy(queuedata, message);
  1772. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1773. #endif
  1774. //#ifdef SystemLogMessage
  1775. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1776. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1777. //#endif
  1778. return result;
  1779. }
  1780. int sendStatusNotificationRequest(int gun_index)
  1781. {
  1782. mtrace();
  1783. int result = FAIL;
  1784. char message[600]={0};
  1785. char guid[37];
  1786. int currentStatus = 0;
  1787. struct timeval tmnow;
  1788. struct tm *tm;
  1789. char buf[28];//, usec_buf[6];
  1790. char tempdata[65]={0};
  1791. gettimeofday(&tmnow, NULL);
  1792. time_t t;
  1793. t = time(NULL);
  1794. /*UTC time and date*/
  1795. tm = gmtime(&t);
  1796. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1797. #if 0 // remove temporally
  1798. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1799. strcat(buf,".");
  1800. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1801. strcat(buf,usec_buf);
  1802. #endif
  1803. printf("%s",buf);
  1804. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1805. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1806. // it's option
  1807. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1808. /*
  1809. enum _SYSTEM_STATUS
  1810. {
  1811. S_BOOTING = 0,
  1812. S_IDLE, = 1
  1813. S_AUTHORIZING, =2
  1814. S_REASSIGN_CHECK, =3
  1815. S_REASSIGN, =4
  1816. S_PRECHARGE, =5
  1817. S_PREPARING_FOR_EV, =6
  1818. S_PREPARING_FOR_EVSE, =7
  1819. S_CHARGING, =8
  1820. S_TERMINATING, =9
  1821. S_COMPLETE, =10
  1822. S_ALARM, =11
  1823. S_FAULT =12
  1824. }
  1825. */
  1826. //check Transaction active
  1827. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1828. {
  1829. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1830. {
  1831. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1832. {
  1833. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1834. {
  1835. currentStatus = 1; //OCPP Status: Preparing
  1836. }
  1837. else
  1838. {
  1839. currentStatus = 0; //OCPP Status: Available
  1840. }
  1841. }
  1842. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1843. {
  1844. currentStatus = 1; //OCPP Status: Preparing
  1845. }
  1846. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1847. {
  1848. currentStatus = 2; //OCPP Status: Charging
  1849. }
  1850. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1851. {
  1852. currentStatus = 5; //OCPP Status: Finishing
  1853. }
  1854. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1855. {
  1856. currentStatus = 4; //OCPP Status: SuspendedEV
  1857. }
  1858. 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
  1859. {
  1860. currentStatus = 7; //OCPP Status: Unavailable
  1861. }
  1862. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM))) //S_ALARM,S_FAULT ---> Faulted
  1863. {
  1864. currentStatus = 8; //OCPP Status: Faulted
  1865. }
  1866. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1867. {
  1868. currentStatus = 6; //OCPP Status: Reserved
  1869. }
  1870. }//end of for CHAdeMO_QUANTITY
  1871. for (int index = 0; index < CCS_QUANTITY; index++)
  1872. {
  1873. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1874. {
  1875. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1876. {
  1877. currentStatus = 1; //OCPP Status: Preparing
  1878. }
  1879. else
  1880. {
  1881. currentStatus = 0; //OCPP Status: Available
  1882. }
  1883. }
  1884. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1885. {
  1886. currentStatus = 1; //OCPP Status: Preparing
  1887. }
  1888. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1889. {
  1890. currentStatus = 2; //OCPP Status: Charging
  1891. }
  1892. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1893. {
  1894. currentStatus = 5; //OCPP Status: Finishing
  1895. }
  1896. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //S_TERMINATING ---> SuspendedEV
  1897. {
  1898. currentStatus = 4; //OCPP Status: SuspendedEV
  1899. }
  1900. 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
  1901. {
  1902. currentStatus = 7; //OCPP Status : Unavailable
  1903. }
  1904. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM))) //S_ALARM ,S_FAULT ---> Faulted
  1905. {
  1906. currentStatus = 8; //OCPP Status: Faulted
  1907. }
  1908. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1909. {
  1910. currentStatus = 6; //OCPP Status: Reserved
  1911. }
  1912. }
  1913. for (int index = 0; index < GB_QUANTITY; index++)
  1914. {
  1915. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1916. {
  1917. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1918. {
  1919. currentStatus = 1; //OCPP Status: Preparing
  1920. }
  1921. else
  1922. {
  1923. currentStatus = 0; //OCPP Status: Available
  1924. }
  1925. }
  1926. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1927. {
  1928. currentStatus = 1; //OCPP Status: Preparing
  1929. }
  1930. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1931. {
  1932. currentStatus = 2; //OCPP Status: Charging
  1933. }
  1934. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1935. {
  1936. currentStatus = 5; //OCPP Status: Finishing
  1937. }
  1938. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1939. {
  1940. currentStatus = 4; //OCPP Status: SuspendedEV
  1941. }
  1942. 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
  1943. {
  1944. currentStatus = 7; //OCPP Status: Unavailable
  1945. }
  1946. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) )) //S_ALARM ,S_FAULT ---> Faulted
  1947. {
  1948. currentStatus = 8; //OCPP Status: Faulted
  1949. }
  1950. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1951. {
  1952. currentStatus = 6; //OCPP Status: Reserved
  1953. }
  1954. }
  1955. }
  1956. else
  1957. {
  1958. for (int index = 0; index < AC_QUANTITY; index++)
  1959. {
  1960. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1961. {
  1962. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  1963. {
  1964. currentStatus = 1; //OCPP Status: Preparing
  1965. }
  1966. else
  1967. {
  1968. currentStatus = 0; //OCPP Status: Available
  1969. }
  1970. }
  1971. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1972. {
  1973. currentStatus = 1; //OCPP Status: Preparing
  1974. }
  1975. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1976. {
  1977. currentStatus = 2; //OCPP Status: Charging
  1978. }
  1979. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1980. {
  1981. currentStatus = 5; //OCPP Status: Finishing
  1982. }
  1983. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_TERMINATING ---> SuspendedEV
  1984. {
  1985. currentStatus = 4; //OCPP Status: SuspendedEV
  1986. }
  1987. 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
  1988. {
  1989. currentStatus = 7; //OCPP Status: Unavailable
  1990. }
  1991. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM))) //S_ALARM,S_FAULT ---> Faulted
  1992. {
  1993. currentStatus = 8; //OCPP Status: Faulted
  1994. }
  1995. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1996. {
  1997. currentStatus = 6; //OCPP Status: Reserved
  1998. }
  1999. }//end of for AC_QUANTITY
  2000. }//END OF ELSE
  2001. //it's option
  2002. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2003. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2004. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2005. random_uuid(guid);
  2006. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2007. , MESSAGE_TYPE_CALL
  2008. , guid
  2009. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2010. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2011. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2012. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2013. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2014. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2015. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2016. LWS_Send(message);
  2017. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2018. 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*/)
  2019. {
  2020. //DEBUG_ERROR("statusNotification mapitem pass");
  2021. result = PASS;
  2022. }
  2023. return result;
  2024. }
  2025. int sendStopTransactionRequest(int gun_index)
  2026. {
  2027. mtrace();
  2028. int result = FAIL;
  2029. //char message[1500]={0};
  2030. char guid[37]={0};
  2031. char tempdata[65]={0};
  2032. //int idx_sample=0;
  2033. DEBUG_ERROR("sendStopTransactionRequest \n");
  2034. memset(queuedata, 0, sizeof(queuedata));
  2035. //ENERGY_ACTIVE_IMPORT_REGISTER
  2036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2037. {
  2038. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2039. {
  2040. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2041. {
  2042. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2043. }
  2044. }// END OF CHAdeMO_QUANTITY
  2045. for (int index = 0; index < CCS_QUANTITY; index++)
  2046. {
  2047. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2048. {
  2049. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2050. }
  2051. }// END OF CCS_QUANTITY
  2052. for (int index = 0; index < GB_QUANTITY; index++)
  2053. {
  2054. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2055. {
  2056. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2057. }
  2058. }// END OF GB_QUANTITY
  2059. }
  2060. else
  2061. {
  2062. for (int index = 0; index < AC_QUANTITY; index++)
  2063. {
  2064. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2065. {
  2066. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2067. }
  2068. }// END OF AC_QUANTITY
  2069. }//END OF ELSE
  2070. //Stop Transaction Time
  2071. struct timeval tmnow;
  2072. struct tm *tm;
  2073. char buf[28];//, usec_buf[6];
  2074. gettimeofday(&tmnow, NULL);
  2075. time_t t;
  2076. t = time(NULL);
  2077. /*UTC time and date*/
  2078. tm = gmtime(&t);
  2079. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2081. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2082. random_uuid(guid);
  2083. /***********************************transactionData******************************************************/
  2084. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2086. //=================================
  2087. // Transaction_Begin
  2088. //=================================
  2089. // Energy.Active.Export.Interval
  2090. //idx_sample=0;
  2091. 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
  2092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2094. 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*/]);
  2095. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2096. {
  2097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2098. }
  2099. else
  2100. {
  2101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2102. }
  2103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2105. //=================================
  2106. // Transaction_End
  2107. //=================================
  2108. //Current.Export
  2109. //idx_sample=1;
  2110. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2111. {
  2112. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2113. {
  2114. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2115. {
  2116. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2117. }
  2118. }
  2119. for (int index = 0; index < CCS_QUANTITY; index++)
  2120. {
  2121. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2122. {
  2123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2124. }
  2125. }
  2126. for (int index = 0; index < GB_QUANTITY; index++)
  2127. {
  2128. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2129. {
  2130. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2131. }
  2132. }
  2133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2134. }
  2135. else
  2136. {
  2137. for (int index = 0; index < AC_QUANTITY; index++)
  2138. {
  2139. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2140. {
  2141. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2142. }
  2143. }
  2144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2145. }// END FOR AC ELSE
  2146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2149. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2152. //Energy.Active.Export.Interval
  2153. //idx_sample=2;
  2154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2155. {
  2156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2157. {
  2158. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2159. {
  2160. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2161. }
  2162. }
  2163. for (int index = 0; index < CCS_QUANTITY; index++)
  2164. {
  2165. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2166. {
  2167. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2168. }
  2169. }
  2170. for (int index = 0; index < GB_QUANTITY; index++)
  2171. {
  2172. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2173. {
  2174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2175. }
  2176. }
  2177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2178. }
  2179. else
  2180. {
  2181. for (int index = 0; index < AC_QUANTITY; index++)
  2182. {
  2183. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2184. {
  2185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2186. }
  2187. }
  2188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2189. }// END FOR AC ELSE
  2190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2193. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2196. //Power.Active.Export
  2197. //idx_sample=3;
  2198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2199. {
  2200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2201. {
  2202. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2203. {
  2204. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2205. }
  2206. }
  2207. for (int index = 0; index < CCS_QUANTITY; index++)
  2208. {
  2209. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2210. {
  2211. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2212. }
  2213. }
  2214. for (int index = 0; index < GB_QUANTITY; index++)
  2215. {
  2216. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2217. {
  2218. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2219. }
  2220. }
  2221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2222. }
  2223. else
  2224. {
  2225. for (int index = 0; index < AC_QUANTITY; index++)
  2226. {
  2227. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2228. {
  2229. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2230. }
  2231. }
  2232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2233. }// END FOR AC ELSE
  2234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2237. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2240. //Voltage
  2241. //idx_sample=4;
  2242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2243. {
  2244. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2245. {
  2246. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2247. {
  2248. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2249. }
  2250. }
  2251. for (int index = 0; index < CCS_QUANTITY; index++)
  2252. {
  2253. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2254. {
  2255. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2256. }
  2257. }
  2258. for (int index = 0; index < GB_QUANTITY; index++)
  2259. {
  2260. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2261. {
  2262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2263. }
  2264. }
  2265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2266. }
  2267. else
  2268. {
  2269. for (int index = 0; index < AC_QUANTITY; index++)
  2270. {
  2271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2272. {
  2273. 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
  2274. }
  2275. }
  2276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2277. }// END FOR AC ELSE
  2278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2281. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2284. //SoC
  2285. //idx_sample=5;
  2286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2287. {
  2288. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2289. {
  2290. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2291. {
  2292. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2293. }
  2294. }
  2295. for (int index = 0; index < CCS_QUANTITY; index++)
  2296. {
  2297. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2298. {
  2299. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2300. }
  2301. }
  2302. for (int index = 0; index < GB_QUANTITY; index++)
  2303. {
  2304. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2305. {
  2306. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2307. }
  2308. }
  2309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2315. } // END FOR DC CASE
  2316. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2317. {
  2318. 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\"}]}]}]"
  2319. ,MESSAGE_TYPE_CALL
  2320. ,guid
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2326. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2336. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2340. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2341. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2342. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2343. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2344. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2345. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2346. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2347. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2348. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2349. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2364. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2366. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2367. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2368. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2369. );
  2370. }
  2371. else
  2372. {
  2373. 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\"}]}]}]"
  2374. ,MESSAGE_TYPE_CALL
  2375. ,guid
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2380. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2381. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2385. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2386. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2387. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2388. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2390. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2391. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2392. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2393. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2394. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2395. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2396. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2397. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2398. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2399. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2400. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2401. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2402. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2403. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2404. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2405. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2406. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2407. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2408. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2409. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2410. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2411. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2412. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2413. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2414. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2415. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2416. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2417. );
  2418. }
  2419. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2420. if(hashmap_operation(0, guid, tempdata) == 1)
  2421. {
  2422. result = PASS;
  2423. DEBUG_INFO("StopTransaction mapitem pass\n");
  2424. }
  2425. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2426. if(GetTransactionQueueNum() == 1)
  2427. {
  2428. LWS_Send(queuedata);
  2429. }
  2430. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2431. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2432. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2433. {
  2434. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2435. }
  2436. #if 0
  2437. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2438. if(hashmap_operation(0, guid, tempdata) == 1)
  2439. {
  2440. result = PASS;
  2441. DEBUG_INFO("StopTransaction mapitem pass\n");
  2442. }
  2443. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2444. #endif
  2445. //for test
  2446. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2447. return result;
  2448. }
  2449. int sendMeterValuesRequest(int gun_index)
  2450. {
  2451. mtrace();
  2452. int result = FAIL;
  2453. // char message[1500]={0};
  2454. char guid[37]={0};
  2455. //int idx_sample=0;
  2456. //int length = 0;
  2457. char tempdata[65]={0};
  2458. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2459. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2460. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2461. {
  2462. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2463. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2464. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2465. return result;
  2466. }
  2467. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2468. {
  2469. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2470. }
  2471. memset(queuedata, 0, sizeof(queuedata));
  2472. //set value
  2473. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2474. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2475. random_uuid(guid);
  2476. //UTC Date time
  2477. struct timeval tmnow;
  2478. struct tm *tm;
  2479. char buf[28];//, usec_buf[6];
  2480. gettimeofday(&tmnow, NULL);
  2481. time_t t;
  2482. t = time(NULL);
  2483. /*UTC time and date*/
  2484. tm = gmtime(&t);
  2485. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2487. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2488. //idx_sample=0;
  2489. //********************************(1)Current.Export************************************************/
  2490. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2491. {
  2492. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2493. {
  2494. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2495. {
  2496. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2497. }
  2498. }
  2499. for (int index = 0; index < CCS_QUANTITY; index++)
  2500. {
  2501. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2502. {
  2503. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2504. }
  2505. }
  2506. for (int index = 0; index < GB_QUANTITY; index++)
  2507. {
  2508. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2509. {
  2510. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2511. }
  2512. }
  2513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2514. }
  2515. else
  2516. {
  2517. for (int index = 0; index < AC_QUANTITY; index++)
  2518. {
  2519. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2520. {
  2521. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2522. }
  2523. }
  2524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2525. }// END FOR AC ELSE
  2526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2527. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2528. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2529. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2531. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2532. //idx_sample=1;
  2533. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2535. {
  2536. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2537. {
  2538. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2539. {
  2540. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2541. }
  2542. }
  2543. for (int index = 0; index < CCS_QUANTITY; index++)
  2544. {
  2545. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2546. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2547. {
  2548. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2549. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2550. }
  2551. }
  2552. for (int index = 0; index < GB_QUANTITY; index++)
  2553. {
  2554. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2555. {
  2556. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2557. }
  2558. }
  2559. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2560. }
  2561. else
  2562. {
  2563. for (int index = 0; index < AC_QUANTITY; index++)
  2564. {
  2565. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2566. {
  2567. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2568. }
  2569. }
  2570. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2571. }//END FOR AC ELSE
  2572. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2575. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2578. //idx_sample=2;
  2579. //********************************(4)Power.Active.Export************************************************/
  2580. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2581. {
  2582. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2583. {
  2584. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2585. {
  2586. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2587. }
  2588. }
  2589. for (int index = 0; index < CCS_QUANTITY; index++)
  2590. {
  2591. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2592. {
  2593. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2594. }
  2595. }
  2596. for (int index = 0; index < GB_QUANTITY; index++)
  2597. {
  2598. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2599. {
  2600. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2601. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2602. }
  2603. }
  2604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2605. }
  2606. else
  2607. {
  2608. for (int index = 0; index < AC_QUANTITY; index++)
  2609. {
  2610. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2611. {
  2612. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2613. }
  2614. }
  2615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2616. }// END FOR AC ELSE
  2617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2619. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2620. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2621. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2622. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2623. //idx_sample=3;
  2624. //***********************************************(5)VOLTAGE******************************************************/
  2625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2626. {
  2627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2628. {
  2629. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2630. {
  2631. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2632. }
  2633. }
  2634. for (int index = 0; index < CCS_QUANTITY; index++)
  2635. {
  2636. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2637. {
  2638. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2639. }
  2640. }
  2641. for (int index = 0; index < GB_QUANTITY; index++)
  2642. {
  2643. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2644. {
  2645. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2646. }
  2647. }
  2648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2649. }
  2650. else
  2651. {
  2652. for (int index = 0; index < AC_QUANTITY; index++)
  2653. {
  2654. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2655. {
  2656. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2657. }
  2658. }
  2659. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2660. }//END FOR AC ELSE
  2661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2662. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2664. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2666. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2667. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2668. {
  2669. //idx_sample=4;
  2670. //sampledValue = NULL;
  2671. //***********************************************(6)SOC******************************************************/
  2672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2673. {
  2674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2675. {
  2676. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2677. }
  2678. }
  2679. for (int index = 0; index < CCS_QUANTITY; index++)
  2680. {
  2681. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2682. {
  2683. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2684. }
  2685. }
  2686. for (int index = 0; index < GB_QUANTITY; index++)
  2687. {
  2688. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2689. {
  2690. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2691. }
  2692. }
  2693. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2694. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2695. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2696. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2697. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2698. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2699. }
  2700. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2701. {
  2702. 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\"}]}]}]"
  2703. ,MESSAGE_TYPE_CALL
  2704. ,guid
  2705. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2706. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2707. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2743. );
  2744. }
  2745. else
  2746. {
  2747. 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\"}]}]}]"
  2748. ,MESSAGE_TYPE_CALL
  2749. ,guid
  2750. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2751. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2752. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2758. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2781. );
  2782. }
  2783. // Put request guid to hash map
  2784. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2785. 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*/)
  2786. {
  2787. result = PASS;
  2788. DEBUG_INFO("MeterValues mapitem pass\n");
  2789. }
  2790. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2791. if(GetTransactionQueueNum() == 1)
  2792. {
  2793. LWS_Send(queuedata);
  2794. }
  2795. #if 0
  2796. // Put request guid to hash map
  2797. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2798. 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*/)
  2799. {
  2800. result = PASS;
  2801. DEBUG_INFO("MeterValues mapitem pass\n");
  2802. }
  2803. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2804. #endif
  2805. return result;
  2806. }
  2807. //==========================================
  2808. // send confirm routine
  2809. //==========================================
  2810. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2811. {
  2812. mtrace();
  2813. int result = FAIL;
  2814. char message[100]={0};
  2815. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2816. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2817. LWS_Send(message);
  2818. result = TRUE;
  2819. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2820. return result;
  2821. }
  2822. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2823. {
  2824. mtrace();
  2825. int result = FAIL;
  2826. char message[100]={0};
  2827. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2828. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2829. LWS_Send(message);
  2830. result = TRUE;
  2831. return result;
  2832. }
  2833. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2834. {
  2835. mtrace();
  2836. int result = FAIL;
  2837. char message[100]={0};
  2838. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2839. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2840. LWS_Send(message);
  2841. result = TRUE;
  2842. return result;
  2843. }
  2844. int sendClearCacheConfirmation(char *uuid,char *payload)
  2845. {
  2846. mtrace();
  2847. int result = FAIL;
  2848. char message[500]={0};
  2849. // int count = 0;
  2850. // int gun_index = 0;
  2851. // char guid[37];
  2852. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2853. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2854. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2855. LWS_Send(message);
  2856. return result;
  2857. }
  2858. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2859. {
  2860. mtrace();
  2861. int result = FAIL;
  2862. char message[500]={0};
  2863. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2864. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2865. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2866. LWS_Send(message);
  2867. return result;
  2868. }
  2869. int sendDataTransferConfirmation(char *uuid,char *payload)
  2870. {
  2871. mtrace();
  2872. char statusStr[20]={0};
  2873. char dataStr[10]={0};
  2874. char sstr[20]={0};
  2875. int c = 0;
  2876. char *loc;
  2877. int result = FAIL;
  2878. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2879. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2880. /**********************status**************************/
  2881. loc = strstr(payload, "status");
  2882. memset(sstr ,0, sizeof(sstr) );
  2883. c = 0;
  2884. while (loc[3+strlen("status")+c] != '\"')
  2885. {
  2886. sstr[c] = loc[3+strlen("status")+c];
  2887. c++;
  2888. }
  2889. sstr[c] = '\0';
  2890. strcpy(statusStr, sstr);
  2891. /**********************data**************************/
  2892. loc = strstr(payload, "data");
  2893. memset(sstr ,0, sizeof(sstr) );
  2894. c = 0;
  2895. while (loc[3+strlen("data")+c] != '\"')
  2896. {
  2897. sstr[c] = loc[3+strlen("data")+c];
  2898. c++;
  2899. }
  2900. sstr[c] = '\0';
  2901. strcpy(dataStr, sstr);
  2902. return result;
  2903. }
  2904. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2905. {
  2906. mtrace();
  2907. int result = FAIL;
  2908. char message[1000]={0};
  2909. double diff_f = 0.0;
  2910. int diff_i = 0;
  2911. int diffSeconds = 0;
  2912. struct tm tp;
  2913. int TimeZero = FALSE;
  2914. int CompositeScheduleIndex = 0;
  2915. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2916. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2917. {
  2918. TimeZero = TRUE;
  2919. }
  2920. else
  2921. {
  2922. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2923. }
  2924. if(TimeZero == FALSE)
  2925. {
  2926. tp.tm_isdst = -1;
  2927. time_t utc = mktime(&tp);
  2928. time_t t = time(NULL);
  2929. diff_f = difftime(t, utc);
  2930. diff_i = (int)diff_f;
  2931. diffSeconds = diff_i % 86400;//86400 seconds/day
  2932. }
  2933. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2934. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2935. #if 0 //remove temporally
  2936. 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}"
  2937. ,MESSAGE_TYPE_CALLRESULT
  2938. ,uuid
  2939. ,payload
  2940. ,connectorIdInt
  2941. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2942. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2943. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2944. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2945. #endif
  2946. if(nPeriod == 0)
  2947. {
  2948. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  2949. {
  2950. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  2951. ,MESSAGE_TYPE_CALLRESULT
  2952. ,uuid
  2953. ,payload
  2954. ,connectorIdInt);
  2955. }
  2956. else
  2957. {
  2958. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2959. ,MESSAGE_TYPE_CALLRESULT
  2960. ,uuid
  2961. ,payload
  2962. ,connectorIdInt
  2963. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2964. }
  2965. }
  2966. else
  2967. {
  2968. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2969. ,MESSAGE_TYPE_CALLRESULT
  2970. ,uuid
  2971. ,payload
  2972. ,connectorIdInt
  2973. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2974. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2975. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2976. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2977. int len = nPeriod;
  2978. //Last Period StartPriod is less than diffSeconds
  2979. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds)
  2980. {
  2981. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2982. , 0
  2983. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2984. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2985. }
  2986. else
  2987. {
  2988. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2989. {
  2990. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) < diffSeconds) && ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod % 86400) > diffSeconds))//if (idx_sample == 0)
  2991. {
  2992. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2993. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2994. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2995. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2996. }
  2997. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2998. {
  2999. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3000. , ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)) //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
  3001. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3002. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3003. }
  3004. }
  3005. }
  3006. sprintf(message + strlen(message), "]}}]");
  3007. }
  3008. LWS_Send(message);
  3009. result = TRUE;
  3010. return result;
  3011. }
  3012. int sendGetConfigurationConfirmation(char *uuid)
  3013. {
  3014. mtrace();
  3015. int result = FAIL;
  3016. int MaxKeySupported = 0;
  3017. int sentConfigurationNumber= 0;
  3018. int sentunConfigurationNumber= 0;
  3019. char message[4000]={0};
  3020. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3021. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3022. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3023. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3024. ,MESSAGE_TYPE_CALLRESULT
  3025. ,uuid );
  3026. //configuration key
  3027. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3028. {
  3029. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3030. {
  3031. if (sentConfigurationNumber == 0)
  3032. {
  3033. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3034. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3035. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3036. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3037. }
  3038. else
  3039. {
  3040. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3041. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3042. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3043. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3044. }
  3045. sentConfigurationNumber = sentConfigurationNumber + 1;
  3046. }
  3047. }
  3048. sprintf(message + strlen(message), "]");
  3049. if(UnknownKeynum != 0)
  3050. {
  3051. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3052. //unkown key
  3053. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3054. {
  3055. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3056. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3057. if(sentunConfigurationNumber == 0)
  3058. {
  3059. sprintf(message + strlen(message), "\"%s\""
  3060. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3061. }
  3062. else
  3063. {
  3064. sprintf(message + strlen(message), ",\"%s\""
  3065. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3066. }
  3067. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3068. }
  3069. sprintf(message + strlen(message), "]");
  3070. }
  3071. sprintf(message + strlen(message), "}]");
  3072. LWS_Send(message);
  3073. return result;
  3074. }
  3075. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3076. {
  3077. mtrace();
  3078. int result = FAIL;
  3079. char message[400]={0};
  3080. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3081. if(strcmp(payload,"")==0)
  3082. {
  3083. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3084. }
  3085. else
  3086. {
  3087. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3088. }
  3089. LWS_Send(message);
  3090. result = TRUE;
  3091. return result;
  3092. }
  3093. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3094. {
  3095. mtrace();
  3096. int result = FAIL;
  3097. char message[80]={0};
  3098. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3099. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3100. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3101. LWS_Send(message);
  3102. result = TRUE;
  3103. return result;
  3104. }
  3105. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3106. {
  3107. mtrace();
  3108. int result = FAIL;
  3109. char message[80]={0};
  3110. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3111. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3112. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3113. LWS_Send(message);
  3114. result = TRUE;
  3115. return result;
  3116. }
  3117. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3118. {
  3119. mtrace();
  3120. int result = FAIL;
  3121. char message[80]={0};
  3122. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3123. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3124. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3125. LWS_Send(message);
  3126. result = TRUE;
  3127. return result;
  3128. }
  3129. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3130. {
  3131. mtrace();
  3132. int result = FAIL;
  3133. char message[80]={0};
  3134. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3135. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3136. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3137. LWS_Send(message);
  3138. result = TRUE;
  3139. return result;
  3140. }
  3141. int sendResetConfirmation(char *uuid,char *payload)
  3142. {
  3143. mtrace();
  3144. int result = FAIL;
  3145. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3146. char message[80]={0};
  3147. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3148. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3149. LWS_Send(message);
  3150. result = TRUE;
  3151. return result;
  3152. }
  3153. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3154. {
  3155. mtrace();
  3156. int result = FAIL;
  3157. char message[500]={0};
  3158. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3159. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3160. LWS_Send(message);
  3161. result = TRUE;
  3162. return result;
  3163. }
  3164. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3165. {
  3166. mtrace();
  3167. int result = FAIL;
  3168. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3169. char message[80]={0};
  3170. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3171. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3172. LWS_Send(message);
  3173. result = TRUE;
  3174. return result;
  3175. }
  3176. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3177. {
  3178. mtrace();
  3179. int result = FAIL;
  3180. char message[80]={0};
  3181. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3182. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3183. LWS_Send(message);
  3184. result = TRUE;
  3185. return result;
  3186. }
  3187. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3188. {
  3189. mtrace();
  3190. int result = FAIL;
  3191. char message[80]={0};
  3192. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3193. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3194. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3195. LWS_Send(message);
  3196. result = TRUE;
  3197. return result;
  3198. }
  3199. int sendUpdateFirmwareConfirmation(char *uuid)
  3200. {
  3201. mtrace();
  3202. int result = FAIL;
  3203. char message[60]={0};
  3204. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3205. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3206. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3207. LWS_Send(message);
  3208. result = TRUE;
  3209. return result;
  3210. }
  3211. //==========================================
  3212. // send CallError routine
  3213. //==========================================
  3214. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3215. {
  3216. mtrace();
  3217. //int result = FAIL;
  3218. char message[220]={0};
  3219. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3220. #ifdef SystemLogMessage
  3221. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3222. uniqueId, action, errorCode, errorDescription);
  3223. #endif
  3224. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3225. LWS_Send(message);
  3226. //result = TRUE;
  3227. }
  3228. //==========================================
  3229. // Handle server request routine Start
  3230. //==========================================
  3231. #define GUN_NUM 1
  3232. int handleCancelReservationRequest(char *uuid, char *payload)
  3233. {
  3234. mtrace();
  3235. int result = FAIL;
  3236. int gunNO = 0;
  3237. int reservationIdInt =0;
  3238. char comfirmstr[20];
  3239. int c = 0;
  3240. char *loc;
  3241. char sstr[100]={0};
  3242. DEBUG_INFO("handle CancelReservationRequest\n");
  3243. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3244. c = 0;
  3245. loc = strstr(payload, "reservationId");
  3246. memset(sstr ,0, sizeof(sstr) );
  3247. while (loc[strlen("reservationId")+2+c] != '}')
  3248. {
  3249. sstr[c] = loc[strlen("reservationId")+2+c];
  3250. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3251. c++;
  3252. }
  3253. sstr[c] = '\0';
  3254. reservationIdInt = atoi(sstr);
  3255. memset(comfirmstr, 0, sizeof comfirmstr);
  3256. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3257. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3258. //check Transaction active
  3259. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3260. {
  3261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3262. {
  3263. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3264. {
  3265. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3266. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3267. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3268. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3269. goto end;
  3270. }
  3271. }
  3272. for (int index = 0; index < CCS_QUANTITY; index++)
  3273. {
  3274. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3275. {
  3276. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3277. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3278. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3279. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3280. goto end;
  3281. }
  3282. }
  3283. for (int index = 0; index < GB_QUANTITY; index++)
  3284. {
  3285. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3286. {
  3287. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3288. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3289. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3290. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3291. goto end;
  3292. }
  3293. }
  3294. }
  3295. else
  3296. {
  3297. for (int index = 0; index < AC_QUANTITY; index++)
  3298. {
  3299. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3300. {
  3301. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3302. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3303. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3304. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3305. goto end;
  3306. }
  3307. }
  3308. }// END FOR AC ELSE
  3309. //The reservationId does NOT match the reservationId
  3310. sendCancelReservationConfirmation(uuid, comfirmstr);
  3311. end:
  3312. // Fill in ocpp packet uuid
  3313. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3314. return result;
  3315. }
  3316. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3317. {
  3318. mtrace();
  3319. int result = FAIL;
  3320. int gunIndex = 0;
  3321. char sstr[90]={0};
  3322. char typeStr[16]={0};
  3323. char comfirmstr[20];
  3324. int specificId = FALSE;
  3325. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3326. char *loc;
  3327. //int intervalInt = 0;
  3328. int c = 0;
  3329. /*** connectorId ****/
  3330. c = 0;
  3331. loc = strstr(payload, "connectorId");
  3332. memset(sstr ,0, sizeof(sstr) );
  3333. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3334. {
  3335. sstr[c] = loc[strlen("connectorId")+2+c];
  3336. c++;
  3337. }
  3338. sstr[c] = '\0';
  3339. gunIndex = atoi(sstr);
  3340. /***type ****/
  3341. loc = strstr(payload, "type");
  3342. memset(sstr ,0, sizeof(sstr) );
  3343. c = 0;
  3344. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3345. {
  3346. sstr[c] = loc[3+strlen("type")+c];
  3347. c++;
  3348. }
  3349. sstr[c] = '\0';
  3350. strcpy(typeStr, sstr);
  3351. if(gunIndex != 0)
  3352. {
  3353. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3354. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3355. }
  3356. else
  3357. {
  3358. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3359. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3360. }
  3361. memset(comfirmstr, 0, sizeof comfirmstr);
  3362. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3363. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3364. {
  3365. specificId = TRUE;
  3366. }
  3367. if(specificId == FALSE)
  3368. goto end;
  3369. if(gunIndex != 0)
  3370. {
  3371. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3372. }
  3373. else
  3374. {
  3375. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3376. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3377. }
  3378. /*
  3379. enum SYSTEM_STATUS
  3380. {
  3381. SYS_MODE_BOOTING = 0,
  3382. SYS_MODE_IDLE = 1,
  3383. SYS_MODE_AUTHORIZING = 2,
  3384. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3385. SYS_MODE_REASSIGN = 4,
  3386. SYS_MODE_PREPARING = 5,
  3387. SYS_MODE_PREPARE_FOR_EV = 6,
  3388. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3389. SYS_MODE_CHARGING = 8,
  3390. SYS_MODE_TERMINATING = 9,
  3391. SYS_MODE_COMPLETE = 10,
  3392. SYS_MODE_ALARM = 11,
  3393. SYS_MODE_FAULT = 12,
  3394. SYS_MODE_RESERVATION = 13,
  3395. SYS_MODE_BOOKING = 14,
  3396. SYS_MODE_MAINTAIN = 15,
  3397. SYS_MODE_DEBUG = 16,
  3398. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3399. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3400. SYS_MODE_UPDATE = 19
  3401. };
  3402. */
  3403. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3404. {
  3405. //check Transaction active
  3406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3407. {
  3408. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3409. {
  3410. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3411. {
  3412. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3413. {
  3414. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3415. }
  3416. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3417. {
  3418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3419. }
  3420. else
  3421. {
  3422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3423. }
  3424. goto end;
  3425. }
  3426. }//END FOR CHAdeMO_QUANTITY
  3427. for (int index = 0; index < CCS_QUANTITY; index++)
  3428. {
  3429. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3430. {
  3431. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3432. {
  3433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3434. }
  3435. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3436. {
  3437. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3438. }
  3439. else
  3440. {
  3441. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3442. }
  3443. goto end;
  3444. }
  3445. }//END FOR CCS_QUANTITY
  3446. for (int index = 0; index < GB_QUANTITY; index++)
  3447. {
  3448. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3449. {
  3450. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3451. {
  3452. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3453. }
  3454. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3455. {
  3456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3457. }
  3458. else
  3459. {
  3460. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3461. }
  3462. goto end;
  3463. }
  3464. }// END FOR GB_QUANTITY
  3465. }
  3466. else
  3467. {
  3468. for (int index = 0; index < AC_QUANTITY; index++)
  3469. {
  3470. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3471. {
  3472. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3473. {
  3474. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3475. }
  3476. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3477. {
  3478. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3479. }
  3480. else
  3481. {
  3482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3483. }
  3484. goto end;
  3485. }
  3486. }//END FOR AC_QUANTITY
  3487. }// END FOR AC ELSE
  3488. }//END FOR AvailabilityTypeStr[Inoperative]
  3489. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3490. {
  3491. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3492. //check Transaction active
  3493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3494. {
  3495. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3496. {
  3497. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3498. {
  3499. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3500. goto end;
  3501. }
  3502. }//END FOR CHAdeMO_QUANTITY
  3503. for (int index = 0; index < CCS_QUANTITY; index++)
  3504. {
  3505. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3506. {
  3507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3508. goto end;
  3509. }
  3510. }//END FOR CCS_QUANTITY
  3511. for (int index = 0; index < GB_QUANTITY; index++)
  3512. {
  3513. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3514. {
  3515. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3516. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3517. goto end;
  3518. }
  3519. }// END FOR GB_QUANTITY
  3520. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3521. }
  3522. else
  3523. {
  3524. for (int index = 0; index < AC_QUANTITY; index++)
  3525. {
  3526. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3527. {
  3528. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3529. goto end;
  3530. }
  3531. }//END FOR CHAdeMO_QUANTITY
  3532. }//END FOR AC ELSE
  3533. }//END FOR AvailabilityTypeStr[Operative]
  3534. end:
  3535. if(gunIndex != 0)
  3536. {
  3537. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3538. }
  3539. else
  3540. {
  3541. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3542. }
  3543. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3544. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3545. return result;
  3546. }
  3547. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3548. {
  3549. mtrace();
  3550. int result = FAIL;
  3551. char sstr[100]={0};
  3552. char keystr[40]={0};
  3553. char valuestr[100]={0};
  3554. char *loc;
  3555. int c = 0;
  3556. char comfirmstr[20]={0};
  3557. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3558. /***key ****/
  3559. loc = strstr(payload, "key");
  3560. memset(sstr ,0, sizeof(sstr) );
  3561. c = 0;
  3562. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3563. {
  3564. sstr[c] = loc[3+strlen("key")+c];
  3565. c++;
  3566. }
  3567. sstr[c] = '\0';
  3568. strcpy(keystr, sstr);
  3569. //DEBUG_INFO( "keystr=%s\n",keystr);
  3570. /***value ****/
  3571. loc = strstr(payload, "value");
  3572. memset(sstr ,0, sizeof(sstr) );
  3573. c = 0;
  3574. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3575. {
  3576. sstr[c] = loc[3+strlen("value")+c];
  3577. c++;
  3578. }
  3579. sstr[c] = '\0';
  3580. strcpy(valuestr, sstr);
  3581. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3582. if((uuid==NULL) || (payload ==NULL) )
  3583. {
  3584. #ifdef Debug
  3585. DEBUG_INFO("payload is null\n");
  3586. #endif
  3587. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3588. }
  3589. else
  3590. {
  3591. int status = setKeyValue(keystr, valuestr);
  3592. switch(status)
  3593. {
  3594. case ConfigurationStatus_Accepted:
  3595. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3596. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3597. StoreConfigurationTable();
  3598. break;
  3599. case ConfigurationStatus_Rejected:
  3600. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3601. break;
  3602. case RebootRequired:
  3603. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3604. StoreConfigurationTable();
  3605. break;
  3606. case NotSupported:
  3607. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3608. break;
  3609. default:
  3610. break;
  3611. }
  3612. }
  3613. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3614. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3615. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3616. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3617. {
  3618. ChageWebSocketPingInterval(atoi(valuestr));
  3619. }
  3620. return result;
  3621. }
  3622. int handleClearCacheRequest(char *uuid, char *payload)
  3623. {
  3624. mtrace();
  3625. int result = FAIL;
  3626. char comfirmstr[20];
  3627. int fd;
  3628. char rmFileCmd[100]={0};
  3629. struct stat stats;
  3630. DEBUG_INFO("handle ClearCacheRequest\n");
  3631. stat("/Storage/OCPP", &stats);
  3632. // Check for directory existence
  3633. if (S_ISDIR(stats.st_mode) == 1)
  3634. {
  3635. //DEBUG_ERROR("\n OCPP directory exist \n");
  3636. }
  3637. else
  3638. {
  3639. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3640. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3641. system(rmFileCmd);
  3642. }
  3643. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3644. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3645. {
  3646. DEBUG_INFO("AuthorizationCache file exist.\n");
  3647. }
  3648. else
  3649. {
  3650. DEBUG_INFO("AuthorizationCache file not exist\n");
  3651. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3652. if(log == NULL)
  3653. {
  3654. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3655. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3656. goto end;
  3657. }
  3658. else
  3659. {
  3660. fclose(log);
  3661. }
  3662. }
  3663. fd = open(AuthorizationCache_JSON,O_RDWR);
  3664. if(fd < 0)
  3665. {
  3666. DEBUG_INFO("open AuthorizationCache file failed\n");
  3667. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3668. }
  3669. else
  3670. {
  3671. DEBUG_INFO("open AuthorizationCache file successful\n");
  3672. //* 清空? 件 */
  3673. ftruncate(fd,0);
  3674. //* ? 新设置? 件? 移??*/
  3675. lseek(fd,0,SEEK_SET);
  3676. close(fd);
  3677. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3678. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3679. }
  3680. end:
  3681. sendClearCacheConfirmation(uuid, comfirmstr);
  3682. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3683. return result;
  3684. }
  3685. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3686. {
  3687. mtrace();
  3688. int result = FAIL;
  3689. int resultRename;
  3690. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3691. char chargingProfilePurposeStr[26]={0};
  3692. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3693. char tempchargingProfilePurposeStr[26]={0};
  3694. char sstr[160]={0};//sstr[200]={ 0 };
  3695. char str[100]={0};
  3696. int c = 0;
  3697. //int i = 0;
  3698. //char * pch;
  3699. char *loc;
  3700. char fname[200]={0};
  3701. char comfirmstr[20]={0};
  3702. char word[1600]={0};
  3703. int clearflag = FALSE;
  3704. int chargingProfileIdIsNULL = FALSE;
  3705. int connectorIsNULL = FALSE;
  3706. int chargingProfilePurposeIsNULL = FALSE;
  3707. int stackLevelIsNULL = FALSE;
  3708. //int GotoEnd = FALSE;
  3709. FILE *fptr1, *fptr2;
  3710. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3711. int n_chargingProfile=0;
  3712. int isEmptyFile = FALSE;
  3713. char sLineWord[1600]={0};
  3714. char chargingProfiles[10][100]={0};
  3715. int ChargeProfileCount = 0;
  3716. char ch;
  3717. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3718. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3719. //***id ****/
  3720. c = 0;
  3721. loc = strstr(payload, "id");
  3722. memset(sstr ,0, sizeof(sstr) );
  3723. if(loc == NULL)
  3724. {
  3725. chargingProfileIdIsNULL = TRUE;
  3726. }
  3727. else
  3728. {
  3729. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3730. {
  3731. sstr[c] = loc[strlen("id")+2+c];
  3732. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3733. c++;
  3734. }
  3735. sstr[c] = '\0';
  3736. chargingProfileIdInt = atoi(sstr);
  3737. }
  3738. //***connectorId ****/
  3739. c=0;
  3740. loc = strstr(payload, "connectorId");
  3741. memset(sstr ,0, sizeof(sstr) );
  3742. if(loc == NULL)
  3743. {
  3744. connectorIsNULL = TRUE;
  3745. }
  3746. else
  3747. {
  3748. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3749. {
  3750. sstr[c] = loc[strlen("connectorId")+2+c];
  3751. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3752. c++;
  3753. }
  3754. sstr[c] = '\0';
  3755. connectorIdInt = atoi(sstr);
  3756. }
  3757. //***chargingProfilePurpose ****/
  3758. loc = strstr(payload, "chargingProfilePurpose");
  3759. memset(sstr ,0, sizeof(sstr) );
  3760. c = 0;
  3761. if(loc == NULL)
  3762. {
  3763. chargingProfilePurposeIsNULL = TRUE;
  3764. }
  3765. else
  3766. {
  3767. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3768. {
  3769. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3770. c++;
  3771. }
  3772. sstr[c] = '\0';
  3773. strcpy(chargingProfilePurposeStr, sstr);
  3774. }
  3775. //***stackLevel ****/
  3776. c=0;
  3777. loc = strstr(payload, "stackLevel");
  3778. memset(sstr ,0, sizeof(sstr) );
  3779. if(loc == NULL)
  3780. {
  3781. stackLevelIsNULL = TRUE;
  3782. }
  3783. else
  3784. {
  3785. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3786. {
  3787. sstr[c] = loc[strlen("stackLevel")+2+c];
  3788. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3789. c++;
  3790. }
  3791. sstr[c] = '\0';
  3792. stackLevelInt = atoi(sstr);
  3793. }
  3794. if(connectorIsNULL == FALSE)
  3795. {
  3796. switch(connectorIdInt)
  3797. {
  3798. case 0:
  3799. if(chargingProfilePurposeIsNULL == TRUE)
  3800. {
  3801. int l = 0;
  3802. strcpy(fname, ChargePointMaxProfile_JSON);
  3803. if((access(fname,F_OK))!=-1)
  3804. {
  3805. strcpy(chargingProfiles[l], fname);
  3806. l = l + 1;
  3807. }
  3808. strcpy(fname, TxDefaultProfile_0_JSON);
  3809. if((access(fname,F_OK))!=-1)
  3810. {
  3811. strcpy(chargingProfiles[l], fname);
  3812. l = l + 1;
  3813. }
  3814. ChargeProfileCount = l;
  3815. }
  3816. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3817. {
  3818. strcpy(fname, ChargePointMaxProfile_JSON);
  3819. if((access(fname,F_OK))!=-1)
  3820. {
  3821. strcpy(chargingProfiles[0], fname);
  3822. ChargeProfileCount = 1;
  3823. }
  3824. }
  3825. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3826. {
  3827. strcpy(fname, TxDefaultProfile_0_JSON);
  3828. if((access(fname,F_OK))!=-1)
  3829. {
  3830. strcpy(chargingProfiles[0], fname);
  3831. ChargeProfileCount = 1;
  3832. }
  3833. }
  3834. break;
  3835. default:
  3836. if(chargingProfilePurposeIsNULL == TRUE)
  3837. {
  3838. int m = 0;
  3839. memset(fname, 0, sizeof fname);
  3840. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3841. if((access(fname,F_OK))!=-1)
  3842. {
  3843. strcpy(chargingProfiles[m], fname);
  3844. m = m + 1;
  3845. }
  3846. memset(fname, 0, sizeof fname);
  3847. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3848. if((access(fname,F_OK))!=-1)
  3849. {
  3850. strcpy(chargingProfiles[m], fname);
  3851. m = m + 1;
  3852. }
  3853. ChargeProfileCount = m;
  3854. }
  3855. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3856. {
  3857. //strcpy(fname, TxDefaultProfile_1_JSON);
  3858. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3859. if((access(fname,F_OK))!=-1)
  3860. {
  3861. strcpy(chargingProfiles[0], fname);
  3862. ChargeProfileCount = 1;
  3863. }
  3864. }
  3865. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3866. {
  3867. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3868. if((access(fname,F_OK))!=-1)
  3869. {
  3870. strcpy(chargingProfiles[0], fname);
  3871. ChargeProfileCount = 1;
  3872. }
  3873. //strcpy(fname, TxProfile_1_JSON);
  3874. }
  3875. //strcpy(fname, ChargePointMaxProfile_JSON );
  3876. break;
  3877. }
  3878. }
  3879. else // Check all Charging Profiles
  3880. {
  3881. int i = 0;
  3882. char fnametemp[200]={0};
  3883. ChargeProfileCount = 0;
  3884. //Check ChargePointMaxProfile.json exit
  3885. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3886. {
  3887. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3888. i = i + 1;
  3889. }
  3890. //Check TxDefaultProfile_0.json exit
  3891. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3892. {
  3893. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3894. i = i + 1;
  3895. }
  3896. //Check TxDefaultProfile_%d.json
  3897. for(int j=1; j <= gunTotalNumber; j++)
  3898. {
  3899. memset(fnametemp, 0, sizeof fnametemp);
  3900. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3901. if((access(fnametemp,F_OK))!=-1)
  3902. {
  3903. strcpy(chargingProfiles[i], fnametemp);
  3904. i = i + 1;
  3905. }
  3906. }
  3907. //Check TxProfile_%d.json
  3908. for(int j=1; j <= gunTotalNumber; j++)
  3909. {
  3910. memset(fnametemp, 0, sizeof fnametemp);
  3911. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3912. if((access(fnametemp,F_OK))!=-1)
  3913. {
  3914. strcpy(chargingProfiles[i], fnametemp);
  3915. i = i + 1;
  3916. }
  3917. }
  3918. ChargeProfileCount = i;
  3919. }// End connectorIsNULL is TRUE
  3920. if(ChargeProfileCount == 0)
  3921. {
  3922. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3923. goto end;
  3924. }
  3925. #if 0
  3926. fptr1 = fopen(fname, "r");
  3927. if (!fptr1)
  3928. {
  3929. //file not exist
  3930. DEBUG_INFO("Unable to open the input file!!\n");
  3931. fptr1 = fopen(fname, "w+");
  3932. }
  3933. fclose(fptr1);
  3934. #endif
  3935. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3936. {
  3937. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3938. goto end;
  3939. }
  3940. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3941. {
  3942. memset(str, 0, sizeof str);
  3943. // clear temp file
  3944. sprintf(str,"rm -f %s",temp);
  3945. system(str);
  3946. for(int k=0; k < ChargeProfileCount; k++)
  3947. {
  3948. memset(str, 0, sizeof str);
  3949. //clear file in C
  3950. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3951. system(str);
  3952. }
  3953. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3954. goto end;
  3955. }
  3956. else if(connectorIsNULL == TRUE)
  3957. {
  3958. for(int k=0; k < ChargeProfileCount; k++)
  3959. {
  3960. fptr1 = fopen(chargingProfiles[k], "r");
  3961. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  3962. //Check Charging Profile Count
  3963. while(fscanf(fptr1, "%s", word) != EOF)
  3964. {
  3965. //DEBUG_INFO("word=%s\n",word);
  3966. if(strstr(word, "chargingProfileId")!= NULL)
  3967. {
  3968. //DEBUG_INFO("test chargingProfileId \n");
  3969. n_chargingProfile = n_chargingProfile + 1;
  3970. //DEBUG_INFO("chargingProfileId Found\n");
  3971. }
  3972. }
  3973. rewind(fptr1);
  3974. //search Charging Profile Element
  3975. //int i= 0;
  3976. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3977. {
  3978. //------------------------tempconnectorIdInt------------------------//
  3979. loc = strstr(sLineWord, "connectorId");
  3980. c = 0;
  3981. memset(sstr ,0, sizeof(sstr) );
  3982. while (loc[strlen("connectorId")+2+c] != ',')
  3983. {
  3984. sstr[c] = loc[strlen("connectorId")+2+c];
  3985. c++;
  3986. }
  3987. sstr[c] = '\0';
  3988. tempconnectorIdInt = atoi(sstr);
  3989. printf("file's gun number is %d\n", tempconnectorIdInt);
  3990. //--------------------------chargingProfileId--------------------//
  3991. c = 0;
  3992. loc = strstr(sLineWord, "chargingProfileId");
  3993. memset(sstr ,0, sizeof(sstr) );
  3994. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3995. {
  3996. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3997. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3998. c++;
  3999. }
  4000. sstr[c] = '\0';
  4001. tempchargingProfileIdInt = atoi(sstr);
  4002. //stackLevel
  4003. c = 0;
  4004. loc = strstr(sLineWord, "stackLevel");
  4005. memset(sstr ,0, sizeof(sstr) );
  4006. while (loc[strlen("stackLevel")+2+c] != ',')
  4007. {
  4008. sstr[c] = loc[strlen("stackLevel")+2+c];
  4009. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4010. c++;
  4011. }
  4012. sstr[c] = '\0';
  4013. tempstackLevelInt = atoi(sstr);
  4014. c = 0;
  4015. loc = strstr(sLineWord, "chargingProfilePurpose");
  4016. memset(sstr ,0, sizeof(sstr) );
  4017. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4018. {
  4019. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4020. c++;
  4021. }
  4022. sstr[c] = '\0';
  4023. strcpy(tempchargingProfilePurposeStr, sstr);
  4024. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4025. {
  4026. //------- not write to fptr2-------//
  4027. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4028. //clearflag = TRUE;
  4029. }
  4030. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4031. {
  4032. //------- not write to fptr2-------//
  4033. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4034. }
  4035. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4036. {
  4037. //------- not write to fptr2-------//
  4038. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4039. }
  4040. else
  4041. {
  4042. fprintf(fptr2, sLineWord);//writing data into file
  4043. }
  4044. memset(sLineWord, 0, sizeof sLineWord);
  4045. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4046. if(clearflag == TRUE)
  4047. {
  4048. fclose(fptr1);
  4049. fclose(fptr2);
  4050. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4051. system(str);
  4052. // clear temp file
  4053. sprintf(str,"rm -f %s",temp);
  4054. system(str);
  4055. }
  4056. else
  4057. {
  4058. fclose(fptr1);
  4059. fclose(fptr2);
  4060. memset(str, 0, sizeof str);
  4061. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4062. system(str);
  4063. resultRename = rename(temp, chargingProfiles[k]);
  4064. if(resultRename == 0)
  4065. {
  4066. DEBUG_INFO("File ChargingProfile renamed successfully");
  4067. }
  4068. else
  4069. {
  4070. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4071. }
  4072. if(comfirmstr[0]== 0)
  4073. {
  4074. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4075. }
  4076. //Check chargingProfile is empty file
  4077. /*------ Read the file ----------------*/
  4078. fptr1=fopen(chargingProfiles[k],"r");
  4079. ch=fgetc(fptr1);
  4080. rewind(fptr1);
  4081. memset(sLineWord, 0, sizeof sLineWord);
  4082. if(ch!=EOF)
  4083. {
  4084. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4085. {
  4086. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4087. if(sLineWord[0]=='\0')
  4088. {
  4089. isEmptyFile = TRUE;
  4090. break;
  4091. }
  4092. else
  4093. {
  4094. isEmptyFile = FALSE;
  4095. break;
  4096. }
  4097. }
  4098. }
  4099. fclose(fptr1);
  4100. if(isEmptyFile == TRUE)
  4101. {
  4102. memset(str, 0, sizeof str);
  4103. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4104. system(str);
  4105. }
  4106. }
  4107. }// End of while(int k=0; k < ChargePointCount; k++)
  4108. }
  4109. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4110. {
  4111. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4112. for(int k=0; k < ChargeProfileCount; k++)
  4113. {
  4114. fptr1 = fopen(chargingProfiles[k], "r");
  4115. fptr2 = fopen(temp, "w+");
  4116. //Check Charging Profile Count
  4117. while(fscanf(fptr1, "%s", word) != EOF)
  4118. {
  4119. //DEBUG_INFO("word=%s\n",word);
  4120. if(strstr(word, "chargingProfileId")!= NULL)
  4121. {
  4122. //DEBUG_INFO("test chargingProfileId \n");
  4123. n_chargingProfile = n_chargingProfile + 1;
  4124. //DEBUG_INFO("chargingProfileId Found\n");
  4125. }
  4126. }
  4127. rewind(fptr1);
  4128. //search Charging Profile Element
  4129. //int i= 0;
  4130. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4131. {
  4132. //*************************tempconnectorIdInt*********************************/
  4133. loc = strstr(sLineWord, "connectorId");
  4134. c = 0;
  4135. memset(sstr ,0, sizeof(sstr) );
  4136. while (loc[strlen("connectorId")+2+c] != ',')
  4137. {
  4138. sstr[c] = loc[strlen("connectorId")+2+c];
  4139. c++;
  4140. }
  4141. sstr[c] = '\0';
  4142. tempconnectorIdInt = atoi(sstr);
  4143. //chargingProfileId
  4144. c = 0;
  4145. loc = strstr(sLineWord, "chargingProfileId");
  4146. memset(sstr ,0, sizeof(sstr) );
  4147. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4148. {
  4149. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4150. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4151. c++;
  4152. }
  4153. sstr[c] = '\0';
  4154. tempchargingProfileIdInt = atoi(sstr);
  4155. //stackLevel
  4156. c = 0;
  4157. loc = strstr(sLineWord, "stackLevel");
  4158. memset(sstr ,0, sizeof(sstr) );
  4159. while (loc[strlen("stackLevel")+2+c] != ',')
  4160. {
  4161. sstr[c] = loc[strlen("stackLevel")+2+c];
  4162. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4163. c++;
  4164. }
  4165. sstr[c] = '\0';
  4166. tempstackLevelInt = atoi(sstr);
  4167. c = 0;
  4168. loc = strstr(sLineWord, "chargingProfilePurpose");
  4169. memset(sstr ,0, sizeof(sstr) );
  4170. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4171. {
  4172. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4173. c++;
  4174. }
  4175. sstr[c] = '\0';
  4176. strcpy(tempchargingProfilePurposeStr, sstr);
  4177. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4178. {
  4179. //------- not write to fptr2-------//
  4180. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4181. //clearflag = TRUE;
  4182. }
  4183. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4184. {
  4185. //------- not write to fptr2-------//
  4186. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4187. }
  4188. else if(stackLevelIsNULL == TRUE)
  4189. {
  4190. //Clear Whole File
  4191. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4192. clearflag = TRUE;
  4193. break;
  4194. }
  4195. else
  4196. {
  4197. fprintf(fptr2, sLineWord);//writing data into file
  4198. }
  4199. memset(sLineWord, 0, sizeof sLineWord);
  4200. }
  4201. if(clearflag == TRUE)
  4202. {
  4203. fclose(fptr1);
  4204. fclose(fptr2);
  4205. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4206. system(str);
  4207. // clear temp file
  4208. sprintf(str,"rm -f %s",temp);
  4209. system(str);
  4210. }
  4211. else
  4212. {
  4213. fclose(fptr1);
  4214. fclose(fptr2);
  4215. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4216. system(str);
  4217. resultRename = rename(temp, chargingProfiles[k]);
  4218. if(resultRename == 0)
  4219. {
  4220. DEBUG_INFO("File ChargingProfile renamed successfully");
  4221. }
  4222. else
  4223. {
  4224. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4225. }
  4226. if(comfirmstr[0]== 0)
  4227. {
  4228. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4229. }
  4230. //Check chargingProfile is empty file
  4231. /*------ Read the file ----------------*/
  4232. fptr1=fopen(chargingProfiles[k],"r");
  4233. ch=fgetc(fptr1);
  4234. rewind(fptr1);
  4235. memset(sLineWord, 0, sizeof sLineWord);
  4236. if(ch!=EOF)
  4237. {
  4238. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4239. {
  4240. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4241. if(sLineWord[0]=='\0')
  4242. {
  4243. isEmptyFile = TRUE;
  4244. break;
  4245. }
  4246. else
  4247. {
  4248. isEmptyFile = FALSE;
  4249. break;
  4250. }
  4251. }
  4252. }
  4253. fclose(fptr1);
  4254. if(isEmptyFile == TRUE)
  4255. {
  4256. memset(str, 0, sizeof str);
  4257. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4258. system(str);
  4259. }
  4260. /*------- End of reading ---------------*/
  4261. }
  4262. } // while(int k=0; k < ChargeProfileCount; k++)
  4263. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4264. end:
  4265. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4266. return result;
  4267. }
  4268. int handleDataTransferRequest(char *uuid, char *payload)
  4269. {
  4270. mtrace();
  4271. int result = FAIL;
  4272. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4273. char tempvendorId[255]={0};
  4274. char tempmessageId[50]={0};
  4275. char tempdata[50]={0};
  4276. char sstr[160]={0};//sstr[200]={ 0 };
  4277. char message[80]={0};
  4278. int c = 0;
  4279. char *loc;
  4280. DEBUG_INFO("handle DataTransferRequest\n");
  4281. if((uuid != NULL) && (payload != NULL))
  4282. {
  4283. //===============================
  4284. // vendorId
  4285. //===============================
  4286. c = 0;
  4287. loc = strstr(payload, "vendorId");
  4288. while (loc[strlen("vendorId")+3+c] != '\"')
  4289. {
  4290. sstr[c] = loc[strlen("vendorId")+3+c];
  4291. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4292. c++;
  4293. }
  4294. sstr[c] = '\0';
  4295. strcpy(tempvendorId,sstr);
  4296. //===============================
  4297. // messageId
  4298. //===============================
  4299. memset(sstr ,0, sizeof(sstr) );
  4300. c = 0;
  4301. loc = strstr(payload, "messageId");
  4302. while (loc[strlen("messageId")+3+c] != '\"')
  4303. {
  4304. sstr[c] = loc[strlen("messageId")+3+c];
  4305. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4306. c++;
  4307. }
  4308. sstr[c] = '\0';
  4309. strcpy(tempmessageId,sstr);
  4310. //===============================
  4311. // data
  4312. //===============================
  4313. memset(sstr ,0, sizeof(sstr) );
  4314. c = 0;
  4315. loc = strstr(payload, "data");
  4316. printf("loc=%s\n",loc);
  4317. while (loc[strlen("data")+3+c] != '\"')
  4318. {
  4319. sstr[c] = loc[strlen("data")+3+c];
  4320. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4321. c++;
  4322. }
  4323. sstr[c] = '\0';
  4324. strcpy(tempdata,sstr);
  4325. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4326. }
  4327. else
  4328. {
  4329. char guid[37]={0};
  4330. random_uuid(guid);
  4331. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4332. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4333. }
  4334. LWS_Send(message);
  4335. return result;
  4336. }
  4337. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4338. {
  4339. mtrace();
  4340. int result = FAIL;
  4341. int connectorIdInt, durationInt;
  4342. char chargingRateUnitStr[4]={0};
  4343. //int tempconnectorIdInt,
  4344. int tempdurationInt;
  4345. float tempminChargingRateFloat = 0.0;
  4346. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4347. int tempStartPeriodInt=0;
  4348. float tempLimitInt=0.0;//0.1;
  4349. int tempNumberPhasesInt=0;
  4350. char fname[200];
  4351. char comfirmstr[20];
  4352. //float totallimit =0.0;
  4353. float MinChargingRate =0.0;
  4354. //double diff_t;
  4355. //struct tm tp;
  4356. FILE *fptr1;
  4357. int c = 0;
  4358. //int i = 0;
  4359. char * pch;
  4360. char *loc;
  4361. char sstr[200]={ 0 };
  4362. int n_chargingProfile = 0;
  4363. int n_SchedulePeriods = 0;
  4364. char SchedulePeriodList[10][200]={0};
  4365. char sLineWord[1600]={0};
  4366. //int n_periods = 0;
  4367. char word[1000]={0};
  4368. int confirmPeriods = 0;
  4369. struct StructProfile ChargePointMaxProfile;
  4370. struct StructProfile TxDefaultProfile;
  4371. struct StructProfile TxProfile;
  4372. struct StructProfile TxDefaultProfiletemp[2]={0};
  4373. int TxDefaultProfileFileIsNull=FALSE;
  4374. int ChargePointMaxProfileIsNull=FALSE;
  4375. int TxProfileIsNull=FALSE;
  4376. int CompositeSceduleIndex = 0;
  4377. char ChargePointMaxProfileScheduleStr[30]={0};
  4378. char TxDefaultProfileScheduleStr[30]={0};
  4379. char TxProfileScheduleStr[30]={0};
  4380. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4381. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4382. memset(&TxProfile,0,sizeof(struct StructProfile));
  4383. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4384. c=0;
  4385. loc = strstr(payload, "connectorId");
  4386. memset(sstr ,0, sizeof(sstr) );
  4387. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4388. {
  4389. sstr[c] = loc[strlen("connectorId")+2+c];
  4390. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4391. c++;
  4392. }
  4393. sstr[c] = '\0';
  4394. connectorIdInt = atoi(sstr);
  4395. c=0;
  4396. loc = strstr(payload, "duration");
  4397. memset(sstr ,0, sizeof(sstr) );
  4398. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4399. {
  4400. sstr[c] = loc[strlen("duration")+2+c];
  4401. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4402. c++;
  4403. }
  4404. sstr[c] = '\0';
  4405. durationInt = atoi(sstr);
  4406. c = 0;
  4407. loc = strstr(payload, "chargingRateUnit");
  4408. memset(sstr ,0, sizeof(sstr) );
  4409. if(loc == NULL)
  4410. {
  4411. }
  4412. else
  4413. {
  4414. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4415. {
  4416. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4417. c++;
  4418. }
  4419. sstr[c] = '\0';
  4420. strcpy(chargingRateUnitStr, sstr);
  4421. }
  4422. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4423. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4424. if(connectorIdInt==0) // connectorId is 0
  4425. {
  4426. //******************************ChargePointMaxProfile*****************************************************/
  4427. strcpy(fname, ChargePointMaxProfile_JSON );
  4428. char word[30]={0};
  4429. char sLineWord[1060]={0};
  4430. int n_chargingProfile=0;
  4431. ChargePointMaxProfileIsNull=TRUE;
  4432. if((access(fname,F_OK))!=-1)
  4433. {
  4434. fptr1 = fopen(fname, "r");
  4435. int c;
  4436. c = fgetc(fptr1);
  4437. //DEBUG_INFO("c:%d\n",c);
  4438. rewind(fptr1);
  4439. if(c == EOF)
  4440. {
  4441. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4442. ChargePointMaxProfileIsNull=TRUE;
  4443. fclose(fptr1);
  4444. }
  4445. else
  4446. {
  4447. ChargePointMaxProfileIsNull=FALSE;
  4448. while(fscanf(fptr1, "%s", word) != EOF)
  4449. {
  4450. if(strcmp(word, "chargingProfileId") == 0)
  4451. {
  4452. n_chargingProfile = n_chargingProfile + 1;
  4453. printf("Found\n");
  4454. }
  4455. }
  4456. rewind(fptr1);
  4457. //search Charging Profile Element
  4458. int i= 0;
  4459. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4460. #if 0
  4461. /***********connectorId****************/
  4462. c = 0;
  4463. loc = strstr(sLineWord, "connectorId");
  4464. // printf("loc=%s\n",loc);
  4465. memset(sstr ,0, sizeof(sstr) );
  4466. while (loc[strlen("connectorId")+2+c] != ',')
  4467. {
  4468. sstr[c] = loc[strlen("connectorId")+2+c];
  4469. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4470. c++;
  4471. }
  4472. sstr[c] = '\0';
  4473. tempconnectorIdInt = atoi(sstr);
  4474. #endif
  4475. //***********validFrom**************/
  4476. c = 0;
  4477. loc = strstr(sLineWord, "validFrom");
  4478. //DEBUG_INFO("loc=%s\n",loc);
  4479. memset(sstr ,0, sizeof(sstr) );
  4480. if(loc != NULL)
  4481. {
  4482. while (loc[3+strlen("validFrom")+c] != '\"')
  4483. {
  4484. sstr[c] = loc[3+strlen("validFrom")+c];
  4485. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4486. c++;
  4487. }
  4488. sstr[c] = '\0';
  4489. DEBUG_INFO("validFrom=%s\n",sstr);
  4490. strcpy(tempvalidFromStr,sstr);
  4491. }
  4492. else
  4493. {
  4494. strcpy(tempvalidFromStr,"");
  4495. }
  4496. //**********startSchedule**********/
  4497. c = 0;
  4498. loc = strstr(sLineWord, "startSchedule");
  4499. //DEBUG_INFO("loc=%s\n",loc);
  4500. memset(sstr ,0, sizeof(sstr) );
  4501. while (loc[3+strlen("startSchedule")+c] != '\"')
  4502. {
  4503. sstr[c] = loc[3+strlen("startSchedule")+c];
  4504. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4505. c++;
  4506. }
  4507. sstr[c] = '\0';
  4508. strcpy(tempstartScheduleStr, sstr);
  4509. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4510. //**********chargingRateUnit**********/
  4511. c = 0;
  4512. loc = strstr(sLineWord, "chargingRateUnit");
  4513. memset(sstr ,0, sizeof(sstr) );
  4514. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4515. {
  4516. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4517. c++;
  4518. }
  4519. sstr[c] = '\0';
  4520. strcpy(tempchargingRateUnitStr, sstr);
  4521. //**********minChargingRate*******/
  4522. c = 0;
  4523. loc = strstr(sLineWord, "minChargingRate");
  4524. //printf("loc=%s\n",loc);
  4525. if(loc != NULL)
  4526. {
  4527. memset(sstr ,0, sizeof(sstr) );
  4528. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4529. {
  4530. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4531. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4532. c++;
  4533. }
  4534. sstr[c] = '\0';
  4535. tempminChargingRateFloat = atof(sstr);
  4536. }
  4537. else
  4538. {
  4539. tempminChargingRateFloat = 0.0;
  4540. }
  4541. //
  4542. #if 0
  4543. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4544. tp.tm_isdst = -1;
  4545. time_t utc = mktime(&tp);
  4546. // current time
  4547. time_t t = time(NULL);
  4548. #endif
  4549. //diff_t = difftime(t, utc);
  4550. //parsing strings to words
  4551. i = 0;
  4552. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4553. loc = loc+3+strlen("chargingSchedulePeriod");
  4554. pch = strtok(loc ,"{");
  4555. while (pch != NULL)
  4556. {
  4557. strcpy(SchedulePeriodList[i], pch);
  4558. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4559. //printf ("%s\n",pch);
  4560. pch = strtok (NULL, "{");
  4561. i = i + 1;
  4562. }
  4563. n_SchedulePeriods = i;
  4564. for(int i=0;i<n_SchedulePeriods;i++)
  4565. {
  4566. //*************startPeriod****************/
  4567. c = 0;
  4568. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4569. memset(sstr ,0, sizeof(sstr) );
  4570. while (loc[strlen("startPeriod")+2+c] != ',')
  4571. {
  4572. sstr[c] = loc[strlen("startPeriod")+2+c];
  4573. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4574. c++;
  4575. }
  4576. sstr[c] = '\0';
  4577. tempStartPeriodInt = atoi(sstr);
  4578. //*************limit****************/
  4579. c = 0;
  4580. loc = strstr(SchedulePeriodList[i], "limit");
  4581. memset(sstr ,0, sizeof(sstr) );
  4582. while (loc[strlen("limit")+2+c] != ',')
  4583. {
  4584. sstr[c] = loc[strlen("limit")+2+c];
  4585. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4586. c++;
  4587. }
  4588. sstr[c] = '\0';
  4589. tempLimitInt = atof(sstr);
  4590. //*************numberPhases****************/
  4591. c = 0;
  4592. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4593. memset(sstr ,0, sizeof(sstr) );
  4594. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4595. {
  4596. sstr[c] = loc[strlen("numberPhases")+2+c];
  4597. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4598. c++;
  4599. }
  4600. sstr[c] = '\0';
  4601. tempNumberPhasesInt = atoi(sstr);
  4602. ChargePointMaxProfile.Duration = durationInt;
  4603. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4604. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4605. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4606. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4607. }
  4608. if(MinChargingRate < tempminChargingRateFloat)
  4609. MinChargingRate = tempminChargingRateFloat;
  4610. }
  4611. }// End of file ChargingProfile
  4612. } //THE END OF ACCESS ChargePointMaxProfile
  4613. //******************************TxDefaultProfile***********************************************/
  4614. strcpy(fname, TxDefaultProfile_0_JSON);
  4615. memset(word, 0, 30);
  4616. memset(sLineWord, 0, 1060);
  4617. //char word[30]={0};
  4618. //char sLineWord[1060]={0};
  4619. n_chargingProfile=0;
  4620. TxDefaultProfileFileIsNull=TRUE;
  4621. if((access(fname,F_OK))!=-1)
  4622. {
  4623. fptr1 = fopen(fname, "r");
  4624. c = 0;
  4625. c = fgetc(fptr1);
  4626. //DEBUG_INFO("c:%d\n",c);
  4627. rewind(fptr1);
  4628. if(c == EOF)
  4629. {
  4630. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4631. TxDefaultProfileFileIsNull=TRUE;
  4632. fclose(fptr1);
  4633. }
  4634. else
  4635. {
  4636. TxDefaultProfileFileIsNull=FALSE;
  4637. while(fscanf(fptr1, "%s", word) != EOF)
  4638. {
  4639. if(strcmp(word, "chargingProfileId") == 0)
  4640. {
  4641. n_chargingProfile = n_chargingProfile + 1;
  4642. printf("Found\n");
  4643. }
  4644. }
  4645. rewind(fptr1);
  4646. //search Charging Profile Element
  4647. int i= 0;
  4648. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4649. #if 0
  4650. /***********connectorId****************/
  4651. c = 0;
  4652. loc = strstr(sLineWord, "connectorId");
  4653. // printf("loc=%s\n",loc);
  4654. memset(sstr ,0, sizeof(sstr) );
  4655. while (loc[strlen("connectorId")+2+c] != ',')
  4656. {
  4657. sstr[c] = loc[strlen("connectorId")+2+c];
  4658. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4659. c++;
  4660. }
  4661. sstr[c] = '\0';
  4662. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4663. tempconnectorIdInt = atoi(sstr);
  4664. #endif
  4665. //***********validFrom**************/
  4666. c = 0;
  4667. loc = strstr(sLineWord, "validFrom");
  4668. //DEBUG_INFO("loc=%s\n",loc);
  4669. memset(sstr ,0, sizeof(sstr) );
  4670. if(loc != NULL)
  4671. {
  4672. while (loc[3+strlen("validFrom")+c] != '\"')
  4673. {
  4674. sstr[c] = loc[3+strlen("validFrom")+c];
  4675. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4676. c++;
  4677. }
  4678. sstr[c] = '\0';
  4679. DEBUG_INFO("validFrom=%s\n",sstr);
  4680. strcpy(tempvalidFromStr,sstr);
  4681. }
  4682. else
  4683. {
  4684. strcpy(tempvalidFromStr,"");
  4685. }
  4686. //**********startSchedule**********/
  4687. c = 0;
  4688. loc = strstr(sLineWord, "startSchedule");
  4689. //DEBUG_INFO("loc=%s\n",loc);
  4690. memset(sstr ,0, sizeof(sstr) );
  4691. while (loc[3+strlen("startSchedule")+c] != '\"')
  4692. {
  4693. sstr[c] = loc[3+strlen("startSchedule")+c];
  4694. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4695. c++;
  4696. }
  4697. sstr[c] = '\0';
  4698. strcpy(tempstartScheduleStr, sstr);
  4699. strcpy(TxDefaultProfileScheduleStr, sstr);
  4700. //**********chargingRateUnit**********/
  4701. c = 0;
  4702. loc = strstr(sLineWord, "chargingRateUnit");
  4703. memset(sstr ,0, sizeof(sstr) );
  4704. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4705. {
  4706. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4707. c++;
  4708. }
  4709. sstr[c] = '\0';
  4710. strcpy(tempchargingRateUnitStr, sstr);
  4711. //**********minChargingRate*******/
  4712. c = 0;
  4713. loc = strstr(sLineWord, "minChargingRate");
  4714. //printf("loc=%s\n",loc);
  4715. if(loc != NULL)
  4716. {
  4717. memset(sstr ,0, sizeof(sstr) );
  4718. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4719. {
  4720. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4721. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4722. c++;
  4723. }
  4724. sstr[c] = '\0';
  4725. tempminChargingRateFloat = atof(sstr);
  4726. }
  4727. else
  4728. {
  4729. tempminChargingRateFloat = 0.0;
  4730. }
  4731. #if 0
  4732. //
  4733. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4734. tp.tm_isdst = -1;
  4735. time_t utc = mktime(&tp);
  4736. // current time
  4737. time_t t = time(NULL);
  4738. //diff_t = difftime(t, utc);
  4739. #endif
  4740. //parsing strings to words
  4741. i = 0;
  4742. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4743. loc = loc+3+strlen("chargingSchedulePeriod");
  4744. pch = strtok(loc ,"{");
  4745. while (pch != NULL)
  4746. {
  4747. strcpy(SchedulePeriodList[i], pch);
  4748. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4749. //printf ("%s\n",pch);
  4750. pch = strtok (NULL, "{");
  4751. i = i + 1;
  4752. }
  4753. n_SchedulePeriods = i;
  4754. for(int i=0;i<n_SchedulePeriods;i++)
  4755. {
  4756. //*************startPeriod****************/
  4757. c = 0;
  4758. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4759. memset(sstr ,0, sizeof(sstr) );
  4760. while (loc[strlen("startPeriod")+2+c] != ',')
  4761. {
  4762. sstr[c] = loc[strlen("startPeriod")+2+c];
  4763. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4764. c++;
  4765. }
  4766. sstr[c] = '\0';
  4767. tempStartPeriodInt = atoi(sstr);
  4768. //*************limit****************/
  4769. c = 0;
  4770. loc = strstr(SchedulePeriodList[i], "limit");
  4771. memset(sstr ,0, sizeof(sstr) );
  4772. while (loc[strlen("limit")+2+c] != ',')
  4773. {
  4774. sstr[c] = loc[strlen("limit")+2+c];
  4775. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4776. c++;
  4777. }
  4778. sstr[c] = '\0';
  4779. tempLimitInt = atof(sstr);
  4780. //*************numberPhases****************/
  4781. c = 0;
  4782. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4783. memset(sstr ,0, sizeof(sstr) );
  4784. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4785. {
  4786. sstr[c] = loc[strlen("numberPhases")+2+c];
  4787. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4788. c++;
  4789. }
  4790. sstr[c] = '\0';
  4791. tempNumberPhasesInt = atoi(sstr);
  4792. TxDefaultProfile.Duration = durationInt;
  4793. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4794. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4795. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4796. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4797. }
  4798. if(MinChargingRate < tempminChargingRateFloat)
  4799. MinChargingRate = tempminChargingRateFloat;
  4800. }
  4801. }
  4802. }// the end of ACCESS TxDefaultProfile
  4803. //--------------------- Composite Schedule-----------------------------//
  4804. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4805. {
  4806. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4807. struct tm tp;
  4808. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4809. tp.tm_isdst = -1;
  4810. time_t utc = mktime(&tp);
  4811. time_t t = time(NULL);
  4812. double diff_f = difftime(t, utc);
  4813. int diff_i; //= (int)diff_f;
  4814. int quotient; //= diff_i / 86400;//86400 seconds/day
  4815. int period = 0;
  4816. if(diff_f >= 0)
  4817. {
  4818. diff_i = (int)diff_f;
  4819. quotient = diff_i / 86400;
  4820. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4821. {
  4822. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4823. {
  4824. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4825. {
  4826. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4827. }
  4828. else
  4829. {
  4830. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  4831. }
  4832. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4833. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4834. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4835. period = period + 1;
  4836. }
  4837. }
  4838. }
  4839. confirmPeriods = period;
  4840. }
  4841. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  4842. {
  4843. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4844. struct tm tp;
  4845. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4846. tp.tm_isdst = -1;
  4847. time_t utc = mktime(&tp);
  4848. time_t t = time(NULL);
  4849. double diff_f = difftime(t, utc);
  4850. int diff_i; // = (int)diff_f;
  4851. int quotient; // = diff_i / 86400;//86400 seconds/day
  4852. int period = 0;
  4853. if(diff_f >= 0)
  4854. {
  4855. diff_i = (int)diff_f;
  4856. quotient = diff_i / 86400;//86400 seconds/day
  4857. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4858. {
  4859. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4860. {
  4861. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4862. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4863. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4864. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4865. period = period + 1;
  4866. }
  4867. }
  4868. }
  4869. confirmPeriods = period;
  4870. }
  4871. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  4872. {
  4873. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  4874. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  4875. {
  4876. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  4877. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  4878. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  4879. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4880. }
  4881. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  4882. }
  4883. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  4884. {
  4885. confirmPeriods = 0;
  4886. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  4887. goto end;
  4888. }
  4889. //* Define temporary variables */
  4890. struct tm *gtime;
  4891. time_t now;
  4892. char buf[28];
  4893. /* Read the current system time */
  4894. time(&now);
  4895. /* Convert the system time to GMT (now UTC) */
  4896. gtime = gmtime(&now);
  4897. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4898. // make .conf
  4899. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4900. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  4901. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  4902. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4903. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4904. }
  4905. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4906. {
  4907. //*****************************ChargePointMaxProfile******************************************/
  4908. strcpy(fname, ChargePointMaxProfile_JSON);
  4909. ChargePointMaxProfileIsNull=TRUE;
  4910. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4911. {
  4912. fptr1 = fopen(fname, "r");
  4913. int c;
  4914. c = fgetc(fptr1);
  4915. //DEBUG_INFO("c:%d\n",c);
  4916. rewind(fptr1);
  4917. if(c == EOF)
  4918. {
  4919. DEBUG_INFO("\n End of file reached.");
  4920. ChargePointMaxProfileIsNull=TRUE;
  4921. fclose(fptr1);
  4922. }
  4923. else
  4924. {
  4925. ChargePointMaxProfileIsNull=FALSE;
  4926. while(fscanf(fptr1, "%s", word) != EOF)
  4927. {
  4928. if(strcmp(word, "chargingProfileId") == 0)
  4929. {
  4930. n_chargingProfile = n_chargingProfile + 1;
  4931. }
  4932. }
  4933. rewind(fptr1);
  4934. //search Charging Profile Element
  4935. int i = 0;
  4936. int j = 0;
  4937. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4938. #if 0
  4939. /***********connectorId****************/
  4940. c = 0;
  4941. loc = strstr(sLineWord, "connectorId");
  4942. memset(sstr ,0, sizeof(sstr) );
  4943. while (loc[strlen("connectorId")+2+c] != ',')
  4944. {
  4945. sstr[c] = loc[strlen("connectorId")+2+c];
  4946. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4947. c++;
  4948. }
  4949. sstr[c] = '\0';
  4950. tempconnectorIdInt = atoi(sstr);
  4951. #endif
  4952. //***********validFrom**************/
  4953. c = 0;
  4954. loc = strstr(sLineWord, "validFrom");
  4955. if(loc != NULL)
  4956. {
  4957. memset(sstr ,0, sizeof(sstr) );
  4958. while (loc[3+strlen("validFrom")+c] != '\"')
  4959. {
  4960. sstr[c] = loc[3+strlen("validFrom")+c];
  4961. c++;
  4962. }
  4963. sstr[c] = '\0';
  4964. strcpy(tempvalidFromStr,sstr);
  4965. }
  4966. else
  4967. {
  4968. strcpy(tempvalidFromStr,"");
  4969. }
  4970. //***********validFrom**************/
  4971. c = 0;
  4972. loc = strstr(sLineWord, "duration");
  4973. if(loc != NULL)
  4974. {
  4975. memset(sstr ,0, sizeof(sstr) );
  4976. while (loc[2+strlen("duration")+c] != ',')
  4977. {
  4978. sstr[c] = loc[2+strlen("duration")+c];
  4979. c++;
  4980. }
  4981. sstr[c] = '\0';
  4982. tempdurationInt = atoi(sstr);
  4983. }
  4984. else
  4985. {
  4986. tempdurationInt = 0;
  4987. }
  4988. //**********startSchedule**********/
  4989. c = 0;
  4990. loc = strstr(sLineWord, "startSchedule");
  4991. memset(sstr ,0, sizeof(sstr) );
  4992. while (loc[3+strlen("startSchedule")+c] != '\"')
  4993. {
  4994. sstr[c] = loc[3+strlen("startSchedule")+c];
  4995. c++;
  4996. }
  4997. sstr[c] = '\0';
  4998. strcpy(tempstartScheduleStr, sstr);
  4999. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5000. //**********chargingRateUnit**********/
  5001. c = 0;
  5002. loc = strstr(sLineWord, "chargingRateUnit");
  5003. memset(sstr ,0, sizeof(sstr) );
  5004. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5005. {
  5006. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5007. c++;
  5008. }
  5009. sstr[c] = '\0';
  5010. strcpy(tempchargingRateUnitStr, sstr);
  5011. //**********minChargingRate*******/
  5012. c = 0;
  5013. loc = strstr(sLineWord, "minChargingRate");
  5014. if(loc != NULL)
  5015. {
  5016. memset(sstr ,0, sizeof(sstr) );
  5017. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5018. {
  5019. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5020. c++;
  5021. }
  5022. sstr[c] = '\0';
  5023. tempminChargingRateFloat = atof(sstr);
  5024. }
  5025. else
  5026. {
  5027. tempminChargingRateFloat = 0.0;
  5028. }
  5029. #if 0
  5030. //
  5031. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5032. tp.tm_isdst = -1;
  5033. time_t utc = mktime(&tp);
  5034. time_t t = time(NULL);
  5035. //diff_t = difftime(t, utc);
  5036. #endif
  5037. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5038. //DEBUG_INFO(" debug 5 -1\n");
  5039. //parsing strings to words
  5040. i = 0;
  5041. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5042. loc = loc+3+strlen("chargingSchedulePeriod");
  5043. pch = strtok(loc ,"{");
  5044. while (pch != NULL)
  5045. {
  5046. strcpy(SchedulePeriodList[i], pch);
  5047. pch = strtok (NULL, "{");
  5048. i = i + 1;
  5049. }
  5050. n_SchedulePeriods = i;
  5051. for(int i=0;i<n_SchedulePeriods;i++)
  5052. {
  5053. //*************startPeriod****************/
  5054. c = 0;
  5055. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5056. memset(sstr ,0, sizeof(sstr) );
  5057. while (loc[strlen("startPeriod")+2+c] != ',')
  5058. {
  5059. sstr[c] = loc[strlen("startPeriod")+2+c];
  5060. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5061. c++;
  5062. }
  5063. sstr[c] = '\0';
  5064. tempStartPeriodInt = atoi(sstr);
  5065. //*************limit****************/
  5066. c = 0;
  5067. loc = strstr(SchedulePeriodList[i], "limit");
  5068. memset(sstr ,0, sizeof(sstr) );
  5069. while (loc[strlen("limit")+2+c] != ',')
  5070. {
  5071. sstr[c] = loc[strlen("limit")+2+c];
  5072. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5073. c++;
  5074. }
  5075. sstr[c] = '\0';
  5076. tempLimitInt = atof(sstr);
  5077. //*************numberPhases****************/
  5078. c = 0;
  5079. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5080. memset(sstr ,0, sizeof(sstr) );
  5081. while (loc[strlen("numberPhases")+2+c] != '}')
  5082. {
  5083. sstr[c] = loc[strlen("numberPhases")+2+c];
  5084. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5085. c++;
  5086. }
  5087. sstr[c] = '\0';
  5088. tempNumberPhasesInt = atoi(sstr);
  5089. if(j == 0)
  5090. {
  5091. ChargePointMaxProfile.Duration = tempdurationInt;
  5092. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5093. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5094. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5095. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5096. }
  5097. }
  5098. if(MinChargingRate < tempminChargingRateFloat)
  5099. {
  5100. MinChargingRate = tempminChargingRateFloat;
  5101. }
  5102. if(confirmPeriods < n_SchedulePeriods)
  5103. {
  5104. confirmPeriods = n_SchedulePeriods;
  5105. }
  5106. j = j + 1;
  5107. }
  5108. fclose(fptr1);
  5109. }
  5110. }// the end of access file ChargePointMaxProfile
  5111. //****************************TxDefaultProfile************************************************/
  5112. #if 0
  5113. switch(connectorIdInt)
  5114. {
  5115. case 0:
  5116. break;
  5117. case 1:
  5118. strcpy(fname, TxDefaultProfile_1_JSON );
  5119. break;
  5120. case 2:
  5121. strcpy(fname, TxDefaultProfile_2_JSON );
  5122. break;
  5123. default:
  5124. strcpy(fname, TxDefaultProfile_1_JSON );
  5125. break;
  5126. }
  5127. #endif
  5128. memset(fname, 0, sizeof fname);
  5129. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5130. TxDefaultProfileFileIsNull=TRUE;
  5131. if((access(fname,F_OK))!=-1)
  5132. {
  5133. fptr1 = fopen(fname, "r");
  5134. c = 0;
  5135. c = fgetc(fptr1);
  5136. //DEBUG_INFO("c:%d\n",c);
  5137. rewind(fptr1);
  5138. if(c == EOF)
  5139. {
  5140. DEBUG_INFO("\n End of file reached.");
  5141. TxDefaultProfileFileIsNull=TRUE;
  5142. fclose(fptr1);
  5143. }
  5144. else
  5145. {
  5146. TxDefaultProfileFileIsNull=FALSE;
  5147. while(fscanf(fptr1, "%s", word) != EOF)
  5148. {
  5149. if(strcmp(word, "chargingProfileId") == 0)
  5150. {
  5151. n_chargingProfile = n_chargingProfile + 1;
  5152. }
  5153. }
  5154. rewind(fptr1);
  5155. //search Charging Profile Element
  5156. int i = 0;
  5157. int j = 0;
  5158. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5159. //DEBUG_INFO(" 1-1\n");
  5160. #if 0
  5161. /***********connectorId****************/
  5162. c = 0;
  5163. loc = strstr(sLineWord, "connectorId");
  5164. memset(sstr ,0, sizeof(sstr) );
  5165. while (loc[strlen("connectorId")+2+c] != ',')
  5166. {
  5167. sstr[c] = loc[strlen("connectorId")+2+c];
  5168. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5169. c++;
  5170. }
  5171. sstr[c] = '\0';
  5172. tempconnectorIdInt = atoi(sstr);
  5173. #endif
  5174. //***********validFrom**************/
  5175. c = 0;
  5176. loc = strstr(sLineWord, "validFrom");
  5177. if(loc != NULL)
  5178. {
  5179. memset(sstr ,0, sizeof(sstr) );
  5180. while (loc[3+strlen("validFrom")+c] != '\"')
  5181. {
  5182. sstr[c] = loc[3+strlen("validFrom")+c];
  5183. c++;
  5184. }
  5185. sstr[c] = '\0';
  5186. strcpy(tempvalidFromStr,sstr);
  5187. }
  5188. else
  5189. {
  5190. strcpy(tempvalidFromStr,"");
  5191. }
  5192. //***********validFrom**************/
  5193. c = 0;
  5194. loc = strstr(sLineWord, "duration");
  5195. if(loc != NULL)
  5196. {
  5197. memset(sstr ,0, sizeof(sstr) );
  5198. while (loc[2+strlen("duration")+c] != ',')
  5199. {
  5200. sstr[c] = loc[2+strlen("duration")+c];
  5201. c++;
  5202. }
  5203. sstr[c] = '\0';
  5204. tempdurationInt = atoi(sstr);
  5205. }
  5206. else
  5207. {
  5208. tempdurationInt = 0;
  5209. }
  5210. //**********startSchedule**********/
  5211. c = 0;
  5212. loc = strstr(sLineWord, "startSchedule");
  5213. memset(sstr ,0, sizeof(sstr) );
  5214. while (loc[3+strlen("startSchedule")+c] != '\"')
  5215. {
  5216. sstr[c] = loc[3+strlen("startSchedule")+c];
  5217. c++;
  5218. }
  5219. sstr[c] = '\0';
  5220. strcpy(tempstartScheduleStr, sstr);
  5221. strcpy(TxDefaultProfileScheduleStr, sstr);
  5222. //**********chargingRateUnit**********/
  5223. c = 0;
  5224. loc = strstr(sLineWord, "chargingRateUnit");
  5225. memset(sstr ,0, sizeof(sstr) );
  5226. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5227. {
  5228. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5229. c++;
  5230. }
  5231. sstr[c] = '\0';
  5232. strcpy(tempchargingRateUnitStr, sstr);
  5233. //**********minChargingRate*******/
  5234. c = 0;
  5235. loc = strstr(sLineWord, "minChargingRate");
  5236. if(loc != NULL)
  5237. {
  5238. memset(sstr ,0, sizeof(sstr) );
  5239. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5240. {
  5241. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5242. c++;
  5243. }
  5244. sstr[c] = '\0';
  5245. tempminChargingRateFloat = atof(sstr);
  5246. }
  5247. else
  5248. {
  5249. tempminChargingRateFloat = 0.0;
  5250. }
  5251. #if 0
  5252. //
  5253. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5254. tp.tm_isdst = -1;
  5255. time_t utc = mktime(&tp);
  5256. time_t t = time(NULL);
  5257. //diff_t = difftime(t, utc);
  5258. #endif
  5259. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5260. //parsing strings to words
  5261. i = 0;
  5262. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5263. loc = loc+3+strlen("chargingSchedulePeriod");
  5264. pch = strtok(loc ,"{");
  5265. while (pch != NULL)
  5266. {
  5267. strcpy(SchedulePeriodList[i], pch);
  5268. pch = strtok (NULL, "{");
  5269. i = i + 1;
  5270. }
  5271. n_SchedulePeriods = i;
  5272. for(int i=0;i<n_SchedulePeriods;i++)
  5273. {
  5274. //*************startPeriod****************/
  5275. c = 0;
  5276. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5277. memset(sstr ,0, sizeof(sstr) );
  5278. while (loc[strlen("startPeriod")+2+c] != ',')
  5279. {
  5280. sstr[c] = loc[strlen("startPeriod")+2+c];
  5281. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5282. c++;
  5283. }
  5284. sstr[c] = '\0';
  5285. tempStartPeriodInt = atoi(sstr);
  5286. //*************limit****************/
  5287. c = 0;
  5288. loc = strstr(SchedulePeriodList[i], "limit");
  5289. memset(sstr ,0, sizeof(sstr) );
  5290. while (loc[strlen("limit")+2+c] != ',')
  5291. {
  5292. sstr[c] = loc[strlen("limit")+2+c];
  5293. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5294. c++;
  5295. }
  5296. sstr[c] = '\0';
  5297. tempLimitInt = atof(sstr);
  5298. //*************numberPhases****************/
  5299. c = 0;
  5300. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5301. memset(sstr ,0, sizeof(sstr) );
  5302. while (loc[strlen("numberPhases")+2+c] != '}')
  5303. {
  5304. sstr[c] = loc[strlen("numberPhases")+2+c];
  5305. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5306. c++;
  5307. }
  5308. sstr[c] = '\0';
  5309. tempNumberPhasesInt = atoi(sstr);
  5310. if(j == 0)
  5311. {
  5312. TxDefaultProfile.Duration = tempdurationInt;
  5313. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5314. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5315. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5316. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5317. }
  5318. else
  5319. {
  5320. //other stack level charging Profile
  5321. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5322. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5323. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5324. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5325. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5326. }
  5327. }
  5328. if(MinChargingRate < tempminChargingRateFloat)
  5329. MinChargingRate = tempminChargingRateFloat;
  5330. if(confirmPeriods < n_SchedulePeriods)
  5331. confirmPeriods = n_SchedulePeriods;
  5332. j = j + 1;
  5333. //DEBUG_INFO(" 1-2\n");
  5334. }
  5335. fclose(fptr1);
  5336. //Stacking Charging Profiles
  5337. for(int l=0; l <(j-1) ;l++)
  5338. {
  5339. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5340. {
  5341. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5342. {
  5343. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5344. {
  5345. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5346. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5347. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5348. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5349. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5350. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5351. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5352. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5353. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5354. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5355. }
  5356. else
  5357. {
  5358. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5359. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5360. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5361. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5362. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5363. }
  5364. }
  5365. }
  5366. }
  5367. //end of Stacking Charging Profiles
  5368. }
  5369. }// the end of ACCESS TxDefaultProfile
  5370. //****************************TxProfile************************************************/
  5371. #if 0
  5372. switch(connectorIdInt)
  5373. {
  5374. case 0:
  5375. break;
  5376. case 1:
  5377. strcpy(fname, TxProfile_1_JSON );
  5378. break;
  5379. case 2:
  5380. strcpy(fname, TxProfile_2_JSON );
  5381. break;
  5382. default:
  5383. strcpy(fname, TxProfile_1_JSON );
  5384. break;
  5385. }
  5386. #endif
  5387. memset(fname, 0, sizeof fname);
  5388. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5389. TxProfileIsNull=TRUE;
  5390. if((access(fname,F_OK))!=-1)
  5391. {
  5392. fptr1 = fopen(fname, "r");
  5393. c = 0;
  5394. c = fgetc(fptr1);
  5395. //DEBUG_INFO("c:%d\n",c);
  5396. rewind(fptr1);
  5397. if(c == EOF)
  5398. {
  5399. DEBUG_INFO("\n End of file reached.");
  5400. TxProfileIsNull=TRUE;
  5401. fclose(fptr1);
  5402. }
  5403. else
  5404. {
  5405. TxProfileIsNull=FALSE;
  5406. while(fscanf(fptr1, "%s", word) != EOF)
  5407. {
  5408. if(strcmp(word, "chargingProfileId") == 0)
  5409. {
  5410. n_chargingProfile = n_chargingProfile + 1;
  5411. }
  5412. }
  5413. rewind(fptr1);
  5414. //search Charging Profile Element
  5415. int i= 0;
  5416. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5417. #if 0
  5418. /***********connectorId****************/
  5419. c = 0;
  5420. loc = strstr(sLineWord, "connectorId");
  5421. memset(sstr ,0, sizeof(sstr) );
  5422. while (loc[strlen("connectorId")+2+c] != ',')
  5423. {
  5424. sstr[c] = loc[strlen("connectorId")+2+c];
  5425. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5426. c++;
  5427. }
  5428. sstr[c] = '\0';
  5429. tempconnectorIdInt = atoi(sstr);
  5430. #endif
  5431. //***********validFrom**************/
  5432. c = 0;
  5433. loc = strstr(sLineWord, "validFrom");
  5434. if(loc != NULL)
  5435. {
  5436. memset(sstr ,0, sizeof(sstr) );
  5437. while (loc[3+strlen("validFrom")+c] != '\"')
  5438. {
  5439. sstr[c] = loc[3+strlen("validFrom")+c];
  5440. c++;
  5441. }
  5442. sstr[c] = '\0';
  5443. strcpy(tempvalidFromStr,sstr);
  5444. }
  5445. else
  5446. {
  5447. strcpy(tempvalidFromStr,"");
  5448. }
  5449. //**********startSchedule**********/
  5450. c = 0;
  5451. loc = strstr(sLineWord, "startSchedule");
  5452. memset(sstr ,0, sizeof(sstr) );
  5453. while (loc[3+strlen("startSchedule")+c] != '\"')
  5454. {
  5455. sstr[c] = loc[3+strlen("startSchedule")+c];
  5456. c++;
  5457. }
  5458. sstr[c] = '\0';
  5459. strcpy(tempstartScheduleStr, sstr);
  5460. strcpy(TxProfileScheduleStr, sstr);
  5461. //**********chargingRateUnit**********/
  5462. c = 0;
  5463. loc = strstr(sLineWord, "chargingRateUnit");
  5464. memset(sstr ,0, sizeof(sstr) );
  5465. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5466. {
  5467. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5468. c++;
  5469. }
  5470. sstr[c] = '\0';
  5471. strcpy(tempchargingRateUnitStr, sstr);
  5472. //**********minChargingRate*******/
  5473. c = 0;
  5474. loc = strstr(sLineWord, "minChargingRate");
  5475. if(loc != NULL)
  5476. {
  5477. memset(sstr ,0, sizeof(sstr) );
  5478. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5479. {
  5480. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5481. c++;
  5482. }
  5483. sstr[c] = '\0';
  5484. tempminChargingRateFloat = atof(sstr);
  5485. }
  5486. else
  5487. {
  5488. tempminChargingRateFloat = 0.0;
  5489. }
  5490. #if 0
  5491. //
  5492. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5493. tp.tm_isdst = -1;
  5494. time_t utc = mktime(&tp);
  5495. time_t t = time(NULL);
  5496. //diff_t = difftime(t, utc);
  5497. #endif
  5498. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5499. //parsing strings to words
  5500. i = 0;
  5501. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5502. loc = loc+3+strlen("chargingSchedulePeriod");
  5503. pch = strtok(loc ,"{");
  5504. while (pch != NULL)
  5505. {
  5506. strcpy(SchedulePeriodList[i], pch);
  5507. pch = strtok (NULL, "{");
  5508. i = i + 1;
  5509. }
  5510. n_SchedulePeriods = i;
  5511. for(int i=0;i<n_SchedulePeriods;i++)
  5512. {
  5513. //*************startPeriod****************/
  5514. c = 0;
  5515. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5516. memset(sstr ,0, sizeof(sstr) );
  5517. while (loc[strlen("startPeriod")+2+c] != ',')
  5518. {
  5519. sstr[c] = loc[strlen("startPeriod")+2+c];
  5520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5521. c++;
  5522. }
  5523. sstr[c] = '\0';
  5524. tempStartPeriodInt = atoi(sstr);
  5525. //*************limit****************/
  5526. c = 0;
  5527. loc = strstr(SchedulePeriodList[i], "limit");
  5528. memset(sstr ,0, sizeof(sstr) );
  5529. while (loc[strlen("limit")+2+c] != ',')
  5530. {
  5531. sstr[c] = loc[strlen("limit")+2+c];
  5532. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5533. c++;
  5534. }
  5535. sstr[c] = '\0';
  5536. tempLimitInt = atof(sstr);
  5537. //*************numberPhases****************/
  5538. c = 0;
  5539. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5540. memset(sstr ,0, sizeof(sstr) );
  5541. while (loc[strlen("numberPhases")+2+c] != '}')
  5542. {
  5543. sstr[c] = loc[strlen("numberPhases")+2+c];
  5544. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5545. c++;
  5546. }
  5547. sstr[c] = '\0';
  5548. tempNumberPhasesInt = atoi(sstr);
  5549. TxProfile.Duration = durationInt;
  5550. TxProfile.TotalPeriod = n_SchedulePeriods;
  5551. TxProfile.Period[i].Limit = tempLimitInt;
  5552. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5553. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5554. }
  5555. if(MinChargingRate < tempminChargingRateFloat)
  5556. MinChargingRate = tempminChargingRateFloat;
  5557. if(confirmPeriods < n_SchedulePeriods)
  5558. confirmPeriods = n_SchedulePeriods;
  5559. }
  5560. fclose(fptr1);
  5561. }
  5562. }// the end of ACCESS TxProfile
  5563. //CompositeSchedule
  5564. int period=0;
  5565. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5566. {
  5567. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5568. struct tm tp;
  5569. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5570. tp.tm_isdst = -1;
  5571. time_t utc = mktime(&tp);
  5572. time_t t = time(NULL);
  5573. double diff_f = difftime(t, utc);
  5574. int diff_i; // = (int)diff_f;
  5575. int quotient; // = diff_i / 86400;//86400 seconds/day
  5576. //int remainder = diff_i % 86400;
  5577. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5578. {
  5579. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5580. {
  5581. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5582. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5583. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5584. period = period + 1;
  5585. }
  5586. else
  5587. {
  5588. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5589. {
  5590. }
  5591. else
  5592. {
  5593. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5594. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5595. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5596. period = period + 1;
  5597. }
  5598. }
  5599. }
  5600. if( diff_f >= 0)
  5601. {
  5602. diff_i = (int)diff_f;
  5603. quotient = diff_i / 86400;//86400 seconds/day
  5604. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5605. {
  5606. if(((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)&& ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod %86400) > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5607. {
  5608. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5609. {
  5610. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5611. }
  5612. else
  5613. {
  5614. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5615. }
  5616. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5617. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  5618. period = period + 1;
  5619. }
  5620. }
  5621. // Check Last Period
  5622. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5623. {
  5624. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5625. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5626. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5627. period = period + 1;
  5628. }
  5629. } // diff_f >= 0
  5630. }
  5631. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5632. {
  5633. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5634. struct tm tp;
  5635. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5636. tp.tm_isdst = -1;
  5637. time_t utc = mktime(&tp);
  5638. time_t t = time(NULL);
  5639. double diff_f = difftime(t, utc);
  5640. int diff_i;// = (int)diff_f;
  5641. int quotient; // = diff_i / 86400;//86400 seconds/day
  5642. //int remainder = diff_i % 86400;
  5643. if(diff_f >= 0)
  5644. {
  5645. diff_i = (int)diff_f;
  5646. quotient = diff_i / 86400;//86400 seconds/day
  5647. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5648. {
  5649. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5650. {
  5651. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5652. {
  5653. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5654. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5655. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5656. period = period + 1;
  5657. }
  5658. else
  5659. {
  5660. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5661. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5662. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5663. period = period + 1;
  5664. }
  5665. }
  5666. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5667. {
  5668. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5669. {
  5670. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5671. {
  5672. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5673. {
  5674. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5675. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5676. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5677. period = period + 1;
  5678. }
  5679. else
  5680. {
  5681. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5682. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5683. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5684. period = period + 1;
  5685. }
  5686. }
  5687. }
  5688. }
  5689. }
  5690. } // end diff_f >= 0
  5691. }
  5692. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5693. {
  5694. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5695. struct tm tp;
  5696. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5697. tp.tm_isdst = -1;
  5698. time_t utc = mktime(&tp);
  5699. time_t t = time(NULL);
  5700. double diff_f = difftime(t, utc);
  5701. int diff_i; // = (int)diff_f;
  5702. int quotient; // = diff_i / 86400;//86400 seconds/day
  5703. //int remainder = diff_i % 86400;
  5704. if(diff_f >= 0)
  5705. {
  5706. diff_i = (int)diff_f;
  5707. quotient = diff_i / 86400;//86400 seconds/day
  5708. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5709. {
  5710. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5711. {
  5712. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5713. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5714. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5715. period = period + 1;
  5716. }
  5717. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5718. {
  5719. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5720. {
  5721. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5722. {
  5723. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5724. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5725. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5726. period = period + 1;
  5727. }
  5728. }
  5729. }
  5730. }
  5731. } // diff_f >= 0
  5732. }
  5733. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  5734. {
  5735. confirmPeriods = 0;
  5736. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5737. goto end;
  5738. }
  5739. confirmPeriods = period;
  5740. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5741. //---- Define StartSchedule----/
  5742. struct tm *gtime;
  5743. time_t now;
  5744. char buf[28];
  5745. //---Read the current system time---/
  5746. time(&now);
  5747. //---Convert the system time to GMT (now UTC)---/
  5748. gtime = gmtime(&now);
  5749. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5750. // make .conf
  5751. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5752. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5753. //DEBUG_INFO(" debug 11\n");
  5754. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5755. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5756. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5757. }
  5758. else
  5759. {
  5760. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5761. }
  5762. end:
  5763. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5764. return result;
  5765. }
  5766. int handleGetConfigurationRequest(char *uuid, char *payload)
  5767. {
  5768. mtrace();
  5769. int result = FAIL;
  5770. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5771. //struct json_object *jsonitem;
  5772. int MaxKeySupported = 0;
  5773. int n_keys = 0;
  5774. char requestKey[43][50]={0};
  5775. char search[]="[";
  5776. char sstr[500]={ 0 };
  5777. //int pos;
  5778. int l, c = 0;
  5779. int i = 0;
  5780. char *delim = "\",\"";
  5781. char * pch;
  5782. char *loc = strstr(payload, search);
  5783. //********************* Parsing String ***********************************/
  5784. if(loc == NULL) {
  5785. DEBUG_INFO("no key match in Configuration \n");
  5786. }
  5787. else {
  5788. //pos = loc - payload;
  5789. l = strlen(loc)-4;
  5790. while (c < l)
  5791. {
  5792. sstr[c] = loc[c+2];
  5793. c++;
  5794. }
  5795. sstr[c] = '\0';
  5796. //parsing strings to words
  5797. pch = strtok(sstr,delim);
  5798. if(pch == NULL)
  5799. {
  5800. strcpy(requestKey[0], sstr);
  5801. }
  5802. else
  5803. {
  5804. while (pch != NULL)
  5805. {
  5806. strcpy(requestKey[i], pch);
  5807. pch = strtok (NULL, delim);
  5808. i = i + 1;
  5809. }
  5810. n_keys = i;
  5811. }
  5812. }
  5813. UnknownKeynum = 0;
  5814. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5815. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5816. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5817. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5818. if(n_keys != 0)
  5819. {
  5820. for(int i=0;i<n_keys;i++)
  5821. {
  5822. getKeyValue(requestKey[i]);
  5823. //json_object_put(jsonitem);
  5824. }
  5825. }
  5826. else
  5827. {
  5828. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5829. getKeyValue("");
  5830. }
  5831. processUnkownKey();
  5832. sendGetConfigurationConfirmation(uuid);
  5833. return result;
  5834. }
  5835. static char fnamePlusPath[100]={0};
  5836. static char fnamePWithNoPath[60]={0};
  5837. void checkUploadLog(void)
  5838. {
  5839. FILE *fp;
  5840. /* Open the command for reading. */
  5841. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5842. if (fp == NULL) {
  5843. printf("Failed to run command\n" );
  5844. exit(1);
  5845. }
  5846. int ftppathlen = 0;
  5847. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5848. int i = 0;
  5849. /* Read the output a line at a time - output it. */
  5850. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5851. if(i==0)
  5852. {
  5853. ftppathlen = strlen(fnamePlusPath);
  5854. printf("%s\n", fnamePlusPath);
  5855. fnamePlusPath[ftppathlen]='\0';
  5856. break;
  5857. }
  5858. i= i+1;
  5859. }
  5860. /* close */
  5861. pclose(fp);
  5862. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5863. {
  5864. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5865. {
  5866. fnamePlusPath[k]='\0';
  5867. }
  5868. }
  5869. i=1;
  5870. //char fname[60]={0};
  5871. while(i < ftppathlen)
  5872. {
  5873. int len=ftppathlen-i;
  5874. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5875. {
  5876. printf("compare '/' all right\n");
  5877. break;
  5878. }
  5879. i=i+1;
  5880. }
  5881. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5882. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5883. fnamePWithNoPath[i+1] = '\0';
  5884. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5885. {
  5886. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5887. {
  5888. fnamePWithNoPath[j]='\0';
  5889. }
  5890. }
  5891. FILE* fp1 = fopen(fnamePlusPath, "r");
  5892. if (fp1)
  5893. {
  5894. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5895. // file exists
  5896. fclose(fp1);
  5897. }
  5898. else
  5899. {
  5900. // file doesn't exist
  5901. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5902. }
  5903. }
  5904. static char GetDiagnosticspayloadData[300]={0};
  5905. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5906. {
  5907. mtrace();
  5908. int result = FAIL;
  5909. pthread_t t; // pthread 變數
  5910. system("exec /root/logPackTools 'log' 6");
  5911. #if 0
  5912. //char buffer [128];
  5913. time (&rawtime);
  5914. //printf("%ld\n", rawtime);
  5915. timeinfo = localtime (&rawtime);
  5916. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5917. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5918. if((access(fnamePlusPath,F_OK))!=-1)
  5919. {
  5920. DEBUG_INFO("fnamePlusPath exist.\n");
  5921. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5922. }
  5923. else
  5924. {
  5925. DEBUG_INFO("fnamePlusPath not exist!\n");
  5926. }
  5927. #endif
  5928. checkUploadLog();
  5929. memset(GetDiagnosticspayloadData, 0, 300);
  5930. strcpy(GetDiagnosticspayloadData, payload);
  5931. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5932. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5933. return result;
  5934. }
  5935. void* GetDiagnosticsProcess(void* data)
  5936. {
  5937. pthread_detach(pthread_self());
  5938. mtrace();
  5939. int retriesInt=0, retryIntervalInt=0;
  5940. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5941. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5942. 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};
  5943. int port=0;
  5944. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5945. int c = 0;
  5946. char *loc;
  5947. int isSuccess = FALSE;
  5948. char ftpbuf[200]={0};
  5949. //char temp[100]={0};
  5950. char * pch;
  5951. // [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"}]
  5952. char str[300]={ 0 };
  5953. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5954. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5955. DEBUG_INFO("GetDiagnosticsProcess\n");
  5956. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5957. //****************location*******************/
  5958. c = 0;
  5959. memset(sstr ,0, sizeof(sstr) );
  5960. loc = strstr(str, "location");
  5961. while (loc[3+strlen("location")+c] != '\"')
  5962. {
  5963. sstr[c] = loc[3+strlen("location")+c];
  5964. c++;
  5965. }
  5966. sstr[c] = '\0';
  5967. strcpy(locationstr,sstr);
  5968. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5969. if(strcmp(locationstr,"")==0)
  5970. {
  5971. DEBUG_INFO("location is <Empty>!\n");
  5972. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5973. goto end;
  5974. }
  5975. //****************retries*******************/
  5976. c = 0;
  5977. loc = strstr(str, "retries");
  5978. if(loc == NULL)
  5979. {
  5980. retriesIsNULL = TRUE;
  5981. }
  5982. else
  5983. {
  5984. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5985. {
  5986. sstr[c] = loc[strlen("retries")+2+c];
  5987. c++;
  5988. }
  5989. sstr[c] = '\0';
  5990. retriesInt = atoi(sstr);
  5991. }
  5992. if(retriesIsNULL == TRUE)
  5993. {
  5994. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5995. }
  5996. //****************retryInterval*******************/
  5997. c = 0;
  5998. loc = strstr(str, "retryInterval");
  5999. if(loc == NULL)
  6000. {
  6001. retryIntervalIsNULL = TRUE;
  6002. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6003. }
  6004. else
  6005. {
  6006. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6007. {
  6008. sstr[c] = loc[strlen("retryInterval")+2+c];
  6009. c++;
  6010. }
  6011. sstr[c] = '\0';
  6012. retryIntervalInt = atoi(sstr);
  6013. }
  6014. //****************startTime*******************/
  6015. c = 0;
  6016. memset(sstr ,0, sizeof(sstr) );
  6017. loc = strstr(str, "startTime");
  6018. if(loc == NULL)
  6019. {
  6020. startTimeIsNULL = TRUE;
  6021. }
  6022. else
  6023. {
  6024. while (loc[3+strlen("startTime")+c] != '\"')
  6025. {
  6026. sstr[c] = loc[3+strlen("startTime")+c];
  6027. c++;
  6028. }
  6029. sstr[c] = '\0';
  6030. strcpy(startTimestr,sstr);
  6031. }
  6032. //****************stopTime*******************/
  6033. c = 0;
  6034. memset(sstr ,0, sizeof(sstr) );
  6035. loc = strstr(str, "stopTime");
  6036. if(loc == NULL)
  6037. {
  6038. stopTimeIsNULL = TRUE;
  6039. }
  6040. else
  6041. {
  6042. while (loc[3+strlen("stopTime")+c] != '\"')
  6043. {
  6044. sstr[c] = loc[3+strlen("stopTime")+c];
  6045. c++;
  6046. }
  6047. sstr[c] = '\0';
  6048. strcpy(stopTimestr,sstr);
  6049. }
  6050. memset(protocol, 0, sizeof(protocol));
  6051. memset(user, 0, sizeof(user) );
  6052. memset(password, 0, sizeof(password));
  6053. memset(host, 0, sizeof(host));
  6054. memset(path, 0, sizeof(path));
  6055. memset(ftppath, 0, sizeof(ftppath));
  6056. memset(host1, 0, sizeof(host1));
  6057. memset(path1, 0, sizeof(path1));
  6058. /*location: ftp://user:password@host:port/path*/
  6059. #if 0
  6060. time_t rawtime;
  6061. struct tm * timeinfo;
  6062. //char buffer [128];
  6063. time (&rawtime);
  6064. //printf("%ld\n", rawtime);
  6065. timeinfo = localtime (&rawtime);
  6066. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6067. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6068. #endif
  6069. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6070. if((access(fnamePlusPath,F_OK))!=-1)
  6071. {
  6072. DEBUG_INFO("fnamePlusPath exist.\n");
  6073. }
  6074. else
  6075. {
  6076. DEBUG_INFO("fnamePlusPath not exist!\n");
  6077. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6078. goto end;
  6079. }
  6080. pch=strchr(locationstr,'@');
  6081. if(pch==NULL)
  6082. {
  6083. sscanf(locationstr,
  6084. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6085. protocol, host, &port, path);
  6086. strcpy(user,"anonymous");
  6087. strcpy(password,"");
  6088. }
  6089. else
  6090. {
  6091. //DEBUG_INFO("pch=%s\n", pch);
  6092. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6093. protocol, user, password, host, &port, path);
  6094. }
  6095. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6096. {
  6097. DEBUG_INFO("protocol is not ftp/http ! \n");
  6098. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6099. goto end;
  6100. }
  6101. if(strncmp(locationstr,"http", 4) == 0)
  6102. {
  6103. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6104. sprintf(ftppath,"/%s", path);
  6105. do{
  6106. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6107. sleep(retryIntervalInt);
  6108. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6109. if(!isSuccess)
  6110. {
  6111. DEBUG_INFO("Diagnostics fail.\n");
  6112. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6113. }
  6114. else
  6115. {
  6116. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6117. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6118. }
  6119. }
  6120. else
  6121. {
  6122. sscanf(host,"%[^/]%s",host1, path1);
  6123. sprintf(ftppath,"%s", path1);
  6124. int ftppathlen=strlen(ftppath);
  6125. int i=1;
  6126. char filenametemp[50];
  6127. while(i < ftppathlen)
  6128. {
  6129. int len=ftppathlen-i;
  6130. if(ftppath[len]== 47) // '/' ascll code: 47
  6131. {
  6132. DEBUG_INFO("find '/' all right\n");
  6133. break;
  6134. }
  6135. i=i+1;
  6136. }
  6137. memset(filenametemp, 0, sizeof(filenametemp));
  6138. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6139. filenametemp[i+1] = 0;
  6140. memset(ftpbuf, 0, sizeof(ftpbuf));
  6141. if(port == 0)
  6142. port = 21;
  6143. do{
  6144. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6145. sleep(retryIntervalInt);
  6146. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6147. if(!isSuccess)
  6148. {
  6149. DEBUG_INFO("Diagnostics fail.\n");
  6150. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6151. }
  6152. else
  6153. {
  6154. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6155. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6156. }
  6157. }
  6158. end:
  6159. DiagnosticsStatusNotificationStatus = 0; //Idle
  6160. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6161. }
  6162. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6163. {
  6164. mtrace();
  6165. int result = FAIL;
  6166. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6167. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6168. {
  6169. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6170. localversion = -1;
  6171. }
  6172. else
  6173. {
  6174. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6175. OCPP_getListVerion();
  6176. }
  6177. //from db.OCPP_getListVerion
  6178. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6179. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6180. sendGetLocalListVersionConfirmation(uuid,"");
  6181. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6182. return result;
  6183. }
  6184. int handleRemoteStartRequest(char *uuid, char *payload)
  6185. {
  6186. mtrace();
  6187. int result = FAIL;
  6188. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6189. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6190. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6191. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6192. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6193. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6194. int chargingSchedulePeriodCount = 0;
  6195. char sstr[30]={ 0 };//sstr[200]={ 0 };
  6196. int c = 0;
  6197. char *loc;
  6198. char comfirmstr[20]={0};
  6199. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6200. if(server_pending == TRUE)
  6201. {
  6202. return 0;
  6203. }
  6204. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6205. //**********connectorId****************/
  6206. c = 0;
  6207. memset(sstr ,0, sizeof(sstr) );
  6208. loc = strstr(payload, "connectorId");
  6209. if(loc == NULL)
  6210. {
  6211. connectorIdIsNULL = TRUE;
  6212. }
  6213. else
  6214. {
  6215. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6216. {
  6217. sstr[c] = loc[strlen("connectorId")+2+c];
  6218. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6219. c++;
  6220. }
  6221. sstr[c] = '\0';
  6222. connectorIdInt = atoi(sstr);
  6223. }
  6224. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6225. {
  6226. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6227. goto end;
  6228. }
  6229. //****************idTag*******************/
  6230. c = 0;
  6231. memset(sstr ,0, sizeof(sstr) );
  6232. loc = strstr(payload, "idTag");
  6233. while (loc[3+strlen("idTag")+c] != '\"')
  6234. {
  6235. sstr[c] = loc[3+strlen("idTag")+c];
  6236. c++;
  6237. }
  6238. sstr[c] = '\0';
  6239. strcpy(idTagstr,sstr);
  6240. //****************chargingProfile*******************/
  6241. c = 0;
  6242. memset(sstr ,0, sizeof(sstr) );
  6243. loc = strstr(payload, "chargingProfile");
  6244. if(loc == NULL)
  6245. {
  6246. chargingProfileIsNULL = TRUE;
  6247. }
  6248. else
  6249. {
  6250. //****************chargingProfileId*******************/
  6251. c=0;
  6252. loc = strstr(payload, "chargingProfileId");
  6253. memset(sstr ,0, sizeof(sstr) );
  6254. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6255. {
  6256. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6257. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6258. c++;
  6259. }
  6260. sstr[c] = '\0';
  6261. chargingProfileIdInt = atoi(sstr);
  6262. //****************transactionId*******************/
  6263. loc = strstr(payload, "transactionId");
  6264. if(loc == NULL)
  6265. {
  6266. transactionIdIsNULL = TRUE;
  6267. }
  6268. else
  6269. {
  6270. c=0;
  6271. memset(sstr ,0, sizeof(sstr) );
  6272. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6273. {
  6274. sstr[c] = loc[strlen("transactionId")+2+c];
  6275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6276. c++;
  6277. }
  6278. sstr[c] = '\0';
  6279. transactionIdInt = atoi(sstr);
  6280. }
  6281. //****************stackLevel*******************/
  6282. c=0;
  6283. loc = strstr(payload, "stackLevel");
  6284. memset(sstr ,0, sizeof(sstr) );
  6285. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6286. {
  6287. sstr[c] = loc[strlen("stackLevel")+2+c];
  6288. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6289. c++;
  6290. }
  6291. sstr[c] = '\0';
  6292. stackLevelInt = atoi(sstr);
  6293. //****************chargingProfilePurpose*******************/
  6294. c = 0;
  6295. memset(sstr ,0, sizeof(sstr) );
  6296. loc = strstr(payload, "chargingProfilePurpose");
  6297. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6298. {
  6299. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6300. c++;
  6301. }
  6302. sstr[c] = '\0';
  6303. strcpy(chargingProfilePurposestr,sstr);
  6304. //****************chargingProfileKind*******************/
  6305. c = 0;
  6306. memset(sstr ,0, sizeof(sstr) );
  6307. loc = strstr(payload, "chargingProfileKind");
  6308. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6309. {
  6310. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6311. c++;
  6312. }
  6313. sstr[c] = '\0';
  6314. strcpy(chargingProfileKindstr,sstr);
  6315. //****************recurrencyKind*******************/
  6316. loc = strstr(payload, "recurrencyKind");
  6317. if(loc == NULL)
  6318. {
  6319. recurrencyKindIsNULL = TRUE;
  6320. }
  6321. else
  6322. {
  6323. c = 0;
  6324. memset(sstr ,0, sizeof(sstr) );
  6325. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6326. {
  6327. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6328. c++;
  6329. }
  6330. sstr[c] = '\0';
  6331. strcpy(recurrencyKindstr,sstr);
  6332. }
  6333. //****************validFrom*******************/
  6334. loc = strstr(payload, "validFrom");
  6335. if(loc == NULL)
  6336. {
  6337. validFromIsNULL = TRUE;
  6338. }
  6339. else
  6340. {
  6341. c = 0;
  6342. memset(sstr ,0, sizeof(sstr) );
  6343. while (loc[3+strlen("validFrom")+c] != '\"')
  6344. {
  6345. sstr[c] = loc[3+strlen("validFrom")+c];
  6346. c++;
  6347. }
  6348. sstr[c] = '\0';
  6349. strcpy(validFromstr,sstr);
  6350. }
  6351. //****************validTo*******************/
  6352. loc = strstr(payload, "validTo");
  6353. if(loc == NULL)
  6354. {
  6355. validToIsNULL = TRUE;
  6356. }
  6357. else
  6358. {
  6359. c = 0;
  6360. memset(sstr ,0, sizeof(sstr) );
  6361. while (loc[3+strlen("validTo")+c] != '\"')
  6362. {
  6363. sstr[c] = loc[3+strlen("validTo")+c];
  6364. c++;
  6365. }
  6366. sstr[c] = '\0';
  6367. strcpy(validTostr,sstr);
  6368. }
  6369. //****************chargingSchedule*******************/
  6370. loc = strstr(payload, "chargingSchedule");
  6371. if(loc != NULL)
  6372. {
  6373. //****************duration*******************/
  6374. loc = strstr(payload, "duration");
  6375. if(loc == NULL)
  6376. {
  6377. durationIsNULL = TRUE;
  6378. }
  6379. else
  6380. {
  6381. c=0;
  6382. memset(sstr ,0, sizeof(sstr) );
  6383. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6384. {
  6385. sstr[c] = loc[strlen("duration")+2+c];
  6386. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6387. c++;
  6388. }
  6389. sstr[c] = '\0';
  6390. durationInt = atoi(sstr);
  6391. }
  6392. //****************startSchedule******************/
  6393. loc = strstr(payload, "startSchedule");
  6394. if(loc == NULL)
  6395. {
  6396. startScheduleIsNULL = TRUE;
  6397. }
  6398. else
  6399. {
  6400. c = 0;
  6401. memset(sstr ,0, sizeof(sstr) );
  6402. while (loc[3+strlen("startSchedule")+c] != '\"')
  6403. {
  6404. sstr[c] = loc[3+strlen("startSchedule")+c];
  6405. c++;
  6406. }
  6407. sstr[c] = '\0';
  6408. strcpy(startSchedulestr,sstr);
  6409. }
  6410. //****************chargingRateUnit*******************/
  6411. c = 0;
  6412. memset(sstr ,0, sizeof(sstr) );
  6413. loc = strstr(payload, "chargingRateUnit");
  6414. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6415. {
  6416. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6417. c++;
  6418. }
  6419. sstr[c] = '\0';
  6420. strcpy(chargingRateUnitstr,sstr);
  6421. //****************minChargingRate*******************/
  6422. loc = strstr(payload, "minChargingRate");
  6423. if(loc == NULL)
  6424. {
  6425. minChargingRateIsNULL = TRUE;
  6426. }
  6427. else
  6428. {
  6429. c=0;
  6430. memset(sstr ,0, sizeof(sstr) );
  6431. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6432. {
  6433. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6434. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6435. c++;
  6436. }
  6437. sstr[c] = '\0';
  6438. minChargingRateflaot = atof(sstr);
  6439. }
  6440. //****************chargingSchedulePeriod count*******************/
  6441. int what_len = strlen("startPeriod");
  6442. char *where = payload;
  6443. while ((where = strstr(where, "startPeriod"))) {
  6444. where += what_len;
  6445. chargingSchedulePeriodCount++;
  6446. }
  6447. where = payload;
  6448. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6449. {
  6450. //****************startPeriod*******************/
  6451. c=0;
  6452. loc = strstr(where, "startPeriod");
  6453. memset(sstr ,0, sizeof(sstr) );
  6454. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6455. {
  6456. sstr[c] = loc[strlen("startPeriod")+2+c];
  6457. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6458. c++;
  6459. }
  6460. sstr[c] = '\0';
  6461. startPeriodInt[periodNums] = atoi(sstr);
  6462. //****************limit*******************/
  6463. c=0;
  6464. loc = strstr(where, "limit");
  6465. memset(sstr ,0, sizeof(sstr) );
  6466. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6467. {
  6468. sstr[c] = loc[strlen("limit")+2+c];
  6469. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6470. c++;
  6471. }
  6472. sstr[c] = '\0';
  6473. limitflaot[periodNums] = atof(sstr);
  6474. //****************numberPhases*******************/
  6475. loc = strstr(where, "numberPhases");
  6476. if(loc == NULL)
  6477. {
  6478. numberPhasesIsNULL = TRUE;
  6479. }
  6480. else
  6481. {
  6482. c=0;
  6483. memset(sstr ,0, sizeof(sstr) );
  6484. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6485. {
  6486. sstr[c] = loc[strlen("numberPhases")+2+c];
  6487. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6488. c++;
  6489. }
  6490. sstr[c] = '\0';
  6491. numberPhasesInt[periodNums] = atoi(sstr);
  6492. }
  6493. where = loc;
  6494. }
  6495. }
  6496. }
  6497. /*
  6498. enum _SYSTEM_STATUS
  6499. {
  6500. S_BOOTING = 0,
  6501. S_IDLE, = 1
  6502. S_AUTHORIZING, =2
  6503. S_REASSIGN_CHECK, =3
  6504. S_REASSIGN, =4
  6505. S_PRECHARGE, =5
  6506. S_PREPARING_FOR_EV, =6
  6507. S_PREPARING_FOR_EVSE, =7
  6508. S_CHARGING, =8
  6509. S_TERMINATING, =9
  6510. S_COMPLETE, =10
  6511. S_ALARM, =11
  6512. S_FAULT =12
  6513. }
  6514. */
  6515. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6516. {
  6517. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6518. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6519. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6520. //check Transaction active
  6521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6522. {
  6523. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6524. {
  6525. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6526. {
  6527. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6528. {
  6529. //Reserved
  6530. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6531. }
  6532. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6533. {
  6534. //Reserved
  6535. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6536. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6537. goto end;
  6538. }
  6539. else
  6540. {
  6541. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6542. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6543. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6544. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6545. {
  6546. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6547. goto end;
  6548. }
  6549. }//END FOR ELSE
  6550. }
  6551. }// END FOR CHAdeMO_QUANTITY
  6552. for (int index = 0; index < CCS_QUANTITY; index++)
  6553. {
  6554. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6555. {
  6556. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6557. {
  6558. //Reserved
  6559. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6560. }
  6561. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6562. {
  6563. //Reserved
  6564. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6565. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6566. goto end;
  6567. }
  6568. else
  6569. {
  6570. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6571. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6572. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6573. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6574. {
  6575. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6576. goto end;
  6577. }
  6578. }// END FOR ELSE
  6579. }
  6580. }// END FOR CCS_QUANTITY
  6581. for (int index = 0; index < GB_QUANTITY; index++)
  6582. {
  6583. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6584. {
  6585. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6586. {
  6587. //Reserved
  6588. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6589. }
  6590. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6591. {
  6592. //Reserved
  6593. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6594. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6595. goto end;
  6596. }
  6597. else
  6598. {
  6599. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6600. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6601. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6602. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6603. {
  6604. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6605. goto end;
  6606. }
  6607. }// END FOR ELSE
  6608. }
  6609. } // END FOR GB_QUANTITY
  6610. }
  6611. else
  6612. {
  6613. for (int index = 0; index < AC_QUANTITY; index++)
  6614. {
  6615. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6616. {
  6617. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6618. {
  6619. //Reserved
  6620. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6621. }
  6622. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6623. {
  6624. //Reserved
  6625. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6626. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6627. goto end;
  6628. }
  6629. else
  6630. {
  6631. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6632. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6633. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6634. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6635. {
  6636. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6637. goto end;
  6638. }
  6639. }//END FOR ELSE
  6640. }
  6641. }// END FOR AC_QUANTITY
  6642. }
  6643. if(chargingProfileIsNULL == FALSE)
  6644. {
  6645. //ChargingProfile
  6646. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6647. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6648. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6649. if(recurrencyKindIsNULL == FALSE) //OPTION
  6650. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6651. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6652. if(transactionIdIsNULL == FALSE) // OPTION
  6653. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6654. if(validFromIsNULL == FALSE) // OPTION
  6655. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6656. if(validToIsNULL == FALSE) //OPTION
  6657. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6658. //ChargingSchedule
  6659. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6660. if(durationIsNULL == FALSE) //OPTION
  6661. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6662. if(minChargingRateIsNULL == FALSE) //OPTION
  6663. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6664. if(startScheduleIsNULL == FALSE) //OPTION
  6665. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6666. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6667. {
  6668. //ChargingSchedulePeriod
  6669. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6670. if(numberPhasesIsNULL == FALSE)
  6671. {
  6672. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6673. }
  6674. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6675. }
  6676. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6677. {
  6678. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6679. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6680. //memset idTag
  6681. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6682. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6683. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6684. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6685. }
  6686. else
  6687. {
  6688. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6689. }
  6690. }
  6691. else
  6692. {
  6693. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6694. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6695. //memset idTag
  6696. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6697. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6698. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6699. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6700. }
  6701. }
  6702. else
  6703. {
  6704. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6705. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6706. }
  6707. end:
  6708. if(connectorIdIsNULL == FALSE)
  6709. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6710. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6711. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6712. //OCPP send RemoteStartConfirmation by first.
  6713. sendRemoteStartConfirmation(uuid, comfirmstr);
  6714. return result;
  6715. }
  6716. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6717. {
  6718. mtrace();
  6719. int result = FAIL;
  6720. int match = FALSE;
  6721. int GunNO = 0;
  6722. int transactionIdInt=0;
  6723. int transactionIdIsNULL= FALSE;
  6724. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6725. int c = 0;
  6726. char *loc;
  6727. char comfirmstr[20];
  6728. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6729. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6730. if(server_pending == TRUE)
  6731. {
  6732. return 0;
  6733. }
  6734. c=0;
  6735. loc = strstr(payload, "transactionId");
  6736. if(loc == NULL)
  6737. {
  6738. transactionIdIsNULL= TRUE;
  6739. }
  6740. else
  6741. {
  6742. memset(sstr ,0, sizeof(sstr) );
  6743. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6744. {
  6745. sstr[c] = loc[strlen("transactionId")+2+c];
  6746. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6747. c++;
  6748. }
  6749. sstr[c] = '\0';
  6750. transactionIdInt = atoi(sstr);
  6751. }
  6752. if(transactionIdIsNULL == FALSE)
  6753. {
  6754. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6755. {
  6756. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6757. {
  6758. //check Transaction active
  6759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6760. {
  6761. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6762. {
  6763. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6764. {
  6765. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6766. {
  6767. match = TRUE;
  6768. GunNO = gun_index;
  6769. }
  6770. }
  6771. }// END FOR CHAdeMO_QUANTITY
  6772. for (int index = 0; index < CCS_QUANTITY; index++)
  6773. {
  6774. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6775. {
  6776. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6777. {
  6778. match = TRUE;
  6779. GunNO = gun_index;
  6780. }
  6781. }
  6782. }// END FOR CCS_QUANTITY
  6783. for (int index = 0; index < GB_QUANTITY; index++)
  6784. {
  6785. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6786. {
  6787. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6788. {
  6789. match = TRUE;
  6790. GunNO = gun_index;
  6791. }
  6792. }
  6793. }// END FOR GB_QUANTITY
  6794. }
  6795. else
  6796. {
  6797. for (int index = 0; index < AC_QUANTITY; index++)
  6798. {
  6799. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6800. {
  6801. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6802. {
  6803. match = TRUE;
  6804. GunNO = gun_index;
  6805. }
  6806. }
  6807. }// END FOR CHAdeMO_QUANTITY
  6808. }// END FOR AC ELSE
  6809. }// CHECK IF ResponseTransactionId == transactionIdInt
  6810. }//END FOR
  6811. if( match == TRUE)
  6812. {
  6813. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6814. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6815. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6816. }
  6817. else
  6818. {
  6819. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6820. }
  6821. }
  6822. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6823. return result;
  6824. }
  6825. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6826. {
  6827. mtrace();
  6828. int result = FAIL;
  6829. int connectorIdInt=0, reservationIdInt=0;
  6830. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6831. char comfirmstr[20]={0};
  6832. char sstr[180]={ 0 };
  6833. int c = 0;
  6834. char *loc;
  6835. //char *ptr;
  6836. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6837. //***(1)connectorId ****/
  6838. c=0;
  6839. loc = strstr(payload, "connectorId");
  6840. memset(sstr ,0, sizeof(sstr) );
  6841. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6842. {
  6843. sstr[c] = loc[strlen("connectorId")+2+c];
  6844. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6845. c++;
  6846. }
  6847. sstr[c] = '\0';
  6848. connectorIdInt = atoi(sstr);
  6849. //***(2)expiryDate ****/
  6850. loc = strstr(payload, "expiryDate");
  6851. memset(sstr ,0, sizeof(sstr) );
  6852. c = 0;
  6853. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6854. {
  6855. sstr[c] = loc[3+strlen("expiryDate")+c];
  6856. c++;
  6857. }
  6858. sstr[c] = '\0';
  6859. strcpy(expiryDatestr, sstr);
  6860. //***(3)idTag ****/
  6861. loc = strstr(payload, "idTag");
  6862. memset(sstr ,0, sizeof(sstr) );
  6863. c = 0;
  6864. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6865. {
  6866. sstr[c] = loc[3+strlen("idTag")+c];
  6867. c++;
  6868. }
  6869. sstr[c] = '\0';
  6870. strcpy(idTagstr, sstr);
  6871. //***(4)parentIdTag ****/
  6872. loc = strstr(payload, "parentIdTag");
  6873. memset(sstr ,0, sizeof(sstr) );
  6874. c = 0;
  6875. if(loc == NULL)
  6876. {
  6877. strcpy(parentIdTagstr, "");
  6878. }
  6879. else
  6880. {
  6881. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6882. {
  6883. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6884. c++;
  6885. }
  6886. sstr[c] = '\0';
  6887. strcpy(parentIdTagstr, sstr);
  6888. }
  6889. //***(5)reservationId ****/
  6890. c=0;
  6891. loc = strstr(payload, "reservationId");
  6892. memset(sstr ,0, sizeof(sstr) );
  6893. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6894. {
  6895. sstr[c] = loc[strlen("reservationId")+2+c];
  6896. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6897. c++;
  6898. }
  6899. sstr[c] = '\0';
  6900. reservationIdInt = atoi(sstr);
  6901. if(reservationIdInt == 0)
  6902. {
  6903. //reservationId's value can not be 0
  6904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6905. goto end;
  6906. }
  6907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6908. /*
  6909. enum SYSTEM_STATUS
  6910. {
  6911. SYS_MODE_BOOTING = 0,
  6912. SYS_MODE_IDLE = 1,
  6913. SYS_MODE_AUTHORIZING = 2,
  6914. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6915. SYS_MODE_REASSIGN = 4,
  6916. SYS_MODE_PREPARING = 5,
  6917. SYS_MODE_PREPARE_FOR_EV = 6,
  6918. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6919. SYS_MODE_CHARGING = 8,
  6920. SYS_MODE_TERMINATING = 9,
  6921. SYS_MODE_COMPLETE = 10,
  6922. SYS_MODE_ALARM = 11,
  6923. SYS_MODE_FAULT = 12,
  6924. SYS_MODE_RESERVATION = 13,
  6925. SYS_MODE_BOOKING = 14,
  6926. SYS_MODE_MAINTAIN = 15,
  6927. SYS_MODE_DEBUG = 16,
  6928. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6929. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6930. SYS_MODE_UPDATE = 19
  6931. };
  6932. */
  6933. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6934. {
  6935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6936. goto end;
  6937. }
  6938. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6939. {
  6940. //check Transaction active
  6941. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6942. {
  6943. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6944. {
  6945. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6946. {
  6947. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6948. {
  6949. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6950. {
  6951. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6952. {
  6953. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6955. }
  6956. 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'))
  6957. {
  6958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6959. }
  6960. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6961. {
  6962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6963. }
  6964. else
  6965. {
  6966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6967. }
  6968. }
  6969. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6970. {
  6971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6972. }
  6973. }
  6974. else
  6975. {
  6976. //replace reservation
  6977. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6979. }
  6980. }
  6981. } // END FOR CHAdeMO_QUANTITY
  6982. for (int index = 0; index < CCS_QUANTITY; index++)
  6983. {
  6984. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6985. {
  6986. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6987. {
  6988. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6989. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6990. {
  6991. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6992. {
  6993. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6995. }
  6996. 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'))
  6997. {
  6998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6999. }
  7000. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7001. {
  7002. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7003. }
  7004. else
  7005. {
  7006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7007. }
  7008. }
  7009. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7010. {
  7011. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7012. }
  7013. }
  7014. else
  7015. {
  7016. //replace reservation
  7017. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7018. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7019. }
  7020. }
  7021. } // END FOR CCS_QUANTITY
  7022. for (int index = 0; index < GB_QUANTITY; index++)
  7023. {
  7024. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  7025. {
  7026. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7027. {
  7028. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7029. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7030. {
  7031. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7032. {
  7033. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7034. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7035. }
  7036. 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'))
  7037. {
  7038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7039. }
  7040. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7041. {
  7042. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7043. }
  7044. else
  7045. {
  7046. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7047. }
  7048. }
  7049. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7050. {
  7051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7052. }
  7053. }
  7054. else
  7055. {
  7056. //replace reservation
  7057. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7059. }
  7060. }
  7061. }// END FOR GB_QUANTITY
  7062. }
  7063. else
  7064. {
  7065. for (int index = 0; index < AC_QUANTITY; index++)
  7066. {
  7067. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  7068. {
  7069. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7070. {
  7071. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7072. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7073. {
  7074. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7075. {
  7076. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7077. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7078. }
  7079. 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'))
  7080. {
  7081. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7082. }
  7083. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7084. {
  7085. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7086. }
  7087. else
  7088. {
  7089. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7090. }
  7091. }
  7092. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7093. {
  7094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7095. }
  7096. }
  7097. else
  7098. {
  7099. //replace reservation
  7100. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7101. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7102. }
  7103. }
  7104. } // END FOR AC_QUANTITY
  7105. }//END FOR AC ELSE
  7106. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7107. }
  7108. else if(connectorIdInt == 0)
  7109. {
  7110. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7111. {
  7112. //check Transaction active
  7113. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7114. {
  7115. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7116. {
  7117. 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'))
  7118. {
  7119. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7120. goto end;
  7121. }
  7122. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7123. {
  7124. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7125. goto end;
  7126. }
  7127. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7128. {
  7129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7130. goto end;
  7131. }
  7132. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7133. {
  7134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7135. goto end;
  7136. }
  7137. }
  7138. }// END FOR CHAdeMO_QUANTITY
  7139. for (int index = 0; index < CCS_QUANTITY; index++)
  7140. {
  7141. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7142. {
  7143. 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'))
  7144. {
  7145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7146. }
  7147. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7148. {
  7149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7150. }
  7151. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7152. {
  7153. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7154. }
  7155. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7156. {
  7157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7158. }
  7159. }
  7160. } // END FOR CCS_QUANTITY
  7161. for (int index = 0; index < GB_QUANTITY; index++)
  7162. {
  7163. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7164. {
  7165. 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'))
  7166. {
  7167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7168. }
  7169. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7170. {
  7171. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7172. }
  7173. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7174. {
  7175. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7176. }
  7177. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7178. {
  7179. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7180. }
  7181. }
  7182. } // END FOR GB_QUANTITY
  7183. }
  7184. else
  7185. {
  7186. for (int index = 0; index < AC_QUANTITY; index++)
  7187. {
  7188. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7189. {
  7190. 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'))
  7191. {
  7192. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7193. goto end;
  7194. }
  7195. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7196. {
  7197. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7198. goto end;
  7199. }
  7200. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7201. {
  7202. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7203. goto end;
  7204. }
  7205. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7206. {
  7207. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7208. goto end;
  7209. }
  7210. }
  7211. }// END FOR AC_QUANTITY
  7212. }
  7213. //The connectorId is 0
  7214. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7216. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7217. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7218. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7219. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7220. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7221. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7222. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7223. result = TRUE;
  7224. return result;
  7225. }
  7226. else
  7227. {
  7228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7229. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7230. }
  7231. if(strcmp(comfirmstr,"Accepted") == 0)
  7232. {
  7233. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7234. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7235. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7236. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7237. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7238. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7239. result = TRUE;
  7240. return result;
  7241. }
  7242. end:
  7243. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7244. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7245. return result;
  7246. }
  7247. int handleResetRequest(char *uuid, char *payload)
  7248. {
  7249. mtrace();
  7250. int result = FAIL;
  7251. char sstr[10]={0};
  7252. char typestr[10]={0};
  7253. char comfirmstr[20]={0};
  7254. int c = 0;
  7255. char *loc;
  7256. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7257. DEBUG_INFO("handleResetRequest ...\n");
  7258. loc = strstr(payload, "type");
  7259. memset(sstr ,0, sizeof(sstr) );
  7260. c = 0;
  7261. while (loc[3+strlen("type")+c] != '\"')
  7262. {
  7263. sstr[c] = loc[3+strlen("type")+c];
  7264. c++;
  7265. }
  7266. sstr[c] = '\0';
  7267. strcpy(typestr,sstr);
  7268. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7269. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7270. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7271. {
  7272. //check Transaction active
  7273. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7274. {
  7275. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7276. {
  7277. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7278. {
  7279. //0: unplug, 1: Plug-in
  7280. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7281. }
  7282. }
  7283. for (int index = 0; index < CCS_QUANTITY; index++)
  7284. {
  7285. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7286. {
  7287. //0: unplug, 1: Plug-in
  7288. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7289. }
  7290. }
  7291. for (int index = 0; index < GB_QUANTITY; index++)
  7292. {
  7293. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7294. {
  7295. //0: unplug, 1: Plug-in
  7296. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7297. }
  7298. }
  7299. }
  7300. else
  7301. {
  7302. for (int index = 0; index < AC_QUANTITY; index++)
  7303. {
  7304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7305. {
  7306. //0: unplug, 1: Plug-in
  7307. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7308. }
  7309. }
  7310. }// END FOR AC ELSE
  7311. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7312. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7313. result = TRUE;
  7314. return result;
  7315. }
  7316. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7317. {
  7318. //check Transaction active
  7319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7320. {
  7321. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7322. {
  7323. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7324. {
  7325. //0: unplug, 1: Plug-in
  7326. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7327. }
  7328. }
  7329. for (int index = 0; index < CCS_QUANTITY; index++)
  7330. {
  7331. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7332. {
  7333. //0: unplug, 1: Plug-in
  7334. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7335. }
  7336. }
  7337. for (int index = 0; index < GB_QUANTITY; index++)
  7338. {
  7339. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7340. {
  7341. //0: unplug, 1: Plug-in
  7342. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7343. }
  7344. }
  7345. }
  7346. else
  7347. {
  7348. for (int index = 0; index < AC_QUANTITY; index++)
  7349. {
  7350. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7351. {
  7352. //0: unplug, 1: Plug-in
  7353. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7354. }
  7355. }
  7356. }// END FOR AC ELSE
  7357. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7358. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7359. result = TRUE;
  7360. return result;
  7361. }
  7362. else
  7363. {
  7364. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7365. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7366. goto errorend;
  7367. }
  7368. errorend:
  7369. sendResetConfirmation(uuid, comfirmstr);
  7370. return result;
  7371. }
  7372. int handleSendLocalListRequest(char *uuid, char *payload)
  7373. {
  7374. mtrace();
  7375. int result = FAIL;
  7376. int listVersionInt;
  7377. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7378. char listsearch[]="listVersion";
  7379. char updateTypesearch[]="updateType";
  7380. char localAuthorizationListsearch[]="localAuthorizationList";
  7381. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7382. char CardList[500][160]={0};
  7383. char updateTypestr[15]={0};
  7384. char idTagstr[20]={0};
  7385. char parentIdTag[20]={0};
  7386. char expiryDate[30]={0};
  7387. char idTagstatus[16]={0};
  7388. int c = 0;
  7389. int i = 0;
  7390. char *delim1 = "}";
  7391. char * pch;
  7392. char *loc;
  7393. //char *ptr;
  7394. char comfirmstr[20];
  7395. //int n_localAuthorizations = 0;
  7396. int checkState_Faulted = FALSE;
  7397. DEBUG_INFO("handleSendLocalListRequest\n");
  7398. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7399. {
  7400. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7401. goto end;
  7402. }
  7403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7404. {
  7405. //check Charge Point state
  7406. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7407. {
  7408. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7409. {
  7410. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7411. }
  7412. }
  7413. for (int index = 0; index < CCS_QUANTITY; index++)
  7414. {
  7415. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7416. {
  7417. checkState_Faulted = TRUE; //OCPP Status
  7418. }
  7419. }
  7420. for (int index = 0; index < GB_QUANTITY; index++)
  7421. {
  7422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7423. {
  7424. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7425. }
  7426. }
  7427. }
  7428. else
  7429. {
  7430. //check Charge Point state
  7431. for (int index = 0; index < AC_QUANTITY; index++)
  7432. {
  7433. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7434. {
  7435. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7436. }
  7437. }
  7438. }// END FOR AC ELSE
  7439. if(checkState_Faulted == TRUE)
  7440. {
  7441. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7442. goto end;
  7443. }
  7444. //listVersion
  7445. c = 0;
  7446. loc = strstr(payload, listsearch);
  7447. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7448. {
  7449. sstr[c] = loc[strlen("listVersion")+2+c];
  7450. c++;
  7451. }
  7452. sstr[c] = '\0';
  7453. listVersionInt = atoi(sstr);
  7454. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7455. //updateType
  7456. loc = strstr(payload, updateTypesearch);
  7457. c = 0;
  7458. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7459. {
  7460. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7461. c++;
  7462. }
  7463. sstr[c] = '\0';
  7464. strcpy(updateTypestr, sstr);
  7465. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7466. //localAuthorizationList
  7467. memset(sstr ,0, sizeof(sstr) );
  7468. loc = strstr(payload, localAuthorizationListsearch);
  7469. if(loc != NULL) // localAuthorizationList is not NULL
  7470. {
  7471. //Check UpdateType
  7472. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7473. {
  7474. //Local list full update
  7475. printf("Local list full update.\n");
  7476. OCPP_getListVerion();
  7477. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7478. {
  7479. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7480. goto end;
  7481. }
  7482. OCPP_cleanLocalList();
  7483. }
  7484. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7485. {
  7486. //Local list different update
  7487. printf("Local list different update.\n");
  7488. OCPP_getListVerion();
  7489. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7490. {
  7491. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7492. goto end;
  7493. }
  7494. }
  7495. else
  7496. {
  7497. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7498. goto end;
  7499. }
  7500. c = 0;
  7501. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7502. {
  7503. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7504. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7505. c++;
  7506. }
  7507. sstr[c] = '\0';
  7508. //DEBUG_INFO("sstr=%s\n", sstr);
  7509. //parsing strings to words
  7510. i = 0;
  7511. pch = strtok(sstr,delim1);
  7512. while (pch != NULL)
  7513. {
  7514. strcpy(CardList[i], pch);
  7515. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7516. pch = strtok (NULL, delim1);
  7517. i = i + 1;
  7518. }
  7519. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7520. //local Authorizations List Numbers
  7521. //n_localAuthorizations = i;
  7522. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7523. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7524. c= 0;
  7525. while(c < i) // i is CardList Number
  7526. {
  7527. //Search "IdToken"
  7528. memset(sstr ,0, sizeof(sstr) );
  7529. loc = strstr(CardList[c], "idTag");
  7530. int j = 0;
  7531. while (loc[3+strlen("idTag")+j] != '\"')
  7532. {
  7533. sstr[j] = loc[3+strlen("idTag")+j];
  7534. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7535. j++;
  7536. }
  7537. sstr[j] = '\0';
  7538. strcpy(idTagstr, sstr);
  7539. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7540. //Search "expiryDate"
  7541. memset(sstr ,0, sizeof(sstr) );
  7542. loc = strstr(CardList[c], "expiryDate");
  7543. j = 0;
  7544. if(loc != NULL)
  7545. {
  7546. while (loc[3+strlen("expiryDate")+j] != '\"')
  7547. {
  7548. sstr[j] = loc[3+strlen("expiryDate")+j];
  7549. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7550. j++;
  7551. }
  7552. sstr[j] = '\0';
  7553. strcpy(expiryDate, sstr);
  7554. }
  7555. else
  7556. {
  7557. strcpy(expiryDate, "");
  7558. }
  7559. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7560. //Search "parentIdTag"
  7561. memset(sstr ,0, sizeof(sstr) );
  7562. loc = strstr(CardList[c], "parentIdTag");
  7563. j = 0;
  7564. if(loc != NULL)
  7565. {
  7566. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7567. {
  7568. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7569. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7570. j++;
  7571. }
  7572. sstr[j] = '\0';
  7573. strcpy(parentIdTag, sstr);
  7574. }
  7575. else
  7576. {
  7577. strcpy(parentIdTag, "");
  7578. }
  7579. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7580. //Search "status"
  7581. memset(sstr ,0, sizeof(sstr) );
  7582. loc = strstr(CardList[c], "status");
  7583. j = 0;
  7584. while (loc[3+strlen("status")+j] != '\"')
  7585. {
  7586. sstr[j] = loc[3+strlen("status")+j];
  7587. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7588. j++;
  7589. }
  7590. sstr[j] = '\0';
  7591. strcpy(idTagstatus, sstr);
  7592. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7593. OCPP_getIdTag(idTagstr);
  7594. //OCPP_getIdTag("test"); For Test
  7595. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7596. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7597. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7598. {
  7599. //Local list full update
  7600. DEBUG_INFO("Local list full update.\n");
  7601. // update list
  7602. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7603. //DEBUG_INFO("Local list full update. 1\n");
  7604. //OCPP_get_TableAuthlocalAllData();
  7605. //DEBUG_INFO("Local list full update. 2\n");
  7606. }
  7607. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7608. {
  7609. #if 0
  7610. if(strcmp(idTagstr, idTagAuthorization) == 0)
  7611. {
  7612. //OCPP_deleteIdTag(idTagstr);
  7613. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7614. }
  7615. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  7616. {
  7617. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7618. }
  7619. #endif
  7620. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7621. }
  7622. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7623. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7624. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7625. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7626. c++;
  7627. }
  7628. }
  7629. else
  7630. {
  7631. //Check UpdateType
  7632. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7633. {
  7634. //Local list full update
  7635. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7636. OCPP_cleanLocalList();
  7637. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7638. goto end;
  7639. }
  7640. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7641. {
  7642. //Local list different update
  7643. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7644. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7645. goto end;
  7646. }
  7647. }
  7648. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7649. end:
  7650. sendSendLocalListConfirmation(uuid, comfirmstr);
  7651. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7652. return result;
  7653. }
  7654. #define MAX 200
  7655. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7656. {
  7657. mtrace();
  7658. int result = FAIL;
  7659. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7660. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7661. char chargingProfilePurposeStr[30]={0};
  7662. char chargingProfileKindStr[16]={0};
  7663. char recurrencyKindStr[10]={0};
  7664. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7665. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7666. int chargingSchedulePeriodCount = 0;
  7667. //int updateflag = FALSE;
  7668. char comfirmstr[20]={0};
  7669. int meet= FALSE;
  7670. char sstr[10]={0};
  7671. int c = 0;
  7672. char *loc;
  7673. FILE *fptr1;//, *fptr2;
  7674. //int lno=0;//, linectr = 0;
  7675. //int modifyflag = FALSE;
  7676. char filename[MAX]={0};
  7677. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  7678. //int resultRename=0;
  7679. char rmFileCmd[50]={0};
  7680. char tempchargingProfilePurposeStr[30]={0};
  7681. char word[1600]={0};
  7682. int n_chargingProfile = 0;
  7683. //[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}}}]
  7684. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7685. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7686. //*********************connectorId***************************/
  7687. loc = strstr(payload, "connectorId");
  7688. c = 0;
  7689. memset(sstr ,0, sizeof(sstr) );
  7690. while (loc[strlen("connectorId")+2+c] != ',')
  7691. {
  7692. sstr[c] = loc[strlen("connectorId")+2+c];
  7693. c++;
  7694. }
  7695. sstr[c] = '\0';
  7696. connectorIdInt = atoi(sstr);
  7697. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7698. {
  7699. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7700. }
  7701. else
  7702. {
  7703. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7704. }
  7705. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7706. //*********************chargingProfileId***************************/
  7707. loc = strstr(payload, "chargingProfileId");
  7708. c = 0;
  7709. memset(sstr ,0, sizeof(sstr) );
  7710. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7711. {
  7712. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7713. c++;
  7714. }
  7715. sstr[c] = '\0';
  7716. chargingProfileIdInt = atoi(sstr);
  7717. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7718. {
  7719. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7720. }
  7721. else
  7722. {
  7723. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7724. }
  7725. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7726. //*********************transactionId***************************/
  7727. loc = strstr(payload, "transactionId");
  7728. if(loc != NULL)
  7729. {
  7730. c = 0;
  7731. memset(sstr ,0, sizeof(sstr) );
  7732. while (loc[strlen("transactionId")+2+c] != ',')
  7733. {
  7734. sstr[c] = loc[strlen("transactionId")+2+c];
  7735. c++;
  7736. }
  7737. sstr[c] = '\0';
  7738. transactionIdInt = atoi(sstr);
  7739. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7740. {
  7741. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7742. }
  7743. else
  7744. {
  7745. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7746. }
  7747. }
  7748. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7749. //*********************stackLevel***************************/
  7750. loc = strstr(payload, "stackLevel");
  7751. c = 0;
  7752. memset(sstr ,0, sizeof(sstr) );
  7753. while (loc[strlen("stackLevel")+2+c] != ',')
  7754. {
  7755. sstr[c] = loc[strlen("stackLevel")+2+c];
  7756. c++;
  7757. }
  7758. sstr[c] = '\0';
  7759. stackLevelInt = atoi(sstr);
  7760. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7761. {
  7762. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7763. }
  7764. else
  7765. {
  7766. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7767. }
  7768. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7769. //*********************chargingProfilePurpose***************************/
  7770. loc = strstr(payload, "chargingProfilePurpose");
  7771. c = 0;
  7772. memset(sstr ,0, sizeof(sstr) );
  7773. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7774. {
  7775. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7777. c++;
  7778. }
  7779. sstr[c] = '\0';
  7780. strcpy(chargingProfilePurposeStr,sstr);
  7781. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7782. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7783. {
  7784. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7785. }
  7786. else
  7787. {
  7788. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7789. }
  7790. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7791. //*********************chargingProfileKind***************************/
  7792. loc = strstr(payload, "chargingProfileKind");
  7793. c = 0;
  7794. memset(sstr ,0, sizeof(sstr) );
  7795. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7796. {
  7797. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7798. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7799. c++;
  7800. }
  7801. sstr[c] = '\0';
  7802. strcpy(chargingProfileKindStr,sstr);
  7803. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7804. {
  7805. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7806. }
  7807. else
  7808. {
  7809. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7810. }
  7811. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7812. //*********************recurrencyKind***************************/
  7813. loc = strstr(payload, "recurrencyKind");
  7814. if(loc != NULL)
  7815. {
  7816. c = 0;
  7817. memset(sstr ,0, sizeof(sstr) );
  7818. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7819. {
  7820. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7821. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7822. c++;
  7823. }
  7824. sstr[c] = '\0';
  7825. strcpy(recurrencyKindStr,sstr);
  7826. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7827. {
  7828. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7829. }
  7830. else
  7831. {
  7832. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7833. }
  7834. }
  7835. else
  7836. {
  7837. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7838. {
  7839. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7840. }
  7841. else
  7842. {
  7843. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7844. }
  7845. }
  7846. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7847. //*********************validFrom***************************/
  7848. loc = strstr(payload, "validFrom");
  7849. if(loc != NULL)
  7850. {
  7851. c = 0;
  7852. memset(sstr ,0, sizeof(sstr) );
  7853. while (loc[3+strlen("validFrom")+c] != '\"')
  7854. {
  7855. sstr[c] = loc[3+strlen("validFrom")+c];
  7856. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7857. c++;
  7858. }
  7859. sstr[c] = '\0';
  7860. strcpy(validFromStr,sstr);
  7861. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7862. {
  7863. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7864. }
  7865. else
  7866. {
  7867. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7868. }
  7869. }
  7870. else
  7871. {
  7872. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7873. {
  7874. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7875. }
  7876. else
  7877. {
  7878. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7879. }
  7880. }
  7881. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7882. //*********************validTo***************************/
  7883. loc = strstr(payload, "validTo");
  7884. if(loc != NULL)
  7885. {
  7886. c = 0;
  7887. memset(sstr ,0, sizeof(sstr) );
  7888. while (loc[3+strlen("validTo")+c] != '\"')
  7889. {
  7890. sstr[c] = loc[3+strlen("validTo")+c];
  7891. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7892. c++;
  7893. }
  7894. sstr[c] = '\0';
  7895. strcpy(validToStr,sstr);
  7896. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7897. {
  7898. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7899. }
  7900. else
  7901. {
  7902. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7903. }
  7904. }
  7905. else
  7906. {
  7907. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7908. {
  7909. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7910. }
  7911. else
  7912. {
  7913. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7914. }
  7915. }
  7916. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7917. //*********************duration***************************/
  7918. loc = strstr(payload, "duration");
  7919. if(loc != NULL)
  7920. {
  7921. c = 0;
  7922. memset(sstr ,0, sizeof(sstr) );
  7923. while (loc[strlen("duration")+2+c] != ',')
  7924. {
  7925. sstr[c] = loc[strlen("duration")+2+c];
  7926. c++;
  7927. }
  7928. sstr[c] = '\0';
  7929. durationInt = atoi(sstr);
  7930. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7931. {
  7932. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7933. }
  7934. else
  7935. {
  7936. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7937. }
  7938. }
  7939. else
  7940. {
  7941. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7942. {
  7943. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7944. }
  7945. else
  7946. {
  7947. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7948. }
  7949. }
  7950. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7951. //*********************startSchedule***************************/
  7952. loc = strstr(payload, "startSchedule");
  7953. if(loc != NULL)
  7954. {
  7955. c = 0;
  7956. memset(sstr ,0, sizeof(sstr) );
  7957. while (loc[3+strlen("startSchedule")+c] != '\"')
  7958. {
  7959. sstr[c] = loc[3+strlen("startSchedule")+c];
  7960. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7961. c++;
  7962. }
  7963. sstr[c] = '\0';
  7964. strcpy(startScheduleStr,sstr);
  7965. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7966. {
  7967. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7968. }
  7969. else
  7970. {
  7971. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7972. }
  7973. }
  7974. else
  7975. {
  7976. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7977. {
  7978. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7979. }
  7980. else
  7981. {
  7982. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7983. }
  7984. }
  7985. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7986. //*********************chargingRateUnit***************************/
  7987. loc = strstr(payload, "chargingRateUnit");
  7988. if(loc != NULL)
  7989. {
  7990. c = 0;
  7991. memset(sstr ,0, sizeof(sstr) );
  7992. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7993. {
  7994. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7995. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7996. c++;
  7997. }
  7998. sstr[c] = '\0';
  7999. strcpy(chargingRateUnitStr,sstr);
  8000. #if 0
  8001. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  8002. {
  8003. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8004. goto end;
  8005. }
  8006. #endif
  8007. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8008. {
  8009. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8010. }
  8011. else
  8012. {
  8013. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8014. }
  8015. }
  8016. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8017. //****************chargingSchedulePeriod count start*******************/
  8018. int what_len = strlen("startPeriod");
  8019. char tempChargingProfile[1000]={0};
  8020. strcpy(tempChargingProfile,(const char*)payload);
  8021. char *where = tempChargingProfile;
  8022. if (what_len)
  8023. {
  8024. while ((where = strstr(where, "startPeriod"))) {
  8025. where += what_len;
  8026. chargingSchedulePeriodCount++;
  8027. }
  8028. }
  8029. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8030. {
  8031. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8032. goto end;
  8033. }
  8034. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8035. //where = payload;
  8036. int templength = 0;
  8037. //int searchstart = 0;
  8038. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8039. {
  8040. //****************startPeriod*******************/
  8041. c=0;
  8042. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8043. memset(sstr ,0, sizeof(sstr) );
  8044. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8045. {
  8046. sstr[c] = loc[strlen("startPeriod")+2+c];
  8047. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8048. c++;
  8049. }
  8050. sstr[c] = '\0';
  8051. startPeriodInt[periodNums] = atoi(sstr);
  8052. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8053. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8054. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8055. {
  8056. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8057. }
  8058. else
  8059. {
  8060. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8061. }
  8062. templength = strlen("startPeriod")+2+c;
  8063. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8064. //****************limit*******************/
  8065. c=0;
  8066. loc = strstr(tempChargingProfile + templength, "limit");
  8067. memset(sstr ,0, sizeof(sstr) );
  8068. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8069. {
  8070. sstr[c] = loc[strlen("limit")+2+c];
  8071. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8072. c++;
  8073. }
  8074. sstr[c] = '\0';
  8075. limitflaot[periodNums] = atof(sstr);
  8076. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8077. {
  8078. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8079. }
  8080. else
  8081. {
  8082. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8083. }
  8084. templength = templength + strlen("limit")+2+c;
  8085. //****************numberPhases*******************/
  8086. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8087. if(loc != NULL)
  8088. {
  8089. c=0;
  8090. memset(sstr ,0, sizeof(sstr) );
  8091. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8092. {
  8093. sstr[c] = loc[strlen("numberPhases")+2+c];
  8094. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8095. c++;
  8096. }
  8097. sstr[c] = '\0';
  8098. numberPhasesInt[periodNums] = atoi(sstr);
  8099. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8100. {
  8101. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8102. }
  8103. else
  8104. {
  8105. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8106. }
  8107. templength = templength + strlen("numberPhases")+2+c;
  8108. }
  8109. //where = loc;
  8110. }
  8111. //****************chargingSchedulePeriod count end*******************/
  8112. //*********************minChargingRate***************************/
  8113. loc = strstr(payload, "minChargingRate");
  8114. if(loc != NULL)
  8115. {
  8116. c = 0;
  8117. memset(sstr ,0, sizeof(sstr) );
  8118. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8119. {
  8120. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8121. c++;
  8122. }
  8123. sstr[c] = '\0';
  8124. minChargingRateFloat = atof(sstr);
  8125. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8126. {
  8127. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8128. }
  8129. else
  8130. {
  8131. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8132. }
  8133. }
  8134. else
  8135. {
  8136. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8137. {
  8138. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8139. }
  8140. else
  8141. {
  8142. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8143. }
  8144. }
  8145. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8146. {
  8147. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8148. if(connectorIdInt != 0)
  8149. {
  8150. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8151. goto end;
  8152. }
  8153. strcpy(filename, ChargePointMaxProfile_JSON );
  8154. fptr1 = fopen(filename, "r");
  8155. if (!fptr1)
  8156. {
  8157. //file not exist
  8158. DEBUG_INFO("Unable to open the input file!!\n");
  8159. fptr1 = fopen(filename, "w+");
  8160. }
  8161. else
  8162. {
  8163. //Check Charging Profile Count
  8164. while(fscanf(fptr1, "%s", word) != EOF)
  8165. {
  8166. //DEBUG_INFO("word=%s\n",word);
  8167. if(strstr(word, "chargingProfileId")!= NULL)
  8168. {
  8169. //DEBUG_INFO("test chargingProfileId \n");
  8170. n_chargingProfile = n_chargingProfile + 1;
  8171. //DEBUG_INFO("chargingProfileId Found\n");
  8172. }
  8173. }
  8174. }
  8175. fclose(fptr1);
  8176. }
  8177. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8178. {
  8179. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8180. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8181. {
  8182. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8183. goto end;
  8184. }
  8185. #if 0
  8186. switch(connectorIdInt)
  8187. {
  8188. case 0:
  8189. strcpy(filename, TxDefaultProfile_0_JSON );
  8190. break;
  8191. case 1:
  8192. strcpy(filename, TxDefaultProfile_1_JSON );
  8193. break;
  8194. case 2:
  8195. strcpy(filename, TxDefaultProfile_2_JSON );
  8196. break;
  8197. default:
  8198. strcpy(filename, TxDefaultProfile_0_JSON );
  8199. break;
  8200. }
  8201. #endif
  8202. memset(filename, 0, sizeof filename);
  8203. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8204. fptr1 = fopen(filename, "r");
  8205. if (!fptr1)
  8206. {
  8207. //file not exist
  8208. //DEBUG_INFO("Unable to open the input file!!\n");
  8209. fptr1 = fopen(filename, "w+");
  8210. }
  8211. else
  8212. {
  8213. //Check Charging Profile Count
  8214. while(fscanf(fptr1, "%s", word) != EOF)
  8215. {
  8216. //DEBUG_INFO("word=%s\n",word);
  8217. if(strstr(word, "chargingProfileId")!= NULL)
  8218. {
  8219. //DEBUG_INFO("test chargingProfileId \n");
  8220. n_chargingProfile = n_chargingProfile + 1;
  8221. //DEBUG_INFO("chargingProfileId Found\n");
  8222. }
  8223. }
  8224. }
  8225. fclose(fptr1);
  8226. }
  8227. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8228. {
  8229. //printf("set chargingProfile 1-4\n");
  8230. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8231. //check Transaction active
  8232. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8233. {
  8234. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8235. {
  8236. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8237. {
  8238. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8239. {
  8240. meet = TRUE;
  8241. break;
  8242. }
  8243. }
  8244. }
  8245. }
  8246. for (int index = 0; index < CCS_QUANTITY; index++)
  8247. {
  8248. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8249. {
  8250. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8251. {
  8252. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8253. {
  8254. meet = TRUE;
  8255. break;
  8256. }
  8257. }
  8258. }
  8259. }
  8260. for (int index = 0; index < GB_QUANTITY; index++)
  8261. {
  8262. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8263. {
  8264. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8265. {
  8266. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8267. {
  8268. meet = TRUE;
  8269. break;
  8270. }
  8271. }
  8272. }
  8273. }
  8274. if(meet == FALSE)
  8275. {
  8276. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8277. goto end;
  8278. }
  8279. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8280. {
  8281. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8282. goto end;
  8283. }
  8284. #if 0
  8285. switch(connectorIdInt)
  8286. {
  8287. case 0:
  8288. break;
  8289. case 1:
  8290. strcpy(filename, TxProfile_1_JSON);
  8291. break;
  8292. case 2:
  8293. strcpy(filename, TxProfile_2_JSON);
  8294. break;
  8295. default:
  8296. strcpy(filename, TxProfile_1_JSON);
  8297. break;
  8298. }
  8299. #endif
  8300. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8301. fptr1 = fopen(filename, "r");
  8302. if (!fptr1)
  8303. {
  8304. //file not exist
  8305. DEBUG_INFO("Unable to open the input file!!\n");
  8306. fptr1 = fopen(filename, "w+");
  8307. }
  8308. else
  8309. {
  8310. //Check Charging Profile Count
  8311. while(fscanf(fptr1, "%s", word) != EOF)
  8312. {
  8313. //DEBUG_INFO("word=%s\n",word);
  8314. if(strstr(word, "chargingProfileId")!= NULL)
  8315. {
  8316. //DEBUG_INFO("test chargingProfileId \n");
  8317. n_chargingProfile = n_chargingProfile + 1;
  8318. //DEBUG_INFO("chargingProfileId Found\n");
  8319. }
  8320. }
  8321. }
  8322. fclose(fptr1);
  8323. DEBUG_INFO("n_chargingProfile_3=%d\n",n_chargingProfile);
  8324. }
  8325. // Check ChargeProfileMaxStackLevel
  8326. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8327. {
  8328. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8329. goto end;
  8330. }
  8331. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8332. {
  8333. int i = 0;
  8334. char fnametemp[200]={0};
  8335. n_chargingProfile = 0;
  8336. //Check ChargePointMaxProfile.json exit
  8337. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8338. {
  8339. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8340. //Check Charging Profile Count
  8341. while(fscanf(fptr1, "%s", word) != EOF)
  8342. {
  8343. //DEBUG_INFO("word=%s\n",word);
  8344. if(strstr(word, "chargingProfileId")!= NULL)
  8345. {
  8346. //DEBUG_INFO("test chargingProfileId \n");
  8347. n_chargingProfile = n_chargingProfile + 1;
  8348. i = i + 1;
  8349. //DEBUG_INFO("chargingProfileId Found\n");
  8350. }
  8351. memset(word, 0, sizeof word);
  8352. }
  8353. fclose(fptr1);
  8354. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8355. }
  8356. //Check TxDefaultProfile_0.json exit
  8357. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8358. {
  8359. i = 0;
  8360. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8361. //Check Charging Profile Count
  8362. while(fscanf(fptr1, "%s", word) != EOF)
  8363. {
  8364. //DEBUG_INFO("word=%s\n",word);
  8365. if(strstr(word, "chargingProfileId")!= NULL)
  8366. {
  8367. //DEBUG_INFO("test chargingProfileId \n");
  8368. n_chargingProfile = n_chargingProfile + 1;
  8369. i = i + 1;
  8370. //DEBUG_INFO("chargingProfileId Found\n");
  8371. }
  8372. memset(word, 0, sizeof word);
  8373. }
  8374. fclose(fptr1);
  8375. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8376. }
  8377. //Check TxDefaultProfile_%d.json
  8378. for(int j=1; j <= gunTotalNumber; j++)
  8379. {
  8380. memset(fnametemp, 0, sizeof fnametemp);
  8381. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8382. if((access(fnametemp,F_OK))!=-1)
  8383. {
  8384. i = 0;
  8385. fptr1 = fopen(fnametemp, "r");
  8386. //Check Charging Profile Count
  8387. while(fscanf(fptr1, "%s", word) != EOF)
  8388. {
  8389. //DEBUG_INFO("word=%s\n",word);
  8390. if(strstr(word, "chargingProfileId")!= NULL)
  8391. {
  8392. //DEBUG_INFO("test chargingProfileId \n");
  8393. n_chargingProfile = n_chargingProfile + 1;
  8394. i = i + 1;
  8395. //DEBUG_INFO("chargingProfileId Found\n");
  8396. }
  8397. memset(word, 0, sizeof word);
  8398. }
  8399. fclose(fptr1);
  8400. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8401. }
  8402. }
  8403. //Check TxProfile_%d.json
  8404. for(int j=1; j <= gunTotalNumber; j++)
  8405. {
  8406. memset(fnametemp, 0, sizeof fnametemp);
  8407. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8408. if((access(fnametemp,F_OK))!=-1)
  8409. {
  8410. i = 0;
  8411. fptr1 = fopen(fnametemp, "r");
  8412. //Check Charging Profile Count
  8413. while(fscanf(fptr1, "%s", word) != EOF)
  8414. {
  8415. //DEBUG_INFO("word=%s\n",word);
  8416. if(strstr(word, "chargingProfileId")!= NULL)
  8417. {
  8418. //DEBUG_INFO("test chargingProfileId \n");
  8419. n_chargingProfile = n_chargingProfile + 1;
  8420. i = i + 1;
  8421. //DEBUG_INFO("chargingProfileId Found\n");
  8422. }
  8423. memset(word, 0, sizeof word);
  8424. }
  8425. fclose(fptr1);
  8426. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8427. }
  8428. }
  8429. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8430. {
  8431. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8432. goto end;
  8433. }
  8434. }
  8435. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8436. //**********************************Write to File********************************************************/
  8437. FILE *infile;
  8438. FILE *outfile;
  8439. // open file for writing
  8440. infile = fopen (filename, "r");
  8441. outfile = fopen (tempfile, "w");
  8442. int d =0;
  8443. d = fgetc(infile);
  8444. //DEBUG_INFO("d:%d\n",d);
  8445. rewind(infile);
  8446. //*检测到文件结束标识返回1,否则返回0。*/
  8447. if(d == EOF)
  8448. {
  8449. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8450. fprintf(outfile,"%s\n",payload);
  8451. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8452. fclose(infile);
  8453. fclose(outfile);
  8454. sprintf(rmFileCmd,"rm -f %s",filename);
  8455. system(rmFileCmd);
  8456. rename(tempfile, filename);
  8457. #if 0
  8458. resultRename = rename(tempfile, filename);
  8459. if(resultRename == 0)
  8460. {
  8461. DEBUG_INFO("File chargingProfile renamed successfully");
  8462. }
  8463. else
  8464. {
  8465. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8466. }
  8467. #endif
  8468. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8469. //system(rmFileCmd);
  8470. }
  8471. else
  8472. {
  8473. char buf[1000]={0};
  8474. int ChargingProfileAdded = FALSE;
  8475. while (fgets(buf, sizeof(buf), infile) != NULL)
  8476. {
  8477. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8478. //*************************tempconnectorIdInt*********************************/
  8479. loc = strstr(buf, "connectorId");
  8480. c = 0;
  8481. memset(sstr ,0, sizeof(sstr) );
  8482. while (loc[strlen("connectorId")+2+c] != ',')
  8483. {
  8484. sstr[c] = loc[strlen("connectorId")+2+c];
  8485. c++;
  8486. }
  8487. sstr[c] = '\0';
  8488. tempconnectorIdInt = atoi(sstr);
  8489. //*************************tempchargingProfileIdInt*********************************/
  8490. loc = strstr(buf, "chargingProfileId");
  8491. c = 0;
  8492. memset(sstr ,0, sizeof(sstr) );
  8493. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8494. {
  8495. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8496. c++;
  8497. }
  8498. sstr[c] = '\0';
  8499. tempchargingProfileIdInt = atoi(sstr);
  8500. //*************************tempstackLevelInt*********************************/
  8501. loc = strstr(buf, "stackLevel");
  8502. c = 0;
  8503. memset(sstr ,0, sizeof(sstr) );
  8504. while (loc[strlen("stackLevel")+2+c] != ',')
  8505. {
  8506. sstr[c] = loc[strlen("stackLevel")+2+c];
  8507. c++;
  8508. }
  8509. sstr[c] = '\0';
  8510. tempstackLevelInt = atoi(sstr);
  8511. //*************************tempchargingProfilePurposeStr*********************************/
  8512. loc = strstr(payload, "chargingProfilePurpose");
  8513. c = 0;
  8514. memset(sstr ,0, sizeof(sstr) );
  8515. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8516. {
  8517. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8518. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8519. c++;
  8520. }
  8521. sstr[c] = '\0';
  8522. strcpy(tempchargingProfilePurposeStr,sstr);
  8523. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8524. {
  8525. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8526. {
  8527. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8528. if(ChargingProfileAdded == FALSE)
  8529. {
  8530. fprintf(outfile,"%s\n",payload);
  8531. ChargingProfileAdded = TRUE;
  8532. }
  8533. }
  8534. else
  8535. {
  8536. if(tempstackLevelInt < stackLevelInt)
  8537. {
  8538. if(ChargingProfileAdded == FALSE)
  8539. {
  8540. fprintf(outfile,"%s\n",payload);
  8541. ChargingProfileAdded = TRUE;
  8542. fprintf(outfile,"%s\n",buf);
  8543. }
  8544. else
  8545. {
  8546. fprintf(outfile,"%s\n",buf);
  8547. }
  8548. }
  8549. else
  8550. {
  8551. if(ChargingProfileAdded == FALSE)
  8552. {
  8553. fprintf(outfile,"%s\n",buf);
  8554. fprintf(outfile,"%s\n",payload);
  8555. ChargingProfileAdded = TRUE;
  8556. }
  8557. else
  8558. {
  8559. fprintf(outfile,"%s\n",buf);
  8560. }
  8561. }
  8562. }
  8563. }
  8564. else
  8565. {
  8566. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8567. {
  8568. if(ChargingProfileAdded == FALSE)
  8569. {
  8570. fprintf(outfile,"%s\n",payload);
  8571. ChargingProfileAdded = TRUE;
  8572. fprintf(outfile,"%s\n",buf);
  8573. }
  8574. else
  8575. {
  8576. fprintf(outfile,"%s\n",buf);
  8577. }
  8578. }
  8579. else if(tempstackLevelInt < stackLevelInt)
  8580. {
  8581. if(ChargingProfileAdded == FALSE)
  8582. {
  8583. fprintf(outfile,"%s\n",payload);
  8584. ChargingProfileAdded = TRUE;
  8585. fprintf(outfile,"%s\n",buf);
  8586. }
  8587. else
  8588. {
  8589. fprintf(outfile,"%s\n",buf);
  8590. }
  8591. }
  8592. else
  8593. {
  8594. if(ChargingProfileAdded == FALSE)
  8595. {
  8596. fprintf(outfile,"%s\n",buf);
  8597. fprintf(outfile,"%s\n",payload);
  8598. ChargingProfileAdded = TRUE;
  8599. }
  8600. else
  8601. {
  8602. fprintf(outfile,"%s\n",buf);
  8603. }
  8604. }
  8605. }
  8606. } // end of while loop
  8607. fclose(infile);
  8608. fclose(outfile);
  8609. sprintf(rmFileCmd,"rm -f %s",filename);
  8610. system(rmFileCmd);
  8611. rename(tempfile, filename);
  8612. #if 0
  8613. resultRename = rename(tempfile, filename);
  8614. if(resultRename == 0)
  8615. {
  8616. DEBUG_INFO("File chargingProfile renamed successfully");
  8617. }
  8618. else
  8619. {
  8620. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8621. }
  8622. #endif
  8623. result = TRUE;
  8624. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8625. }
  8626. end:
  8627. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8628. return result;
  8629. return result;
  8630. }
  8631. int handleTriggerMessageRequest(char *uuid, char *payload)
  8632. {
  8633. mtrace();
  8634. int result = FAIL;
  8635. int connectorIdIsNULL = FALSE;
  8636. int connectorIdInt =0;
  8637. char sstr[40]={0};
  8638. char requestedMessagestr[40]={0};
  8639. char comfirmstr[20]={0};
  8640. int c = 0;
  8641. char *loc;
  8642. DEBUG_INFO("handleTriggerMessageRequest\n");
  8643. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8644. c = 0;
  8645. loc = strstr(payload, "requestedMessage");
  8646. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8647. {
  8648. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8649. c++;
  8650. }
  8651. sstr[c] = '\0';
  8652. strcpy(requestedMessagestr, sstr);
  8653. c = 0;
  8654. loc = strstr(payload, "connectorId");
  8655. if(loc == NULL)
  8656. {
  8657. connectorIdIsNULL = TRUE;
  8658. }
  8659. else
  8660. {
  8661. memset(sstr ,0, sizeof(sstr) );
  8662. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8663. {
  8664. sstr[c] = loc[strlen("connectorId")+2+c];
  8665. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8666. c++;
  8667. }
  8668. sstr[c] = '\0';
  8669. connectorIdInt = atoi(sstr);
  8670. }
  8671. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8672. {
  8673. //connectorIdInt = json_object_get_int(connectorId);
  8674. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8675. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8676. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8677. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8678. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8679. }
  8680. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8681. {
  8682. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8683. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8684. return TRUE;
  8685. }
  8686. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8687. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8688. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8689. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8690. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8691. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8692. {
  8693. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8694. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8695. return TRUE;
  8696. }
  8697. else
  8698. {
  8699. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8700. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8701. }
  8702. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8703. {
  8704. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8705. {
  8706. FirmwareStatusNotificationStatus = 3;
  8707. }
  8708. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8709. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8710. }
  8711. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8712. {
  8713. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8714. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8715. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8716. }
  8717. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8718. {
  8719. sendBootNotificationRequest();
  8720. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8721. }
  8722. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8723. {
  8724. sendHeartbeatRequest(connectorIdInt);
  8725. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8726. }
  8727. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8728. {
  8729. if(connectorIdIsNULL == FALSE)
  8730. {
  8731. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8732. {
  8733. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8734. sendMeterValuesRequest(connectorIdInt -1);
  8735. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8736. }
  8737. }
  8738. else
  8739. {
  8740. for(int idx=0;idx< gunTotalNumber;idx++)
  8741. {
  8742. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8743. sendMeterValuesRequest(idx);
  8744. }
  8745. }
  8746. }
  8747. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8748. {
  8749. if(connectorIdIsNULL == FALSE)
  8750. {
  8751. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8752. {
  8753. sendStatusNotificationRequest(connectorIdInt -1);
  8754. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8755. }
  8756. }
  8757. else
  8758. {
  8759. for(int idx=0;idx< gunTotalNumber;idx++)
  8760. sendStatusNotificationRequest(idx);
  8761. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8762. }
  8763. }
  8764. return result;
  8765. }
  8766. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8767. {
  8768. mtrace();
  8769. int result = FAIL;
  8770. char sstr[6]={0};
  8771. int connectorIdInt =0;
  8772. char comfirmstr[20]={0};
  8773. int c = 0;
  8774. char *loc;
  8775. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8776. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8777. c = 0;
  8778. loc = strstr(payload, "connectorId");
  8779. memset(sstr ,0, sizeof(sstr) );
  8780. while (loc[strlen("connectorId")+2+c] != '}')
  8781. {
  8782. sstr[c] = loc[strlen("connectorId")+2+c];
  8783. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8784. c++;
  8785. }
  8786. sstr[c] = '\0';
  8787. connectorIdInt = atoi(sstr);
  8788. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8789. if(gunTotalNumber == 0)
  8790. {
  8791. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8792. goto end;
  8793. }
  8794. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8795. {
  8796. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8797. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8798. goto end;
  8799. }
  8800. else
  8801. {
  8802. //check Transaction active
  8803. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8804. {
  8805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8806. {
  8807. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8808. {
  8809. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8810. }
  8811. }
  8812. for (int index = 0; index < CCS_QUANTITY; index++)
  8813. {
  8814. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8815. {
  8816. //stop Transaction
  8817. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8818. }
  8819. }
  8820. for (int index = 0; index < GB_QUANTITY; index++)
  8821. {
  8822. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8823. {
  8824. //stop Transaction
  8825. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8826. }
  8827. }
  8828. }
  8829. else
  8830. {
  8831. for (int index = 0; index < AC_QUANTITY; index++)
  8832. {
  8833. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8834. {
  8835. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8836. }
  8837. }
  8838. }// END FOR AC ELSE
  8839. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8840. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8841. result = TRUE;
  8842. return result;
  8843. }
  8844. end:
  8845. //json_object_put(obj); --- remove temporally
  8846. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8847. return result;
  8848. }
  8849. static char UpdateFirmwarepayloadData[300]={0};
  8850. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8851. {
  8852. mtrace();
  8853. int result = FAIL;
  8854. pthread_t t;
  8855. sendUpdateFirmwareConfirmation(uuid);
  8856. memset(UpdateFirmwarepayloadData, 0, 300);
  8857. strcpy(UpdateFirmwarepayloadData, payload);
  8858. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8859. ////pthread_join(t, NULL); //
  8860. //pthread_detach(t);
  8861. //sendUpdateFirmwareConfirmation(uuid);
  8862. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8863. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8864. return result;
  8865. }
  8866. void *UpdateFirmwareProcess(void *data)
  8867. {
  8868. pthread_detach(pthread_self());
  8869. mtrace();
  8870. int retriesInt =0, retryIntervalInt=0;
  8871. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8872. int port=0;
  8873. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8874. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8875. //char comfirmstr[20];
  8876. int isSuccess = 0;
  8877. char ftpbuf[200];
  8878. char temp[100];
  8879. char * pch;
  8880. int retriesISNULL=FALSE;
  8881. int retryInterval=FALSE;
  8882. int c = 0;
  8883. //int i = 0;
  8884. char *loc;
  8885. char sstr[300]={ 0 };
  8886. char str[300]={ 0 };
  8887. //char *str = (char*) data; // ? ?輸入資 ?
  8888. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8889. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8890. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8891. //***************location **************/
  8892. loc = strstr(str, "location");
  8893. memset(sstr ,0, sizeof(sstr) );
  8894. c = 0;
  8895. while (loc[3+strlen("location")+c] != '\"')
  8896. {
  8897. sstr[c] = loc[3+strlen("location")+c];
  8898. c++;
  8899. }
  8900. sstr[c] = '\0';
  8901. strcpy(locationstr, sstr);
  8902. //***************retries**************/
  8903. c = 0;
  8904. loc = strstr(str, "retries");
  8905. if(loc == NULL)
  8906. {
  8907. retriesISNULL=TRUE;
  8908. }
  8909. else
  8910. {
  8911. memset(sstr ,0, sizeof(sstr) );
  8912. while (loc[strlen("retries")+2+c] != ',')
  8913. {
  8914. sstr[c] = loc[strlen("retries")+2+c];
  8915. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8916. c++;
  8917. }
  8918. sstr[c] = '\0';
  8919. }
  8920. if(retriesISNULL == FALSE)
  8921. {
  8922. retriesInt = atoi(sstr);
  8923. }
  8924. //***************retrieveDate **************/
  8925. loc = strstr(str, "retrieveDate");
  8926. memset(sstr ,0, sizeof(sstr) );
  8927. c = 0;
  8928. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8929. {
  8930. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8931. c++;
  8932. }
  8933. sstr[c] = '\0';
  8934. strcpy(retrieveDatestr, sstr);
  8935. //***************retryInterval **************/
  8936. c = 0;
  8937. loc = strstr(str, "retryInterval");
  8938. memset(sstr ,0, sizeof(sstr) );
  8939. if(loc == NULL)
  8940. {
  8941. retryInterval=TRUE;
  8942. }
  8943. else
  8944. {
  8945. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8946. {
  8947. sstr[c] = loc[strlen("retryInterval")+2+c];
  8948. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8949. c++;
  8950. }
  8951. sstr[c] = '\0';
  8952. }
  8953. if(retryInterval==FALSE)
  8954. {
  8955. retryIntervalInt = atoi(sstr);
  8956. }
  8957. memset(ftppath, 0, sizeof(ftppath));
  8958. memset(path, 0, sizeof(path));
  8959. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8960. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8961. if(strncmp(locationstr,"http", 4) == 0)
  8962. {
  8963. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8964. protocol, host, path);
  8965. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8966. // protocol, user, password, host, path);
  8967. sprintf(ftppath,"/%s", path);
  8968. //DEBUG_INFO("protocol =%s\n",protocol);
  8969. //DEBUG_INFO("host =%s\n",host);
  8970. //DEBUG_INFO("path =%s\n",path);
  8971. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8972. int ftppathlen=strlen(ftppath);
  8973. int i=1;
  8974. char filenametemp[50];
  8975. while(i < ftppathlen)
  8976. {
  8977. int len=ftppathlen-i;
  8978. if(ftppath[len]== 47) // '/' ascll code: 47
  8979. {
  8980. DEBUG_INFO("compare '/' all right\n");
  8981. break;
  8982. }
  8983. i=i+1;
  8984. }
  8985. memset(filenametemp, 0, sizeof(filenametemp));
  8986. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8987. filenametemp[i+1] = 0;
  8988. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8989. do{
  8990. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8991. sleep(retryIntervalInt);
  8992. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8993. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8994. if(!isSuccess)
  8995. {
  8996. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8997. }
  8998. else
  8999. {
  9000. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9001. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9002. isUpdateRequest = TRUE;
  9003. }
  9004. }
  9005. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9006. {
  9007. memset(ftpbuf, 0, sizeof(ftpbuf));
  9008. memset(temp, 0, sizeof(temp));
  9009. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9010. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9011. int ftppathlen=strlen(ftpbuf);
  9012. int i=1;
  9013. char filenametemp[50];
  9014. while(i < ftppathlen)
  9015. {
  9016. int len=ftppathlen-i;
  9017. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9018. {
  9019. DEBUG_INFO(" compare '/' all right\n");
  9020. break;
  9021. }
  9022. i=i+1;
  9023. }
  9024. memset(filenametemp, 0, sizeof(filenametemp));
  9025. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9026. filenametemp[i+1] = 0;
  9027. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9028. pch=strchr(temp,'@');
  9029. if(pch==NULL)
  9030. {
  9031. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9032. protocol, host, &port, path);
  9033. strcpy(user,"anonymous");
  9034. strcpy(password,"");
  9035. }
  9036. else
  9037. {
  9038. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9039. protocol, user, password, host, &port, path);
  9040. }
  9041. sscanf(host,"%[^/]%s",host1, path1);
  9042. sprintf(ftppath,"%s", path1);
  9043. //DEBUG_INFO("protocol =%s\n",protocol);
  9044. //DEBUG_INFO("user =%s\n",user);
  9045. //DEBUG_INFO("password =%s\n",password);
  9046. //DEBUG_INFO("host1 =%s\n",host1);
  9047. //DEBUG_INFO("port =%d\n",port);
  9048. //DEBUG_INFO("path1 =%s\n",path1);
  9049. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9050. //ftpFile(host, user, password, port, ftppath, fname);
  9051. //download firmware pthred
  9052. if(port == 0)
  9053. {
  9054. port = 21;
  9055. }
  9056. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9057. do{
  9058. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9059. sleep(retryIntervalInt);
  9060. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9061. if(!isSuccess)
  9062. {
  9063. //BulldogUtil.sleepMs(interval*1000);
  9064. DEBUG_INFO("Update firmware request and download file fail.\n");
  9065. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9066. }
  9067. else
  9068. {
  9069. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9070. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9071. isUpdateRequest = TRUE;
  9072. }
  9073. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9074. }
  9075. else
  9076. {
  9077. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9078. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9079. }
  9080. pthread_exit(NULL);
  9081. }
  9082. //==========================================
  9083. // Handle server response routine
  9084. //==========================================
  9085. void handleAuthorizeResponse(char *payload, int gun_index)
  9086. {
  9087. mtrace();
  9088. char expiryDatestr[30]={0};
  9089. char parentIdTagstr[20]={0};
  9090. char statusstr[20]={0};
  9091. char expiryDatestrtemp[30]={0};
  9092. char parentIdTagstrtemp[20]={0};
  9093. char IdTagstrtemp[20]={0};
  9094. char statusstrtemp[20]={0};
  9095. int expiryDateISNULL=FALSE;
  9096. int parentIdTagISNULL=FALSE;
  9097. char sstr[160]={ 0 };
  9098. char* filename = AuthorizationCache_JSON;
  9099. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9100. int c = 0;
  9101. char *loc;
  9102. int resultRename=0;
  9103. int responseIdTagInfoAsZero= 0;
  9104. char rmFileCmd[50]={0};
  9105. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9106. //***********expiryDate*************/
  9107. loc = strstr(payload, "expiryDate");
  9108. memset(sstr ,0, sizeof(sstr) );
  9109. c = 0;
  9110. if(loc == NULL)
  9111. {
  9112. expiryDateISNULL = TRUE;
  9113. }
  9114. else
  9115. {
  9116. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9117. {
  9118. sstr[c] = loc[3+strlen("expiryDate")+c];
  9119. c++;
  9120. }
  9121. sstr[c] = '\0';
  9122. strcpy(expiryDatestr, sstr);
  9123. }
  9124. //***********parentIdTag*************/
  9125. loc = strstr(payload, "parentIdTag");
  9126. memset(sstr ,0, sizeof(sstr) );
  9127. c = 0;
  9128. if(loc == NULL)
  9129. {
  9130. parentIdTagISNULL = TRUE;
  9131. }
  9132. else
  9133. {
  9134. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9135. {
  9136. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9137. c++;
  9138. }
  9139. sstr[c] = '\0';
  9140. strcpy(parentIdTagstr, sstr);
  9141. }
  9142. //***********status*************/
  9143. loc = strstr(payload, "status");
  9144. memset(sstr ,0, sizeof(sstr) );
  9145. c = 0;
  9146. while (loc[3+strlen("status")+c] != '\"')
  9147. {
  9148. sstr[c] = loc[3+strlen("status")+c];
  9149. c++;
  9150. }
  9151. sstr[c] = '\0';
  9152. strcpy(statusstr, sstr);
  9153. if(expiryDateISNULL == FALSE)
  9154. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9155. if(parentIdTagISNULL == FALSE)
  9156. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9157. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9158. //Update idTag information to authorization cache if supproted
  9159. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9160. {
  9161. if((access(filename,F_OK))!=-1)
  9162. {
  9163. printf("AuthorizationCache exist.\n");
  9164. }
  9165. else
  9166. {
  9167. printf("AuthorizationCache not exist\n");
  9168. FILE *log = fopen(filename, "w+");
  9169. if(log == NULL)
  9170. {
  9171. printf("log is NULL\n");
  9172. goto out;
  9173. }
  9174. else
  9175. {
  9176. fclose(log);
  9177. }
  9178. }
  9179. FILE *infile;
  9180. FILE *outfile;
  9181. // open file for writing
  9182. infile = fopen (filename, "r");
  9183. outfile = fopen (tempfile, "w");
  9184. //*检测到文件结束标识返回1,否则返回0。*/
  9185. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9186. int c;
  9187. c = fgetc(infile);
  9188. //DEBUG_INFO("c:%d\n",c);
  9189. rewind(infile);
  9190. if(c == EOF)
  9191. {
  9192. DEBUG_INFO("Orignal File is NULL\n");
  9193. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9194. {
  9195. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9196. }
  9197. else
  9198. {
  9199. strcpy(expiryDatestrtemp, "");
  9200. }
  9201. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9202. {
  9203. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9204. }
  9205. else
  9206. {
  9207. //write Authorize IdTag
  9208. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9209. }
  9210. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9211. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9212. fclose(infile);
  9213. fclose(outfile);
  9214. sprintf(rmFileCmd,"rm -f %s",filename);
  9215. system(rmFileCmd);
  9216. resultRename = rename(tempfile, filename);
  9217. if(resultRename == 0)
  9218. {
  9219. printf("File renamed successfully");
  9220. }
  9221. else
  9222. {
  9223. printf("Error: unable to rename the file");
  9224. }
  9225. }
  9226. else
  9227. {
  9228. char buf[160]={0};
  9229. while (fgets(buf, sizeof(buf), infile) != NULL)
  9230. {
  9231. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9232. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9233. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9234. memset(statusstr, 0, sizeof(statusstrtemp));
  9235. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9236. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9237. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9238. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9239. //------------------IdTag-----------------------
  9240. loc = strstr(buf, "idTag");
  9241. memset(sstr ,0, sizeof(sstr) );
  9242. c = 0;
  9243. while (loc[3+strlen("idTag")+c] != '\"')
  9244. {
  9245. sstr[c] = loc[3+strlen("idTag")+c];
  9246. c++;
  9247. }
  9248. sstr[c] = '\0';
  9249. strcpy(IdTagstrtemp,sstr);
  9250. //*********************expiryDate***************/
  9251. loc = strstr(buf, "expiryDate");
  9252. memset(sstr ,0, sizeof(sstr) );
  9253. c = 0;
  9254. while (loc[3+strlen("expiryDate")+c] != '\"')
  9255. {
  9256. sstr[c] = loc[3+strlen("expiryDate")+c];
  9257. c++;
  9258. }
  9259. sstr[c] = '\0';
  9260. strcpy(expiryDatestr,sstr);
  9261. //*********************parentIdTag***************/
  9262. loc = strstr(buf, "parentIdTag");
  9263. memset(sstr ,0, sizeof(sstr) );
  9264. c = 0;
  9265. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9266. {
  9267. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9268. c++;
  9269. }
  9270. sstr[c] = '\0';
  9271. strcpy(parentIdTagstr,sstr);
  9272. //*********************status***************/
  9273. loc = strstr(buf, "status");
  9274. memset(sstr ,0, sizeof(sstr) );
  9275. c = 0;
  9276. while (loc[3+strlen("status")+c] != '\"')
  9277. {
  9278. sstr[c] = loc[3+strlen("status")+c];
  9279. c++;
  9280. }
  9281. sstr[c] = '\0';
  9282. strcpy(statusstr,sstr);
  9283. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9284. {
  9285. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9286. responseIdTagInfoAsZero = 1;
  9287. }
  9288. else
  9289. {
  9290. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9291. }
  9292. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9293. {
  9294. //modify item
  9295. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9296. {
  9297. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9298. }
  9299. else
  9300. {
  9301. strcpy(expiryDatestrtemp, "");
  9302. }
  9303. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9304. {
  9305. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9306. }
  9307. else
  9308. {
  9309. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9310. }
  9311. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9312. }
  9313. else
  9314. {
  9315. //wrie original item
  9316. strcpy(expiryDatestrtemp, expiryDatestr);
  9317. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9318. strcpy(statusstrtemp, statusstr);
  9319. }
  9320. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9321. }
  9322. fclose(infile);
  9323. fclose(outfile);
  9324. sprintf(rmFileCmd,"rm -f %s",filename);
  9325. system(rmFileCmd);
  9326. resultRename = rename(tempfile, filename);
  9327. if(resultRename == 0)
  9328. {
  9329. DEBUG_INFO("File renamed successfully");
  9330. }
  9331. else
  9332. {
  9333. DEBUG_INFO("Error: unable to rename the file");
  9334. }
  9335. }
  9336. }
  9337. out:
  9338. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9339. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9340. authorizeRetryTimes = 0;
  9341. }
  9342. void handleBootNotificationResponse(char *payload, int gun_index)
  9343. {
  9344. mtrace();
  9345. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9346. char statusStr[12]={0};
  9347. char currentTimeStr[30]={0};
  9348. char *loc;
  9349. int intervalInt = 0;
  9350. int c = 0;
  9351. //double diff_t;
  9352. struct tm tp;
  9353. char buf[28]={0};
  9354. char timebuf[50]={0};
  9355. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9356. //*** interval ****/
  9357. c = 0;
  9358. loc = strstr(payload, "interval");
  9359. //printf("loc=%s\n",loc);
  9360. memset(sstr ,0, sizeof(sstr) );
  9361. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9362. {
  9363. sstr[c] = loc[strlen("interval")+2+c];
  9364. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9365. c++;
  9366. }
  9367. sstr[c] = '\0';
  9368. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9369. intervalInt = atoi(sstr);
  9370. //***status ****/
  9371. loc = strstr(payload, "status");
  9372. memset(sstr ,0, sizeof(sstr) );
  9373. c = 0;
  9374. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9375. {
  9376. sstr[c] = loc[3+strlen("status")+c];
  9377. c++;
  9378. }
  9379. sstr[c] = '\0';
  9380. strcpy(statusStr, sstr);
  9381. //***currentTime ****/
  9382. loc = strstr(payload, "currentTime");
  9383. //printf("loc=%s\n",loc);
  9384. memset(sstr ,0, sizeof(sstr) );
  9385. c = 0;
  9386. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9387. {
  9388. sstr[c] = loc[3+strlen("currentTime")+c];
  9389. c++;
  9390. }
  9391. sstr[c] = '\0';
  9392. strcpy(currentTimeStr, sstr);
  9393. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9394. HeartBeatWaitTime = BootNotificationInterval;
  9395. clientTime.Heartbeat=time((time_t*)NULL);
  9396. //write back to ShmOCPP16Data->BootNotification
  9397. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9398. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9399. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9400. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9401. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9402. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9403. {
  9404. server_sign = TRUE;
  9405. server_pending =FALSE;
  9406. }
  9407. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9408. {
  9409. server_pending = TRUE;
  9410. }
  9411. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9412. tp.tm_isdst = -1;
  9413. //time_t utc = mktime(&tp);
  9414. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9415. memset(timebuf, 0, sizeof timebuf);
  9416. sprintf(timebuf,"date -s '%s'",buf);
  9417. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9418. system(timebuf);
  9419. //==============================================
  9420. // RTC sync
  9421. //==============================================
  9422. system("/sbin/hwclock -w --systohc");
  9423. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9424. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9425. }
  9426. void handleDataTransferResponse(char *payload, int gun_index)
  9427. {
  9428. char sstr[160]={0};//sstr[200]={ 0 };
  9429. int c = 0;
  9430. char *loc;
  9431. DEBUG_INFO("handleDataTransferResponse ...\n");
  9432. loc = strstr(payload, "status");
  9433. printf("loc=%s\n",loc);
  9434. c = 0;
  9435. while (loc[3+strlen("status")+c] != '\"')
  9436. {
  9437. sstr[c] = loc[3+strlen("status")+c];
  9438. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9439. c++;
  9440. }
  9441. sstr[c] = '\0';
  9442. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9443. }
  9444. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9445. {
  9446. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9447. //struct json_object *obj;
  9448. // obj = json_tokener_parse(payload);
  9449. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9450. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9451. //No fields are defined.
  9452. }
  9453. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9454. {
  9455. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9456. //struct json_object *obj;
  9457. // obj = json_tokener_parse(payload);
  9458. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9459. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9460. //No fields are defined.
  9461. }
  9462. void handleHeartbeatResponse(char *payload, int gun_index)
  9463. {
  9464. mtrace();
  9465. //double diff_t;
  9466. struct tm tp;
  9467. char buf[28]={0};
  9468. char timebuf[50]={0};
  9469. char sstr[30]={ 0 };
  9470. int c = 0;
  9471. char *loc;
  9472. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9473. c = 0;
  9474. loc = strstr(payload, "currentTime");
  9475. memset(sstr ,0, sizeof(sstr) );
  9476. while (loc[3+strlen("currentTime")+c] != '\"')
  9477. {
  9478. sstr[c] = loc[3+strlen("currentTime")+c];
  9479. c++;
  9480. }
  9481. sstr[c] = '\0';
  9482. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9483. // #ifdef SystemLogMessage
  9484. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9485. // #endif
  9486. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9487. tp.tm_isdst = -1;
  9488. //time_t utc = mktime(&tp);
  9489. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9490. memset(timebuf, 0, sizeof timebuf);
  9491. sprintf(timebuf,"date -s '%s'",buf);
  9492. system(timebuf);
  9493. //==============================================
  9494. // RTC sync
  9495. //==============================================
  9496. system("/sbin/hwclock -w --systohc");
  9497. if(FirstHeartBeat == 0)
  9498. {
  9499. FirstHeartBeat = 1;
  9500. }
  9501. HeartBeatWithNOResponse = 0;
  9502. //--------Print Out HeartBeat log
  9503. {
  9504. double diff_t;
  9505. struct tm tp,tp1;
  9506. // BootNotification Receive Time
  9507. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9508. tp.tm_isdst = -1;
  9509. time_t BootNotificationReceiveTime = mktime(&tp);
  9510. //HeartBeat Receive Time
  9511. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9512. tp1.tm_isdst = -1;
  9513. time_t HeartBeatReceiveTime = mktime(&tp1);
  9514. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9515. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9516. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9517. {
  9518. HeartBeatCountPerHour = (int)diff_t / 3600;
  9519. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9520. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9521. }
  9522. }
  9523. }
  9524. void handleMeterValuesResponse(char *payload, int gun_index)
  9525. {
  9526. mtrace();
  9527. //struct json_object *obj;
  9528. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9529. //No fields are defined.
  9530. }
  9531. void handleStartTransactionResponse(char *payload, int gun_index)
  9532. {
  9533. mtrace();
  9534. char sstr[28]={ 0 };
  9535. int c = 0;
  9536. char *loc;
  9537. int transactionIdInt = 0;
  9538. FILE *outfile;
  9539. char data[100]={0};
  9540. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9541. DEBUG_INFO("handleStartTransactionResponse\n");
  9542. //****************expiryDate********************/
  9543. loc = strstr(payload, "expiryDate");
  9544. if(loc == NULL)
  9545. {
  9546. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9547. }
  9548. else
  9549. {
  9550. c = 0;
  9551. memset(sstr ,0, sizeof(sstr) );
  9552. while (loc[3+strlen("expiryDate")+c] != '\"')
  9553. {
  9554. sstr[c] = loc[3+strlen("expiryDate")+c];
  9555. c++;
  9556. }
  9557. sstr[c] = '\0';
  9558. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9559. }
  9560. //****************parentIdTag********************/
  9561. loc = strstr(payload, "parentIdTag");
  9562. if(loc == NULL)
  9563. {
  9564. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9565. }
  9566. else
  9567. {
  9568. c = 0;
  9569. memset(sstr ,0, sizeof(sstr) );
  9570. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9571. {
  9572. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9573. c++;
  9574. }
  9575. sstr[c] = '\0';
  9576. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9577. }
  9578. //****************status********************/
  9579. loc = strstr(payload, "status");
  9580. if(loc == NULL)
  9581. {
  9582. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9583. }
  9584. else
  9585. {
  9586. c = 0;
  9587. memset(sstr ,0, sizeof(sstr) );
  9588. while (loc[3+strlen("status")+c] != '\"')
  9589. {
  9590. sstr[c] = loc[3+strlen("status")+c];
  9591. c++;
  9592. }
  9593. sstr[c] = '\0';
  9594. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9595. }
  9596. //****************transactionId********************/
  9597. c=0;
  9598. loc = strstr(payload, "transactionId");
  9599. memset(sstr ,0, sizeof(sstr) );
  9600. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9601. {
  9602. sstr[c] = loc[strlen("transactionId")+2+c];
  9603. c++;
  9604. }
  9605. sstr[c] = '\0';
  9606. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9607. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9608. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9609. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9610. //-----------Start : write to the Queue TransactionId file -----------------//
  9611. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9612. {
  9613. //DEBUG_INFO("QueueTransactionId exist.\n");
  9614. }
  9615. else
  9616. {
  9617. //DEBUG_INFO("QueueTransactionId not exist\n");
  9618. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9619. if(log == NULL)
  9620. {
  9621. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9622. return ;
  9623. }
  9624. else
  9625. {
  9626. fclose(log);
  9627. }
  9628. }
  9629. // open file for writing
  9630. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9631. //DEBUG_INFO("data=%s\n",data);
  9632. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9633. fputs(data, outfile);
  9634. //fputs("\n", outfile);
  9635. fclose (outfile);
  9636. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9637. TransactionId[gun_index] = transactionIdInt;
  9638. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9639. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9640. #ifdef SystemLogMessage
  9641. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9642. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9643. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9644. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9645. #endif
  9646. }
  9647. void handleStatusNotificationResponse(char *payload, int gun_index)
  9648. {
  9649. mtrace();
  9650. printf("handleStatusNotificationResponse\n");
  9651. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9652. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9653. }
  9654. void handleStopTransactionnResponse(char *payload, int gun_index)
  9655. {
  9656. mtrace();
  9657. char sstr[30]={ 0 };
  9658. int c = 0;
  9659. char *loc;
  9660. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9661. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9662. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9663. loc = strstr(payload, "idTagInfo");
  9664. //***********************idTagInfo************************/
  9665. if(loc != NULL)
  9666. {
  9667. //***********************expiryDate************************/
  9668. loc = strstr(payload, "expiryDate");
  9669. if(loc != NULL)
  9670. {
  9671. memset(sstr ,0, sizeof(sstr) );
  9672. c = 0;
  9673. while (loc[3+strlen("expiryDate")+c] != '\"')
  9674. {
  9675. sstr[c] = loc[3+strlen("expiryDate")+c];
  9676. c++;
  9677. }
  9678. sstr[c] = '\0';
  9679. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9680. }
  9681. //***********************parentIdTag************************/
  9682. loc = strstr(payload, "parentIdTag");
  9683. if(loc != NULL)
  9684. {
  9685. memset(sstr ,0, sizeof(sstr) );
  9686. c = 0;
  9687. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9688. {
  9689. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9690. c++;
  9691. }
  9692. sstr[c] = '\0';
  9693. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9694. }
  9695. //***********************status************************/
  9696. loc = strstr(payload, "status");
  9697. memset(sstr ,0, sizeof(sstr) );
  9698. c = 0;
  9699. while (loc[3+strlen("status")+c] != '\"')
  9700. {
  9701. sstr[c] = loc[3+strlen("status")+c];
  9702. c++;
  9703. }
  9704. sstr[c] = '\0';
  9705. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9706. }
  9707. #ifdef SystemLogMessage
  9708. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9709. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9710. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9711. #endif
  9712. }
  9713. //==========================================
  9714. // Handle Error routine
  9715. //==========================================
  9716. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9717. {
  9718. mtrace();
  9719. #ifdef SystemLogMessage
  9720. DEBUG_INFO("errorCode: %s\n", errorCode);
  9721. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9722. DEBUG_INFO("errorDetails: %s\n", payload);
  9723. #endif
  9724. }
  9725. //===============================================
  9726. // Common routine
  9727. //===============================================
  9728. int initialConfigurationTable(void)
  9729. {
  9730. //clock_t start_t, end_t, total_t;
  9731. FILE *fp;
  9732. FILE *outfile;
  9733. char str[200]={0};
  9734. char sstr[100]={0};
  9735. int c = 0;
  9736. char *loc;
  9737. printf("initialConfigurationTable \n");
  9738. //start_t = clock();
  9739. //printf("Starting of the program, start_t = %ld\n", start_t);
  9740. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9741. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9742. {
  9743. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9744. if(outfile == NULL) {
  9745. DEBUG_INFO("Error opening file");
  9746. return FALSE;
  9747. }
  9748. /*Core Profile*/
  9749. //AllowOfflineTxForUnknownId
  9750. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 0;
  9751. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "true", "FALSE");
  9755. //AuthorizationCacheEnabled
  9756. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9760. //AuthorizeRemoteTxRequests
  9761. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9765. //BlinkRepeat
  9766. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9770. //ClockAlignedDataInterval
  9771. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9775. //ConnectionTimeOut
  9776. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9780. //GetConfigurationMaxKeys
  9781. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9785. // HeartbeatInterval
  9786. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9790. // LightIntensity
  9791. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9795. // LocalAuthorizeOffline
  9796. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9800. // LocalPreAuthorize
  9801. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9805. // MaxEnergyOnInvalidId
  9806. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9809. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9811. // MeterValuesAlignedData
  9812. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  9813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9816. // MeterValuesAlignedDataMaxLength
  9817. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9821. // MeterValuesSampledData
  9822. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  9823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9826. // MeterValuesSampledDataMaxLength
  9827. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9831. // MeterValueSampleInterval
  9832. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9836. // MinimumStatusDuration
  9837. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  9840. server_cycle_Status = 120; //StatusNotification cycle
  9841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  9842. // NumberOfConnectors
  9843. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9845. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9846. {
  9847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9848. }
  9849. else
  9850. {
  9851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9852. }
  9853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9854. // ResetRetries
  9855. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9859. // ConnectorPhaseRotation
  9860. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9864. // ConnectorPhaseRotationMaxLength
  9865. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9869. // StopTransactionOnEVSideDisconnect
  9870. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9874. // StopTransactionOnInvalidId
  9875. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  9876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  9879. // StopTxnAlignedData
  9880. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  9881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  9884. // StopTxnAlignedDataMaxLength
  9885. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9889. // StopTxnSampledData
  9890. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  9891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9894. // StopTxnSampledDataMaxLength
  9895. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9898. {
  9899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9900. }
  9901. else
  9902. {
  9903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9904. }
  9905. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9907. // SupportedFeatureProfiles
  9908. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9912. // SupportedFeatureProfilesMaxLength
  9913. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9917. // TransactionMessageAttempts
  9918. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9921. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9923. // TransactionMessageRetryInterval
  9924. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9927. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9929. // UnlockConnectorOnEVSideDisconnect
  9930. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9934. // WebSocketPingInterval
  9935. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9939. //* Local Auth List Management Profile*/
  9940. #if 0
  9941. //For OCTT Test Case
  9942. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9945. #endif
  9946. #if 1
  9947. //LocalAuthListEnabled
  9948. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9952. #endif
  9953. //LocalAuthListMaxLength
  9954. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9958. //SendLocalListMaxLength
  9959. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9963. //ReserveConnectorZeroSupported
  9964. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9968. //* Smart Charging Profile */
  9969. //ChargeProfileMaxStackLevel
  9970. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9974. // ChargingScheduleAllowedChargingRateUnit
  9975. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9979. // ChargingScheduleMaxPeriods
  9980. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9984. // ConnectorSwitch3to1PhaseSupported
  9985. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9989. // MaxChargingProfilesInstalled
  9990. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9994. fclose(outfile);
  9995. }
  9996. else
  9997. {
  9998. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9999. char keystr[60]={0};
  10000. char readonlystr[10]={0};
  10001. char valuestr[100]={0};
  10002. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10003. if(fp == NULL) {
  10004. DEBUG_INFO("Error opening file");
  10005. return FALSE;
  10006. }
  10007. while( fgets (str, sizeof(str), fp)!=NULL )
  10008. {
  10009. //DEBUG_INFO("Get Configuration \n");
  10010. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10011. //*************************key*********************************/
  10012. loc = strstr(str, "key");
  10013. c = 0;
  10014. memset(sstr ,0, sizeof(sstr) );
  10015. while (loc[strlen("key")+3+c] != '\"')
  10016. {
  10017. sstr[c] = loc[strlen("key")+3+c];
  10018. c++;
  10019. }
  10020. sstr[c] = '\0';
  10021. strcpy(keystr,sstr);
  10022. //*************************readonly*********************************/
  10023. loc = strstr(str, "readonly");
  10024. c = 0;
  10025. memset(sstr ,0, sizeof(sstr) );
  10026. while (loc[strlen("readonly")+2+c] != ',')
  10027. {
  10028. sstr[c] = loc[strlen("readonly")+2+c];
  10029. c++;
  10030. }
  10031. sstr[c] = '\0';
  10032. strcpy(readonlystr,sstr);
  10033. //*************************value*********************************/
  10034. loc = strstr(str, "value");
  10035. c = 0;
  10036. memset(sstr ,0, sizeof(sstr) );
  10037. while (loc[strlen("value")+3+c] != '\"')
  10038. {
  10039. sstr[c] = loc[strlen("value")+3+c];
  10040. c++;
  10041. }
  10042. sstr[c] = '\0';
  10043. strcpy(valuestr,sstr);
  10044. // DEBUG_INFO("keystr=%s\n",keystr);
  10045. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10046. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10047. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10048. {
  10049. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10050. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10052. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10053. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10054. }
  10055. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10056. {
  10057. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10058. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10060. }
  10061. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10062. {
  10063. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10065. }
  10066. if(strcmp(keystr, "BlinkRepeat") == 0)
  10067. {
  10068. //Charger.BlinkRepeat = Integer.parseInt(value);
  10069. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10071. }
  10072. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10073. {
  10074. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10076. }
  10077. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10078. {
  10079. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10081. }
  10082. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10083. {
  10084. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10086. }
  10087. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10088. {
  10089. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10091. HeartBeatWaitTime = atoi(valuestr);
  10092. }
  10093. if(strcmp(keystr, "LightIntensity") == 0)
  10094. {
  10095. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10097. }
  10098. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10099. {
  10100. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10101. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10102. }
  10103. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10104. {
  10105. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10107. }
  10108. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10109. {
  10110. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10112. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10113. }
  10114. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10115. {
  10116. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10118. }
  10119. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10120. {
  10121. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10123. }
  10124. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10125. {
  10126. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10128. }
  10129. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10130. {
  10131. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10133. }
  10134. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10135. {
  10136. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10138. }
  10139. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10140. {
  10141. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10143. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10144. }
  10145. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10146. {
  10147. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10149. }
  10150. if(strcmp(keystr, "ResetRetries") == 0)
  10151. {
  10152. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10154. }
  10155. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10156. {
  10157. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10159. }
  10160. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10161. {
  10162. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10164. }
  10165. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10166. {
  10167. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10169. }
  10170. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10171. {
  10172. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10174. }
  10175. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10176. {
  10177. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10179. }
  10180. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10181. {
  10182. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10184. }
  10185. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10186. {
  10187. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10189. }
  10190. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10191. {
  10192. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10194. }
  10195. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10196. {
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10199. }
  10200. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10201. {
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10204. }
  10205. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10206. {
  10207. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10209. TransactionMessageAttemptsValue = atoi(valuestr);
  10210. }
  10211. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10212. {
  10213. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10215. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10216. }
  10217. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10218. {
  10219. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10221. }
  10222. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10223. {
  10224. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10226. }
  10227. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10228. {
  10229. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10231. }
  10232. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10233. {
  10234. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10236. }
  10237. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10238. {
  10239. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10241. }
  10242. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10243. {
  10244. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10246. }
  10247. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10248. {
  10249. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10251. }
  10252. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10253. {
  10254. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10256. }
  10257. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10258. {
  10259. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10261. }
  10262. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10263. {
  10264. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10266. }
  10267. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10268. {
  10269. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10271. }
  10272. }
  10273. fclose(fp);
  10274. }
  10275. //end_t = clock();
  10276. //printf("End of the big loop, end_t = %ld\n", end_t);
  10277. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  10278. //printf("Total time taken by CPU: %f\n", total_t );
  10279. return 0;
  10280. }
  10281. void StoreConfigurationTable(void)
  10282. {
  10283. FILE *outfile;
  10284. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10285. if(outfile == NULL)
  10286. {
  10287. DEBUG_INFO("Error opening file");
  10288. return ;
  10289. }
  10290. /*Core Profile*/
  10291. //AllowOfflineTxForUnknownId
  10292. /*
  10293. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10294. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10297. */
  10298. //DEBUG_INFO("data=%s\n",data);
  10299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10300. //AuthorizationCacheEnabled
  10301. /*
  10302. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10305. */
  10306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10307. //AuthorizeRemoteTxRequests
  10308. /*
  10309. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10312. */
  10313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10314. //BlinkRepeat
  10315. /*
  10316. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10319. */
  10320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10321. //ClockAlignedDataInterval
  10322. /*
  10323. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10326. */
  10327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10328. //ConnectionTimeOut
  10329. /*
  10330. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10333. */
  10334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10335. //GetConfigurationMaxKeys
  10336. /*
  10337. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10340. */
  10341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10342. // HeartbeatInterval
  10343. /*
  10344. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10347. */
  10348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10349. // LightIntensity
  10350. /*
  10351. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10354. */
  10355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10356. // LocalAuthorizeOffline
  10357. /*
  10358. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10361. */
  10362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10363. // LocalPreAuthorize
  10364. /*
  10365. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10368. */
  10369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10370. // MaxEnergyOnInvalidId
  10371. /*
  10372. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10375. */
  10376. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10378. // MeterValuesAlignedData
  10379. /*
  10380. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10383. */
  10384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10385. // MeterValuesAlignedDataMaxLength
  10386. /*
  10387. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10390. */
  10391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10392. // MeterValuesSampledData
  10393. /*
  10394. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10397. */
  10398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10399. // MeterValuesSampledDataMaxLength
  10400. /*
  10401. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10404. */
  10405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10406. // MeterValueSampleInterval
  10407. /*
  10408. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10411. */
  10412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10413. // MinimumStatusDuration
  10414. /*
  10415. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10418. */
  10419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10420. // NumberOfConnectors
  10421. /*
  10422. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10425. {
  10426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10427. }
  10428. else
  10429. {
  10430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10431. }
  10432. */
  10433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10434. // ResetRetries
  10435. /*
  10436. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10439. */
  10440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10441. // ConnectorPhaseRotation
  10442. /*
  10443. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10446. */
  10447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10448. // ConnectorPhaseRotationMaxLength
  10449. /*
  10450. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10453. */
  10454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10455. // StopTransactionOnEVSideDisconnect
  10456. /*
  10457. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10460. */
  10461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10462. // StopTransactionOnInvalidId
  10463. /*
  10464. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10467. */
  10468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10469. // StopTxnAlignedData
  10470. /*
  10471. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10474. */
  10475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10476. // StopTxnAlignedDataMaxLength
  10477. /*
  10478. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10481. */
  10482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10483. // StopTxnSampledData
  10484. /*
  10485. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10488. */
  10489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10490. // StopTxnSampledDataMaxLength
  10491. /*
  10492. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10495. */
  10496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10497. // SupportedFeatureProfiles
  10498. /*
  10499. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10502. */
  10503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10504. // SupportedFeatureProfilesMaxLength
  10505. /*
  10506. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10509. */
  10510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10511. // TransactionMessageAttempts
  10512. /*
  10513. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10516. */
  10517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10518. // TransactionMessageRetryInterval
  10519. /*
  10520. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10523. */
  10524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10525. // UnlockConnectorOnEVSideDisconnect
  10526. /*
  10527. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10530. */
  10531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10532. // WebSocketPingInterval
  10533. /*
  10534. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10537. */
  10538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10539. //* Local Auth List Management Profile*/
  10540. //LocalAuthListEnabled
  10541. /*
  10542. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10545. */
  10546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10547. //LocalAuthListMaxLength
  10548. /*
  10549. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10552. */
  10553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10554. //SendLocalListMaxLength
  10555. /*
  10556. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10559. */
  10560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10561. //ReserveConnectorZeroSupported
  10562. /*
  10563. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10566. */
  10567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10568. //* Smart Charging Profile */
  10569. //ChargeProfileMaxStackLevel
  10570. /*
  10571. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10574. */
  10575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10576. // ChargingScheduleAllowedChargingRateUnit
  10577. /*
  10578. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10581. */
  10582. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10583. // ChargingScheduleMaxPeriods
  10584. /*
  10585. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10588. */
  10589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10590. // ConnectorSwitch3to1PhaseSupported
  10591. /*
  10592. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10595. */
  10596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10597. // MaxChargingProfilesInstalled
  10598. /*
  10599. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10602. */
  10603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10604. fclose(outfile);
  10605. }
  10606. void getKeyValue(char *keyReq)
  10607. {
  10608. int isEmpty = FALSE;
  10609. int isKnowKey = FALSE;
  10610. //int unKnowIndex = 0;
  10611. DEBUG_INFO("getKeyValue \n");
  10612. DEBUG_INFO("keyReq=%s \n",keyReq);
  10613. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10614. isEmpty = TRUE;
  10615. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10616. {
  10617. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10619. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10620. {
  10621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10622. }
  10623. else
  10624. {
  10625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10626. }
  10627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10628. isKnowKey = TRUE;
  10629. }
  10630. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10631. {
  10632. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10634. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10635. {
  10636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10637. }
  10638. else
  10639. {
  10640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10641. }
  10642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10643. isKnowKey = TRUE;
  10644. }
  10645. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10646. {
  10647. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10649. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10650. {
  10651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10652. }
  10653. else
  10654. {
  10655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10656. }
  10657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10658. isKnowKey = TRUE;
  10659. }
  10660. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10661. {
  10662. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10664. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10665. {
  10666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10667. }
  10668. else
  10669. {
  10670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10671. }
  10672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10673. isKnowKey = TRUE;
  10674. }
  10675. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10676. {
  10677. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10680. {
  10681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10682. }
  10683. else
  10684. {
  10685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10686. }
  10687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10688. isKnowKey = TRUE;
  10689. }
  10690. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10691. {
  10692. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10694. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10695. {
  10696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10697. }
  10698. else
  10699. {
  10700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10701. }
  10702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10703. isKnowKey = TRUE;
  10704. }
  10705. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10706. {
  10707. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10709. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10710. {
  10711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10712. }
  10713. else
  10714. {
  10715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10716. }
  10717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10718. isKnowKey = TRUE;
  10719. }
  10720. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10721. {
  10722. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10725. {
  10726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10727. }
  10728. else
  10729. {
  10730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10731. }
  10732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10733. isKnowKey = TRUE;
  10734. }
  10735. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10736. {
  10737. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10740. {
  10741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10742. }
  10743. else
  10744. {
  10745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10746. }
  10747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10748. isKnowKey = TRUE;
  10749. }
  10750. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10751. {
  10752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10755. {
  10756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10757. }
  10758. else
  10759. {
  10760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10761. }
  10762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10763. isKnowKey = TRUE;
  10764. }
  10765. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10766. {
  10767. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10770. {
  10771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10772. }
  10773. else
  10774. {
  10775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10776. }
  10777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10778. isKnowKey = TRUE;
  10779. }
  10780. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10781. {
  10782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10785. {
  10786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10787. }
  10788. else
  10789. {
  10790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10791. }
  10792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10793. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10794. isKnowKey = TRUE;
  10795. }
  10796. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10797. {
  10798. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10801. {
  10802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10803. }
  10804. else
  10805. {
  10806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10807. }
  10808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10809. isKnowKey = TRUE;
  10810. }
  10811. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10812. {
  10813. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10816. {
  10817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10818. }
  10819. else
  10820. {
  10821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10822. }
  10823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10824. isKnowKey = TRUE;
  10825. }
  10826. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10827. {
  10828. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10830. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10831. {
  10832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10833. }
  10834. else
  10835. {
  10836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10837. }
  10838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10839. isKnowKey = TRUE;
  10840. }
  10841. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10842. {
  10843. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10846. {
  10847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10848. }
  10849. else
  10850. {
  10851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10852. }
  10853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10854. isKnowKey = TRUE;
  10855. }
  10856. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10857. {
  10858. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10861. {
  10862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10863. }
  10864. else
  10865. {
  10866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10867. }
  10868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10869. isKnowKey = TRUE;
  10870. }
  10871. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10872. {
  10873. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10875. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10876. {
  10877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10878. }
  10879. else
  10880. {
  10881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10882. }
  10883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10884. isKnowKey = TRUE;
  10885. }
  10886. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10887. {
  10888. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10890. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10891. {
  10892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10893. }
  10894. else
  10895. {
  10896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10897. }
  10898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10899. isKnowKey = TRUE;
  10900. }
  10901. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10902. {
  10903. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10906. {
  10907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10908. }
  10909. else
  10910. {
  10911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10912. }
  10913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10914. isKnowKey = TRUE;
  10915. }
  10916. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10917. {
  10918. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10921. {
  10922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10923. }
  10924. else
  10925. {
  10926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10927. }
  10928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10929. isKnowKey = TRUE;
  10930. }
  10931. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10932. {
  10933. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10936. {
  10937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10938. }
  10939. else
  10940. {
  10941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10942. }
  10943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10944. isKnowKey = TRUE;
  10945. }
  10946. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10947. {
  10948. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10951. {
  10952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10953. }
  10954. else
  10955. {
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10957. }
  10958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10959. isKnowKey = TRUE;
  10960. }
  10961. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10962. {
  10963. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10966. {
  10967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10968. }
  10969. else
  10970. {
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10972. }
  10973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10974. isKnowKey = TRUE;
  10975. }
  10976. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10977. {
  10978. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10981. {
  10982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10983. }
  10984. else
  10985. {
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10987. }
  10988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10989. isKnowKey = TRUE;
  10990. }
  10991. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10992. {
  10993. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10996. {
  10997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10998. }
  10999. else
  11000. {
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11002. }
  11003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11004. isKnowKey = TRUE;
  11005. }
  11006. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11007. {
  11008. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11011. {
  11012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11013. }
  11014. else
  11015. {
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11017. }
  11018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11019. isKnowKey = TRUE;
  11020. }
  11021. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11022. {
  11023. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11026. {
  11027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11028. }
  11029. else
  11030. {
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11032. }
  11033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11034. isKnowKey = TRUE;
  11035. }
  11036. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11037. {
  11038. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11041. {
  11042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11043. }
  11044. else
  11045. {
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11047. }
  11048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11049. isKnowKey = TRUE;
  11050. }
  11051. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11052. {
  11053. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11056. {
  11057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11058. }
  11059. else
  11060. {
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11062. }
  11063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11064. isKnowKey = TRUE;
  11065. }
  11066. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11067. {
  11068. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11071. {
  11072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11073. }
  11074. else
  11075. {
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11077. }
  11078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11079. isKnowKey = TRUE;
  11080. }
  11081. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11082. {
  11083. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11086. {
  11087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11088. }
  11089. else
  11090. {
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11092. }
  11093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11094. isKnowKey = TRUE;
  11095. }
  11096. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11097. {
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11101. {
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11103. }
  11104. else
  11105. {
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11107. }
  11108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11109. isKnowKey = TRUE;
  11110. }
  11111. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11112. {
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11116. {
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11118. }
  11119. else
  11120. {
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11122. }
  11123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11124. isKnowKey = TRUE;
  11125. }
  11126. #if 0
  11127. //For OCTT Test Case
  11128. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11129. {
  11130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11132. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11133. {
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11135. }
  11136. else
  11137. {
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11139. }
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11141. isKnowKey = TRUE;
  11142. }
  11143. #endif
  11144. #if 1
  11145. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11146. {
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11149. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11150. {
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11152. }
  11153. else
  11154. {
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11156. }
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11158. isKnowKey = TRUE;
  11159. }
  11160. #endif
  11161. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11162. {
  11163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11165. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11166. {
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11168. }
  11169. else
  11170. {
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11172. }
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11174. isKnowKey = TRUE;
  11175. }
  11176. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11177. {
  11178. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11180. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11181. {
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11183. }
  11184. else
  11185. {
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11187. }
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11189. isKnowKey = TRUE;
  11190. }
  11191. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11192. {
  11193. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11195. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11196. {
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11198. }
  11199. else
  11200. {
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11202. }
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11204. isKnowKey = TRUE;
  11205. }
  11206. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11207. {
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11210. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11211. {
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11213. }
  11214. else
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11217. }
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11219. isKnowKey = TRUE;
  11220. }
  11221. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11222. {
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11225. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11226. {
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11228. }
  11229. else
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11232. }
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11234. isKnowKey = TRUE;
  11235. }
  11236. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11237. {
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11240. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11241. {
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11243. }
  11244. else
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11247. }
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11249. isKnowKey = TRUE;
  11250. }
  11251. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11252. {
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11255. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11256. {
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11258. }
  11259. else
  11260. {
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11262. }
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11264. isKnowKey = TRUE;
  11265. }
  11266. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11267. {
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11270. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11271. {
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11273. }
  11274. else
  11275. {
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11277. }
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11279. isKnowKey = TRUE;
  11280. }
  11281. //=========================================================
  11282. if(!isEmpty && !isKnowKey)
  11283. {
  11284. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11285. strcpy(unknownkey[UnknownKeynum], keyReq);
  11286. UnknownKeynum = UnknownKeynum + 1;
  11287. }
  11288. }
  11289. void processUnkownKey(void)
  11290. {
  11291. DEBUG_INFO("processUnkownKey\n");
  11292. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11293. for(int index=0; index < UnknownKeynum; index++)
  11294. {
  11295. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11296. {
  11297. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11298. }
  11299. }
  11300. }
  11301. int setKeyValue(char *key, char *value)
  11302. {
  11303. int isSuccess = NotSupported;
  11304. int check_ascii=0;
  11305. char str[10]={0};
  11306. #ifdef Debug
  11307. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11308. #endif
  11309. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11310. {
  11311. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11313. {
  11314. strcpy(str, (const char*)value);
  11315. for(int i = 0; str[i]; i++){
  11316. str[i] = tolower(str[i]);
  11317. }
  11318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11319. isSuccess = ConfigurationStatus_Accepted;
  11320. }
  11321. else
  11322. {
  11323. isSuccess = ConfigurationStatus_Rejected;
  11324. }
  11325. }
  11326. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11327. {
  11328. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11330. {
  11331. strcpy(str, (const char*)value);
  11332. for(int i = 0; str[i]; i++){
  11333. str[i] = tolower(str[i]);
  11334. }
  11335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11336. isSuccess = ConfigurationStatus_Accepted;
  11337. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11338. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11339. }
  11340. else
  11341. {
  11342. isSuccess = ConfigurationStatus_Rejected;
  11343. }
  11344. }
  11345. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11346. {
  11347. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11348. {
  11349. strcpy(str, (const char*)value);
  11350. for(int i = 0; str[i]; i++)
  11351. {
  11352. str[i] = tolower(str[i]);
  11353. }
  11354. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11356. isSuccess = ConfigurationStatus_Accepted;
  11357. }
  11358. else
  11359. {
  11360. isSuccess = ConfigurationStatus_Rejected;
  11361. }
  11362. }
  11363. if(strcmp(key, "BlinkRepeat") == 0)
  11364. {
  11365. //Charger.BlinkRepeat = Integer.parseInt(value);
  11366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11367. {
  11368. check_ascii = value[0];
  11369. if( (check_ascii < 48) || (check_ascii > 57) )
  11370. {
  11371. isSuccess = ConfigurationStatus_Rejected;
  11372. }
  11373. else
  11374. {
  11375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11376. isSuccess = ConfigurationStatus_Accepted;
  11377. }
  11378. }
  11379. else
  11380. {
  11381. isSuccess = ConfigurationStatus_Rejected;
  11382. }
  11383. }
  11384. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11385. {
  11386. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11387. {
  11388. check_ascii = value[0];
  11389. if( (check_ascii < 48) || (check_ascii > 57) )
  11390. {
  11391. isSuccess = ConfigurationStatus_Rejected;
  11392. }
  11393. else
  11394. {
  11395. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11397. isSuccess = ConfigurationStatus_Accepted;
  11398. }
  11399. }
  11400. else
  11401. {
  11402. isSuccess = ConfigurationStatus_Rejected;
  11403. }
  11404. }
  11405. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11406. {
  11407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11408. {
  11409. check_ascii = value[0];
  11410. if( (check_ascii < 48) || (check_ascii > 57) )
  11411. {
  11412. isSuccess = ConfigurationStatus_Rejected;
  11413. }
  11414. else
  11415. {
  11416. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11418. isSuccess = ConfigurationStatus_Accepted;
  11419. }
  11420. }
  11421. else
  11422. {
  11423. isSuccess = ConfigurationStatus_Rejected;
  11424. }
  11425. }
  11426. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11427. {
  11428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11429. {
  11430. check_ascii = value[0];
  11431. if( (check_ascii < 48) || (check_ascii > 57) )
  11432. {
  11433. isSuccess = ConfigurationStatus_Rejected;
  11434. }
  11435. else
  11436. {
  11437. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11439. isSuccess = ConfigurationStatus_Accepted;
  11440. }
  11441. }
  11442. else
  11443. {
  11444. isSuccess = ConfigurationStatus_Rejected;
  11445. }
  11446. }
  11447. if(strcmp(key, "HeartbeatInterval") == 0)
  11448. {
  11449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11450. {
  11451. check_ascii = value[0];
  11452. if( (check_ascii < 48) || (check_ascii > 57) )
  11453. {
  11454. isSuccess = ConfigurationStatus_Rejected;
  11455. }
  11456. else
  11457. {
  11458. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11460. HeartBeatWaitTime = atoi(value);
  11461. isSuccess = ConfigurationStatus_Accepted;
  11462. }
  11463. }
  11464. else
  11465. {
  11466. isSuccess = ConfigurationStatus_Rejected;
  11467. }
  11468. }
  11469. if(strcmp(key, "LightIntensity") == 0)
  11470. {
  11471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11472. {
  11473. check_ascii = value[0];
  11474. if( (check_ascii < 48) || (check_ascii > 57) )
  11475. {
  11476. isSuccess = ConfigurationStatus_Rejected;
  11477. }
  11478. else
  11479. {
  11480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11481. isSuccess = ConfigurationStatus_Accepted;
  11482. }
  11483. }
  11484. else
  11485. {
  11486. isSuccess = ConfigurationStatus_Rejected;
  11487. }
  11488. }
  11489. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11490. {
  11491. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11492. {
  11493. strcpy(str, (const char*)value);
  11494. for(int i = 0; str[i]; i++)
  11495. {
  11496. str[i] = tolower(str[i]);
  11497. }
  11498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11499. isSuccess = ConfigurationStatus_Accepted;
  11500. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11501. }
  11502. else
  11503. {
  11504. isSuccess = ConfigurationStatus_Rejected;
  11505. }
  11506. }
  11507. if(strcmp(key, "LocalPreAuthorize") == 0)
  11508. {
  11509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11510. {
  11511. strcpy(str, (const char*)value);
  11512. for(int i = 0; str[i]; i++)
  11513. {
  11514. str[i] = tolower(str[i]);
  11515. }
  11516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11517. isSuccess = ConfigurationStatus_Accepted;
  11518. }
  11519. else
  11520. {
  11521. isSuccess = ConfigurationStatus_Rejected;
  11522. }
  11523. }
  11524. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11525. {
  11526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11527. {
  11528. check_ascii = value[0];
  11529. if( (check_ascii < 48) || (check_ascii > 57) )
  11530. {
  11531. isSuccess = ConfigurationStatus_Rejected;
  11532. }
  11533. else
  11534. {
  11535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11536. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11537. isSuccess = ConfigurationStatus_Accepted;
  11538. }
  11539. }
  11540. else
  11541. {
  11542. isSuccess = ConfigurationStatus_Rejected;
  11543. }
  11544. }
  11545. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11546. {
  11547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11548. {
  11549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11550. isSuccess = ConfigurationStatus_Accepted;
  11551. }
  11552. else
  11553. {
  11554. isSuccess = ConfigurationStatus_Rejected;
  11555. }
  11556. }
  11557. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11558. {
  11559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11560. {
  11561. check_ascii = value[0];
  11562. if( (check_ascii < 48) || (check_ascii > 57) )
  11563. {
  11564. isSuccess = ConfigurationStatus_Rejected;
  11565. }
  11566. else
  11567. {
  11568. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11570. isSuccess = ConfigurationStatus_Accepted;
  11571. }
  11572. }
  11573. else
  11574. {
  11575. isSuccess = ConfigurationStatus_Rejected;
  11576. }
  11577. }
  11578. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11579. {
  11580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11581. {
  11582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11583. isSuccess = ConfigurationStatus_Accepted;
  11584. }
  11585. else
  11586. {
  11587. isSuccess = ConfigurationStatus_Rejected;
  11588. }
  11589. }
  11590. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11591. {
  11592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11593. {
  11594. check_ascii = value[0];
  11595. if( (check_ascii < 48) || (check_ascii > 57) )
  11596. {
  11597. isSuccess = ConfigurationStatus_Rejected;
  11598. }
  11599. else
  11600. {
  11601. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11603. isSuccess = ConfigurationStatus_Accepted;
  11604. }
  11605. }
  11606. else
  11607. {
  11608. isSuccess = ConfigurationStatus_Rejected;
  11609. }
  11610. }
  11611. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11612. {
  11613. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11614. {
  11615. check_ascii = value[0];
  11616. if( (check_ascii < 48) || (check_ascii > 57) )
  11617. {
  11618. isSuccess = ConfigurationStatus_Rejected;
  11619. }
  11620. else
  11621. {
  11622. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11624. isSuccess = ConfigurationStatus_Accepted;
  11625. }
  11626. }
  11627. else
  11628. {
  11629. isSuccess = ConfigurationStatus_Rejected;
  11630. }
  11631. }
  11632. if(strcmp(key, "MinimumStatusDuration") == 0)
  11633. {
  11634. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11635. {
  11636. check_ascii = value[0];
  11637. if( (check_ascii < 48) || (check_ascii > 57) )
  11638. {
  11639. isSuccess = ConfigurationStatus_Rejected;
  11640. }
  11641. else
  11642. {
  11643. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11644. {
  11645. isSuccess = ConfigurationStatus_Rejected;
  11646. }
  11647. else
  11648. {
  11649. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11651. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11652. isSuccess = ConfigurationStatus_Accepted;
  11653. }
  11654. }
  11655. }
  11656. else
  11657. {
  11658. isSuccess = ConfigurationStatus_Rejected;
  11659. }
  11660. }
  11661. if(strcmp(key, "NumberOfConnectors") == 0)
  11662. {
  11663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11664. {
  11665. check_ascii = value[0];
  11666. if( (check_ascii < 48) || (check_ascii > 57) )
  11667. {
  11668. isSuccess = ConfigurationStatus_Rejected;
  11669. }
  11670. else
  11671. {
  11672. //Charger.ResetRetries = Integer.parseInt(value);
  11673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11674. isSuccess = ConfigurationStatus_Accepted;
  11675. }
  11676. }
  11677. else
  11678. {
  11679. isSuccess = ConfigurationStatus_Rejected;
  11680. }
  11681. }
  11682. if(strcmp(key, "ResetRetries") == 0)
  11683. {
  11684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11685. {
  11686. check_ascii = value[0];
  11687. if( (check_ascii < 48) || (check_ascii > 57) )
  11688. {
  11689. isSuccess = ConfigurationStatus_Rejected;
  11690. }
  11691. else
  11692. {
  11693. //Charger.ResetRetries = Integer.parseInt(value);
  11694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11695. isSuccess = ConfigurationStatus_Accepted;
  11696. }
  11697. }
  11698. else
  11699. {
  11700. isSuccess = ConfigurationStatus_Rejected;
  11701. }
  11702. }
  11703. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11704. {
  11705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11706. {
  11707. strcpy(str, (const char*)value);
  11708. for(int i = 0; str[i]; i++)
  11709. {
  11710. str[i] = tolower(str[i]);
  11711. }
  11712. if(strcmp(str, "notapplicable")== 0)
  11713. {
  11714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  11715. isSuccess = ConfigurationStatus_Accepted;
  11716. }
  11717. else if(strcmp(str, "unknown")== 0)
  11718. {
  11719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  11720. isSuccess = ConfigurationStatus_Accepted;
  11721. }
  11722. else if(strcmp(str, "rst")== 0)
  11723. {
  11724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  11725. isSuccess = ConfigurationStatus_Accepted;
  11726. }
  11727. else if(strcmp(str, "rts")== 0)
  11728. {
  11729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  11730. isSuccess = ConfigurationStatus_Accepted;
  11731. }
  11732. else if(strcmp(str, "srt")== 0)
  11733. {
  11734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  11735. isSuccess = ConfigurationStatus_Accepted;
  11736. }
  11737. else if(strcmp(str, "str")== 0)
  11738. {
  11739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  11740. isSuccess = ConfigurationStatus_Accepted;
  11741. }
  11742. else if(strcmp(str, "trs")== 0)
  11743. {
  11744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  11745. isSuccess = ConfigurationStatus_Accepted;
  11746. }
  11747. else if(strcmp(str, "tsr")== 0)
  11748. {
  11749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  11750. isSuccess = ConfigurationStatus_Accepted;
  11751. }
  11752. else
  11753. {
  11754. isSuccess = ConfigurationStatus_Rejected;
  11755. }
  11756. }
  11757. else
  11758. {
  11759. isSuccess = ConfigurationStatus_Rejected;
  11760. }
  11761. }
  11762. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11763. {
  11764. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11765. {
  11766. check_ascii = value[0];
  11767. if( (check_ascii < 48) || (check_ascii > 57) )
  11768. {
  11769. isSuccess = ConfigurationStatus_Rejected;
  11770. }
  11771. else
  11772. {
  11773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11774. isSuccess = ConfigurationStatus_Accepted;
  11775. }
  11776. }
  11777. else
  11778. {
  11779. isSuccess = ConfigurationStatus_Rejected;
  11780. }
  11781. }
  11782. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11783. {
  11784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11785. {
  11786. strcpy(str, (const char*)value);
  11787. for(int i = 0; str[i]; i++)
  11788. {
  11789. str[i] = tolower(str[i]);
  11790. }
  11791. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11792. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11793. isSuccess = ConfigurationStatus_Accepted;
  11794. }
  11795. else
  11796. {
  11797. isSuccess = ConfigurationStatus_Rejected;
  11798. }
  11799. }
  11800. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11801. {
  11802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11803. {
  11804. strcpy(str, (const char*)value);
  11805. for(int i = 0; str[i]; i++)
  11806. {
  11807. str[i] = tolower(str[i]);
  11808. }
  11809. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11811. isSuccess = ConfigurationStatus_Accepted;
  11812. }
  11813. else
  11814. {
  11815. isSuccess = ConfigurationStatus_Rejected;
  11816. }
  11817. }
  11818. if(strcmp(key, "StopTxnAlignedData") == 0)
  11819. {
  11820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11821. {
  11822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11823. isSuccess = ConfigurationStatus_Accepted;
  11824. }
  11825. else
  11826. {
  11827. isSuccess = ConfigurationStatus_Rejected;
  11828. }
  11829. }
  11830. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11831. {
  11832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11833. {
  11834. check_ascii = value[0];
  11835. if( (check_ascii < 48) || (check_ascii > 57) )
  11836. {
  11837. isSuccess = ConfigurationStatus_Rejected;
  11838. }
  11839. else
  11840. {
  11841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11842. isSuccess = ConfigurationStatus_Accepted;
  11843. }
  11844. }
  11845. else
  11846. {
  11847. isSuccess = ConfigurationStatus_Rejected;
  11848. }
  11849. }
  11850. if(strcmp(key, "StopTxnSampledData") == 0)
  11851. {
  11852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11853. {
  11854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11855. isSuccess = ConfigurationStatus_Accepted;
  11856. }
  11857. else
  11858. {
  11859. isSuccess = ConfigurationStatus_Rejected;
  11860. }
  11861. }
  11862. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11863. {
  11864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11865. {
  11866. check_ascii = value[0];
  11867. if( (check_ascii < 48) || (check_ascii > 57) )
  11868. {
  11869. isSuccess = ConfigurationStatus_Rejected;
  11870. }
  11871. else
  11872. {
  11873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11874. isSuccess = ConfigurationStatus_Accepted;
  11875. }
  11876. }
  11877. else
  11878. {
  11879. isSuccess = ConfigurationStatus_Rejected;
  11880. }
  11881. }
  11882. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11883. {
  11884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11885. {
  11886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11887. isSuccess = ConfigurationStatus_Accepted;
  11888. }
  11889. else
  11890. {
  11891. isSuccess = ConfigurationStatus_Rejected;
  11892. }
  11893. }
  11894. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11895. {
  11896. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11897. {
  11898. check_ascii = value[0];
  11899. if( (check_ascii < 48) || (check_ascii > 57) )
  11900. {
  11901. isSuccess = ConfigurationStatus_Rejected;
  11902. }
  11903. else
  11904. {
  11905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11906. isSuccess = ConfigurationStatus_Accepted;
  11907. }
  11908. }
  11909. else
  11910. {
  11911. isSuccess = ConfigurationStatus_Rejected;
  11912. }
  11913. }
  11914. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11915. {
  11916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11917. {
  11918. check_ascii = value[0];
  11919. if( (check_ascii < 48) || (check_ascii > 57) )
  11920. {
  11921. isSuccess = ConfigurationStatus_Rejected;
  11922. }
  11923. else
  11924. {
  11925. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11927. TransactionMessageAttemptsValue = atoi(value);
  11928. isSuccess = ConfigurationStatus_Accepted;
  11929. }
  11930. }
  11931. else
  11932. {
  11933. isSuccess = ConfigurationStatus_Rejected;
  11934. }
  11935. }
  11936. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11937. {
  11938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11939. {
  11940. check_ascii = value[0];
  11941. if( (check_ascii < 48) || (check_ascii > 57) )
  11942. {
  11943. isSuccess = ConfigurationStatus_Rejected;
  11944. }
  11945. else
  11946. {
  11947. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11949. TransactionMessageRetryIntervalValue = atoi(value);
  11950. isSuccess = ConfigurationStatus_Accepted;
  11951. }
  11952. }
  11953. else
  11954. {
  11955. isSuccess = ConfigurationStatus_Rejected;
  11956. }
  11957. }
  11958. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11959. {
  11960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11961. {
  11962. strcpy(str, (const char*)value);
  11963. for(int i = 0; str[i]; i++)
  11964. {
  11965. str[i] = tolower(str[i]);
  11966. }
  11967. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11969. isSuccess = ConfigurationStatus_Accepted;
  11970. }
  11971. else
  11972. {
  11973. isSuccess = ConfigurationStatus_Rejected;
  11974. }
  11975. }
  11976. if(strcmp(key, "WebSocketPingInterval") == 0)
  11977. {
  11978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11979. {
  11980. check_ascii = value[0];
  11981. if( (check_ascii < 48) || (check_ascii > 57) )
  11982. {
  11983. isSuccess = ConfigurationStatus_Rejected;
  11984. }
  11985. else
  11986. {
  11987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11988. isSuccess = ConfigurationStatus_Accepted;
  11989. }
  11990. }
  11991. else
  11992. {
  11993. isSuccess = ConfigurationStatus_Rejected;
  11994. }
  11995. }
  11996. #if 0
  11997. //For OCPP Test Case
  11998. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11999. {
  12000. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12001. {
  12002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12003. isSuccess = ConfigurationStatus_Accepted;
  12004. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12005. }
  12006. else
  12007. {
  12008. isSuccess = ConfigurationStatus_Rejected;
  12009. }
  12010. }
  12011. #endif
  12012. #if 1
  12013. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12014. {
  12015. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12016. {
  12017. strcpy(str, (const char*)value);
  12018. for(int i = 0; str[i]; i++)
  12019. {
  12020. str[i] = tolower(str[i]);
  12021. }
  12022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12023. isSuccess = ConfigurationStatus_Accepted;
  12024. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12025. }
  12026. else
  12027. {
  12028. isSuccess = ConfigurationStatus_Rejected;
  12029. }
  12030. }
  12031. #endif
  12032. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12033. {
  12034. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12035. {
  12036. check_ascii = value[0];
  12037. if( (check_ascii < 48) || (check_ascii > 57) )
  12038. {
  12039. isSuccess = ConfigurationStatus_Rejected;
  12040. }
  12041. else
  12042. {
  12043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12044. isSuccess = ConfigurationStatus_Accepted;
  12045. }
  12046. }
  12047. else
  12048. {
  12049. isSuccess = ConfigurationStatus_Rejected;
  12050. }
  12051. }
  12052. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12053. {
  12054. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12055. {
  12056. check_ascii = value[0];
  12057. if( (check_ascii < 48) || (check_ascii > 57) )
  12058. {
  12059. isSuccess = ConfigurationStatus_Rejected;
  12060. }
  12061. else
  12062. {
  12063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12064. isSuccess = ConfigurationStatus_Accepted;
  12065. }
  12066. }
  12067. else
  12068. {
  12069. isSuccess = ConfigurationStatus_Rejected;
  12070. }
  12071. }
  12072. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12073. {
  12074. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12075. {
  12076. strcpy(str, (const char*)value);
  12077. for(int i = 0; str[i]; i++)
  12078. {
  12079. str[i] = tolower(str[i]);
  12080. }
  12081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12082. isSuccess = ConfigurationStatus_Accepted;
  12083. }
  12084. else
  12085. {
  12086. isSuccess = ConfigurationStatus_Rejected;
  12087. }
  12088. }
  12089. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12090. {
  12091. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12092. {
  12093. check_ascii = value[0];
  12094. if( (check_ascii < 48) || (check_ascii > 57) )
  12095. {
  12096. isSuccess = ConfigurationStatus_Rejected;
  12097. }
  12098. else
  12099. {
  12100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12101. isSuccess = ConfigurationStatus_Accepted;
  12102. }
  12103. }
  12104. else
  12105. {
  12106. isSuccess = ConfigurationStatus_Rejected;
  12107. }
  12108. }
  12109. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12110. {
  12111. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12112. {
  12113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12114. isSuccess = ConfigurationStatus_Accepted;
  12115. }
  12116. else
  12117. {
  12118. isSuccess = ConfigurationStatus_Rejected;
  12119. }
  12120. }
  12121. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12122. {
  12123. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12124. {
  12125. check_ascii = value[0];
  12126. if( (check_ascii < 48) || (check_ascii > 57) )
  12127. {
  12128. isSuccess = ConfigurationStatus_Rejected;
  12129. }
  12130. else
  12131. {
  12132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12133. isSuccess = ConfigurationStatus_Accepted;
  12134. }
  12135. }
  12136. else
  12137. {
  12138. isSuccess = ConfigurationStatus_Rejected;
  12139. }
  12140. }
  12141. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12142. {
  12143. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12144. {
  12145. strcpy(str, (const char*)value);
  12146. for(int i = 0; str[i]; i++)
  12147. {
  12148. str[i] = tolower(str[i]);
  12149. }
  12150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12151. isSuccess = ConfigurationStatus_Accepted;
  12152. }
  12153. else
  12154. {
  12155. isSuccess = ConfigurationStatus_Rejected;
  12156. }
  12157. }
  12158. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12159. {
  12160. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12161. {
  12162. check_ascii = value[0];
  12163. if( (check_ascii < 48) || (check_ascii > 57) )
  12164. {
  12165. isSuccess = ConfigurationStatus_Rejected;
  12166. }
  12167. else
  12168. {
  12169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12170. isSuccess = ConfigurationStatus_Accepted;
  12171. }
  12172. }
  12173. else
  12174. {
  12175. isSuccess = ConfigurationStatus_Rejected;
  12176. }
  12177. }
  12178. return isSuccess;
  12179. }
  12180. int updateSetting(char *key, char *value)
  12181. {
  12182. mtrace();
  12183. int isSuccess = FALSE;
  12184. char string[1000]={0}, buffer[1000]={0};
  12185. char strtemp[50]={0};
  12186. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12187. int pos, c = 0;
  12188. char *loc;
  12189. int pos1=0;
  12190. FILE *f = fopen("/var/www/settings1", "r");
  12191. if(f == NULL)
  12192. {
  12193. #ifdef Debug
  12194. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12195. #endif
  12196. return isSuccess;
  12197. }
  12198. fseek(f, 0, SEEK_END);
  12199. long fsize = ftell(f);
  12200. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12201. fread(string, 1, fsize, f);
  12202. fclose(f);
  12203. string[fsize] = 0;
  12204. loc = strstr(string, key);
  12205. if(loc != NULL)
  12206. {
  12207. DEBUG_INFO("key exist!\n");
  12208. pos = loc - string-1;
  12209. f = fopen("/var/www/settings1", "w");
  12210. strncpy(buffer, string, pos);
  12211. fprintf(f, "%s", buffer);
  12212. memset(sstr ,0, sizeof(sstr) );
  12213. c = 0;
  12214. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12215. {
  12216. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12217. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12218. c++;
  12219. }
  12220. sstr[c] = '\0';
  12221. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12222. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12223. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12224. memset(buffer ,0, sizeof(buffer) );
  12225. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12226. //printf("buffer=%s",buffer);
  12227. fprintf(f, "%s", buffer);
  12228. fclose(f);
  12229. }
  12230. else
  12231. {
  12232. printf("key not exist!\n");
  12233. f = fopen("/var/www/settings1", "w+");
  12234. fputs(string, f);
  12235. fseek(f, -1, SEEK_CUR);
  12236. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12237. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12238. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12239. fclose(f);
  12240. }
  12241. isSuccess = TRUE;
  12242. return isSuccess;
  12243. }
  12244. int TransactionMessageAttemptsGet(void)
  12245. {
  12246. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12247. }
  12248. int FirstHeartBeatResponse(void)
  12249. {
  12250. return FirstHeartBeat;
  12251. }
  12252. int TransactionMessageRetryIntervalGet(void)
  12253. {
  12254. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12255. }
  12256. #define SA struct sockaddr
  12257. #define MAXBUF 1024
  12258. //static int m_socket_data;
  12259. //static int sockfd;
  12260. int ReadHttpStatus(int sock){
  12261. //char c;
  12262. char buff[1024]="",*ptr=buff+1;
  12263. int bytes_received, status;
  12264. DEBUG_INFO("Begin Response ..\n");
  12265. while((bytes_received = recv(sock, ptr, 1, 0))){
  12266. if(bytes_received==-1){
  12267. perror("ReadHttpStatus");
  12268. exit(1);
  12269. }
  12270. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12271. ptr++;
  12272. }
  12273. *ptr=0;
  12274. ptr=buff+1;
  12275. sscanf(ptr,"%*s %d ", &status);
  12276. DEBUG_INFO("%s\n",ptr);
  12277. DEBUG_INFO("status=%d\n",status);
  12278. DEBUG_INFO("End Response ..\n");
  12279. return (bytes_received>0)?status:0;
  12280. }
  12281. //the only filed that it parsed is 'Content-Length'
  12282. int ParseHeader(int sock){
  12283. //char c;
  12284. char buff[1024]="",*ptr=buff+4;
  12285. int bytes_received;
  12286. DEBUG_INFO("Begin HEADER ..\n");
  12287. while((bytes_received = recv(sock, ptr, 1, 0))){
  12288. if(bytes_received==-1){
  12289. perror("Parse Header");
  12290. exit(1);
  12291. }
  12292. if(
  12293. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12294. (ptr[-1]=='\r') && (*ptr=='\n' )
  12295. ) break;
  12296. ptr++;
  12297. }
  12298. *ptr=0;
  12299. ptr=buff+4;
  12300. //printf("%s",ptr);
  12301. if(bytes_received){
  12302. ptr=strstr(ptr,"Content-Length:");
  12303. if(ptr){
  12304. sscanf(ptr,"%*s %d",&bytes_received);
  12305. }else
  12306. bytes_received=-1; //unknown size
  12307. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12308. }
  12309. DEBUG_INFO("End HEADER ..\n");
  12310. return bytes_received ;
  12311. }
  12312. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12313. {
  12314. char rmFileCmd[100]={0};
  12315. char FilePath[100]={0};
  12316. char ftpbuf[200];
  12317. int systemresult;
  12318. //DEBUG_INFO("filename=%s\n",filename);
  12319. //DEBUG_INFO("url=%s\n",url);
  12320. sprintf(FilePath,"/mnt/%s",filename);
  12321. if((access(FilePath,F_OK))!=-1)
  12322. {
  12323. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12324. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12325. system(rmFileCmd);
  12326. }
  12327. memset(ftpbuf, 0, sizeof(ftpbuf));
  12328. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12329. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12330. systemresult = system(ftpbuf);
  12331. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12332. if(systemresult != 0)
  12333. {
  12334. DEBUG_INFO("http DownLoad error!\n");
  12335. return FALSE;
  12336. }
  12337. return TRUE;
  12338. }
  12339. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12340. {
  12341. char rmFileCmd[100]={0};
  12342. char FilePath[100]={0};
  12343. char ftpbuf[200];
  12344. int systemresult;
  12345. //char temp[100];
  12346. #if 0
  12347. struct hostent* server;
  12348. char *IPbuffer;
  12349. server = gethostbyname(location);
  12350. // To convert an Internet network
  12351. // address into ASCII string
  12352. IPbuffer = inet_ntoa(*((struct in_addr*)
  12353. server->h_addr_list[0]));
  12354. #endif
  12355. sprintf(FilePath,"/mnt/%s",filename);
  12356. if((access(FilePath,F_OK))!=-1)
  12357. {
  12358. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12359. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12360. system(rmFileCmd);
  12361. }
  12362. memset(ftpbuf, 0, sizeof(ftpbuf));
  12363. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12364. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12365. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12366. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12367. systemresult = system(ftpbuf);
  12368. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12369. if(systemresult != 0)
  12370. {
  12371. printf("wget error!\n");
  12372. return FALSE;
  12373. }
  12374. return TRUE;
  12375. }
  12376. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12377. {
  12378. char rmFileCmd[100]={0};
  12379. char FilePath[100]={0};
  12380. char ftpbuf[200];
  12381. char filenametemp[60]={0};
  12382. int systemresult;
  12383. //DEBUG_INFO("filename=%s\n",filename);
  12384. //DEBUG_INFO("url=%s\n",url);
  12385. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12386. if((access(FilePath,F_OK))!=-1)
  12387. {
  12388. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12389. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12390. system(rmFileCmd);
  12391. }
  12392. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12393. if(fp == NULL)
  12394. {
  12395. DEBUG_INFO("log is NULL\n");
  12396. return FALSE;
  12397. }
  12398. else
  12399. {
  12400. fprintf(fp, "%s\n", url);
  12401. sscanf(filename, "%*2[.]%s", filenametemp);
  12402. fprintf(fp, "%s\n", filenametemp);
  12403. fclose(fp);
  12404. }
  12405. memset(ftpbuf, 0, sizeof(ftpbuf));
  12406. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12407. systemresult = system(ftpbuf);
  12408. DEBUG_INFO("systemresult=%d\n",systemresult);
  12409. if(systemresult != 0)
  12410. {
  12411. DEBUG_INFO("http upload error!\n");
  12412. return FALSE;
  12413. }
  12414. return TRUE;
  12415. }
  12416. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12417. {
  12418. struct hostent* server;
  12419. char *IPbuffer;
  12420. char ftpbuf[200];
  12421. int systemresult;
  12422. // To retrieve host information
  12423. server = gethostbyname(location);
  12424. // To convert an Internet network
  12425. // address into ASCII string
  12426. IPbuffer = inet_ntoa(*((struct in_addr*)
  12427. server->h_addr_list[0]));
  12428. memset(ftpbuf, 0, sizeof(ftpbuf));
  12429. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12430. /* format : ftpput -u username -p passwd IP target source*/
  12431. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12432. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12433. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12434. systemresult = system(ftpbuf);
  12435. DEBUG_INFO("systemresult=%d\n",systemresult);
  12436. if(systemresult != 0)
  12437. {
  12438. DEBUG_INFO("ftpput error!\n");
  12439. return FALSE;
  12440. }
  12441. return TRUE;
  12442. }
  12443. int SettingChargingRecord(int target, int transactionId)
  12444. {
  12445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12446. {
  12447. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12448. {
  12449. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12450. {
  12451. addBuff(target, transactionId, 0);
  12452. return TRUE;
  12453. }
  12454. }
  12455. for (int index = 0; index < CCS_QUANTITY; index++)
  12456. {
  12457. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12458. {
  12459. addBuff(target, transactionId, 0);
  12460. return TRUE;
  12461. }
  12462. }
  12463. for (int index = 0; index < GB_QUANTITY; index++)
  12464. {
  12465. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12466. {
  12467. addBuff(target, transactionId, 0);
  12468. return TRUE;
  12469. }
  12470. }
  12471. }
  12472. else
  12473. {
  12474. for (int index = 0; index < AC_QUANTITY; index++)
  12475. {
  12476. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12477. {
  12478. addBuff(target, transactionId, 0);
  12479. return TRUE;
  12480. }
  12481. }
  12482. }
  12483. return FALSE;
  12484. }
  12485. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12486. {
  12487. int isSuccess = FALSE;
  12488. //char *query = NULL;
  12489. sqlite3_stmt *stmt;
  12490. int rc; // return code
  12491. char str[20];
  12492. sprintf(str,"%d",user_id);
  12493. 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 */
  12494. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12495. rc = sqlite3_step(stmt); /* 3 */
  12496. if (rc != SQLITE_DONE) {
  12497. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12498. goto out;
  12499. }
  12500. sqlite3_finalize(stmt);
  12501. // free(query);
  12502. out:
  12503. //----------------------
  12504. // close SQLite database
  12505. //----------------------
  12506. sqlite3_close(db);
  12507. printf("database closed.\n");
  12508. return isSuccess;
  12509. }
  12510. /**
  12511. * Place the contents of the specified file into a memory buffer
  12512. *
  12513. * @param[in] filename The path and name of the file to read
  12514. * @param[out] filebuffer A pointer to the contents in memory
  12515. * @return status 0 success, 1 on failure
  12516. */
  12517. int get_file_contents(const char* filename, char** outbuffer) {
  12518. FILE* file = NULL;
  12519. long filesize;
  12520. const int blocksize = 1;
  12521. size_t readsize;
  12522. char* filebuffer;
  12523. // Open the file
  12524. file = fopen(filename, "r");
  12525. if (NULL == file)
  12526. {
  12527. printf("'%s' not opened\n", filename);
  12528. exit(EXIT_FAILURE);
  12529. }
  12530. // Determine the file size
  12531. fseek(file, 0, SEEK_END);
  12532. filesize = ftell(file);
  12533. rewind (file);
  12534. // Allocate memory for the file contents
  12535. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12536. *outbuffer = filebuffer;
  12537. if (filebuffer == NULL)
  12538. {
  12539. fputs ("malloc out-of-memory", stderr);
  12540. exit(EXIT_FAILURE);
  12541. }
  12542. // Read in the file
  12543. readsize = fread(filebuffer, blocksize, filesize, file);
  12544. if (readsize != filesize)
  12545. {
  12546. fputs ("didn't read file completely",stderr);
  12547. exit(EXIT_FAILURE);
  12548. }
  12549. // Clean exit
  12550. fclose(file);
  12551. return EXIT_SUCCESS;
  12552. }
  12553. static int selectSqlCount = 0;
  12554. static int callback(void *data, int argc, char **argv, char **azColName){
  12555. int i;
  12556. //printf("%s: ", (const char*)data);
  12557. selectSqlCount = argc;
  12558. for(i = 0; i<argc; i++){
  12559. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12560. }
  12561. //printf("\n");
  12562. return 0;
  12563. }
  12564. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12565. //int i;
  12566. //printf("%s:\n", (const char*)data);
  12567. localversion = argv[5] ? atoi(argv[5]) : 0;
  12568. //printf("localversion=%d\n", localversion);
  12569. return 0;
  12570. }
  12571. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12572. //int i;
  12573. //printf("%s:\n", (const char*)data);
  12574. //idTag
  12575. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12576. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12577. //parentIdTag
  12578. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12579. //expir_date
  12580. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12581. //status
  12582. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12583. //version
  12584. idTagQuery.listVersionInt = atoi(argv[5]);
  12585. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12586. return 0;
  12587. }
  12588. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12589. #if 0
  12590. int i;
  12591. //printf("%s:\n", (const char*)data);
  12592. for(i=0; i<argc; i++){
  12593. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12594. }
  12595. //printf("");
  12596. #endif
  12597. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12598. // printf("localversion=%d\n", localversion);
  12599. return 0;
  12600. }
  12601. /** sqlite3_exec的回调。
  12602. *
  12603. * 向控制台打印查询的结果。
  12604. *
  12605. * @param in data 传递给回调函数的数据。
  12606. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12607. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12608. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12609. * @return 状态码。
  12610. */
  12611. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12612. {
  12613. for (int i = 0; i < n_columns; i++)
  12614. {
  12615. DEBUG_INFO("%s/t", col_values[i]);
  12616. }
  12617. DEBUG_INFO("/n");
  12618. return 0;
  12619. }
  12620. void OCPP_getListVerion()
  12621. {
  12622. int rc = 0;
  12623. // const char* data = "Callback function called";
  12624. char sql[100];
  12625. char zErrMsg[100];
  12626. memset(sql, 0, 100);
  12627. memset(zErrMsg, 0, 100);
  12628. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12629. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12630. /* Execute SQL statement */
  12631. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12632. DEBUG_INFO("rc=%d\n",rc);
  12633. if( rc != SQLITE_OK ){
  12634. DEBUG_INFO("SQL error: %s", zErrMsg);
  12635. //sqlite3_free(zErrMsg);
  12636. }
  12637. }
  12638. void OCPP_getIdTag(char idTag[])
  12639. {
  12640. int rc = 0;
  12641. // const char* data = "Callback function called";
  12642. char sql[100];
  12643. char zErrMsg[100];
  12644. memset(sql, 0, 100);
  12645. memset(zErrMsg, 0, 100);
  12646. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12647. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12648. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12649. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12650. /* Execute SQL statement */
  12651. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12652. if( rc != SQLITE_OK ){
  12653. DEBUG_INFO("SQL error: %s", zErrMsg);
  12654. //sqlite3_free(zErrMsg);
  12655. }
  12656. //return ver;
  12657. }
  12658. void OCPP_get_TableAuthlocalAllData(void)
  12659. {
  12660. int rc = 0;
  12661. // const char* data = "Callback function called";
  12662. char sql[100];
  12663. char zErrMsg[100];
  12664. memset(sql, 0, 100);
  12665. memset(zErrMsg, 0, 100);
  12666. sprintf(sql,"select * from ocpp_auth_local ");
  12667. /* Execute SQL statement */
  12668. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12669. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12670. if( rc != SQLITE_OK ){
  12671. DEBUG_INFO("SQL error: %s", zErrMsg);
  12672. //sqlite3_free(zErrMsg);
  12673. }
  12674. //return ver;
  12675. }
  12676. int OCPP_cleanLocalList()
  12677. {
  12678. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12679. char *errMsg = 0;
  12680. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12681. if (SQLITE_OK != rc)
  12682. {
  12683. DEBUG_INFO("%s\n",errMsg);
  12684. return FALSE;
  12685. }
  12686. else
  12687. {
  12688. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12689. }
  12690. return TRUE;
  12691. }
  12692. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12693. {
  12694. int isSuccess = FALSE;
  12695. int ret = 0;
  12696. //const char* data = "Callback function called";
  12697. char sql[300];
  12698. char zErrMsg[200];
  12699. memset(sql, 0, 300);
  12700. memset(zErrMsg, 0, 200);
  12701. 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);
  12702. //* Execute SQL statement */
  12703. //zErrMsg = 0;
  12704. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12705. if( ret != SQLITE_OK ){
  12706. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12707. // free(zErrMsg);
  12708. // free(sql);
  12709. return isSuccess;
  12710. }
  12711. memset(sql, 0, 300);
  12712. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12713. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12714. if( ret != SQLITE_OK ){
  12715. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12716. // free(zErrMsg);
  12717. // free(sql);
  12718. return isSuccess;
  12719. }
  12720. // DEBUG_INFO("successfully Insert records created\n");
  12721. isSuccess = TRUE;
  12722. return isSuccess;
  12723. }
  12724. void OCPP_deleteIdTag(char idTag[])
  12725. {
  12726. //int ver = 0;
  12727. //int isSuccess = FALSE;
  12728. int rc = 0;
  12729. char sql[100];
  12730. char zErrMsg[100];
  12731. memset(sql, 0, 100);
  12732. memset(zErrMsg, 0, 100);
  12733. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12734. //* Execute SQL statement */
  12735. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12736. if( rc != SQLITE_OK ){
  12737. DEBUG_INFO("SQL error: %s", zErrMsg);
  12738. //sqlite3_free(zErrMsg);
  12739. }
  12740. }
  12741. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12742. {
  12743. int isSuccess = FALSE;
  12744. int ret = 0;
  12745. const char* data = "Callback function called";
  12746. char sql[200];
  12747. char zErrMsg[100];
  12748. memset(sql, 0, 200);
  12749. memset(zErrMsg, 0, 100);
  12750. //* selectFromTable */
  12751. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12752. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12753. //* Execute SQL statement */
  12754. selectSqlCount = 0;
  12755. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12756. if( ret != SQLITE_OK ){
  12757. printf("Error SQL: %s\n", zErrMsg);
  12758. }
  12759. printf("successfully select operation done\n");
  12760. memset(sql, 0, 200);
  12761. memset(zErrMsg, 0, 100);
  12762. if(selectSqlCount == 0)
  12763. {
  12764. //Insert
  12765. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12766. 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);
  12767. DEBUG_INFO("sql:%s\n", sql);
  12768. //* Execute SQL statement */
  12769. //zErrMsg = 0;
  12770. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12771. if( ret != SQLITE_OK ){
  12772. printf("SQL error: %s\n", zErrMsg);
  12773. return isSuccess;
  12774. }
  12775. DEBUG_INFO("successfully Insert records created\n");
  12776. isSuccess = TRUE;
  12777. }
  12778. else
  12779. {
  12780. //Update
  12781. //* Create merged SQL statement */
  12782. 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);
  12783. /* Execute SQL statement */
  12784. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12785. if( ret != SQLITE_OK ){
  12786. printf("SQL error: %s\n", zErrMsg);
  12787. //sqlite3_free(zErrMsg);
  12788. //sqlite3_free(sql);
  12789. return isSuccess;
  12790. }
  12791. DEBUG_INFO("Successfully operation done \n");
  12792. isSuccess = TRUE;
  12793. }
  12794. return isSuccess;
  12795. }
  12796. int GetOcppServerURL()
  12797. {
  12798. int result = FALSE;
  12799. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12800. memset(OcppHost, 0, sizeof(OcppHost));
  12801. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12802. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12803. {
  12804. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12805. #if 1
  12806. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12807. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12808. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12809. #endif
  12810. #if 0
  12811. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12812. "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
  12813. OcppProtocol, OcppHost, OcppTempPath);
  12814. OcppPort = 443;
  12815. #endif
  12816. result = TRUE;
  12817. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12818. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12819. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12820. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12821. goto End;
  12822. }
  12823. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12824. {
  12825. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12826. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12827. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12828. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12829. result = TRUE;
  12830. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12831. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12832. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12833. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12834. goto End;
  12835. }
  12836. else
  12837. {
  12838. strcpy(OcppHost,"");
  12839. }
  12840. End:
  12841. return result;
  12842. }
  12843. int GetOcppPath()
  12844. {
  12845. int result = FALSE;
  12846. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12847. {
  12848. if(OcppTempPath == NULL)
  12849. {
  12850. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12851. }
  12852. else
  12853. {
  12854. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12855. }
  12856. result = TRUE;
  12857. goto End;
  12858. }
  12859. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12860. {
  12861. if(OcppTempPath == NULL)
  12862. {
  12863. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12864. }
  12865. else
  12866. {
  12867. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12868. }
  12869. result = TRUE;
  12870. goto End;
  12871. }
  12872. else
  12873. {
  12874. strcpy(OcppPath,"");
  12875. }
  12876. End:
  12877. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12878. return result;
  12879. }
  12880. int GetOcppPort()
  12881. {
  12882. return OcppPort;
  12883. }
  12884. int GetOcppConnStatus(void)
  12885. {
  12886. return ShmOCPP16Data->OcppConnStatus;
  12887. }
  12888. void SetOcppConnStatus(uint8_t status)
  12889. {
  12890. ShmOCPP16Data->OcppConnStatus = status;
  12891. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12892. if(status == FALSE)
  12893. {
  12894. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12895. {
  12896. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12897. }
  12898. else
  12899. {
  12900. SystemInitial = AC_QUANTITY;
  12901. }
  12902. }
  12903. }
  12904. int GetHeartBeatWithNOResponse(void)
  12905. {
  12906. return HeartBeatWithNOResponse;
  12907. }
  12908. void SetHeartBeatWithNOResponse(void)
  12909. {
  12910. HeartBeatWithNOResponse = 0;
  12911. }
  12912. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12913. /*
  12914. src 源字串的首地址(buf的地址)
  12915. separator 指定的分割字元
  12916. dest 接收子字串的陣列
  12917. num 分割後子字串的個數
  12918. */
  12919. char *pNext;
  12920. int count = 0;
  12921. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12922. return;
  12923. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12924. return;
  12925. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12926. while(pNext != NULL) {
  12927. *dest++ = pNext;
  12928. ++count;
  12929. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12930. }
  12931. *num = count;
  12932. }
  12933. int GetTransactionId(int gunindex, unsigned char idTag[])
  12934. {
  12935. char ch;
  12936. FILE *fptr1;
  12937. int temptransactionId;
  12938. char str[100]={0};
  12939. temptransactionId = 0;
  12940. /*------ Read the file ----------------*/
  12941. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12942. if (!fptr1)
  12943. {
  12944. printf(" File not found or unable to open the input file!!\n");
  12945. return temptransactionId;
  12946. }
  12947. ch=fgetc(fptr1);
  12948. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12949. rewind(fptr1);
  12950. if(ch!=EOF)
  12951. {
  12952. // printf("%c",ch);
  12953. while (fgets(str, 100, fptr1) != NULL)
  12954. {
  12955. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12956. if(str[0]=='\0')
  12957. {
  12958. break;
  12959. }
  12960. char *revbuf[8] = {0}; //存放分割後的子字串
  12961. int num = 0;//分割後子字串的個數
  12962. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12963. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  12964. {
  12965. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12966. {
  12967. temptransactionId = atoi(revbuf[2]);
  12968. break;
  12969. }
  12970. }
  12971. }
  12972. }
  12973. fclose(fptr1);
  12974. /*------- End of reading ---------------*/
  12975. return temptransactionId;
  12976. }
  12977. void SetTransactionIdZero(int transactionId)
  12978. {
  12979. //TransactionId[gunindex] = 0;
  12980. char ch;
  12981. FILE *fptr1, *fptr2;
  12982. int temptransactionId = 0;
  12983. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  12984. printf("\n\n Delete a specific line from a file :\n");
  12985. printf("-----------------------------------------\n");
  12986. //scanf("%s",fname);
  12987. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12988. if (!fptr1)
  12989. {
  12990. printf(" File not found or unable to open the input file!!\n");
  12991. return ;
  12992. }
  12993. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12994. if (!fptr2)
  12995. {
  12996. printf("Unable to open a temporary file to write!!\n");
  12997. fclose(fptr1);
  12998. return ;
  12999. }
  13000. ch=fgetc(fptr1);
  13001. //printf(" Now the content of the file %s is : \n",fname);
  13002. rewind(fptr1);
  13003. if(ch!=EOF)
  13004. {
  13005. // copy all contents to the temporary file except the specific line
  13006. while (fgets(str, 100, fptr1) != NULL)
  13007. {
  13008. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13009. if(str[0]=='\0')
  13010. {
  13011. break;
  13012. }
  13013. char *revbuf[8] = {0}; //存放分割後的子字串
  13014. int num = 0;//分割後子字串的個數
  13015. strcpy(strtemp, str);
  13016. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13017. if(revbuf[2][0] != '\0')
  13018. {
  13019. temptransactionId = atoi(revbuf[2]);
  13020. if(transactionId != temptransactionId)
  13021. {
  13022. fprintf(fptr2, "%s", strtemp);
  13023. }
  13024. }
  13025. }
  13026. }
  13027. fclose(fptr1);
  13028. fclose(fptr2);
  13029. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13030. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13031. /*------ Read the file ----------------*/
  13032. }
  13033. int InternetDisconnect(void)
  13034. {
  13035. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  13036. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  13037. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  13038. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13039. }
  13040. void GetChargingProfileRequest(int gunindex)
  13041. {
  13042. mtrace();
  13043. //int connectorIdInt, durationInt;
  13044. //char chargingRateUnitStr[4]={0};
  13045. int tempdurationInt = 0;
  13046. int tempchargingProfileId = 0;
  13047. int tempstackLevel = 0;
  13048. int temptransactionId = 0;
  13049. float tempminChargingRateFloat = 0.0;
  13050. char tempchargingProfilePurposeStr[24]={0};
  13051. char tempchargingProfileKindStr[12]={0};
  13052. char temprecurrencyKindStr[8]={0};
  13053. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  13054. char tempvalidToStr[28]={0};
  13055. int tempStartPeriodInt = 0;
  13056. float tempLimitInt = 0.0;//0.1;
  13057. int tempNumberPhasesInt=0;
  13058. char fname[200];
  13059. //char comfirmstr[20];
  13060. float MinChargingRate =0.0;
  13061. double diff_t;
  13062. struct tm tp;
  13063. FILE *fptr1;//, *fptr2;
  13064. int c = 0;
  13065. char * pch;
  13066. char *loc;
  13067. char sstr[200]={ 0 };
  13068. int n_chargingProfile = 0;
  13069. int n_SchedulePeriods = 0;
  13070. char SchedulePeriodList[10][200]={0};
  13071. char sLineWord[1600]={0};
  13072. char word[1000]={0};
  13073. int confirmPeriods = 0;
  13074. struct StructProfile ChargePointMaxProfile;
  13075. struct StructProfile TxDefaultProfile;
  13076. struct StructProfile TxProfile;
  13077. struct StructProfile TxDefaultProfiletemp[2]={0};
  13078. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  13079. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  13080. struct StructChargingProfile TxProfile_TEMP={0};
  13081. int TxDefaultProfileFileIsNull=FALSE;
  13082. int ChargePointMaxProfileIsNull=FALSE;
  13083. int TxProfileIsNull=FALSE;
  13084. // int CompositeSceduleIndex = 0;
  13085. char ChargePointMaxProfileScheduleStr[30]={0};
  13086. char TxDefaultProfileScheduleStr[30]={0};
  13087. char TxProfileScheduleStr[30]={0};
  13088. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13089. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13090. memset(&TxProfile,0,sizeof(struct StructProfile));
  13091. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13092. DEBUG_INFO("GetChargingProfileRequest\n");
  13093. //*****************************ChargePointMaxProfile******************************************/
  13094. strcpy(fname, ChargePointMaxProfile_JSON);
  13095. ChargePointMaxProfileIsNull=TRUE;
  13096. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13097. {
  13098. fptr1 = fopen(fname, "r");
  13099. int c;
  13100. c = fgetc(fptr1);
  13101. //DEBUG_INFO("c:%d\n",c);
  13102. rewind(fptr1);
  13103. if(c == EOF)
  13104. {
  13105. DEBUG_INFO("\n End of file reached.");
  13106. ChargePointMaxProfileIsNull=TRUE;
  13107. fclose(fptr1);
  13108. }
  13109. else
  13110. {
  13111. ChargePointMaxProfileIsNull=FALSE;
  13112. while(fscanf(fptr1, "%s", word) != EOF)
  13113. {
  13114. if(strcmp(word, "chargingProfileId") == 0)
  13115. {
  13116. n_chargingProfile = n_chargingProfile + 1;
  13117. }
  13118. }
  13119. rewind(fptr1);
  13120. //search Charging Profile Element
  13121. int i = 0;
  13122. int j = 0;
  13123. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13124. //***********chargingProfileId**************/
  13125. c = 0;
  13126. loc = strstr(sLineWord, "chargingProfileId");
  13127. //DEBUG_INFO("loc=%s\n",loc);
  13128. memset(sstr ,0, sizeof(sstr) );
  13129. if(loc != NULL)
  13130. {
  13131. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13132. {
  13133. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13134. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13135. c++;
  13136. }
  13137. sstr[c] = '\0';
  13138. tempchargingProfileId = atoi(sstr);
  13139. }
  13140. else
  13141. {
  13142. tempchargingProfileId = 0;
  13143. }
  13144. //***********stackLevel**************/
  13145. c = 0;
  13146. loc = strstr(sLineWord, "stackLevel");
  13147. //DEBUG_INFO("loc=%s\n",loc);
  13148. memset(sstr ,0, sizeof(sstr) );
  13149. if(loc != NULL)
  13150. {
  13151. while (loc[2+strlen("stackLevel")+c] != '\"')
  13152. {
  13153. sstr[c] = loc[2+strlen("stackLevel")+c];
  13154. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13155. c++;
  13156. }
  13157. sstr[c] = '\0';
  13158. tempstackLevel = atoi(sstr);
  13159. }
  13160. else
  13161. {
  13162. tempstackLevel = 0;
  13163. }
  13164. //***********chargingProfilePurpose **************/
  13165. c = 0;
  13166. loc = strstr(sLineWord, "chargingProfilePurpose");
  13167. //DEBUG_INFO("loc=%s\n",loc);
  13168. memset(sstr ,0, sizeof(sstr) );
  13169. if(loc != NULL)
  13170. {
  13171. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13172. {
  13173. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13174. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13175. c++;
  13176. }
  13177. sstr[c] = '\0';
  13178. strcpy(tempchargingProfilePurposeStr,sstr);
  13179. }
  13180. else
  13181. {
  13182. strcpy(tempchargingProfilePurposeStr,"");
  13183. }
  13184. //***********chargingProfileKind **************/
  13185. c = 0;
  13186. loc = strstr(sLineWord, "chargingProfileKind");
  13187. //DEBUG_INFO("loc=%s\n",loc);
  13188. memset(sstr ,0, sizeof(sstr) );
  13189. if(loc != NULL)
  13190. {
  13191. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13192. {
  13193. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13194. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13195. c++;
  13196. }
  13197. sstr[c] = '\0';
  13198. strcpy(tempchargingProfileKindStr,sstr);
  13199. }
  13200. else
  13201. {
  13202. strcpy(tempchargingProfileKindStr,"");
  13203. }
  13204. //***********recurrencyKind **************/
  13205. c = 0;
  13206. loc = strstr(sLineWord, "recurrencyKind");
  13207. //DEBUG_INFO("loc=%s\n",loc);
  13208. memset(sstr ,0, sizeof(sstr) );
  13209. if(loc != NULL)
  13210. {
  13211. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13212. {
  13213. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13214. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13215. c++;
  13216. }
  13217. sstr[c] = '\0';
  13218. strcpy(temprecurrencyKindStr,sstr);
  13219. }
  13220. else
  13221. {
  13222. strcpy(temprecurrencyKindStr,"");
  13223. }
  13224. //***********validFrom**************/
  13225. c = 0;
  13226. loc = strstr(sLineWord, "validFrom");
  13227. //DEBUG_INFO("loc=%s\n",loc);
  13228. memset(sstr ,0, sizeof(sstr) );
  13229. if(loc != NULL)
  13230. {
  13231. while (loc[3+strlen("validFrom")+c] != '\"')
  13232. {
  13233. sstr[c] = loc[3+strlen("validFrom")+c];
  13234. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13235. c++;
  13236. }
  13237. sstr[c] = '\0';
  13238. strcpy(tempvalidFromStr,sstr);
  13239. }
  13240. else
  13241. {
  13242. strcpy(tempvalidFromStr,"");
  13243. }
  13244. //***********validTo **************/
  13245. c = 0;
  13246. loc = strstr(sLineWord, "validTo");
  13247. //DEBUG_INFO("loc=%s\n",loc);
  13248. memset(sstr ,0, sizeof(sstr) );
  13249. if(loc != NULL)
  13250. {
  13251. while (loc[3+strlen("validTo")+c] != '\"')
  13252. {
  13253. sstr[c] = loc[3+strlen("validTo")+c];
  13254. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13255. c++;
  13256. }
  13257. sstr[c] = '\0';
  13258. strcpy(tempvalidToStr,sstr);
  13259. }
  13260. else
  13261. {
  13262. strcpy(tempvalidToStr,"");
  13263. }
  13264. //***********validFrom**************/
  13265. c = 0;
  13266. loc = strstr(sLineWord, "validFrom");
  13267. if(loc != NULL)
  13268. {
  13269. memset(sstr ,0, sizeof(sstr) );
  13270. while (loc[3+strlen("validFrom")+c] != '\"')
  13271. {
  13272. sstr[c] = loc[3+strlen("validFrom")+c];
  13273. c++;
  13274. }
  13275. sstr[c] = '\0';
  13276. strcpy(tempvalidFromStr,sstr);
  13277. }
  13278. else
  13279. {
  13280. strcpy(tempvalidFromStr,"");
  13281. }
  13282. //***********validTo **************/
  13283. c = 0;
  13284. loc = strstr(sLineWord, "validTo");
  13285. if(loc != NULL)
  13286. {
  13287. memset(sstr ,0, sizeof(sstr) );
  13288. while (loc[3+strlen("validTo")+c] != '\"')
  13289. {
  13290. sstr[c] = loc[3+strlen("validTo")+c];
  13291. c++;
  13292. }
  13293. sstr[c] = '\0';
  13294. strcpy(tempvalidToStr,sstr);
  13295. }
  13296. else
  13297. {
  13298. strcpy(tempvalidToStr,"");
  13299. }
  13300. //***********duration**************/
  13301. c = 0;
  13302. loc = strstr(sLineWord, "duration");
  13303. if(loc != NULL)
  13304. {
  13305. memset(sstr ,0, sizeof(sstr) );
  13306. while (loc[2+strlen("duration")+c] != ',')
  13307. {
  13308. sstr[c] = loc[2+strlen("duration")+c];
  13309. c++;
  13310. }
  13311. sstr[c] = '\0';
  13312. tempdurationInt = atoi(sstr);
  13313. }
  13314. else
  13315. {
  13316. tempdurationInt = 0;
  13317. }
  13318. //**********startSchedule**********/
  13319. c = 0;
  13320. loc = strstr(sLineWord, "startSchedule");
  13321. memset(sstr ,0, sizeof(sstr) );
  13322. while (loc[3+strlen("startSchedule")+c] != '\"')
  13323. {
  13324. sstr[c] = loc[3+strlen("startSchedule")+c];
  13325. c++;
  13326. }
  13327. sstr[c] = '\0';
  13328. strcpy(tempstartScheduleStr, sstr);
  13329. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  13330. //**********chargingRateUnit**********/
  13331. c = 0;
  13332. loc = strstr(sLineWord, "chargingRateUnit");
  13333. memset(sstr ,0, sizeof(sstr) );
  13334. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13335. {
  13336. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13337. c++;
  13338. }
  13339. sstr[c] = '\0';
  13340. strcpy(tempchargingRateUnitStr, sstr);
  13341. //**********minChargingRate*******/
  13342. c = 0;
  13343. loc = strstr(sLineWord, "minChargingRate");
  13344. if(loc != NULL)
  13345. {
  13346. memset(sstr ,0, sizeof(sstr) );
  13347. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13348. {
  13349. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13350. c++;
  13351. }
  13352. sstr[c] = '\0';
  13353. tempminChargingRateFloat = atof(sstr);
  13354. }
  13355. else
  13356. {
  13357. tempminChargingRateFloat = 0.0;
  13358. }
  13359. //
  13360. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13361. tp.tm_isdst = -1;
  13362. time_t utc = mktime(&tp);
  13363. time_t t = time(NULL);
  13364. diff_t = difftime(t, utc);
  13365. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13366. //parsing strings to words
  13367. i = 0;
  13368. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13369. loc = loc+3+strlen("chargingSchedulePeriod");
  13370. pch = strtok(loc ,"{");
  13371. while (pch != NULL)
  13372. {
  13373. strcpy(SchedulePeriodList[i], pch);
  13374. pch = strtok (NULL, "{");
  13375. i = i + 1;
  13376. }
  13377. n_SchedulePeriods = i;
  13378. for(int i=0;i<n_SchedulePeriods;i++)
  13379. {
  13380. //*************startPeriod****************/
  13381. c = 0;
  13382. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13383. memset(sstr ,0, sizeof(sstr) );
  13384. while (loc[strlen("startPeriod")+2+c] != ',')
  13385. {
  13386. sstr[c] = loc[strlen("startPeriod")+2+c];
  13387. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13388. c++;
  13389. }
  13390. sstr[c] = '\0';
  13391. tempStartPeriodInt = atoi(sstr);
  13392. //*************limit****************/
  13393. c = 0;
  13394. loc = strstr(SchedulePeriodList[i], "limit");
  13395. memset(sstr ,0, sizeof(sstr) );
  13396. while (loc[strlen("limit")+2+c] != ',')
  13397. {
  13398. sstr[c] = loc[strlen("limit")+2+c];
  13399. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13400. c++;
  13401. }
  13402. sstr[c] = '\0';
  13403. tempLimitInt = atof(sstr);
  13404. //*************numberPhases****************/
  13405. c = 0;
  13406. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13407. memset(sstr ,0, sizeof(sstr) );
  13408. while (loc[strlen("numberPhases")+2+c] != '}')
  13409. {
  13410. sstr[c] = loc[strlen("numberPhases")+2+c];
  13411. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13412. c++;
  13413. }
  13414. sstr[c] = '\0';
  13415. tempNumberPhasesInt = atoi(sstr);
  13416. if(j == 0)
  13417. {
  13418. ChargePointMaxProfile.Duration = tempdurationInt;
  13419. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13420. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13421. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13422. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13423. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13424. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13425. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13426. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13427. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13428. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13429. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13430. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13431. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13432. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13433. }
  13434. }
  13435. if(MinChargingRate < tempminChargingRateFloat)
  13436. {
  13437. MinChargingRate = tempminChargingRateFloat;
  13438. }
  13439. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13440. if(confirmPeriods < n_SchedulePeriods)
  13441. {
  13442. confirmPeriods = n_SchedulePeriods;
  13443. }
  13444. j = j + 1;
  13445. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13446. fclose(fptr1);
  13447. }// end else
  13448. }// the end of access file ChargePointMaxProfile
  13449. //****************************TxDefaultProfile************************************************/
  13450. #if 0
  13451. switch(gunindex + 1)
  13452. {
  13453. case 0:
  13454. strcpy(fname, TxDefaultProfile_0_JSON );
  13455. break;
  13456. case 1:
  13457. strcpy(fname, TxDefaultProfile_1_JSON );
  13458. break;
  13459. case 2:
  13460. strcpy(fname, TxDefaultProfile_2_JSON );
  13461. break;
  13462. default:
  13463. strcpy(fname, TxDefaultProfile_1_JSON );
  13464. break;
  13465. }
  13466. #endif
  13467. memset(fname, 0, sizeof fname);
  13468. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13469. TxDefaultProfileFileIsNull=TRUE;
  13470. if((access(fname,F_OK))!=-1)
  13471. {
  13472. fptr1 = fopen(fname, "r");
  13473. c = 0;
  13474. c = fgetc(fptr1);
  13475. //DEBUG_INFO("c:%d\n",c);
  13476. rewind(fptr1);
  13477. if(c == EOF)
  13478. {
  13479. DEBUG_INFO("\n End of file reached.");
  13480. TxDefaultProfileFileIsNull=TRUE;
  13481. fclose(fptr1);
  13482. }
  13483. else
  13484. {
  13485. TxDefaultProfileFileIsNull=FALSE;
  13486. while(fscanf(fptr1, "%s", word) != EOF)
  13487. {
  13488. if(strcmp(word, "chargingProfileId") == 0)
  13489. {
  13490. n_chargingProfile = n_chargingProfile + 1;
  13491. }
  13492. }
  13493. rewind(fptr1);
  13494. //search Charging Profile Element
  13495. int i = 0;
  13496. int j = 0;
  13497. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13498. {
  13499. #if 0
  13500. //***********connectorId****************/
  13501. c = 0;
  13502. loc = strstr(sLineWord, "connectorId");
  13503. memset(sstr ,0, sizeof(sstr) );
  13504. while (loc[strlen("connectorId")+2+c] != ',')
  13505. {
  13506. sstr[c] = loc[strlen("connectorId")+2+c];
  13507. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13508. c++;
  13509. }
  13510. sstr[c] = '\0';
  13511. tempconnectorIdInt = atoi(sstr);
  13512. #endif
  13513. //***********chargingProfileId**************/
  13514. c = 0;
  13515. loc = strstr(sLineWord, "chargingProfileId");
  13516. //DEBUG_INFO("loc=%s\n",loc);
  13517. memset(sstr ,0, sizeof(sstr) );
  13518. if(loc != NULL)
  13519. {
  13520. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13521. {
  13522. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13523. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13524. c++;
  13525. }
  13526. sstr[c] = '\0';
  13527. tempchargingProfileId = atoi(sstr);
  13528. }
  13529. else
  13530. {
  13531. tempchargingProfileId = 0;
  13532. }
  13533. //***********stackLevel**************/
  13534. c = 0;
  13535. loc = strstr(sLineWord, "stackLevel");
  13536. //DEBUG_INFO("loc=%s\n",loc);
  13537. memset(sstr ,0, sizeof(sstr) );
  13538. if(loc != NULL)
  13539. {
  13540. while (loc[2+strlen("stackLevel")+c] != '\"')
  13541. {
  13542. sstr[c] = loc[2+strlen("stackLevel")+c];
  13543. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13544. c++;
  13545. }
  13546. sstr[c] = '\0';
  13547. tempstackLevel = atoi(sstr);
  13548. }
  13549. else
  13550. {
  13551. tempstackLevel = 0;
  13552. }
  13553. //***********chargingProfilePurpose **************/
  13554. c = 0;
  13555. loc = strstr(sLineWord, "chargingProfilePurpose");
  13556. //DEBUG_INFO("loc=%s\n",loc);
  13557. memset(sstr ,0, sizeof(sstr) );
  13558. if(loc != NULL)
  13559. {
  13560. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13561. {
  13562. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13563. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13564. c++;
  13565. }
  13566. sstr[c] = '\0';
  13567. strcpy(tempchargingProfilePurposeStr,sstr);
  13568. }
  13569. else
  13570. {
  13571. strcpy(tempchargingProfilePurposeStr,"");
  13572. }
  13573. //***********chargingProfileKind **************/
  13574. c = 0;
  13575. loc = strstr(sLineWord, "chargingProfileKind");
  13576. //DEBUG_INFO("loc=%s\n",loc);
  13577. memset(sstr ,0, sizeof(sstr) );
  13578. if(loc != NULL)
  13579. {
  13580. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13581. {
  13582. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13583. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13584. c++;
  13585. }
  13586. sstr[c] = '\0';
  13587. strcpy(tempchargingProfileKindStr,sstr);
  13588. }
  13589. else
  13590. {
  13591. strcpy(tempchargingProfileKindStr,"");
  13592. }
  13593. //***********recurrencyKind **************/
  13594. c = 0;
  13595. loc = strstr(sLineWord, "recurrencyKind");
  13596. //DEBUG_INFO("loc=%s\n",loc);
  13597. memset(sstr ,0, sizeof(sstr) );
  13598. if(loc != NULL)
  13599. {
  13600. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13601. {
  13602. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13603. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13604. c++;
  13605. }
  13606. sstr[c] = '\0';
  13607. strcpy(temprecurrencyKindStr,sstr);
  13608. }
  13609. else
  13610. {
  13611. strcpy(temprecurrencyKindStr,"");
  13612. }
  13613. //***********validFrom**************/
  13614. c = 0;
  13615. loc = strstr(sLineWord, "validFrom");
  13616. if(loc != NULL)
  13617. {
  13618. memset(sstr ,0, sizeof(sstr) );
  13619. while (loc[3+strlen("validFrom")+c] != '\"')
  13620. {
  13621. sstr[c] = loc[3+strlen("validFrom")+c];
  13622. c++;
  13623. }
  13624. sstr[c] = '\0';
  13625. strcpy(tempvalidFromStr,sstr);
  13626. }
  13627. else
  13628. {
  13629. strcpy(tempvalidFromStr,"");
  13630. }
  13631. //***********validTo **************/
  13632. c = 0;
  13633. loc = strstr(sLineWord, "validTo");
  13634. if(loc != NULL)
  13635. {
  13636. memset(sstr ,0, sizeof(sstr) );
  13637. while (loc[3+strlen("validTo")+c] != '\"')
  13638. {
  13639. sstr[c] = loc[3+strlen("validTo")+c];
  13640. c++;
  13641. }
  13642. sstr[c] = '\0';
  13643. strcpy(tempvalidToStr,sstr);
  13644. }
  13645. else
  13646. {
  13647. strcpy(tempvalidToStr,"");
  13648. }
  13649. //***********duration**************/
  13650. c = 0;
  13651. loc = strstr(sLineWord, "duration");
  13652. if(loc != NULL)
  13653. {
  13654. memset(sstr ,0, sizeof(sstr) );
  13655. while (loc[2+strlen("duration")+c] != ',')
  13656. {
  13657. sstr[c] = loc[2+strlen("duration")+c];
  13658. c++;
  13659. }
  13660. sstr[c] = '\0';
  13661. tempdurationInt = atoi(sstr);
  13662. }
  13663. else
  13664. {
  13665. tempdurationInt = 0;
  13666. }
  13667. //**********startSchedule**********/
  13668. c = 0;
  13669. loc = strstr(sLineWord, "startSchedule");
  13670. memset(sstr ,0, sizeof(sstr) );
  13671. while (loc[3+strlen("startSchedule")+c] != '\"')
  13672. {
  13673. sstr[c] = loc[3+strlen("startSchedule")+c];
  13674. c++;
  13675. }
  13676. sstr[c] = '\0';
  13677. strcpy(tempstartScheduleStr, sstr);
  13678. strcpy(TxDefaultProfileScheduleStr, sstr);
  13679. //**********chargingRateUnit**********/
  13680. c = 0;
  13681. loc = strstr(sLineWord, "chargingRateUnit");
  13682. memset(sstr ,0, sizeof(sstr) );
  13683. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13684. {
  13685. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13686. c++;
  13687. }
  13688. sstr[c] = '\0';
  13689. strcpy(tempchargingRateUnitStr, sstr);
  13690. //**********minChargingRate*******/
  13691. c = 0;
  13692. loc = strstr(sLineWord, "minChargingRate");
  13693. if(loc != NULL)
  13694. {
  13695. memset(sstr ,0, sizeof(sstr) );
  13696. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13697. {
  13698. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13699. c++;
  13700. }
  13701. sstr[c] = '\0';
  13702. tempminChargingRateFloat = atof(sstr);
  13703. }
  13704. else
  13705. {
  13706. tempminChargingRateFloat = 0.0;
  13707. }
  13708. //
  13709. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13710. tp.tm_isdst = -1;
  13711. time_t utc = mktime(&tp);
  13712. time_t t = time(NULL);
  13713. diff_t = difftime(t, utc);
  13714. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13715. //parsing strings to words
  13716. i = 0;
  13717. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13718. loc = loc+3+strlen("chargingSchedulePeriod");
  13719. pch = strtok(loc ,"{");
  13720. while (pch != NULL)
  13721. {
  13722. strcpy(SchedulePeriodList[i], pch);
  13723. pch = strtok (NULL, "{");
  13724. i = i + 1;
  13725. }
  13726. n_SchedulePeriods = i;
  13727. for(int i=0;i<n_SchedulePeriods;i++)
  13728. {
  13729. //*************startPeriod****************/
  13730. c = 0;
  13731. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13732. memset(sstr ,0, sizeof(sstr) );
  13733. while (loc[strlen("startPeriod")+2+c] != ',')
  13734. {
  13735. sstr[c] = loc[strlen("startPeriod")+2+c];
  13736. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13737. c++;
  13738. }
  13739. sstr[c] = '\0';
  13740. tempStartPeriodInt = atoi(sstr);
  13741. //*************limit****************/
  13742. c = 0;
  13743. loc = strstr(SchedulePeriodList[i], "limit");
  13744. memset(sstr ,0, sizeof(sstr) );
  13745. while (loc[strlen("limit")+2+c] != ',')
  13746. {
  13747. sstr[c] = loc[strlen("limit")+2+c];
  13748. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13749. c++;
  13750. }
  13751. sstr[c] = '\0';
  13752. tempLimitInt = atof(sstr);
  13753. //*************numberPhases****************/
  13754. c = 0;
  13755. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13756. memset(sstr ,0, sizeof(sstr) );
  13757. while (loc[strlen("numberPhases")+2+c] != '}')
  13758. {
  13759. sstr[c] = loc[strlen("numberPhases")+2+c];
  13760. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13761. c++;
  13762. }
  13763. sstr[c] = '\0';
  13764. tempNumberPhasesInt = atoi(sstr);
  13765. if(j == 0)
  13766. {
  13767. TxDefaultProfile.Duration = tempdurationInt;
  13768. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13769. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13770. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13771. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13772. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13773. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13774. TxDefaultProfile_TEMP.TransactionId = 0;
  13775. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13776. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13777. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13778. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13779. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13780. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13781. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13782. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13783. }
  13784. else
  13785. {
  13786. //other stack level charging Profile
  13787. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13788. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13789. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13790. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13791. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13792. }
  13793. }
  13794. if(MinChargingRate < tempminChargingRateFloat)
  13795. {
  13796. MinChargingRate = tempminChargingRateFloat;
  13797. }
  13798. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13799. if(confirmPeriods < n_SchedulePeriods)
  13800. confirmPeriods = n_SchedulePeriods;
  13801. j = j + 1;
  13802. }
  13803. fclose(fptr1);
  13804. //Stacking Charging Profiles
  13805. for(int l=0; l <(j-1) ;l++)
  13806. {
  13807. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13808. {
  13809. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13810. {
  13811. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13812. {
  13813. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13814. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13815. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13816. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13817. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13818. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13819. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13820. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13821. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13822. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13823. }
  13824. else
  13825. {
  13826. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13827. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13828. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13829. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13830. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13831. }
  13832. }
  13833. }
  13834. }//end of Stacking Charging Profiles
  13835. }// end else
  13836. }// the end of ACCESS TxDefaultProfile
  13837. //****************************TxProfile************************************************/
  13838. #if 0
  13839. switch(gunindex + 1)
  13840. {
  13841. case 0:
  13842. break;
  13843. case 1:
  13844. strcpy(fname, TxProfile_1_JSON );
  13845. break;
  13846. case 2:
  13847. strcpy(fname, TxProfile_2_JSON );
  13848. break;
  13849. default:
  13850. strcpy(fname, TxProfile_1_JSON );
  13851. break;
  13852. }
  13853. #endif
  13854. memset(fname, 0, sizeof fname);
  13855. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  13856. TxProfileIsNull=TRUE;
  13857. if((access(fname,F_OK))!=-1)
  13858. {
  13859. fptr1 = fopen(fname, "r");
  13860. c = 0;
  13861. c = fgetc(fptr1);
  13862. //DEBUG_INFO("c:%d\n",c);
  13863. rewind(fptr1);
  13864. if(c == EOF)
  13865. {
  13866. DEBUG_INFO("\n End of file reached.");
  13867. TxProfileIsNull=TRUE;
  13868. fclose(fptr1);
  13869. }
  13870. else
  13871. {
  13872. TxProfileIsNull=FALSE;
  13873. while(fscanf(fptr1, "%s", word) != EOF)
  13874. {
  13875. if(strcmp(word, "chargingProfileId") == 0)
  13876. {
  13877. n_chargingProfile = n_chargingProfile + 1;
  13878. }
  13879. }
  13880. rewind(fptr1);
  13881. //search Charging Profile Element
  13882. int i= 0;
  13883. int j= 0;
  13884. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13885. #if 0
  13886. /***********connectorId****************/
  13887. c = 0;
  13888. loc = strstr(sLineWord, "connectorId");
  13889. memset(sstr ,0, sizeof(sstr) );
  13890. while (loc[strlen("connectorId")+2+c] != ',')
  13891. {
  13892. sstr[c] = loc[strlen("connectorId")+2+c];
  13893. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13894. c++;
  13895. }
  13896. sstr[c] = '\0';
  13897. tempconnectorIdInt = atoi(sstr);
  13898. #endif
  13899. //***********chargingProfileId**************/
  13900. c = 0;
  13901. loc = strstr(sLineWord, "chargingProfileId");
  13902. memset(sstr ,0, sizeof(sstr) );
  13903. if(loc != NULL)
  13904. {
  13905. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13906. {
  13907. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13908. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13909. c++;
  13910. }
  13911. sstr[c] = '\0';
  13912. tempchargingProfileId = atoi(sstr);
  13913. }
  13914. else
  13915. {
  13916. tempchargingProfileId = 0;
  13917. }
  13918. //***********transactionId **************/
  13919. c = 0;
  13920. loc = strstr(sLineWord, "transactionId");
  13921. //DEBUG_INFO("loc=%s\n",loc);
  13922. memset(sstr ,0, sizeof(sstr) );
  13923. if(loc != NULL)
  13924. {
  13925. while (loc[2+strlen("transactionId")+c] != '\"')
  13926. {
  13927. sstr[c] = loc[2+strlen("transactionId")+c];
  13928. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13929. c++;
  13930. }
  13931. sstr[c] = '\0';
  13932. temptransactionId = atoi(sstr);
  13933. }
  13934. else
  13935. {
  13936. temptransactionId = 0;
  13937. }
  13938. //***********stackLevel**************/
  13939. c = 0;
  13940. loc = strstr(sLineWord, "stackLevel");
  13941. //DEBUG_INFO("loc=%s\n",loc);
  13942. memset(sstr ,0, sizeof(sstr) );
  13943. if(loc != NULL)
  13944. {
  13945. while (loc[2+strlen("stackLevel")+c] != '\"')
  13946. {
  13947. sstr[c] = loc[2+strlen("stackLevel")+c];
  13948. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13949. c++;
  13950. }
  13951. sstr[c] = '\0';
  13952. tempstackLevel = atoi(sstr);
  13953. }
  13954. else
  13955. {
  13956. tempstackLevel = 0;
  13957. }
  13958. //***********chargingProfilePurpose **************/
  13959. c = 0;
  13960. loc = strstr(sLineWord, "chargingProfilePurpose");
  13961. //DEBUG_INFO("loc=%s\n",loc);
  13962. memset(sstr ,0, sizeof(sstr) );
  13963. if(loc != NULL)
  13964. {
  13965. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13966. {
  13967. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13968. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13969. c++;
  13970. }
  13971. sstr[c] = '\0';
  13972. strcpy(tempchargingProfilePurposeStr,sstr);
  13973. }
  13974. else
  13975. {
  13976. strcpy(tempchargingProfilePurposeStr,"");
  13977. }
  13978. //***********chargingProfileKind **************/
  13979. c = 0;
  13980. loc = strstr(sLineWord, "chargingProfileKind");
  13981. //DEBUG_INFO("loc=%s\n",loc);
  13982. memset(sstr ,0, sizeof(sstr) );
  13983. if(loc != NULL)
  13984. {
  13985. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13986. {
  13987. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13988. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13989. c++;
  13990. }
  13991. sstr[c] = '\0';
  13992. strcpy(tempchargingProfileKindStr,sstr);
  13993. }
  13994. else
  13995. {
  13996. strcpy(tempchargingProfileKindStr,"");
  13997. }
  13998. //***********recurrencyKind **************/
  13999. c = 0;
  14000. loc = strstr(sLineWord, "recurrencyKind");
  14001. //DEBUG_INFO("loc=%s\n",loc);
  14002. memset(sstr ,0, sizeof(sstr) );
  14003. if(loc != NULL)
  14004. {
  14005. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14006. {
  14007. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14008. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14009. c++;
  14010. }
  14011. sstr[c] = '\0';
  14012. strcpy(temprecurrencyKindStr,sstr);
  14013. }
  14014. else
  14015. {
  14016. strcpy(temprecurrencyKindStr,"");
  14017. }
  14018. //***********validFrom**************/
  14019. c = 0;
  14020. loc = strstr(sLineWord, "validFrom");
  14021. if(loc != NULL)
  14022. {
  14023. memset(sstr ,0, sizeof(sstr) );
  14024. while (loc[3+strlen("validFrom")+c] != '\"')
  14025. {
  14026. sstr[c] = loc[3+strlen("validFrom")+c];
  14027. c++;
  14028. }
  14029. sstr[c] = '\0';
  14030. strcpy(tempvalidFromStr,sstr);
  14031. }
  14032. else
  14033. {
  14034. strcpy(tempvalidFromStr,"");
  14035. }
  14036. //***********validTo**************/
  14037. c = 0;
  14038. loc = strstr(sLineWord, "validTo");
  14039. if(loc != NULL)
  14040. {
  14041. memset(sstr ,0, sizeof(sstr) );
  14042. while (loc[3+strlen("validTo")+c] != '\"')
  14043. {
  14044. sstr[c] = loc[3+strlen("validTo")+c];
  14045. c++;
  14046. }
  14047. sstr[c] = '\0';
  14048. strcpy(tempvalidToStr,sstr);
  14049. }
  14050. else
  14051. {
  14052. strcpy(tempvalidToStr,"");
  14053. }
  14054. //***********duration**************/
  14055. c = 0;
  14056. loc = strstr(sLineWord, "duration");
  14057. //DEBUG_INFO("loc=%s\n",loc);
  14058. memset(sstr ,0, sizeof(sstr) );
  14059. if(loc != NULL)
  14060. {
  14061. while (loc[2+strlen("duration")+c] != '\"')
  14062. {
  14063. sstr[c] = loc[2+strlen("duration")+c];
  14064. c++;
  14065. }
  14066. sstr[c] = '\0';
  14067. tempdurationInt = atoi(sstr);
  14068. }
  14069. else
  14070. {
  14071. tempdurationInt = 0;
  14072. }
  14073. //**********startSchedule**********/
  14074. c = 0;
  14075. loc = strstr(sLineWord, "startSchedule");
  14076. memset(sstr ,0, sizeof(sstr) );
  14077. while (loc[3+strlen("startSchedule")+c] != '\"')
  14078. {
  14079. sstr[c] = loc[3+strlen("startSchedule")+c];
  14080. c++;
  14081. }
  14082. sstr[c] = '\0';
  14083. strcpy(tempstartScheduleStr, sstr);
  14084. strcpy(TxProfileScheduleStr, sstr);
  14085. //**********chargingRateUnit**********/
  14086. c = 0;
  14087. loc = strstr(sLineWord, "chargingRateUnit");
  14088. memset(sstr ,0, sizeof(sstr) );
  14089. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14090. {
  14091. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14092. c++;
  14093. }
  14094. sstr[c] = '\0';
  14095. strcpy(tempchargingRateUnitStr, sstr);
  14096. //**********minChargingRate*******/
  14097. c = 0;
  14098. loc = strstr(sLineWord, "minChargingRate");
  14099. if(loc != NULL)
  14100. {
  14101. memset(sstr ,0, sizeof(sstr) );
  14102. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14103. {
  14104. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14105. c++;
  14106. }
  14107. sstr[c] = '\0';
  14108. tempminChargingRateFloat = atof(sstr);
  14109. }
  14110. else
  14111. {
  14112. tempminChargingRateFloat = 0.0;
  14113. }
  14114. //
  14115. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14116. tp.tm_isdst = -1;
  14117. time_t utc = mktime(&tp);
  14118. time_t t = time(NULL);
  14119. diff_t = difftime(t, utc);
  14120. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14121. //parsing strings to words
  14122. i = 0;
  14123. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14124. loc = loc+3+strlen("chargingSchedulePeriod");
  14125. pch = strtok(loc ,"{");
  14126. while (pch != NULL)
  14127. {
  14128. strcpy(SchedulePeriodList[i], pch);
  14129. pch = strtok (NULL, "{");
  14130. i = i + 1;
  14131. }
  14132. n_SchedulePeriods = i;
  14133. for(int i=0;i<n_SchedulePeriods;i++)
  14134. {
  14135. //*************startPeriod****************/
  14136. c = 0;
  14137. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14138. memset(sstr ,0, sizeof(sstr) );
  14139. while (loc[strlen("startPeriod")+2+c] != ',')
  14140. {
  14141. sstr[c] = loc[strlen("startPeriod")+2+c];
  14142. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14143. c++;
  14144. }
  14145. sstr[c] = '\0';
  14146. tempStartPeriodInt = atoi(sstr);
  14147. //*************limit****************/
  14148. c = 0;
  14149. loc = strstr(SchedulePeriodList[i], "limit");
  14150. memset(sstr ,0, sizeof(sstr) );
  14151. while (loc[strlen("limit")+2+c] != ',')
  14152. {
  14153. sstr[c] = loc[strlen("limit")+2+c];
  14154. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14155. c++;
  14156. }
  14157. sstr[c] = '\0';
  14158. tempLimitInt = atof(sstr);
  14159. //*************numberPhases****************/
  14160. c = 0;
  14161. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14162. memset(sstr ,0, sizeof(sstr) );
  14163. while (loc[strlen("numberPhases")+2+c] != '}')
  14164. {
  14165. sstr[c] = loc[strlen("numberPhases")+2+c];
  14166. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14167. c++;
  14168. }
  14169. sstr[c] = '\0';
  14170. tempNumberPhasesInt = atoi(sstr);
  14171. //TxProfile.Duration = durationInt;
  14172. TxProfile.TotalPeriod = n_SchedulePeriods;
  14173. TxProfile.Period[i].Limit = tempLimitInt;
  14174. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14175. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14176. }
  14177. if(MinChargingRate < tempminChargingRateFloat)
  14178. {
  14179. MinChargingRate = tempminChargingRateFloat;
  14180. }
  14181. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14182. if(confirmPeriods < n_SchedulePeriods)
  14183. confirmPeriods = n_SchedulePeriods;
  14184. if(j == 0)
  14185. {
  14186. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14187. TxProfile_TEMP.StackLevel = tempstackLevel;
  14188. TxProfile_TEMP.TransactionId = 0;
  14189. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14190. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14191. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14192. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14193. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14194. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14195. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14196. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14197. }
  14198. }
  14199. fclose(fptr1);
  14200. }
  14201. }// the end of ACCESS TxProfile
  14202. //-----------------------------------------------CompositeSchedule--------------------------//
  14203. int period=0;
  14204. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14205. {
  14206. //TxProfile
  14207. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14208. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14209. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14210. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14211. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14212. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14213. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14214. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14215. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14216. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14217. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14218. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14219. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14220. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14221. {
  14222. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14223. {
  14224. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14225. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14226. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14227. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14228. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14229. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14230. period = period + 1;
  14231. }
  14232. else
  14233. {
  14234. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14235. {
  14236. }
  14237. else
  14238. {
  14239. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14240. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14241. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14242. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14243. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14244. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14245. period = period + 1;
  14246. }
  14247. }
  14248. }
  14249. struct tm tp;
  14250. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14251. tp.tm_isdst = -1;
  14252. time_t utc = mktime(&tp);
  14253. time_t t = time(NULL);
  14254. double diff_f = difftime(t, utc);
  14255. int diff_i;// = (int)diff_f;
  14256. int quotient; // = diff_i / 86400;//86400 seconds/day
  14257. if(diff_f >= 0)
  14258. {
  14259. diff_i = (int)diff_f;
  14260. quotient = diff_i / 86400;//86400 seconds/day
  14261. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14262. {
  14263. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  14264. {
  14265. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14266. {
  14267. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14268. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14269. }
  14270. else
  14271. {
  14272. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14273. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14274. }
  14275. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14276. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14277. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14278. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14279. period = period + 1;
  14280. }
  14281. }
  14282. }// end of if(diff_f >= 0)
  14283. }
  14284. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14285. {
  14286. //TxDefaultProfile
  14287. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14288. struct tm tp;
  14289. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14290. tp.tm_isdst = -1;
  14291. time_t utc = mktime(&tp);
  14292. time_t t = time(NULL);
  14293. double diff_f = difftime(t, utc);
  14294. int diff_i;// = (int)diff_f;
  14295. int quotient; // = diff_i / 86400;//86400 seconds/day
  14296. int remainder;
  14297. //---- Define StartSchedule----/
  14298. struct tm *gtime;
  14299. time_t now;
  14300. char buf[28];
  14301. //---Read the current system time---/
  14302. time(&now);
  14303. //---Convert the system time to GMT (now UTC)---/
  14304. gtime = gmtime(&now);
  14305. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14306. if(diff_f >= 0)
  14307. {
  14308. diff_i = (int)diff_f;
  14309. quotient = diff_i / 86400;//86400 seconds/day
  14310. remainder = diff_i % 86400;
  14311. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14312. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14313. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14314. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  14315. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14316. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14317. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14318. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14319. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14320. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14321. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14322. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14323. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14324. {
  14325. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14326. {
  14327. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14328. {
  14329. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14330. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14331. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14332. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14333. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14334. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14335. period = period + 1;
  14336. }
  14337. else
  14338. {
  14339. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14340. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14341. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14342. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14343. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14344. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14345. period = period + 1;
  14346. }
  14347. }
  14348. }
  14349. } // end of diff_f >= 0
  14350. }
  14351. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14352. {
  14353. //TxDefaultProfile
  14354. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14355. struct tm tp;
  14356. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14357. tp.tm_isdst = -1;
  14358. time_t utc = mktime(&tp);
  14359. time_t t = time(NULL);
  14360. double diff_f = difftime(t, utc);
  14361. int diff_i;// = (int)diff_f;
  14362. int quotient; // = diff_i / 86400;//86400 seconds/day
  14363. int remainder;
  14364. //---- Define StartSchedule----/
  14365. struct tm *gtime;
  14366. time_t now;
  14367. char buf[28];
  14368. //---Read the current system time---/
  14369. time(&now);
  14370. //---Convert the system time to GMT (now UTC)---/
  14371. gtime = gmtime(&now);
  14372. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14373. if(diff_f >= 0)
  14374. {
  14375. diff_i = (int)diff_f;
  14376. quotient = diff_i / 86400;//86400 seconds/day
  14377. remainder = diff_i % 86400;
  14378. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14379. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14380. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14381. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14383. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14384. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14385. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14386. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14387. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  14388. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14389. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14390. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14391. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14392. {
  14393. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14394. {
  14395. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14396. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14397. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14398. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14399. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14400. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14401. period = period + 1;
  14402. }
  14403. }
  14404. } //end of diff_f >= 0
  14405. }
  14406. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14407. {
  14408. //ChargePointMaxProfile
  14409. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14410. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14411. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14412. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14413. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14414. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14415. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14416. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14417. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14418. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14419. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14420. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14421. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14422. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  14423. {
  14424. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14425. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14426. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14427. period = period + 1;
  14428. }
  14429. }
  14430. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14431. {
  14432. //TxProfile Daily
  14433. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14434. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14435. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14436. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14437. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14438. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14439. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14440. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14441. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14442. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14443. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14444. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14445. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14446. for(int l=0; l< TxProfile.TotalPeriod; l++)
  14447. {
  14448. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  14449. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  14450. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  14451. }
  14452. }
  14453. confirmPeriods = period;
  14454. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14455. 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,"
  14456. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14457. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14458. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14459. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14460. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14461. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14462. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14463. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14464. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14465. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14466. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14467. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14468. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14469. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14470. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14471. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14472. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14473. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14474. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14475. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14476. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14477. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14478. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14479. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14480. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14481. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14482. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14483. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14484. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14485. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14486. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14487. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14488. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14489. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14490. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14491. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14492. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14493. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14494. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14495. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14496. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14497. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14498. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14499. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14500. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14501. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14502. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14503. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14504. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14505. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14506. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14507. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14508. }
  14509. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14510. {
  14511. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14512. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14513. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14514. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14515. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14516. }
  14517. int GetWebSocketPingInterval(void)
  14518. {
  14519. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14520. }
  14521. int GetInternetConn(void)
  14522. {
  14523. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14524. }
  14525. void LWS_Send(char * str)
  14526. {
  14527. //=====================================================
  14528. // Check InternetConn 0: disconnected, 1: connected
  14529. //====================================================
  14530. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14531. {
  14532. DEBUG_INFO("\n offline now !!!\n");
  14533. return;
  14534. }
  14535. pthread_mutex_lock(&lock);
  14536. memset(SendBuffer,0,SendBufLen);
  14537. sprintf((char *)SendBuffer, "%s", str);
  14538. pthread_mutex_unlock(&lock);
  14539. lws_callback_on_writable(wsi_client);
  14540. lws_service(context, 10000);//timeout_ms
  14541. }