MessageHandler.c 609 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898
  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. // Configuration: unknownkey
  87. //===============================
  88. static char unknownkey[10][20]={0};
  89. static int UnknownKeynum = 0;
  90. //===============================
  91. // Gun Total Numbers
  92. //===============================
  93. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  94. static int gunTotalNumber=0;
  95. //===============================
  96. // Local List Version
  97. //===============================
  98. static int localversion=0;
  99. static char idTagAuthorization[32]={0};
  100. //===============================
  101. // OCPP Path
  102. //===============================
  103. extern char OcppPath[160];
  104. extern char OcppProtocol[10];
  105. extern char OcppHost[50];
  106. extern char OcppTempPath[50];
  107. int OcppPort=0;
  108. //===============================
  109. // OCPP sign variable
  110. //===============================
  111. int server_sign = FALSE;
  112. int server_pending = FALSE;
  113. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  114. int BootNotificationInterval = 0;
  115. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  116. //===============================
  117. // OCPP auth variable
  118. //===============================
  119. int authenrequest = FALSE;
  120. int authorizeRetryTimes = 0; //number of Retry times
  121. //===============================
  122. // OCPP StartTransaction transactionId variables
  123. //===============================
  124. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  125. //===============================
  126. // OCPP other variables
  127. //===============================
  128. int isUpdateRequest = FALSE;
  129. static int HeartBeatWaitTime = 10;
  130. static int FirstHeartBeat = 0;
  131. static int FirmwareStatusNotificationStatus = 3; // Idle
  132. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  133. static char CurrentChargingProfileScheduleStr[30]={0};
  134. //========================================
  135. // OCPP status/previous related variables
  136. //========================================
  137. static int GunStatusInterval = 10;
  138. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  139. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  140. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  141. static int GbPreviousSystemStatus[GB_QUANTITY];
  142. static int AcPreviousSystemStatus[AC_QUANTITY];
  143. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  144. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  145. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  146. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  147. int TransactionMessageAttemptsValue = 0;
  148. int TransactionMessageRetryIntervalValue = 0;
  149. static struct OCPPAuthLocalElemet
  150. {
  151. int listVersionInt;
  152. char idTagstr[20];
  153. char parentIdTag[20];
  154. char expiryDate[30];
  155. char idTagstatus[16];
  156. }idTagQuery;
  157. //=============================================
  158. // OCPP HeartBeat Response Not Receive Counts
  159. //============================================
  160. static int HeartBeatWithNOResponse = 0;
  161. static int HeartBeatCountPerHour = 0;
  162. extern struct lws *wsi_client;
  163. extern struct lws_context *context;
  164. extern unsigned char SendBuffer[4096];
  165. extern int SendBufLen;
  166. extern char *random_uuid( char buf[37] );
  167. extern void split(char **arr, char *str, const char *del);
  168. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  169. extern int GetTransactionQueueNum(void);
  170. extern pthread_mutex_t mutex1;
  171. extern struct Charger_Info Charger;
  172. extern sqlite3 *db;
  173. int TransactionMessageAttemptsGet(void);
  174. int TransactionMessageRetryIntervalGet(void);
  175. int GetOcppConnStatus(void);
  176. void SetOcppConnStatus(uint8_t status);
  177. int updateSetting(char *key, char *value);
  178. int setKeyValue(char *key, char *value);
  179. void OCPP_get_TableAuthlocalAllData(void);
  180. void processUnkownKey(void);
  181. struct StructOCPPMeterValue
  182. {
  183. unsigned char TimeStamp[28];
  184. struct StructSampledValue SampledValue[10];
  185. };
  186. struct ClientTime
  187. {
  188. unsigned int Heartbeat;
  189. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  190. unsigned int StartTransaction;
  191. unsigned int StopTransaction;
  192. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  193. }clientTime;
  194. typedef union
  195. {
  196. //Operations Initiated by Central System
  197. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  198. struct
  199. {
  200. //CsMsgValue[0]
  201. unsigned char StatusNotificationReq :1; //bit 0,
  202. unsigned char StatusNotificationConf :1; //bit 0,
  203. unsigned char :6; //bit 2~7
  204. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  205. }CpinitiateMsg;
  206. CpinitiateMsg cpinitateMsg;
  207. //==========================================
  208. // Init all Enumeration & Mapping String
  209. //==========================================
  210. /*ChargePointErrorCode*/
  211. typedef enum {
  212. ConnectorLockFailure,
  213. EVCommunicationError,
  214. GroundFailure,
  215. HighTemperature,
  216. InternalError,
  217. LocalListConflict,
  218. NoError,
  219. OtherError,
  220. OverCurrentFailure,
  221. OverVoltage,
  222. PowerMeterFailure,
  223. PowerSwitchFailure,
  224. ReaderFailure,
  225. ResetFailure,
  226. UnderVoltage,
  227. WeakSignal
  228. } ChargePointErrorCode;
  229. #if 0
  230. static char *ChargePointErrorCodeStr[] = {
  231. MACROSTR(ConnectorLockFailure),
  232. MACROSTR(EVCommunicationError),
  233. MACROSTR(GroundFailure),
  234. MACROSTR(HighTemperature),
  235. MACROSTR(InternalError),
  236. MACROSTR(LocalListConflict),
  237. MACROSTR(NoError),
  238. MACROSTR(OtherError),
  239. MACROSTR(OverCurrentFailure),
  240. MACROSTR(OverVoltage),
  241. MACROSTR(PowerMeterFailure),
  242. MACROSTR(PowerSwitchFailure),
  243. MACROSTR(ReaderFailure),
  244. MACROSTR(ResetFailure),
  245. MACROSTR(UnderVoltage),
  246. MACROSTR(WeakSignal)
  247. };
  248. #endif
  249. /*ChargePointStatus*/
  250. typedef enum {
  251. Available =0,
  252. Preparing,
  253. Charging,
  254. SuspendedEVSE,
  255. SuspendedEV,
  256. Finishing,
  257. Reserved,
  258. Unavailable,
  259. Faulted
  260. } ChargePointStatus;
  261. static char * ChargePointStatusStr[] = {
  262. MACROSTR(Available),
  263. MACROSTR(Preparing),
  264. MACROSTR(Charging),
  265. MACROSTR(SuspendedEVSE),
  266. MACROSTR(SuspendedEV),
  267. MACROSTR(Finishing),
  268. MACROSTR(Reserved),
  269. MACROSTR(Unavailable),
  270. MACROSTR(Faulted)
  271. };
  272. /*AvailabilityType*/
  273. typedef enum {
  274. RegistrationStatus_Accepted,
  275. RegistrationStatus_Pending,
  276. RegistrationStatus_Rejected
  277. } RegistrationStatus;
  278. static char *RegistrationStatusStr[] = {
  279. MACROSTR(Accepted),
  280. MACROSTR(Pending),
  281. MACROSTR(Rejected)
  282. };
  283. /*AvailabilityType*/
  284. typedef enum {
  285. Inoperative,
  286. Operative
  287. } AvailabilityType;
  288. static char *AvailabilityTypeStr[] = {
  289. MACROSTR(Inoperative),
  290. MACROSTR(Operative)
  291. };
  292. /*AvailabilityStatus*/
  293. typedef enum {
  294. Accepted,
  295. Rejected,
  296. Scheduled
  297. } AvailabilityStatus;
  298. static char *AvailabilityStatusStr[] = {
  299. MACROSTR(Accepted),
  300. MACROSTR(Rejected),
  301. MACROSTR(Scheduled)
  302. };
  303. /*ConfigurationStatus*/
  304. typedef enum {
  305. ConfigurationStatus_Accepted,
  306. ConfigurationStatus_Rejected,
  307. RebootRequired,
  308. NotSupported
  309. } ConfigurationStatus;
  310. static char *ConfigurationStatusStr[] = {
  311. MACROSTR(Accepted),
  312. MACROSTR(Rejected),
  313. MACROSTR(RebootRequired),
  314. MACROSTR(NotSupported)
  315. };
  316. /*ClearCacheStatus*/
  317. typedef enum {
  318. ClearCacheStatus_Accepted,
  319. ClearCacheStatus_Rejected
  320. } ClearCacheStatus;
  321. static char *ClearCacheStatusStr[] = {
  322. MACROSTR(Accepted),
  323. MACROSTR(Rejected)
  324. };
  325. /*ChargingProfilePurposeType*/
  326. typedef enum {
  327. ChargePointMaxProfile,
  328. TxDefaultProfile,
  329. TxProfile
  330. } ChargingProfilePurposeType;
  331. static char *ChargingProfilePurposeTypeStr[] = {
  332. MACROSTR(ChargePointMaxProfile),
  333. MACROSTR(TxDefaultProfile),
  334. MACROSTR(TxProfile)
  335. };
  336. /*ChargingProfileStatus*/
  337. typedef enum {
  338. ChargingProfileStatus_Accepted,
  339. ChargingProfileStatus_Rejected,
  340. ChargingProfileStatus_NotSupported
  341. } ChargingProfileStatus;
  342. static char *ChargingProfileStatusStr[] = {
  343. MACROSTR(Accepted),
  344. MACROSTR(Rejected),
  345. MACROSTR(NotSupported)
  346. };
  347. /*ClearChargingProfileStatus*/
  348. typedef enum {
  349. ClearChargingProfileStatus_Accepted,
  350. ClearChargingProfileStatus_Unknown
  351. } ClearChargingProfileStatus;
  352. static char *ClearChargingProfileStatusStr[] = {
  353. MACROSTR(Accepted),
  354. MACROSTR(Unknown)
  355. };
  356. /*GetCompositeScheduleStatus*/
  357. typedef enum {
  358. GetCompositeScheduleStatus_Accepted,
  359. GetCompositeScheduleStatus_Rejected
  360. } GetCompositeScheduleStatus;
  361. static char *GetCompositeScheduleStatusStr[] = {
  362. MACROSTR(Accepted),
  363. MACROSTR(Rejected)
  364. };
  365. /*ChargingRateUnitType*/
  366. typedef enum {
  367. ChargingRateUnitType_W,
  368. ChargingRateUnitType_A
  369. } ChargingRateUnitType;
  370. /*AuthorizationStatus*/
  371. typedef enum {
  372. AuthorizationStatus_Accepted ,
  373. AuthorizationStatus_Blocked ,
  374. AuthorizationStatus_Expired ,
  375. AuthorizationStatus_Invalid ,
  376. AuthorizationStatus_ConcurrentTx
  377. } AuthorizationStatus;
  378. /*UpdateType*/
  379. typedef enum {
  380. Differential ,
  381. Full
  382. } UpdateType;
  383. static char *UpdateTypeStr[] = {
  384. MACROSTR(Differential),
  385. MACROSTR(Full)
  386. };
  387. /*UpdateStatus*/
  388. typedef enum {
  389. UpdateStatus_Accepted ,
  390. UpdateStatus_Failed ,
  391. UpdateStatus_NotSupported ,
  392. UpdateStatus_VersionMismatch
  393. } UpdateStatus;
  394. static char *UpdateStatusStr[] = {
  395. MACROSTR(Accepted),
  396. MACROSTR(Failed),
  397. MACROSTR(NotSupported),
  398. MACROSTR(VersionMismatch)
  399. };
  400. /*RemoteStartStopStatus*/
  401. typedef enum {
  402. RemoteStartStopStatus_Accepted,
  403. RemoteStartStopStatus_Rejected
  404. } RemoteStartStopStatus;
  405. static char *RemoteStartStopStatusStr[] = {
  406. MACROSTR(Accepted),
  407. MACROSTR(Rejected)
  408. };
  409. /*ReservationStatus*/
  410. typedef enum {
  411. ReservationStatus_Accepted,
  412. ReservationStatus_Faulted,
  413. ReservationStatus_Occupied,
  414. ReservationStatus_Rejected,
  415. ReservationStatus_Unavailable
  416. } ReservationStatus;
  417. static char *ReservationStatusStr[] = {
  418. MACROSTR(Accepted),
  419. MACROSTR(Faulted),
  420. MACROSTR(Occupied),
  421. MACROSTR(Rejected),
  422. MACROSTR(Unavailable)
  423. };
  424. /*ResetType*/
  425. typedef enum {
  426. Hard,
  427. Soft
  428. } ResetType;
  429. static char *ResetTypeStr[] = {
  430. MACROSTR(Hard),
  431. MACROSTR(Soft)
  432. };
  433. /*ResetStatus*/
  434. typedef enum {
  435. ResetStatus_Accepted,
  436. ResetStatus_Rejected
  437. } ResetStatus;
  438. static char *ResetStatusStr[] = {
  439. MACROSTR(Accepted),
  440. MACROSTR(Rejected)
  441. };
  442. /*DiagnosticsStatus*/
  443. typedef enum {
  444. DiagnosticsStatus_Idle,
  445. DiagnosticsStatus_Uploaded,
  446. DiagnosticsStatus_UploadFailed,
  447. DiagnosticsStatus_Uploading
  448. } DiagnosticsStatus;
  449. static char * DiagnosticsStatusStr[] = {
  450. MACROSTR(Idle),
  451. MACROSTR(Uploaded),
  452. MACROSTR(UploadFailed),
  453. MACROSTR(Uploading)
  454. };
  455. /*FirmwareStatus*/
  456. typedef enum {
  457. FirmwareStatus_Downloaded,
  458. FirmwareStatus_DownloadFailed,
  459. FirmwareStatus_Downloading,
  460. FirmwareStatus_Idle,
  461. FirmwareStatus_InstallationFailed,
  462. FirmwareStatus_Installing,
  463. FirmwareStatus_Installed
  464. } FirmwareStatus;
  465. static char * FirmwareStatusStr[] = {
  466. MACROSTR(Downloaded),
  467. MACROSTR(DownloadFailed),
  468. MACROSTR(Downloading),
  469. MACROSTR(Idle),
  470. MACROSTR(InstallationFailed),
  471. MACROSTR(Installing),
  472. MACROSTR(Installed)
  473. };
  474. /*MessageTrigger*/
  475. typedef enum {
  476. BootNotification,
  477. DiagnosticsStatusNotification,
  478. FirmwareStatusNotification,
  479. Heartbeat,
  480. MeterValues,
  481. StatusNotification
  482. } MessageTrigger;
  483. static char * MessageTriggerStr[] = {
  484. MACROSTR(BootNotification),
  485. MACROSTR(DiagnosticsStatusNotification),
  486. MACROSTR(FirmwareStatusNotification),
  487. MACROSTR(Heartbeat),
  488. MACROSTR(MeterValues),
  489. MACROSTR(StatusNotification)
  490. };
  491. /*TriggerMessageStatus*/
  492. typedef enum {
  493. TriggerMessageStatus_Accepted ,
  494. TriggerMessageStatus_Rejected ,
  495. TriggerMessageStatus_NotImplemented
  496. } TriggerMessageStatus;
  497. static char * TriggerMessageStatusStr[] = {
  498. MACROSTR(Accepted),
  499. MACROSTR(Rejected),
  500. MACROSTR(NotImplemented)
  501. };
  502. /*UnlockStatus*/
  503. typedef enum {
  504. Unlocked,
  505. UnlockFailed,
  506. UnlockStatus_NotSupported
  507. } UnlockStatus;
  508. static char * UnlockStatusStr[] = {
  509. MACROSTR(Unlocked),
  510. MACROSTR(UnlockFailed),
  511. MACROSTR(NotSupported)
  512. };
  513. /*StopTransactionReason*/
  514. typedef enum {
  515. EmergencyStop,
  516. EVDisconnected,
  517. HardReset,
  518. Local,
  519. Other,
  520. PowerLoss,
  521. Reboot,
  522. Remote,
  523. SoftReset,
  524. UnlockCommand,
  525. DeAuthorized
  526. } StopTransactionReason;
  527. #if 0
  528. static char * StopTransactionReasonStr[] = {
  529. MACROSTR(EmergencyStop),
  530. MACROSTR(EVDisconnected),
  531. MACROSTR(HardReset),
  532. MACROSTR(Local),
  533. MACROSTR(Other),
  534. MACROSTR(PowerLoss),
  535. MACROSTR(Reboot),
  536. MACROSTR(Remote),
  537. MACROSTR(SoftReset),
  538. MACROSTR(UnlockCommand),
  539. MACROSTR(DeAuthorized)
  540. };
  541. #endif
  542. /*CancelReservationStatus*/
  543. typedef enum {
  544. CancelReservationStatus_Accepted,
  545. CancelReservationStatus_Rejected
  546. } CancelReservationStatus;
  547. static char * CancelReservationStatusStr[] = {
  548. MACROSTR(Accepted),
  549. MACROSTR(Rejected)
  550. };
  551. /*ReadingContext*/
  552. typedef enum {
  553. ReadingContext_Interruption_Begin,
  554. ReadingContext_Interruption_End,
  555. ReadingContext_Other,
  556. ReadingContext_Sample_Clock,
  557. ReadingContext_Sample_Periodic ,
  558. ReadingContext_Transaction_Begin ,
  559. ReadingContext_Transaction_End,
  560. ReadingContext_Trigger
  561. } ReadingContext;
  562. static char * ReadingContextStr[] = {
  563. MACROSTR(Interruption.Begin),
  564. MACROSTR(Interruption.End),
  565. MACROSTR(Other),
  566. MACROSTR(Sample.Clock),
  567. MACROSTR(Sample.Periodic),
  568. MACROSTR(Transaction.Begin),
  569. MACROSTR(Transaction.End),
  570. MACROSTR(Trigger)
  571. };
  572. /*ValueFormat*/
  573. typedef enum {
  574. Raw,
  575. SignedData
  576. } ValueFormat;
  577. static char * ValueFormatStr[] = {
  578. MACROSTR(Raw),
  579. MACROSTR(SignedData)
  580. };
  581. /*Measurand*/
  582. typedef enum {
  583. Current_Export ,
  584. Current_Import,
  585. Current_Offered,
  586. Energy_Active_Export_Register,
  587. Energy_Active_Import_Register,
  588. Energy_Reactive_Export_Register,
  589. Energy_Reactive_Import_Register,
  590. Energy_Active_Export_Interval,
  591. Energy_Active_Import_Interval,
  592. Energy_Reactive_Export_Interval,
  593. Energy_Reactive_Import_Interval,
  594. Frequency,
  595. Power_Active_Export ,
  596. Power_Active_Import,
  597. Power_Factor,
  598. Power_Offered,
  599. Power_Reactive_Export,
  600. Power_Reactive_Import,
  601. RPM,
  602. SoC,
  603. Temperature ,
  604. Voltage
  605. } Measurand;
  606. static char * MeasurandStr[] = {
  607. MACROSTR(Current.Export),
  608. MACROSTR(Current.Import),
  609. MACROSTR(Current.Offered),
  610. MACROSTR(Energy.Active.Export.Register),
  611. MACROSTR(Energy.Active.Import.Register),
  612. MACROSTR(Energy.Reactive.Export.Register),
  613. MACROSTR(Energy.Reactive.Import.Register),
  614. MACROSTR(Energy.Active.Export.Interval),
  615. MACROSTR(Energy.Active.Import.Interval),
  616. MACROSTR(Energy.Reactive.Export.Interval),
  617. MACROSTR(Energy.Reactive.Import.Interval),
  618. MACROSTR(Frequency),
  619. MACROSTR(Power.Active.Export),
  620. MACROSTR(Power.Active.Import),
  621. MACROSTR(Power.Factor),
  622. MACROSTR(Power.Offered),
  623. MACROSTR(Power.Reactive.ExportMACROSTR),
  624. MACROSTR(Power.Reactive.Import),
  625. MACROSTR(RPM),
  626. MACROSTR(SoC),
  627. MACROSTR(Temperature),
  628. MACROSTR(Voltage)
  629. };
  630. /*Location*/
  631. typedef enum {
  632. Location_Body,
  633. Location_Cable,
  634. Location_EV,
  635. Location_Inlet ,
  636. Location_Outlet
  637. } Location;
  638. static char * LocationStr[] = {
  639. MACROSTR(Body),
  640. MACROSTR(Cable),
  641. MACROSTR(EV),
  642. MACROSTR(Inlet),
  643. MACROSTR(Outlet)
  644. };
  645. /*Phase*/
  646. typedef enum {
  647. L1,
  648. L2,
  649. L3,
  650. N,
  651. L1_N,
  652. L2_N,
  653. L3_N,
  654. L1_L2,
  655. L2_L3,
  656. L3_L1
  657. } Phase;
  658. static char * PhaseStr[] = {
  659. MACROSTR(L1),
  660. MACROSTR(L2),
  661. MACROSTR(L3),
  662. MACROSTR(N),
  663. MACROSTR(L1-N),
  664. MACROSTR(L2-N),
  665. MACROSTR(L3-N),
  666. MACROSTR(L1-L2),
  667. MACROSTR(L2-L3),
  668. MACROSTR(L3-L1)
  669. };
  670. /*UnitOfMeasure*/
  671. typedef enum {
  672. UnitOfMeasure_Wh,
  673. UnitOfMeasure_kWh ,
  674. UnitOfMeasure_varh ,
  675. UnitOfMeasure_kvarh ,
  676. UnitOfMeasure_W ,
  677. UnitOfMeasure_kW ,
  678. UnitOfMeasure_VA ,
  679. UnitOfMeasure_kVA ,
  680. UnitOfMeasure_var ,
  681. UnitOfMeasure_kvar ,
  682. UnitOfMeasure_A ,
  683. UnitOfMeasure_V ,
  684. UnitOfMeasure_Celsius ,
  685. UnitOfMeasure_Fahrenheit ,
  686. UnitOfMeasure_K ,
  687. UnitOfMeasure_Percent
  688. } UnitOfMeasure;
  689. static char * UnitOfMeasureStr[] = {
  690. MACROSTR(Wh),
  691. MACROSTR(kWh),
  692. MACROSTR(varh),
  693. MACROSTR(kvarh),
  694. MACROSTR(W),
  695. MACROSTR(kW),
  696. MACROSTR(VA),
  697. MACROSTR(kVA),
  698. MACROSTR(var),
  699. MACROSTR(kvar),
  700. MACROSTR(A),
  701. MACROSTR(V),
  702. MACROSTR(Celsius),
  703. MACROSTR(Fahrenheit),
  704. MACROSTR(K),
  705. MACROSTR(Percent)
  706. };
  707. #if 0
  708. /*Configuration enum*/
  709. enum CoreProfile {
  710. AllowOfflineTxForUnknownId=0,
  711. AuthorizationCacheEnabled,
  712. AuthorizeRemoteTxRequests,
  713. BlinkRepeat,
  714. ClockAlignedDataInterval,
  715. ConnectionTimeOut,
  716. GetConfigurationMaxKeys,
  717. HeartbeatInterval,
  718. LightIntensity,
  719. LocalAuthorizeOffline,
  720. LocalPreAuthorize,
  721. MaxEnergyOnInvalidId,
  722. MeterValuesAlignedData,
  723. MeterValuesAlignedDataMaxLength,
  724. MeterValuesSampledData,
  725. MeterValuesSampledDataMaxLength,
  726. MeterValueSampleInterval,
  727. MinimumStatusDuration,
  728. NumberOfConnectors,
  729. ResetRetries,
  730. ConnectorPhaseRotation,
  731. ConnectorPhaseRotationMaxLength,
  732. StopTransactionOnEVSideDisconnect,
  733. StopTransactionOnInvalidId,
  734. StopTxnAlignedData,
  735. StopTxnAlignedDataMaxLength,
  736. StopTxnSampledData,
  737. StopTxnSampledDataMaxLength,
  738. SupportedFeatureProfiles,
  739. SupportedFeatureProfilesMaxLength,
  740. TransactionMessageAttempts,
  741. TransactionMessageRetryInterval,
  742. UnlockConnectorOnEVSideDisconnect,
  743. WebSocketPingInterval,
  744. _CoreProfile_CNT
  745. };
  746. #endif
  747. enum LocalAuthListManagementProfile{
  748. LocalAuthListEnabled=0,
  749. LocalAuthListMaxLength,
  750. SendLocalListMaxLength,
  751. _LocalAuthListManagementProfile_CNT
  752. };
  753. enum ReservationProfile{
  754. ReserveConnectorZeroSupported
  755. };
  756. enum SmartChargingProfile{
  757. ChargeProfileMaxStackLevel,
  758. ChargingScheduleAllowedChargingRateUnit,
  759. ChargingScheduleMaxPeriods,
  760. ConnectorSwitch3to1PhaseSupported,
  761. MaxChargingProfilesInstalled
  762. };
  763. enum ChargerSystemStatus{
  764. ChargerSystemStatus_Booting,
  765. ChargerSystemStatus_Idle,
  766. ChargerSystemStatus_Authorizing,
  767. ChargerSystemStatus_Preparing,
  768. ChargerSystemStatus_Charging,
  769. ChargerSystemStatus_Terminating,
  770. ChargerSystemStatus_Alarm,
  771. ChargerSystemStatus_Fault
  772. };
  773. enum GetConfigurationKey {
  774. GetConfiguration_AllowOfflineTxForUnknownId=0,
  775. GetConfiguration_AuthorizationCacheEnabled,
  776. GetConfiguration_AuthorizeRemoteTxRequests,
  777. GetConfiguration_BlinkRepeat,
  778. GetConfiguration_ClockAlignedDataInterval,
  779. GetConfiguration_ConnectionTimeOut,
  780. GetConfiguration_GetConfigurationMaxKeys,
  781. GetConfiguration_HeartbeatInterval,
  782. GetConfiguration_LightIntensity,
  783. GetConfiguration_LocalAuthorizeOffline,
  784. GetConfiguration_LocalPreAuthorize,
  785. GetConfiguration_MaxEnergyOnInvalidId,
  786. GetConfiguration_MeterValuesAlignedData,
  787. GetConfiguration_MeterValuesAlignedDataMaxLength,
  788. GetConfiguration_MeterValuesSampledData,
  789. GetConfiguration_MeterValuesSampledDataMaxLength,
  790. GetConfiguration_MeterValueSampleInterval,
  791. GetConfiguration_MinimumStatusDuration,
  792. GetConfiguration_NumberOfConnectors,
  793. GetConfiguration_ResetRetries,
  794. GetConfiguration_ConnectorPhaseRotation,
  795. GetConfiguration_ConnectorPhaseRotationMaxLength,
  796. GetConfiguration_StopTransactionOnEVSideDisconnect,
  797. GetConfiguration_StopTransactionOnInvalidId,
  798. GetConfiguration_StopTxnAlignedData,
  799. GetConfiguration_StopTxnAlignedDataMaxLength,
  800. GetConfiguration_StopTxnSampledData,
  801. GetConfiguration_StopTxnSampledDataMaxLength,
  802. GetConfiguration_SupportedFeatureProfiles,
  803. GetConfiguration_SupportedFeatureProfilesMaxLength,
  804. GetConfiguration_TransactionMessageAttempts,
  805. GetConfiguration_TransactionMessageRetryInterval,
  806. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  807. GetConfiguration_WebSocketPingInterval,
  808. GetConfiguration_LocalAuthListEnabled,
  809. GetConfiguration_LocalAuthListMaxLength,
  810. GetConfiguration_SendLocalListMaxLength,
  811. GetConfiguration_ReserveConnectorZeroSupported,
  812. GetConfiguration_ChargeProfileMaxStackLevel,
  813. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  814. GetConfiguration_ChargingScheduleMaxPeriods,
  815. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  816. GetConfiguration_MaxChargingProfilesInstalled,
  817. };
  818. //GetConfiguration Array
  819. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  820. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  821. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  822. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  823. //==========================================
  824. // Init all share memory
  825. //==========================================
  826. int InitShareMemory()
  827. {
  828. int result = PASS;
  829. int MeterSMId;
  830. //creat ShmSysConfigAndInfo
  831. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  832. {
  833. #ifdef SystemLogMessage
  834. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  835. #endif
  836. result = FAIL;
  837. }
  838. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  839. {
  840. #ifdef SystemLogMessage
  841. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  842. #endif
  843. result = FAIL;
  844. }
  845. else
  846. {}
  847. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  848. {
  849. #ifdef SystemLogMessage
  850. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  851. #endif
  852. result = FAIL;
  853. }
  854. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  855. {
  856. #ifdef SystemLogMessage
  857. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  858. #endif
  859. result = FAIL;
  860. }
  861. else
  862. {}
  863. //creat ShmPsuData
  864. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  865. {
  866. #ifdef SystemLogMessage
  867. DEBUG_ERROR("shmget ShmPsuData NG\n");
  868. #endif
  869. result = FAIL;
  870. }
  871. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  872. {
  873. #ifdef SystemLogMessage
  874. DEBUG_ERROR("shmat ShmPsuData NG\n");
  875. #endif
  876. result = FAIL;
  877. }
  878. else
  879. {}
  880. //creat ShmOCPP16Data
  881. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  882. {
  883. #ifdef SystemLogMessage
  884. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  885. #endif
  886. result = FAIL;
  887. }
  888. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  889. {
  890. #ifdef SystemLogMessage
  891. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  892. #endif
  893. result = FAIL;
  894. }
  895. else
  896. {}
  897. /****************************** For Initial Settings************************************************/
  898. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  899. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  900. {
  901. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  902. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  903. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  904. }
  905. // Charger PRE_SYS_MODE
  906. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  907. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  908. clientTime.Heartbeat=time((time_t*)NULL);
  909. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  910. {
  911. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  912. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  913. }
  914. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  915. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  916. // allocate Configuration memory address
  917. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  918. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  919. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  920. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  921. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  922. {
  923. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  924. DEBUG_INFO("DC ...\n");
  925. }
  926. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  927. {
  928. SystemInitial = AC_QUANTITY;
  929. DEBUG_INFO("AC ...\n");
  930. }
  931. //Status / ConnectorPlugIn Setting
  932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  933. {
  934. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  935. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  936. }
  937. for (int index = 0; index < CCS_QUANTITY; index++)
  938. {
  939. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  940. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  941. }
  942. for (int index = 0; index < GB_QUANTITY; index++)
  943. {
  944. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  945. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  946. }
  947. for (int index = 0; index < AC_QUANTITY; index++)
  948. {
  949. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  950. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  951. }
  952. return result;
  953. }
  954. int ProcessShareMemory()
  955. {
  956. if(InitShareMemory() == FAIL)
  957. {
  958. #ifdef SystemLogMessage
  959. DEBUG_ERROR("InitShareMemory NG\n");
  960. #endif
  961. if(ShmStatusCodeData!=NULL)
  962. {
  963. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  964. }
  965. sleep(5);
  966. return FAIL;
  967. }
  968. return PASS;
  969. }
  970. //---------------------------------------------
  971. // new:
  972. // enum SYSTEM_STATUS
  973. // {
  974. // SYS_MODE_BOOTING = 0,
  975. // SYS_MODE_IDLE = 1,
  976. // SYS_MODE_AUTHORIZING = 2,
  977. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  978. // SYS_MODE_REASSIGN = 4,
  979. // SYS_MODE_PREPARING = 5,
  980. // SYS_MODE_PREPARE_FOR_EV = 6,
  981. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  982. // SYS_MODE_CHARGING = 8,
  983. // SYS_MODE_TERMINATING = 9,
  984. // SYS_MODE_COMPLETE = 10,
  985. // SYS_MODE_ALARM = 11,
  986. // SYS_MODE_FAULT = 12,
  987. // SYS_MODE_RESERVATION = 13,
  988. // SYS_MODE_BOOKING = 14,
  989. // SYS_MODE_MAINTAIN = 15,
  990. // SYS_MODE_DEBUG = 16,
  991. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  992. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  993. // SYS_MODE_UPDATE = 19
  994. // };
  995. //
  996. //
  997. //-----------------------------------------
  998. void CheckSystemValue(void)
  999. {
  1000. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1001. int IdleModeCnt = 0;
  1002. char filenmae[100]={0};
  1003. char str[100]={0};
  1004. //===============================
  1005. // send Heartbeat
  1006. //===============================
  1007. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1008. {
  1009. printf("Heartbeat !!!\n");
  1010. //parameter for test
  1011. sendHeartbeatRequest(0);
  1012. //==============================================
  1013. // Reset Waiting Time
  1014. //==============================================
  1015. clientTime.Heartbeat=time((time_t*)NULL);
  1016. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1017. }
  1018. //==============================================
  1019. // Update firmware request
  1020. //==============================================
  1021. if(isUpdateRequest == TRUE )
  1022. {
  1023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1024. {
  1025. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1026. {
  1027. //check SystemStatus
  1028. /*************************DC*******************************/
  1029. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1030. {
  1031. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1032. {
  1033. IdleModeCnt = IdleModeCnt + 1;
  1034. }
  1035. }
  1036. for (int index = 0; index < CCS_QUANTITY; index++)
  1037. {
  1038. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1039. {
  1040. IdleModeCnt = IdleModeCnt + 1;
  1041. }
  1042. }
  1043. for (int index = 0; index < GB_QUANTITY; index++)
  1044. {
  1045. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1046. {
  1047. IdleModeCnt = IdleModeCnt + 1;
  1048. }
  1049. }
  1050. }
  1051. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1052. {
  1053. isUpdateRequest = FALSE;
  1054. }
  1055. }
  1056. else
  1057. {
  1058. /*************************AC*******************************/
  1059. for (int index = 0; index < AC_QUANTITY; index++)
  1060. {
  1061. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1062. {
  1063. IdleModeCnt = IdleModeCnt + 1;
  1064. }
  1065. }
  1066. if(IdleModeCnt == AC_QUANTITY)
  1067. {
  1068. isUpdateRequest = FALSE;
  1069. }
  1070. }
  1071. }
  1072. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1073. {
  1074. //===============================
  1075. // CSU Trigger Reset Conf
  1076. //===============================
  1077. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1078. {
  1079. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1080. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1081. {
  1082. server_sign = FALSE;
  1083. }
  1084. }
  1085. //===============================
  1086. // CSU Trigger Authorize Request
  1087. //===============================
  1088. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1089. {
  1090. sendAuthorizeRequest(0);
  1091. authorizeRetryTimes = authorizeRetryTimes + 1;
  1092. if(authorizeRetryTimes < 3)
  1093. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1094. }
  1095. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1096. {
  1097. authorizeRetryTimes = 0;
  1098. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1099. server_sign = FALSE;
  1100. }
  1101. 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))
  1102. {
  1103. sendAuthorizeRequest(0);
  1104. }
  1105. //===============================
  1106. // CSU Trigger Smart Charging Profilw
  1107. //===============================
  1108. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1109. {
  1110. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1111. GetChargingProfileRequest(gun_index);
  1112. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1113. }
  1114. //==============================================
  1115. // Charger start transaction
  1116. //==============================================
  1117. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1118. {
  1119. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1120. sendStartTransactionRequest(gun_index);
  1121. clientTime.StartTransaction = time((time_t*)NULL);
  1122. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1123. }
  1124. //==============================================
  1125. // Charger stop transaction
  1126. //==============================================
  1127. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1128. {
  1129. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1130. sendStopTransactionRequest(gun_index);
  1131. clientTime.StopTransaction = time((time_t*)NULL);
  1132. }
  1133. //==============================================
  1134. // Charger status report
  1135. //==============================================
  1136. /* Check Mode Change */
  1137. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1138. {
  1139. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1140. {
  1141. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1142. {
  1143. 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]*/ )
  1144. {
  1145. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1146. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1147. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1148. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1149. statusModeChage[gun_index] = TRUE;
  1150. }
  1151. }
  1152. }
  1153. for (int index = 0; index < CCS_QUANTITY; index++)
  1154. {
  1155. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1156. {
  1157. 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]*/ )
  1158. {
  1159. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1160. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1161. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1162. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1163. statusModeChage[gun_index] = TRUE;
  1164. }
  1165. }
  1166. }
  1167. for (int index = 0; index < GB_QUANTITY; index++)
  1168. {
  1169. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1170. {
  1171. 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]*/ )
  1172. {
  1173. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1174. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1175. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1176. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1177. statusModeChage[gun_index] = TRUE;
  1178. }
  1179. }
  1180. }
  1181. }
  1182. else //AC
  1183. {
  1184. for (int index = 0; index < AC_QUANTITY; index++)
  1185. {
  1186. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1187. {
  1188. 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]*/ )
  1189. {
  1190. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1191. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1192. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1193. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1194. statusModeChage[gun_index] = TRUE;
  1195. }
  1196. }
  1197. }// END OF FOR
  1198. }// END OF ELSE
  1199. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1200. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1201. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1202. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1203. {
  1204. if(SystemInitial != 0)
  1205. SystemInitial = SystemInitial -1;
  1206. sendStatusNotificationRequest(gun_index);
  1207. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1208. statusModeChage[gun_index] = FALSE;
  1209. }
  1210. //==============================================
  1211. // Meter report
  1212. //==============================================
  1213. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1214. {
  1215. //check Transaction active
  1216. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1217. {
  1218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1219. {
  1220. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1221. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1222. {
  1223. meterValueSend[gun_index] =1;
  1224. }
  1225. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1226. {
  1227. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1228. if((access(filenmae,F_OK))!=-1)
  1229. {
  1230. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1231. sprintf(str,"rm -f %s",filenmae);
  1232. system(str);
  1233. }
  1234. }
  1235. }// End for CHAdeMO
  1236. for (int index = 0; index < CCS_QUANTITY; index++)
  1237. {
  1238. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1239. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1240. {
  1241. meterValueSend[gun_index] =1;
  1242. }
  1243. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1244. {
  1245. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1246. if((access(filenmae,F_OK))!=-1)
  1247. {
  1248. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1249. sprintf(str,"rm -f %s",filenmae);
  1250. system(str);
  1251. }
  1252. }
  1253. } // End for CCS
  1254. for (int index = 0; index < GB_QUANTITY; index++)
  1255. {
  1256. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1257. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1258. {
  1259. meterValueSend[gun_index] =1;
  1260. }
  1261. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1262. {
  1263. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1264. if((access(filenmae,F_OK))!=-1)
  1265. {
  1266. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1267. sprintf(str,"rm -f %s",filenmae);
  1268. system(str);
  1269. }
  1270. }
  1271. }// End for GB
  1272. }
  1273. else
  1274. {
  1275. for (int index = 0; index < AC_QUANTITY; index++)
  1276. {
  1277. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1278. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1279. {
  1280. meterValueSend[gun_index] =1;
  1281. }
  1282. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1283. {
  1284. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1285. if((access(filenmae,F_OK))!=-1)
  1286. {
  1287. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1288. sprintf(str,"rm -f %s",filenmae);
  1289. system(str);
  1290. }
  1291. }
  1292. }//End for AC
  1293. }//END OF ELSE
  1294. // sleep(1);
  1295. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1296. if(meterValueSend[gun_index] == 1)
  1297. sendMeterValuesRequest(gun_index);
  1298. }
  1299. //==============================================
  1300. // Check Connector reserved
  1301. //==============================================
  1302. //===============================
  1303. // Check if Reserve is expired
  1304. //===============================
  1305. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1306. {
  1307. double diff_t;
  1308. struct tm tp;
  1309. // current time
  1310. time_t t = time(NULL);
  1311. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1312. tp.tm_isdst = -1;
  1313. time_t utc = mktime(&tp);
  1314. diff_t = difftime(utc, t);
  1315. if(diff_t <= 0)
  1316. {
  1317. DEBUG_INFO("reserve expired !!! \n");
  1318. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1319. }
  1320. }//END OF Check if Reserve is expired
  1321. //==========================================
  1322. // csu trigger FirmwareStatusNotificationReq
  1323. //==========================================
  1324. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1325. {
  1326. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1327. }
  1328. //==========================================
  1329. // csu trigger CancelReservationConf
  1330. //==========================================
  1331. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1332. {
  1333. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1334. }
  1335. //==========================================
  1336. // csu trigger ChangeAvailabilityConf
  1337. //==========================================
  1338. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1339. {
  1340. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1341. }
  1342. //==========================================
  1343. // csu trigger UnlockConnectorConf
  1344. //==========================================
  1345. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1346. {
  1347. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1348. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1349. }
  1350. //==========================================
  1351. // csu trigger ReserveNowConf
  1352. //==========================================
  1353. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1354. {
  1355. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1356. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1357. }
  1358. //==========================================
  1359. // csu trigger DataTransferReq
  1360. //==========================================
  1361. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1362. {
  1363. sendDataTransferRequest(gun_index);
  1364. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1365. }
  1366. }
  1367. }
  1368. //==========================================
  1369. // send request routine
  1370. //==========================================
  1371. int sendAuthorizeRequest(int gun_index)
  1372. {
  1373. mtrace();
  1374. int result = FAIL;
  1375. char message[100]={0};
  1376. char guid[37];
  1377. char tempdata[65]={0};
  1378. DEBUG_INFO("sendAuthorizeRequest \n");
  1379. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1380. //Local Authorize
  1381. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1382. {
  1383. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1384. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1385. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1386. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1387. result = PASS;
  1388. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1389. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1390. authorizeRetryTimes = 0;
  1391. return result;
  1392. }
  1393. 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))||
  1394. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1395. {
  1396. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1397. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1398. {
  1399. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1400. {
  1401. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1402. }
  1403. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1404. {
  1405. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1406. }
  1407. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1408. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1409. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1410. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1411. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1412. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1413. authorizeRetryTimes = 0;
  1414. return result;
  1415. }
  1416. else
  1417. {
  1418. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1419. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1420. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1421. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1422. result = PASS;
  1423. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1424. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1425. authorizeRetryTimes = 0;
  1426. return result;
  1427. }
  1428. }
  1429. //initailize struct Authorize
  1430. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1431. //get data from shared memory
  1432. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1433. random_uuid(guid);
  1434. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1435. LWS_Send(message);
  1436. sprintf(tempdata, "Authorize,%d", gun_index);
  1437. if(hashmap_operation(0, guid, tempdata) == 1)
  1438. {
  1439. result = PASS;
  1440. DEBUG_ERROR("Authorize mapItem pass\n");
  1441. }
  1442. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1443. return result;
  1444. }
  1445. int sendBootNotificationRequest(void)
  1446. {
  1447. mtrace();
  1448. int result = FAIL;
  1449. char message[500]={0}, payload[700]={0};
  1450. char guid[37]={0};
  1451. char tempdata[65]={0};
  1452. int IsGunCharging = FALSE;
  1453. //check Transaction active
  1454. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1455. {
  1456. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1457. {
  1458. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1459. {
  1460. IsGunCharging = TRUE;
  1461. }
  1462. }
  1463. for (int index = 0; index < CCS_QUANTITY; index++)
  1464. {
  1465. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1466. {
  1467. IsGunCharging = TRUE;
  1468. }
  1469. }
  1470. for (int index = 0; index < GB_QUANTITY; index++)
  1471. {
  1472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1473. {
  1474. IsGunCharging = TRUE;
  1475. }
  1476. }
  1477. }
  1478. else
  1479. {
  1480. for (int index = 0; index < AC_QUANTITY; index++)
  1481. {
  1482. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1483. {
  1484. IsGunCharging = TRUE;
  1485. }
  1486. }
  1487. }
  1488. if(IsGunCharging == TRUE)
  1489. {
  1490. server_sign = TRUE;
  1491. return result;
  1492. }
  1493. // Fill BootNotification fields
  1494. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1495. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1496. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1497. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1498. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1499. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1500. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1501. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1502. ShmOCPP16Data->ChargeBoxId
  1503. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1504. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1505. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1506. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1507. ,ShmOCPP16Data->BootNotification.CpIccid
  1508. ,ShmOCPP16Data->BootNotification.CpImsi
  1509. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1510. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1511. random_uuid(guid);
  1512. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1513. LWS_Send(message);
  1514. sprintf(tempdata, "BootNotification,0");
  1515. 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*/)
  1516. {
  1517. result = PASS;
  1518. }
  1519. memset(queuedata, 0, sizeof(queuedata));
  1520. strcpy(queuedata,message);
  1521. return result;
  1522. }
  1523. int sendDataTransferRequest(int gun_index)
  1524. {
  1525. mtrace();
  1526. char message[1000]={0};
  1527. char guid[37]={0};
  1528. char tempdata[65]={0};
  1529. int result = FAIL;
  1530. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1531. random_uuid(guid);
  1532. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1533. MESSAGE_TYPE_CALL,
  1534. guid,
  1535. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1536. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1537. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1538. LWS_Send(message);
  1539. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1540. 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*/)
  1541. {
  1542. result = PASS;
  1543. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1544. }
  1545. return result;
  1546. }
  1547. int sendDiagnosticsStatusNotificationRequest(char *status)
  1548. {
  1549. mtrace();
  1550. int result = FAIL;
  1551. char message[110]={0};
  1552. char guid[37]={0};
  1553. char tempdata[65]={0};
  1554. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1555. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1556. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1557. random_uuid(guid);
  1558. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1559. LWS_Send(message);
  1560. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1561. if(hashmap_operation(0, guid, tempdata) == 1)
  1562. {
  1563. result = PASS;
  1564. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1565. }
  1566. //#ifdef SystemLogMessage
  1567. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1568. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1569. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1570. //#endif
  1571. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1572. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1573. //record status
  1574. if(strcmp(status,"Idle")==0)
  1575. {
  1576. DiagnosticsStatusNotificationStatus = 0;
  1577. }
  1578. else if(strcmp(status,"Uploaded")==0)
  1579. {
  1580. DiagnosticsStatusNotificationStatus = 1;
  1581. }
  1582. else if(strcmp(status,"UploadFailed")==0)
  1583. {
  1584. DiagnosticsStatusNotificationStatus = 2;
  1585. }
  1586. else if(strcmp(status,"Uploading")==0)
  1587. {
  1588. DiagnosticsStatusNotificationStatus = 3;
  1589. }
  1590. return result;
  1591. }
  1592. int sendFirmwareStatusNotificationRequest(char *status)
  1593. {
  1594. mtrace();
  1595. int result = FAIL;
  1596. char message[110]={0};
  1597. char guid[37]={0};
  1598. char tempdata[65]={0};
  1599. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1600. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1601. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1602. random_uuid(guid);
  1603. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1604. LWS_Send(message);
  1605. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1606. 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*/)
  1607. {
  1608. result = PASS;
  1609. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1610. }
  1611. //#ifdef SystemLogMessage
  1612. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1613. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1614. //#endif
  1615. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1616. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1617. //record status
  1618. if(strcmp(status,"Downloaded")==0)
  1619. {
  1620. FirmwareStatusNotificationStatus = 0;
  1621. }
  1622. else if(strcmp(status,"DownloadFailed")==0)
  1623. {
  1624. FirmwareStatusNotificationStatus = 1;
  1625. }
  1626. else if(strcmp(status,"Downloading")==0)
  1627. {
  1628. FirmwareStatusNotificationStatus = 2;
  1629. }
  1630. else if(strcmp(status,"Idle")==0)
  1631. {
  1632. FirmwareStatusNotificationStatus = 3;
  1633. }
  1634. else if(strcmp(status,"InstallationFailed")==0)
  1635. {
  1636. FirmwareStatusNotificationStatus = 4;
  1637. }
  1638. else if(strcmp(status,"Installing")==0)
  1639. {
  1640. FirmwareStatusNotificationStatus = 5;
  1641. }
  1642. else if(strcmp(status,"Installed")==0)
  1643. {
  1644. FirmwareStatusNotificationStatus = 6;
  1645. }
  1646. return result;
  1647. }
  1648. int sendHeartbeatRequest(int gun_index)
  1649. {
  1650. mtrace();
  1651. int result = FAIL;
  1652. char message[80]={0};
  1653. char guid[37]={0};
  1654. char tempdata[65]={0};
  1655. random_uuid(guid);
  1656. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1657. , MESSAGE_TYPE_CALL
  1658. , guid );
  1659. LWS_Send(message);
  1660. sprintf(tempdata, "Heartbeat,%d", 0);
  1661. 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*/)
  1662. {
  1663. result = PASS;
  1664. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1665. }
  1666. return result;
  1667. }
  1668. int sendStartTransactionRequest(int gun_index)
  1669. {
  1670. mtrace();
  1671. int result = FAIL;
  1672. char message[250]={0};
  1673. char guid[37]={0};
  1674. struct timeval tmnow;
  1675. struct tm *tm;
  1676. char buf[28];//, usec_buf[6];
  1677. char tempdata[65]={0};
  1678. DEBUG_INFO("sendStartTransactionRequest...");
  1679. gettimeofday(&tmnow, NULL);
  1680. time_t t;
  1681. t = time(NULL);
  1682. /*UTC time and date*/
  1683. tm = gmtime(&t);
  1684. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1685. #if 0 // remove temporally
  1686. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1687. strcat(buf,".");
  1688. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1689. strcat(buf,usec_buf);
  1690. #endif
  1691. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1692. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1693. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1694. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1695. {
  1696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1697. {
  1698. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1699. {
  1700. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1701. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1702. }
  1703. }
  1704. for (int index = 0; index < CCS_QUANTITY; index++)
  1705. {
  1706. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1707. {
  1708. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1709. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1710. }
  1711. }
  1712. for (int index = 0; index < GB_QUANTITY; index++)
  1713. {
  1714. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1715. {
  1716. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1717. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1718. }
  1719. }
  1720. }
  1721. else
  1722. {
  1723. for (int index = 0; index < AC_QUANTITY; index++)
  1724. {
  1725. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1726. {
  1727. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1728. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1729. }
  1730. }
  1731. }//END OF ELSE
  1732. random_uuid(guid);
  1733. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1734. , MESSAGE_TYPE_CALL
  1735. , guid
  1736. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1737. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1738. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1739. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1740. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1741. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1742. 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*/)
  1743. {
  1744. result = PASS;
  1745. }
  1746. strcpy(queuedata, message);
  1747. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1748. if(GetTransactionQueueNum() == 1)
  1749. {
  1750. LWS_Send(message);
  1751. }
  1752. #if 0
  1753. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1754. 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*/)
  1755. {
  1756. result = PASS;
  1757. }
  1758. strcpy(queuedata, message);
  1759. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1760. #endif
  1761. //#ifdef SystemLogMessage
  1762. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1763. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1764. //#endif
  1765. return result;
  1766. }
  1767. int sendStatusNotificationRequest(int gun_index)
  1768. {
  1769. mtrace();
  1770. int result = FAIL;
  1771. char message[600]={0};
  1772. char guid[37];
  1773. int currentStatus = 0;
  1774. struct timeval tmnow;
  1775. struct tm *tm;
  1776. char buf[28];//, usec_buf[6];
  1777. char tempdata[65]={0};
  1778. gettimeofday(&tmnow, NULL);
  1779. time_t t;
  1780. t = time(NULL);
  1781. /*UTC time and date*/
  1782. tm = gmtime(&t);
  1783. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1784. #if 0 // remove temporally
  1785. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1786. strcat(buf,".");
  1787. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1788. strcat(buf,usec_buf);
  1789. #endif
  1790. printf("%s",buf);
  1791. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1792. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1793. // it's option
  1794. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1795. /*
  1796. enum _SYSTEM_STATUS
  1797. {
  1798. S_BOOTING = 0,
  1799. S_IDLE, = 1
  1800. S_AUTHORIZING, =2
  1801. S_REASSIGN_CHECK, =3
  1802. S_REASSIGN, =4
  1803. S_PRECHARGE, =5
  1804. S_PREPARING_FOR_EV, =6
  1805. S_PREPARING_FOR_EVSE, =7
  1806. S_CHARGING, =8
  1807. S_TERMINATING, =9
  1808. S_COMPLETE, =10
  1809. S_ALARM, =11
  1810. S_FAULT =12
  1811. }
  1812. */
  1813. //check Transaction active
  1814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1815. {
  1816. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1817. {
  1818. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1819. {
  1820. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1821. {
  1822. currentStatus = 1; //OCPP Status: Preparing
  1823. }
  1824. else
  1825. {
  1826. currentStatus = 0; //OCPP Status: Available
  1827. }
  1828. }
  1829. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1830. {
  1831. currentStatus = 1; //OCPP Status: Preparing
  1832. }
  1833. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1834. {
  1835. currentStatus = 2; //OCPP Status: Charging
  1836. }
  1837. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1838. {
  1839. currentStatus = 5; //OCPP Status: Finishing
  1840. }
  1841. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1842. {
  1843. currentStatus = 4; //OCPP Status: SuspendedEV
  1844. }
  1845. 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
  1846. {
  1847. currentStatus = 7; //OCPP Status: Unavailable
  1848. }
  1849. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1850. {
  1851. currentStatus = 8; //OCPP Status: Faulted
  1852. }
  1853. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1854. {
  1855. currentStatus = 6; //OCPP Status: Reserved
  1856. }
  1857. }//end of for CHAdeMO_QUANTITY
  1858. for (int index = 0; index < CCS_QUANTITY; index++)
  1859. {
  1860. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1861. {
  1862. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1863. {
  1864. currentStatus = 1; //OCPP Status: Preparing
  1865. }
  1866. else
  1867. {
  1868. currentStatus = 0; //OCPP Status: Available
  1869. }
  1870. }
  1871. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1872. {
  1873. currentStatus = 1; //OCPP Status: Preparing
  1874. }
  1875. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1876. {
  1877. currentStatus = 2; //OCPP Status: Charging
  1878. }
  1879. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1880. {
  1881. currentStatus = 5; //OCPP Status: Finishing
  1882. }
  1883. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM ,S_TERMINATING ---> SuspendedEV
  1884. {
  1885. currentStatus = 4; //OCPP Status: SuspendedEV
  1886. }
  1887. 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
  1888. {
  1889. currentStatus = 7; //OCPP Status : Unavailable
  1890. }
  1891. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1892. {
  1893. currentStatus = 8; //OCPP Status: Faulted
  1894. }
  1895. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1896. {
  1897. currentStatus = 6; //OCPP Status: Reserved
  1898. }
  1899. }
  1900. for (int index = 0; index < GB_QUANTITY; index++)
  1901. {
  1902. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1903. {
  1904. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1905. {
  1906. currentStatus = 1; //OCPP Status: Preparing
  1907. }
  1908. else
  1909. {
  1910. currentStatus = 0; //OCPP Status: Available
  1911. }
  1912. }
  1913. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1914. {
  1915. currentStatus = 1; //OCPP Status: Preparing
  1916. }
  1917. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1918. {
  1919. currentStatus = 2; //OCPP Status: Charging
  1920. }
  1921. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1922. {
  1923. currentStatus = 5; //OCPP Status: Finishing
  1924. }
  1925. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM , S_TERMINATING ---> SuspendedEV
  1926. {
  1927. currentStatus = 4; //OCPP Status: SuspendedEV
  1928. }
  1929. 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
  1930. {
  1931. currentStatus = 7; //OCPP Status: Unavailable
  1932. }
  1933. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1934. {
  1935. currentStatus = 8; //OCPP Status: Faulted
  1936. }
  1937. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1938. {
  1939. currentStatus = 6; //OCPP Status: Reserved
  1940. }
  1941. }
  1942. }
  1943. else
  1944. {
  1945. for (int index = 0; index < AC_QUANTITY; index++)
  1946. {
  1947. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1948. {
  1949. 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))
  1950. {
  1951. currentStatus = 1; //OCPP Status: Preparing
  1952. }
  1953. else
  1954. {
  1955. currentStatus = 0; //OCPP Status: Available
  1956. }
  1957. }
  1958. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1959. {
  1960. currentStatus = 1; //OCPP Status: Preparing
  1961. }
  1962. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1963. {
  1964. currentStatus = 2; //OCPP Status: Charging
  1965. }
  1966. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1967. {
  1968. currentStatus = 5; //OCPP Status: Finishing
  1969. }
  1970. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_ALARM, S_TERMINATING ---> SuspendedEV
  1971. {
  1972. currentStatus = 4; //OCPP Status: SuspendedEV
  1973. }
  1974. 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
  1975. {
  1976. currentStatus = 7; //OCPP Status: Unavailable
  1977. }
  1978. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1979. {
  1980. currentStatus = 8; //OCPP Status: Faulted
  1981. }
  1982. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1983. {
  1984. currentStatus = 6; //OCPP Status: Reserved
  1985. }
  1986. }//end of for AC_QUANTITY
  1987. }//END OF ELSE
  1988. //it's option
  1989. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1990. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1991. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1992. random_uuid(guid);
  1993. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1994. , MESSAGE_TYPE_CALL
  1995. , guid
  1996. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1997. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1998. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1999. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2000. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2001. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2002. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2003. LWS_Send(message);
  2004. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2005. 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*/)
  2006. {
  2007. //DEBUG_ERROR("statusNotification mapitem pass");
  2008. result = PASS;
  2009. }
  2010. return result;
  2011. }
  2012. int sendStopTransactionRequest(int gun_index)
  2013. {
  2014. mtrace();
  2015. int result = FAIL;
  2016. //char message[1500]={0};
  2017. char guid[37]={0};
  2018. char tempdata[65]={0};
  2019. //int idx_sample=0;
  2020. DEBUG_ERROR("sendStopTransactionRequest \n");
  2021. memset(queuedata, 0, sizeof(queuedata));
  2022. //ENERGY_ACTIVE_IMPORT_REGISTER
  2023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2024. {
  2025. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2026. {
  2027. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2028. {
  2029. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2030. }
  2031. }// END OF CHAdeMO_QUANTITY
  2032. for (int index = 0; index < CCS_QUANTITY; index++)
  2033. {
  2034. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2035. {
  2036. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2037. }
  2038. }// END OF CCS_QUANTITY
  2039. for (int index = 0; index < GB_QUANTITY; index++)
  2040. {
  2041. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2042. {
  2043. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2044. }
  2045. }// END OF GB_QUANTITY
  2046. }
  2047. else
  2048. {
  2049. for (int index = 0; index < AC_QUANTITY; index++)
  2050. {
  2051. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2052. {
  2053. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2054. }
  2055. }// END OF AC_QUANTITY
  2056. }//END OF ELSE
  2057. //Stop Transaction Time
  2058. struct timeval tmnow;
  2059. struct tm *tm;
  2060. char buf[28];//, usec_buf[6];
  2061. gettimeofday(&tmnow, NULL);
  2062. time_t t;
  2063. t = time(NULL);
  2064. /*UTC time and date*/
  2065. tm = gmtime(&t);
  2066. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2068. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2069. random_uuid(guid);
  2070. /***********************************transactionData******************************************************/
  2071. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2073. //=================================
  2074. // Transaction_Begin
  2075. //=================================
  2076. // Energy.Active.Export.Interval
  2077. //idx_sample=0;
  2078. 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
  2079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2081. 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*/]);
  2082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2083. {
  2084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2085. }
  2086. else
  2087. {
  2088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2089. }
  2090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2092. //=================================
  2093. // Transaction_End
  2094. //=================================
  2095. //Current.Export
  2096. //idx_sample=1;
  2097. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2098. {
  2099. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2100. {
  2101. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2102. {
  2103. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2104. }
  2105. }
  2106. for (int index = 0; index < CCS_QUANTITY; index++)
  2107. {
  2108. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2109. {
  2110. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2111. }
  2112. }
  2113. for (int index = 0; index < GB_QUANTITY; index++)
  2114. {
  2115. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2116. {
  2117. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2118. }
  2119. }
  2120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2121. }
  2122. else
  2123. {
  2124. for (int index = 0; index < AC_QUANTITY; index++)
  2125. {
  2126. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2127. {
  2128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2129. }
  2130. }
  2131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2132. }// END FOR AC ELSE
  2133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2136. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2139. //Energy.Active.Export.Interval
  2140. //idx_sample=2;
  2141. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2142. {
  2143. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2144. {
  2145. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2146. {
  2147. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2148. }
  2149. }
  2150. for (int index = 0; index < CCS_QUANTITY; index++)
  2151. {
  2152. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2153. {
  2154. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2155. }
  2156. }
  2157. for (int index = 0; index < GB_QUANTITY; index++)
  2158. {
  2159. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2160. {
  2161. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2162. }
  2163. }
  2164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2165. }
  2166. else
  2167. {
  2168. for (int index = 0; index < AC_QUANTITY; index++)
  2169. {
  2170. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2171. {
  2172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2173. }
  2174. }
  2175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2176. }// END FOR AC ELSE
  2177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2180. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2183. //Power.Active.Export
  2184. //idx_sample=3;
  2185. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2186. {
  2187. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2188. {
  2189. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2190. {
  2191. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2192. }
  2193. }
  2194. for (int index = 0; index < CCS_QUANTITY; index++)
  2195. {
  2196. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2197. {
  2198. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2199. }
  2200. }
  2201. for (int index = 0; index < GB_QUANTITY; index++)
  2202. {
  2203. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2204. {
  2205. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2206. }
  2207. }
  2208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2209. }
  2210. else
  2211. {
  2212. for (int index = 0; index < AC_QUANTITY; index++)
  2213. {
  2214. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2215. {
  2216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2217. }
  2218. }
  2219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2220. }// END FOR AC ELSE
  2221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2224. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2227. //Voltage
  2228. //idx_sample=4;
  2229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2230. {
  2231. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2232. {
  2233. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2234. {
  2235. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2236. }
  2237. }
  2238. for (int index = 0; index < CCS_QUANTITY; index++)
  2239. {
  2240. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2241. {
  2242. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2243. }
  2244. }
  2245. for (int index = 0; index < GB_QUANTITY; index++)
  2246. {
  2247. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2248. {
  2249. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2250. }
  2251. }
  2252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2253. }
  2254. else
  2255. {
  2256. for (int index = 0; index < AC_QUANTITY; index++)
  2257. {
  2258. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2259. {
  2260. 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
  2261. }
  2262. }
  2263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2264. }// END FOR AC ELSE
  2265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2267. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2268. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2270. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2271. //SoC
  2272. //idx_sample=5;
  2273. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2274. {
  2275. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2276. {
  2277. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2278. {
  2279. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2280. }
  2281. }
  2282. for (int index = 0; index < CCS_QUANTITY; index++)
  2283. {
  2284. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2285. {
  2286. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2287. }
  2288. }
  2289. for (int index = 0; index < GB_QUANTITY; index++)
  2290. {
  2291. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2292. {
  2293. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2294. }
  2295. }
  2296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2302. } // END FOR DC CASE
  2303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2304. {
  2305. 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\"}]}]}]"
  2306. ,MESSAGE_TYPE_CALL
  2307. ,guid
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2313. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2336. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2340. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2341. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2342. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2343. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2344. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2345. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2346. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2347. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2348. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2349. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2356. );
  2357. }
  2358. else
  2359. {
  2360. 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\"}]}]}]"
  2361. ,MESSAGE_TYPE_CALL
  2362. ,guid
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2364. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2366. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2367. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2368. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2369. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2370. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2385. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2386. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2387. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2388. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2390. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2391. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2392. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2393. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2394. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2395. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2396. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2397. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2398. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2399. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2400. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2401. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2402. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2403. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2404. );
  2405. }
  2406. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2407. if(hashmap_operation(0, guid, tempdata) == 1)
  2408. {
  2409. result = PASS;
  2410. DEBUG_INFO("StopTransaction mapitem pass\n");
  2411. }
  2412. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2413. if(GetTransactionQueueNum() == 1)
  2414. {
  2415. LWS_Send(queuedata);
  2416. }
  2417. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2418. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2419. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2420. {
  2421. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2422. }
  2423. #if 0
  2424. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2425. if(hashmap_operation(0, guid, tempdata) == 1)
  2426. {
  2427. result = PASS;
  2428. DEBUG_INFO("StopTransaction mapitem pass\n");
  2429. }
  2430. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2431. #endif
  2432. //for test
  2433. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2434. return result;
  2435. }
  2436. int sendMeterValuesRequest(int gun_index)
  2437. {
  2438. mtrace();
  2439. int result = FAIL;
  2440. // char message[1500]={0};
  2441. char guid[37]={0};
  2442. //int idx_sample=0;
  2443. //int length = 0;
  2444. char tempdata[65]={0};
  2445. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2446. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2447. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2448. {
  2449. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2450. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2451. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2452. return result;
  2453. }
  2454. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2455. {
  2456. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2457. }
  2458. memset(queuedata, 0, sizeof(queuedata));
  2459. //set value
  2460. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2461. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2462. random_uuid(guid);
  2463. //UTC Date time
  2464. struct timeval tmnow;
  2465. struct tm *tm;
  2466. char buf[28];//, usec_buf[6];
  2467. gettimeofday(&tmnow, NULL);
  2468. time_t t;
  2469. t = time(NULL);
  2470. /*UTC time and date*/
  2471. tm = gmtime(&t);
  2472. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2474. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2475. //idx_sample=0;
  2476. //********************************(1)Current.Export************************************************/
  2477. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2478. {
  2479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2480. {
  2481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2482. {
  2483. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2484. }
  2485. }
  2486. for (int index = 0; index < CCS_QUANTITY; index++)
  2487. {
  2488. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2489. {
  2490. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2491. }
  2492. }
  2493. for (int index = 0; index < GB_QUANTITY; index++)
  2494. {
  2495. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2496. {
  2497. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2498. }
  2499. }
  2500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2501. }
  2502. else
  2503. {
  2504. for (int index = 0; index < AC_QUANTITY; index++)
  2505. {
  2506. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2507. {
  2508. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2509. }
  2510. }
  2511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2512. }// END FOR AC ELSE
  2513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2515. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2516. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2519. //idx_sample=1;
  2520. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2522. {
  2523. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2524. {
  2525. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2526. {
  2527. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2528. }
  2529. }
  2530. for (int index = 0; index < CCS_QUANTITY; index++)
  2531. {
  2532. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2533. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2534. {
  2535. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2536. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2537. }
  2538. }
  2539. for (int index = 0; index < GB_QUANTITY; index++)
  2540. {
  2541. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2542. {
  2543. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2544. }
  2545. }
  2546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2547. }
  2548. else
  2549. {
  2550. for (int index = 0; index < AC_QUANTITY; index++)
  2551. {
  2552. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2553. {
  2554. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2555. }
  2556. }
  2557. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2558. }//END FOR AC ELSE
  2559. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2560. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2562. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2565. //idx_sample=2;
  2566. //********************************(4)Power.Active.Export************************************************/
  2567. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2568. {
  2569. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2570. {
  2571. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2572. {
  2573. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2574. }
  2575. }
  2576. for (int index = 0; index < CCS_QUANTITY; index++)
  2577. {
  2578. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2579. {
  2580. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2581. }
  2582. }
  2583. for (int index = 0; index < GB_QUANTITY; index++)
  2584. {
  2585. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2586. {
  2587. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2588. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2589. }
  2590. }
  2591. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2592. }
  2593. else
  2594. {
  2595. for (int index = 0; index < AC_QUANTITY; index++)
  2596. {
  2597. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2598. {
  2599. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2600. }
  2601. }
  2602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2603. }// END FOR AC ELSE
  2604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2607. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2609. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2610. //idx_sample=3;
  2611. //***********************************************(5)VOLTAGE******************************************************/
  2612. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2613. {
  2614. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2615. {
  2616. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2617. {
  2618. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2619. }
  2620. }
  2621. for (int index = 0; index < CCS_QUANTITY; index++)
  2622. {
  2623. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2624. {
  2625. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2626. }
  2627. }
  2628. for (int index = 0; index < GB_QUANTITY; index++)
  2629. {
  2630. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2631. {
  2632. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2633. }
  2634. }
  2635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2636. }
  2637. else
  2638. {
  2639. for (int index = 0; index < AC_QUANTITY; index++)
  2640. {
  2641. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2642. {
  2643. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2644. }
  2645. }
  2646. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2647. }//END FOR AC ELSE
  2648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2651. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2655. {
  2656. //idx_sample=4;
  2657. //sampledValue = NULL;
  2658. //***********************************************(6)SOC******************************************************/
  2659. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2660. {
  2661. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2662. {
  2663. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2664. }
  2665. }
  2666. for (int index = 0; index < CCS_QUANTITY; index++)
  2667. {
  2668. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2669. {
  2670. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2671. }
  2672. }
  2673. for (int index = 0; index < GB_QUANTITY; index++)
  2674. {
  2675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2676. {
  2677. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2678. }
  2679. }
  2680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2684. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2685. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2686. }
  2687. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2688. {
  2689. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2690. ,MESSAGE_TYPE_CALL
  2691. ,guid
  2692. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2693. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2694. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2730. );
  2731. }
  2732. else
  2733. {
  2734. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2735. ,MESSAGE_TYPE_CALL
  2736. ,guid
  2737. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2738. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2739. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2758. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2768. );
  2769. }
  2770. // Put request guid to hash map
  2771. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2772. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2773. {
  2774. result = PASS;
  2775. DEBUG_INFO("MeterValues mapitem pass\n");
  2776. }
  2777. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2778. if(GetTransactionQueueNum() == 1)
  2779. {
  2780. LWS_Send(queuedata);
  2781. }
  2782. #if 0
  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. #endif
  2792. return result;
  2793. }
  2794. //==========================================
  2795. // send confirm routine
  2796. //==========================================
  2797. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2798. {
  2799. mtrace();
  2800. int result = FAIL;
  2801. char message[100]={0};
  2802. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2803. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2804. LWS_Send(message);
  2805. result = TRUE;
  2806. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2807. return result;
  2808. }
  2809. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2810. {
  2811. mtrace();
  2812. int result = FAIL;
  2813. char message[100]={0};
  2814. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2815. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2816. LWS_Send(message);
  2817. result = TRUE;
  2818. return result;
  2819. }
  2820. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2821. {
  2822. mtrace();
  2823. int result = FAIL;
  2824. char message[100]={0};
  2825. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2826. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2827. LWS_Send(message);
  2828. result = TRUE;
  2829. return result;
  2830. }
  2831. int sendClearCacheConfirmation(char *uuid,char *payload)
  2832. {
  2833. mtrace();
  2834. int result = FAIL;
  2835. char message[500]={0};
  2836. // int count = 0;
  2837. // int gun_index = 0;
  2838. // char guid[37];
  2839. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2840. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2841. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2842. LWS_Send(message);
  2843. return result;
  2844. }
  2845. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2846. {
  2847. mtrace();
  2848. int result = FAIL;
  2849. char message[500]={0};
  2850. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2851. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2852. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2853. LWS_Send(message);
  2854. return result;
  2855. }
  2856. int sendDataTransferConfirmation(char *uuid,char *payload)
  2857. {
  2858. mtrace();
  2859. char statusStr[20]={0};
  2860. char dataStr[10]={0};
  2861. char sstr[20]={0};
  2862. int c = 0;
  2863. char *loc;
  2864. int result = FAIL;
  2865. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2866. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2867. /**********************status**************************/
  2868. loc = strstr(payload, "status");
  2869. memset(sstr ,0, sizeof(sstr) );
  2870. c = 0;
  2871. while (loc[3+strlen("status")+c] != '\"')
  2872. {
  2873. sstr[c] = loc[3+strlen("status")+c];
  2874. c++;
  2875. }
  2876. sstr[c] = '\0';
  2877. strcpy(statusStr, sstr);
  2878. /**********************data**************************/
  2879. loc = strstr(payload, "data");
  2880. memset(sstr ,0, sizeof(sstr) );
  2881. c = 0;
  2882. while (loc[3+strlen("data")+c] != '\"')
  2883. {
  2884. sstr[c] = loc[3+strlen("data")+c];
  2885. c++;
  2886. }
  2887. sstr[c] = '\0';
  2888. strcpy(dataStr, sstr);
  2889. return result;
  2890. }
  2891. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2892. {
  2893. mtrace();
  2894. int result = FAIL;
  2895. char message[1000]={0};
  2896. double diff_f = 0.0;
  2897. int diff_i = 0;
  2898. int diffSeconds = 0;
  2899. struct tm tp;
  2900. int TimeZero = FALSE;
  2901. int CompositeScheduleIndex = 0;
  2902. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2903. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2904. {
  2905. TimeZero = TRUE;
  2906. }
  2907. else
  2908. {
  2909. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2910. }
  2911. if(TimeZero == FALSE)
  2912. {
  2913. tp.tm_isdst = -1;
  2914. time_t utc = mktime(&tp);
  2915. time_t t = time(NULL);
  2916. diff_f = difftime(t, utc);
  2917. diff_i = (int)diff_f;
  2918. diffSeconds = diff_i % 86400;//86400 seconds/day
  2919. }
  2920. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2921. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2922. #if 0 //remove temporally
  2923. 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}"
  2924. ,MESSAGE_TYPE_CALLRESULT
  2925. ,uuid
  2926. ,payload
  2927. ,connectorIdInt
  2928. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2929. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2930. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2931. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2932. #endif
  2933. if(nPeriod == 0)
  2934. {
  2935. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  2936. {
  2937. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  2938. ,MESSAGE_TYPE_CALLRESULT
  2939. ,uuid
  2940. ,payload
  2941. ,connectorIdInt);
  2942. }
  2943. else
  2944. {
  2945. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2946. ,MESSAGE_TYPE_CALLRESULT
  2947. ,uuid
  2948. ,payload
  2949. ,connectorIdInt
  2950. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2951. }
  2952. }
  2953. else
  2954. {
  2955. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2956. ,MESSAGE_TYPE_CALLRESULT
  2957. ,uuid
  2958. ,payload
  2959. ,connectorIdInt
  2960. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2961. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2962. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2963. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2964. int len = nPeriod;
  2965. //Last Period StartPriod is less than diffSeconds
  2966. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds)
  2967. {
  2968. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2969. , 0
  2970. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2971. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2972. }
  2973. else
  2974. {
  2975. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2976. {
  2977. 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)
  2978. {
  2979. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2980. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2981. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2982. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2983. }
  2984. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2985. {
  2986. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2987. , ((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*/))
  2988. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2989. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2990. }
  2991. }
  2992. }
  2993. sprintf(message + strlen(message), "]}}]");
  2994. }
  2995. LWS_Send(message);
  2996. result = TRUE;
  2997. return result;
  2998. }
  2999. int sendGetConfigurationConfirmation(char *uuid)
  3000. {
  3001. mtrace();
  3002. int result = FAIL;
  3003. int MaxKeySupported = 0;
  3004. int sentConfigurationNumber= 0;
  3005. int sentunConfigurationNumber= 0;
  3006. char message[4000]={0};
  3007. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3008. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3009. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3010. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3011. ,MESSAGE_TYPE_CALLRESULT
  3012. ,uuid );
  3013. //configuration key
  3014. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3015. {
  3016. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3017. {
  3018. if (sentConfigurationNumber == 0)
  3019. {
  3020. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3021. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3022. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3023. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3024. }
  3025. else
  3026. {
  3027. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3028. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3029. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3030. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3031. }
  3032. sentConfigurationNumber = sentConfigurationNumber + 1;
  3033. }
  3034. }
  3035. sprintf(message + strlen(message), "]");
  3036. if(UnknownKeynum != 0)
  3037. {
  3038. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3039. //unkown key
  3040. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3041. {
  3042. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3043. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3044. if(sentunConfigurationNumber == 0)
  3045. {
  3046. sprintf(message + strlen(message), "\"%s\""
  3047. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3048. }
  3049. else
  3050. {
  3051. sprintf(message + strlen(message), ",\"%s\""
  3052. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3053. }
  3054. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3055. }
  3056. sprintf(message + strlen(message), "]");
  3057. }
  3058. sprintf(message + strlen(message), "}]");
  3059. LWS_Send(message);
  3060. return result;
  3061. }
  3062. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3063. {
  3064. mtrace();
  3065. int result = FAIL;
  3066. char message[400]={0};
  3067. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3068. if(strcmp(payload,"")==0)
  3069. {
  3070. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3071. }
  3072. else
  3073. {
  3074. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3075. }
  3076. LWS_Send(message);
  3077. result = TRUE;
  3078. return result;
  3079. }
  3080. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3081. {
  3082. mtrace();
  3083. int result = FAIL;
  3084. char message[80]={0};
  3085. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3086. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3087. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3088. LWS_Send(message);
  3089. result = TRUE;
  3090. return result;
  3091. }
  3092. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3093. {
  3094. mtrace();
  3095. int result = FAIL;
  3096. char message[80]={0};
  3097. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3098. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3099. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3100. LWS_Send(message);
  3101. result = TRUE;
  3102. return result;
  3103. }
  3104. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3105. {
  3106. mtrace();
  3107. int result = FAIL;
  3108. char message[80]={0};
  3109. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3110. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3111. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3112. LWS_Send(message);
  3113. result = TRUE;
  3114. return result;
  3115. }
  3116. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3117. {
  3118. mtrace();
  3119. int result = FAIL;
  3120. char message[80]={0};
  3121. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3122. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3123. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3124. LWS_Send(message);
  3125. result = TRUE;
  3126. return result;
  3127. }
  3128. int sendResetConfirmation(char *uuid,char *payload)
  3129. {
  3130. mtrace();
  3131. int result = FAIL;
  3132. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3133. char message[80]={0};
  3134. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3135. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3136. LWS_Send(message);
  3137. result = TRUE;
  3138. return result;
  3139. }
  3140. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3141. {
  3142. mtrace();
  3143. int result = FAIL;
  3144. char message[500]={0};
  3145. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3146. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3147. LWS_Send(message);
  3148. result = TRUE;
  3149. return result;
  3150. }
  3151. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3152. {
  3153. mtrace();
  3154. int result = FAIL;
  3155. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3156. char message[80]={0};
  3157. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3158. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3159. LWS_Send(message);
  3160. result = TRUE;
  3161. return result;
  3162. }
  3163. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3164. {
  3165. mtrace();
  3166. int result = FAIL;
  3167. char message[80]={0};
  3168. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3169. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3170. LWS_Send(message);
  3171. result = TRUE;
  3172. return result;
  3173. }
  3174. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3175. {
  3176. mtrace();
  3177. int result = FAIL;
  3178. char message[80]={0};
  3179. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3180. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3181. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3182. LWS_Send(message);
  3183. result = TRUE;
  3184. return result;
  3185. }
  3186. int sendUpdateFirmwareConfirmation(char *uuid)
  3187. {
  3188. mtrace();
  3189. int result = FAIL;
  3190. char message[60]={0};
  3191. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3192. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3193. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3194. LWS_Send(message);
  3195. result = TRUE;
  3196. return result;
  3197. }
  3198. //==========================================
  3199. // send CallError routine
  3200. //==========================================
  3201. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3202. {
  3203. mtrace();
  3204. //int result = FAIL;
  3205. char message[220]={0};
  3206. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3207. #ifdef SystemLogMessage
  3208. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3209. uniqueId, action, errorCode, errorDescription);
  3210. #endif
  3211. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3212. LWS_Send(message);
  3213. //result = TRUE;
  3214. }
  3215. //==========================================
  3216. // Handle server request routine Start
  3217. //==========================================
  3218. #define GUN_NUM 1
  3219. int handleCancelReservationRequest(char *uuid, char *payload)
  3220. {
  3221. mtrace();
  3222. int result = FAIL;
  3223. int gunNO = 0;
  3224. int reservationIdInt =0;
  3225. char comfirmstr[20];
  3226. int c = 0;
  3227. char *loc;
  3228. char sstr[100]={0};
  3229. DEBUG_INFO("handle CancelReservationRequest\n");
  3230. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3231. c = 0;
  3232. loc = strstr(payload, "reservationId");
  3233. memset(sstr ,0, sizeof(sstr) );
  3234. while (loc[strlen("reservationId")+2+c] != '}')
  3235. {
  3236. sstr[c] = loc[strlen("reservationId")+2+c];
  3237. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3238. c++;
  3239. }
  3240. sstr[c] = '\0';
  3241. reservationIdInt = atoi(sstr);
  3242. memset(comfirmstr, 0, sizeof comfirmstr);
  3243. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3244. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3245. //check Transaction active
  3246. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3247. {
  3248. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3249. {
  3250. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3251. {
  3252. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3253. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3254. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3255. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3256. goto end;
  3257. }
  3258. }
  3259. for (int index = 0; index < CCS_QUANTITY; index++)
  3260. {
  3261. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3262. {
  3263. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3264. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3265. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3266. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3267. goto end;
  3268. }
  3269. }
  3270. for (int index = 0; index < GB_QUANTITY; index++)
  3271. {
  3272. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3273. {
  3274. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3275. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3276. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3277. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3278. goto end;
  3279. }
  3280. }
  3281. }
  3282. else
  3283. {
  3284. for (int index = 0; index < AC_QUANTITY; index++)
  3285. {
  3286. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3287. {
  3288. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3289. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3290. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3291. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3292. goto end;
  3293. }
  3294. }
  3295. }// END FOR AC ELSE
  3296. //The reservationId does NOT match the reservationId
  3297. sendCancelReservationConfirmation(uuid, comfirmstr);
  3298. end:
  3299. // Fill in ocpp packet uuid
  3300. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3301. return result;
  3302. }
  3303. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3304. {
  3305. mtrace();
  3306. int result = FAIL;
  3307. int gunIndex = 0;
  3308. char sstr[90]={0};
  3309. char typeStr[16]={0};
  3310. char comfirmstr[20];
  3311. int specificId = FALSE;
  3312. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3313. char *loc;
  3314. //int intervalInt = 0;
  3315. int c = 0;
  3316. /*** connectorId ****/
  3317. c = 0;
  3318. loc = strstr(payload, "connectorId");
  3319. memset(sstr ,0, sizeof(sstr) );
  3320. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3321. {
  3322. sstr[c] = loc[strlen("connectorId")+2+c];
  3323. c++;
  3324. }
  3325. sstr[c] = '\0';
  3326. gunIndex = atoi(sstr);
  3327. /***type ****/
  3328. loc = strstr(payload, "type");
  3329. memset(sstr ,0, sizeof(sstr) );
  3330. c = 0;
  3331. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3332. {
  3333. sstr[c] = loc[3+strlen("type")+c];
  3334. c++;
  3335. }
  3336. sstr[c] = '\0';
  3337. strcpy(typeStr, sstr);
  3338. if(gunIndex != 0)
  3339. {
  3340. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3341. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3342. }
  3343. else
  3344. {
  3345. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3346. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3347. }
  3348. memset(comfirmstr, 0, sizeof comfirmstr);
  3349. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3350. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3351. {
  3352. specificId = TRUE;
  3353. }
  3354. if(specificId == FALSE)
  3355. goto end;
  3356. if(gunIndex != 0)
  3357. {
  3358. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3359. }
  3360. else
  3361. {
  3362. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3363. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3364. }
  3365. /*
  3366. enum SYSTEM_STATUS
  3367. {
  3368. SYS_MODE_BOOTING = 0,
  3369. SYS_MODE_IDLE = 1,
  3370. SYS_MODE_AUTHORIZING = 2,
  3371. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3372. SYS_MODE_REASSIGN = 4,
  3373. SYS_MODE_PREPARING = 5,
  3374. SYS_MODE_PREPARE_FOR_EV = 6,
  3375. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3376. SYS_MODE_CHARGING = 8,
  3377. SYS_MODE_TERMINATING = 9,
  3378. SYS_MODE_COMPLETE = 10,
  3379. SYS_MODE_ALARM = 11,
  3380. SYS_MODE_FAULT = 12,
  3381. SYS_MODE_RESERVATION = 13,
  3382. SYS_MODE_BOOKING = 14,
  3383. SYS_MODE_MAINTAIN = 15,
  3384. SYS_MODE_DEBUG = 16,
  3385. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3386. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3387. SYS_MODE_UPDATE = 19
  3388. };
  3389. */
  3390. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3391. {
  3392. //check Transaction active
  3393. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3394. {
  3395. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3396. {
  3397. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3398. {
  3399. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3400. {
  3401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3402. }
  3403. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3404. {
  3405. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3406. }
  3407. else
  3408. {
  3409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3410. }
  3411. goto end;
  3412. }
  3413. }//END FOR CHAdeMO_QUANTITY
  3414. for (int index = 0; index < CCS_QUANTITY; index++)
  3415. {
  3416. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3417. {
  3418. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3419. {
  3420. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3421. }
  3422. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3423. {
  3424. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3425. }
  3426. else
  3427. {
  3428. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3429. }
  3430. goto end;
  3431. }
  3432. }//END FOR CCS_QUANTITY
  3433. for (int index = 0; index < GB_QUANTITY; index++)
  3434. {
  3435. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3436. {
  3437. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3438. {
  3439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3440. }
  3441. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3442. {
  3443. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3444. }
  3445. else
  3446. {
  3447. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3448. }
  3449. goto end;
  3450. }
  3451. }// END FOR GB_QUANTITY
  3452. }
  3453. else
  3454. {
  3455. for (int index = 0; index < AC_QUANTITY; index++)
  3456. {
  3457. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3458. {
  3459. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3460. {
  3461. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3462. }
  3463. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3464. {
  3465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3466. }
  3467. else
  3468. {
  3469. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3470. }
  3471. goto end;
  3472. }
  3473. }//END FOR AC_QUANTITY
  3474. }// END FOR AC ELSE
  3475. }//END FOR AvailabilityTypeStr[Inoperative]
  3476. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3477. {
  3478. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3479. //check Transaction active
  3480. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3481. {
  3482. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3483. {
  3484. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3485. {
  3486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3487. goto end;
  3488. }
  3489. }//END FOR CHAdeMO_QUANTITY
  3490. for (int index = 0; index < CCS_QUANTITY; index++)
  3491. {
  3492. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3493. {
  3494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3495. goto end;
  3496. }
  3497. }//END FOR CCS_QUANTITY
  3498. for (int index = 0; index < GB_QUANTITY; index++)
  3499. {
  3500. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3501. {
  3502. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3504. goto end;
  3505. }
  3506. }// END FOR GB_QUANTITY
  3507. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3508. }
  3509. else
  3510. {
  3511. for (int index = 0; index < AC_QUANTITY; index++)
  3512. {
  3513. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3514. {
  3515. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3516. goto end;
  3517. }
  3518. }//END FOR CHAdeMO_QUANTITY
  3519. }//END FOR AC ELSE
  3520. }//END FOR AvailabilityTypeStr[Operative]
  3521. end:
  3522. if(gunIndex != 0)
  3523. {
  3524. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3525. }
  3526. else
  3527. {
  3528. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3529. }
  3530. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3531. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3532. return result;
  3533. }
  3534. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3535. {
  3536. mtrace();
  3537. int result = FAIL;
  3538. char sstr[100]={0};
  3539. char keystr[40]={0};
  3540. char valuestr[100]={0};
  3541. char *loc;
  3542. int c = 0;
  3543. char comfirmstr[20]={0};
  3544. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3545. /***key ****/
  3546. loc = strstr(payload, "key");
  3547. memset(sstr ,0, sizeof(sstr) );
  3548. c = 0;
  3549. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3550. {
  3551. sstr[c] = loc[3+strlen("key")+c];
  3552. c++;
  3553. }
  3554. sstr[c] = '\0';
  3555. strcpy(keystr, sstr);
  3556. //DEBUG_INFO( "keystr=%s\n",keystr);
  3557. /***value ****/
  3558. loc = strstr(payload, "value");
  3559. memset(sstr ,0, sizeof(sstr) );
  3560. c = 0;
  3561. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3562. {
  3563. sstr[c] = loc[3+strlen("value")+c];
  3564. c++;
  3565. }
  3566. sstr[c] = '\0';
  3567. strcpy(valuestr, sstr);
  3568. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3569. if((uuid==NULL) || (payload ==NULL) )
  3570. {
  3571. #ifdef Debug
  3572. DEBUG_INFO("payload is null\n");
  3573. #endif
  3574. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3575. }
  3576. else
  3577. {
  3578. int status = setKeyValue(keystr, valuestr);
  3579. switch(status)
  3580. {
  3581. case ConfigurationStatus_Accepted:
  3582. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3583. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3584. StoreConfigurationTable();
  3585. break;
  3586. case ConfigurationStatus_Rejected:
  3587. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3588. break;
  3589. case RebootRequired:
  3590. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3591. StoreConfigurationTable();
  3592. break;
  3593. case NotSupported:
  3594. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3595. break;
  3596. default:
  3597. break;
  3598. }
  3599. }
  3600. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3601. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3602. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3603. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3604. {
  3605. ChageWebSocketPingInterval(atoi(valuestr));
  3606. }
  3607. return result;
  3608. }
  3609. int handleClearCacheRequest(char *uuid, char *payload)
  3610. {
  3611. mtrace();
  3612. int result = FAIL;
  3613. char comfirmstr[20];
  3614. int fd;
  3615. char rmFileCmd[100]={0};
  3616. struct stat stats;
  3617. DEBUG_INFO("handle ClearCacheRequest\n");
  3618. stat("/Storage/OCPP", &stats);
  3619. // Check for directory existence
  3620. if (S_ISDIR(stats.st_mode) == 1)
  3621. {
  3622. //DEBUG_ERROR("\n OCPP directory exist \n");
  3623. }
  3624. else
  3625. {
  3626. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3627. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3628. system(rmFileCmd);
  3629. }
  3630. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3631. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3632. {
  3633. DEBUG_INFO("AuthorizationCache file exist.\n");
  3634. }
  3635. else
  3636. {
  3637. DEBUG_INFO("AuthorizationCache file not exist\n");
  3638. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3639. if(log == NULL)
  3640. {
  3641. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3642. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3643. goto end;
  3644. }
  3645. else
  3646. {
  3647. fclose(log);
  3648. }
  3649. }
  3650. fd = open(AuthorizationCache_JSON,O_RDWR);
  3651. if(fd < 0)
  3652. {
  3653. DEBUG_INFO("open AuthorizationCache file failed\n");
  3654. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3655. }
  3656. else
  3657. {
  3658. DEBUG_INFO("open AuthorizationCache file successful\n");
  3659. //* 清空? 件 */
  3660. ftruncate(fd,0);
  3661. //* ? 新设置? 件? 移??*/
  3662. lseek(fd,0,SEEK_SET);
  3663. close(fd);
  3664. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3665. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3666. }
  3667. end:
  3668. sendClearCacheConfirmation(uuid, comfirmstr);
  3669. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3670. return result;
  3671. }
  3672. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3673. {
  3674. mtrace();
  3675. int result = FAIL;
  3676. int resultRename;
  3677. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3678. char chargingProfilePurposeStr[26]={0};
  3679. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3680. char tempchargingProfilePurposeStr[26]={0};
  3681. char sstr[160]={0};//sstr[200]={ 0 };
  3682. char str[100]={0};
  3683. int c = 0;
  3684. //int i = 0;
  3685. //char * pch;
  3686. char *loc;
  3687. char fname[200]={0};
  3688. char comfirmstr[20]={0};
  3689. char word[1600]={0};
  3690. int clearflag = FALSE;
  3691. int chargingProfileIdIsNULL = FALSE;
  3692. int connectorIsNULL = FALSE;
  3693. int chargingProfilePurposeIsNULL = FALSE;
  3694. int stackLevelIsNULL = FALSE;
  3695. //int GotoEnd = FALSE;
  3696. FILE *fptr1, *fptr2;
  3697. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3698. int n_chargingProfile=0;
  3699. int isEmptyFile = FALSE;
  3700. char sLineWord[1600]={0};
  3701. char chargingProfiles[10][100]={0};
  3702. int ChargeProfileCount = 0;
  3703. char ch;
  3704. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3705. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3706. //***id ****/
  3707. c = 0;
  3708. loc = strstr(payload, "id");
  3709. memset(sstr ,0, sizeof(sstr) );
  3710. if(loc == NULL)
  3711. {
  3712. chargingProfileIdIsNULL = TRUE;
  3713. }
  3714. else
  3715. {
  3716. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3717. {
  3718. sstr[c] = loc[strlen("id")+2+c];
  3719. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3720. c++;
  3721. }
  3722. sstr[c] = '\0';
  3723. chargingProfileIdInt = atoi(sstr);
  3724. }
  3725. //***connectorId ****/
  3726. c=0;
  3727. loc = strstr(payload, "connectorId");
  3728. memset(sstr ,0, sizeof(sstr) );
  3729. if(loc == NULL)
  3730. {
  3731. connectorIsNULL = TRUE;
  3732. }
  3733. else
  3734. {
  3735. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3736. {
  3737. sstr[c] = loc[strlen("connectorId")+2+c];
  3738. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3739. c++;
  3740. }
  3741. sstr[c] = '\0';
  3742. connectorIdInt = atoi(sstr);
  3743. }
  3744. //***chargingProfilePurpose ****/
  3745. loc = strstr(payload, "chargingProfilePurpose");
  3746. memset(sstr ,0, sizeof(sstr) );
  3747. c = 0;
  3748. if(loc == NULL)
  3749. {
  3750. chargingProfilePurposeIsNULL = TRUE;
  3751. }
  3752. else
  3753. {
  3754. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3755. {
  3756. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3757. c++;
  3758. }
  3759. sstr[c] = '\0';
  3760. strcpy(chargingProfilePurposeStr, sstr);
  3761. }
  3762. //***stackLevel ****/
  3763. c=0;
  3764. loc = strstr(payload, "stackLevel");
  3765. memset(sstr ,0, sizeof(sstr) );
  3766. if(loc == NULL)
  3767. {
  3768. stackLevelIsNULL = TRUE;
  3769. }
  3770. else
  3771. {
  3772. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3773. {
  3774. sstr[c] = loc[strlen("stackLevel")+2+c];
  3775. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3776. c++;
  3777. }
  3778. sstr[c] = '\0';
  3779. stackLevelInt = atoi(sstr);
  3780. }
  3781. if(connectorIsNULL == FALSE)
  3782. {
  3783. switch(connectorIdInt)
  3784. {
  3785. case 0:
  3786. if(chargingProfilePurposeIsNULL == TRUE)
  3787. {
  3788. int l = 0;
  3789. strcpy(fname, ChargePointMaxProfile_JSON);
  3790. if((access(fname,F_OK))!=-1)
  3791. {
  3792. strcpy(chargingProfiles[l], fname);
  3793. l = l + 1;
  3794. }
  3795. strcpy(fname, TxDefaultProfile_0_JSON);
  3796. if((access(fname,F_OK))!=-1)
  3797. {
  3798. strcpy(chargingProfiles[l], fname);
  3799. l = l + 1;
  3800. }
  3801. ChargeProfileCount = l;
  3802. }
  3803. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3804. {
  3805. strcpy(fname, ChargePointMaxProfile_JSON);
  3806. if((access(fname,F_OK))!=-1)
  3807. {
  3808. strcpy(chargingProfiles[0], fname);
  3809. ChargeProfileCount = 1;
  3810. }
  3811. }
  3812. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3813. {
  3814. strcpy(fname, TxDefaultProfile_0_JSON);
  3815. if((access(fname,F_OK))!=-1)
  3816. {
  3817. strcpy(chargingProfiles[0], fname);
  3818. ChargeProfileCount = 1;
  3819. }
  3820. }
  3821. break;
  3822. default:
  3823. if(chargingProfilePurposeIsNULL == TRUE)
  3824. {
  3825. int m = 0;
  3826. memset(fname, 0, sizeof fname);
  3827. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3828. if((access(fname,F_OK))!=-1)
  3829. {
  3830. strcpy(chargingProfiles[m], fname);
  3831. m = m + 1;
  3832. }
  3833. memset(fname, 0, sizeof fname);
  3834. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3835. if((access(fname,F_OK))!=-1)
  3836. {
  3837. strcpy(chargingProfiles[m], fname);
  3838. m = m + 1;
  3839. }
  3840. ChargeProfileCount = m;
  3841. }
  3842. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3843. {
  3844. //strcpy(fname, TxDefaultProfile_1_JSON);
  3845. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3846. if((access(fname,F_OK))!=-1)
  3847. {
  3848. strcpy(chargingProfiles[0], fname);
  3849. ChargeProfileCount = 1;
  3850. }
  3851. }
  3852. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3853. {
  3854. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3855. if((access(fname,F_OK))!=-1)
  3856. {
  3857. strcpy(chargingProfiles[0], fname);
  3858. ChargeProfileCount = 1;
  3859. }
  3860. //strcpy(fname, TxProfile_1_JSON);
  3861. }
  3862. //strcpy(fname, ChargePointMaxProfile_JSON );
  3863. break;
  3864. }
  3865. }
  3866. else // Check all Charging Profiles
  3867. {
  3868. int i = 0;
  3869. char fnametemp[200]={0};
  3870. ChargeProfileCount = 0;
  3871. //Check ChargePointMaxProfile.json exit
  3872. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3873. {
  3874. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3875. i = i + 1;
  3876. }
  3877. //Check TxDefaultProfile_0.json exit
  3878. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3879. {
  3880. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3881. i = i + 1;
  3882. }
  3883. //Check TxDefaultProfile_%d.json
  3884. for(int j=1; j <= gunTotalNumber; j++)
  3885. {
  3886. memset(fnametemp, 0, sizeof fnametemp);
  3887. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3888. if((access(fnametemp,F_OK))!=-1)
  3889. {
  3890. strcpy(chargingProfiles[i], fnametemp);
  3891. i = i + 1;
  3892. }
  3893. }
  3894. //Check TxProfile_%d.json
  3895. for(int j=1; j <= gunTotalNumber; j++)
  3896. {
  3897. memset(fnametemp, 0, sizeof fnametemp);
  3898. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3899. if((access(fnametemp,F_OK))!=-1)
  3900. {
  3901. strcpy(chargingProfiles[i], fnametemp);
  3902. i = i + 1;
  3903. }
  3904. }
  3905. ChargeProfileCount = i;
  3906. }// End connectorIsNULL is TRUE
  3907. if(ChargeProfileCount == 0)
  3908. {
  3909. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3910. goto end;
  3911. }
  3912. #if 0
  3913. fptr1 = fopen(fname, "r");
  3914. if (!fptr1)
  3915. {
  3916. //file not exist
  3917. DEBUG_INFO("Unable to open the input file!!\n");
  3918. fptr1 = fopen(fname, "w+");
  3919. }
  3920. fclose(fptr1);
  3921. #endif
  3922. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3923. {
  3924. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3925. goto end;
  3926. }
  3927. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3928. {
  3929. memset(str, 0, sizeof str);
  3930. // clear temp file
  3931. sprintf(str,"rm -f %s",temp);
  3932. system(str);
  3933. for(int k=0; k < ChargeProfileCount; k++)
  3934. {
  3935. memset(str, 0, sizeof str);
  3936. //clear file in C
  3937. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3938. system(str);
  3939. }
  3940. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3941. goto end;
  3942. }
  3943. else if(connectorIsNULL == TRUE)
  3944. {
  3945. for(int k=0; k < ChargeProfileCount; k++)
  3946. {
  3947. fptr1 = fopen(chargingProfiles[k], "r");
  3948. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  3949. //Check Charging Profile Count
  3950. while(fscanf(fptr1, "%s", word) != EOF)
  3951. {
  3952. //DEBUG_INFO("word=%s\n",word);
  3953. if(strstr(word, "chargingProfileId")!= NULL)
  3954. {
  3955. //DEBUG_INFO("test chargingProfileId \n");
  3956. n_chargingProfile = n_chargingProfile + 1;
  3957. //DEBUG_INFO("chargingProfileId Found\n");
  3958. }
  3959. }
  3960. rewind(fptr1);
  3961. //search Charging Profile Element
  3962. //int i= 0;
  3963. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3964. {
  3965. //------------------------tempconnectorIdInt------------------------//
  3966. loc = strstr(sLineWord, "connectorId");
  3967. c = 0;
  3968. memset(sstr ,0, sizeof(sstr) );
  3969. while (loc[strlen("connectorId")+2+c] != ',')
  3970. {
  3971. sstr[c] = loc[strlen("connectorId")+2+c];
  3972. c++;
  3973. }
  3974. sstr[c] = '\0';
  3975. tempconnectorIdInt = atoi(sstr);
  3976. printf("file's gun number is %d\n", tempconnectorIdInt);
  3977. //--------------------------chargingProfileId--------------------//
  3978. c = 0;
  3979. loc = strstr(sLineWord, "chargingProfileId");
  3980. memset(sstr ,0, sizeof(sstr) );
  3981. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3982. {
  3983. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3984. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3985. c++;
  3986. }
  3987. sstr[c] = '\0';
  3988. tempchargingProfileIdInt = atoi(sstr);
  3989. //stackLevel
  3990. c = 0;
  3991. loc = strstr(sLineWord, "stackLevel");
  3992. memset(sstr ,0, sizeof(sstr) );
  3993. while (loc[strlen("stackLevel")+2+c] != ',')
  3994. {
  3995. sstr[c] = loc[strlen("stackLevel")+2+c];
  3996. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3997. c++;
  3998. }
  3999. sstr[c] = '\0';
  4000. tempstackLevelInt = atoi(sstr);
  4001. c = 0;
  4002. loc = strstr(sLineWord, "chargingProfilePurpose");
  4003. memset(sstr ,0, sizeof(sstr) );
  4004. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4005. {
  4006. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4007. c++;
  4008. }
  4009. sstr[c] = '\0';
  4010. strcpy(tempchargingProfilePurposeStr, sstr);
  4011. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4012. {
  4013. //------- not write to fptr2-------//
  4014. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4015. //clearflag = TRUE;
  4016. }
  4017. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4018. {
  4019. //------- not write to fptr2-------//
  4020. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4021. }
  4022. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4023. {
  4024. //------- not write to fptr2-------//
  4025. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4026. }
  4027. else
  4028. {
  4029. fprintf(fptr2, sLineWord);//writing data into file
  4030. }
  4031. memset(sLineWord, 0, sizeof sLineWord);
  4032. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4033. if(clearflag == TRUE)
  4034. {
  4035. fclose(fptr1);
  4036. fclose(fptr2);
  4037. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4038. system(str);
  4039. // clear temp file
  4040. sprintf(str,"rm -f %s",temp);
  4041. system(str);
  4042. }
  4043. else
  4044. {
  4045. fclose(fptr1);
  4046. fclose(fptr2);
  4047. memset(str, 0, sizeof str);
  4048. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4049. system(str);
  4050. resultRename = rename(temp, chargingProfiles[k]);
  4051. if(resultRename == 0)
  4052. {
  4053. DEBUG_INFO("File ChargingProfile renamed successfully");
  4054. }
  4055. else
  4056. {
  4057. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4058. }
  4059. if(comfirmstr[0]== 0)
  4060. {
  4061. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4062. }
  4063. //Check chargingProfile is empty file
  4064. /*------ Read the file ----------------*/
  4065. fptr1=fopen(chargingProfiles[k],"r");
  4066. ch=fgetc(fptr1);
  4067. rewind(fptr1);
  4068. memset(sLineWord, 0, sizeof sLineWord);
  4069. if(ch!=EOF)
  4070. {
  4071. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4072. {
  4073. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4074. if(sLineWord[0]=='\0')
  4075. {
  4076. isEmptyFile = TRUE;
  4077. break;
  4078. }
  4079. else
  4080. {
  4081. isEmptyFile = FALSE;
  4082. break;
  4083. }
  4084. }
  4085. }
  4086. fclose(fptr1);
  4087. if(isEmptyFile == TRUE)
  4088. {
  4089. memset(str, 0, sizeof str);
  4090. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4091. system(str);
  4092. }
  4093. }
  4094. }// End of while(int k=0; k < ChargePointCount; k++)
  4095. }
  4096. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4097. {
  4098. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4099. for(int k=0; k < ChargeProfileCount; k++)
  4100. {
  4101. fptr1 = fopen(chargingProfiles[k], "r");
  4102. fptr2 = fopen(temp, "w+");
  4103. //Check Charging Profile Count
  4104. while(fscanf(fptr1, "%s", word) != EOF)
  4105. {
  4106. //DEBUG_INFO("word=%s\n",word);
  4107. if(strstr(word, "chargingProfileId")!= NULL)
  4108. {
  4109. //DEBUG_INFO("test chargingProfileId \n");
  4110. n_chargingProfile = n_chargingProfile + 1;
  4111. //DEBUG_INFO("chargingProfileId Found\n");
  4112. }
  4113. }
  4114. rewind(fptr1);
  4115. //search Charging Profile Element
  4116. //int i= 0;
  4117. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4118. {
  4119. //*************************tempconnectorIdInt*********************************/
  4120. loc = strstr(sLineWord, "connectorId");
  4121. c = 0;
  4122. memset(sstr ,0, sizeof(sstr) );
  4123. while (loc[strlen("connectorId")+2+c] != ',')
  4124. {
  4125. sstr[c] = loc[strlen("connectorId")+2+c];
  4126. c++;
  4127. }
  4128. sstr[c] = '\0';
  4129. tempconnectorIdInt = atoi(sstr);
  4130. //chargingProfileId
  4131. c = 0;
  4132. loc = strstr(sLineWord, "chargingProfileId");
  4133. memset(sstr ,0, sizeof(sstr) );
  4134. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4135. {
  4136. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4137. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4138. c++;
  4139. }
  4140. sstr[c] = '\0';
  4141. tempchargingProfileIdInt = atoi(sstr);
  4142. //stackLevel
  4143. c = 0;
  4144. loc = strstr(sLineWord, "stackLevel");
  4145. memset(sstr ,0, sizeof(sstr) );
  4146. while (loc[strlen("stackLevel")+2+c] != ',')
  4147. {
  4148. sstr[c] = loc[strlen("stackLevel")+2+c];
  4149. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4150. c++;
  4151. }
  4152. sstr[c] = '\0';
  4153. tempstackLevelInt = atoi(sstr);
  4154. c = 0;
  4155. loc = strstr(sLineWord, "chargingProfilePurpose");
  4156. memset(sstr ,0, sizeof(sstr) );
  4157. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4158. {
  4159. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4160. c++;
  4161. }
  4162. sstr[c] = '\0';
  4163. strcpy(tempchargingProfilePurposeStr, sstr);
  4164. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4165. {
  4166. //------- not write to fptr2-------//
  4167. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4168. //clearflag = TRUE;
  4169. }
  4170. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4171. {
  4172. //------- not write to fptr2-------//
  4173. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4174. }
  4175. else if(stackLevelIsNULL == TRUE)
  4176. {
  4177. //Clear Whole File
  4178. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4179. clearflag = TRUE;
  4180. break;
  4181. }
  4182. else
  4183. {
  4184. fprintf(fptr2, sLineWord);//writing data into file
  4185. }
  4186. memset(sLineWord, 0, sizeof sLineWord);
  4187. }
  4188. if(clearflag == TRUE)
  4189. {
  4190. fclose(fptr1);
  4191. fclose(fptr2);
  4192. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4193. system(str);
  4194. // clear temp file
  4195. sprintf(str,"rm -f %s",temp);
  4196. system(str);
  4197. }
  4198. else
  4199. {
  4200. fclose(fptr1);
  4201. fclose(fptr2);
  4202. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4203. system(str);
  4204. resultRename = rename(temp, chargingProfiles[k]);
  4205. if(resultRename == 0)
  4206. {
  4207. DEBUG_INFO("File ChargingProfile renamed successfully");
  4208. }
  4209. else
  4210. {
  4211. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4212. }
  4213. if(comfirmstr[0]== 0)
  4214. {
  4215. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4216. }
  4217. //Check chargingProfile is empty file
  4218. /*------ Read the file ----------------*/
  4219. fptr1=fopen(chargingProfiles[k],"r");
  4220. ch=fgetc(fptr1);
  4221. rewind(fptr1);
  4222. memset(sLineWord, 0, sizeof sLineWord);
  4223. if(ch!=EOF)
  4224. {
  4225. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4226. {
  4227. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4228. if(sLineWord[0]=='\0')
  4229. {
  4230. isEmptyFile = TRUE;
  4231. break;
  4232. }
  4233. else
  4234. {
  4235. isEmptyFile = FALSE;
  4236. break;
  4237. }
  4238. }
  4239. }
  4240. fclose(fptr1);
  4241. if(isEmptyFile == TRUE)
  4242. {
  4243. memset(str, 0, sizeof str);
  4244. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4245. system(str);
  4246. }
  4247. /*------- End of reading ---------------*/
  4248. }
  4249. } // while(int k=0; k < ChargeProfileCount; k++)
  4250. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4251. end:
  4252. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4253. return result;
  4254. }
  4255. int handleDataTransferRequest(char *uuid, char *payload)
  4256. {
  4257. mtrace();
  4258. int result = FAIL;
  4259. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4260. char tempvendorId[255]={0};
  4261. char tempmessageId[50]={0};
  4262. char tempdata[50]={0};
  4263. char sstr[160]={0};//sstr[200]={ 0 };
  4264. char message[80]={0};
  4265. int c = 0;
  4266. char *loc;
  4267. DEBUG_INFO("handle DataTransferRequest\n");
  4268. if((uuid != NULL) && (payload != NULL))
  4269. {
  4270. //===============================
  4271. // vendorId
  4272. //===============================
  4273. c = 0;
  4274. loc = strstr(payload, "vendorId");
  4275. while (loc[strlen("vendorId")+3+c] != '\"')
  4276. {
  4277. sstr[c] = loc[strlen("vendorId")+3+c];
  4278. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4279. c++;
  4280. }
  4281. sstr[c] = '\0';
  4282. strcpy(tempvendorId,sstr);
  4283. //===============================
  4284. // messageId
  4285. //===============================
  4286. memset(sstr ,0, sizeof(sstr) );
  4287. c = 0;
  4288. loc = strstr(payload, "messageId");
  4289. while (loc[strlen("messageId")+3+c] != '\"')
  4290. {
  4291. sstr[c] = loc[strlen("messageId")+3+c];
  4292. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4293. c++;
  4294. }
  4295. sstr[c] = '\0';
  4296. strcpy(tempmessageId,sstr);
  4297. //===============================
  4298. // data
  4299. //===============================
  4300. memset(sstr ,0, sizeof(sstr) );
  4301. c = 0;
  4302. loc = strstr(payload, "data");
  4303. printf("loc=%s\n",loc);
  4304. while (loc[strlen("data")+3+c] != '\"')
  4305. {
  4306. sstr[c] = loc[strlen("data")+3+c];
  4307. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4308. c++;
  4309. }
  4310. sstr[c] = '\0';
  4311. strcpy(tempdata,sstr);
  4312. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4313. }
  4314. else
  4315. {
  4316. char guid[37]={0};
  4317. random_uuid(guid);
  4318. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4319. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4320. }
  4321. LWS_Send(message);
  4322. return result;
  4323. }
  4324. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4325. {
  4326. mtrace();
  4327. int result = FAIL;
  4328. int connectorIdInt, durationInt;
  4329. char chargingRateUnitStr[4]={0};
  4330. //int tempconnectorIdInt,
  4331. int tempdurationInt;
  4332. float tempminChargingRateFloat = 0.0;
  4333. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4334. int tempStartPeriodInt=0;
  4335. float tempLimitInt=0.0;//0.1;
  4336. int tempNumberPhasesInt=0;
  4337. char fname[200];
  4338. char comfirmstr[20];
  4339. //float totallimit =0.0;
  4340. float MinChargingRate =0.0;
  4341. //double diff_t;
  4342. //struct tm tp;
  4343. FILE *fptr1;
  4344. int c = 0;
  4345. //int i = 0;
  4346. char * pch;
  4347. char *loc;
  4348. char sstr[200]={ 0 };
  4349. int n_chargingProfile = 0;
  4350. int n_SchedulePeriods = 0;
  4351. char SchedulePeriodList[10][200]={0};
  4352. char sLineWord[1600]={0};
  4353. //int n_periods = 0;
  4354. char word[1000]={0};
  4355. int confirmPeriods = 0;
  4356. struct StructProfile ChargePointMaxProfile;
  4357. struct StructProfile TxDefaultProfile;
  4358. struct StructProfile TxProfile;
  4359. struct StructProfile TxDefaultProfiletemp[2]={0};
  4360. int TxDefaultProfileFileIsNull=FALSE;
  4361. int ChargePointMaxProfileIsNull=FALSE;
  4362. int TxProfileIsNull=FALSE;
  4363. int CompositeSceduleIndex = 0;
  4364. char ChargePointMaxProfileScheduleStr[30]={0};
  4365. char TxDefaultProfileScheduleStr[30]={0};
  4366. char TxProfileScheduleStr[30]={0};
  4367. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4368. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4369. memset(&TxProfile,0,sizeof(struct StructProfile));
  4370. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4371. c=0;
  4372. loc = strstr(payload, "connectorId");
  4373. memset(sstr ,0, sizeof(sstr) );
  4374. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4375. {
  4376. sstr[c] = loc[strlen("connectorId")+2+c];
  4377. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4378. c++;
  4379. }
  4380. sstr[c] = '\0';
  4381. connectorIdInt = atoi(sstr);
  4382. c=0;
  4383. loc = strstr(payload, "duration");
  4384. memset(sstr ,0, sizeof(sstr) );
  4385. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4386. {
  4387. sstr[c] = loc[strlen("duration")+2+c];
  4388. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4389. c++;
  4390. }
  4391. sstr[c] = '\0';
  4392. durationInt = atoi(sstr);
  4393. c = 0;
  4394. loc = strstr(payload, "chargingRateUnit");
  4395. memset(sstr ,0, sizeof(sstr) );
  4396. if(loc == NULL)
  4397. {
  4398. }
  4399. else
  4400. {
  4401. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4402. {
  4403. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4404. c++;
  4405. }
  4406. sstr[c] = '\0';
  4407. strcpy(chargingRateUnitStr, sstr);
  4408. }
  4409. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4410. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4411. if(connectorIdInt==0) // connectorId is 0
  4412. {
  4413. //******************************ChargePointMaxProfile*****************************************************/
  4414. strcpy(fname, ChargePointMaxProfile_JSON );
  4415. char word[30]={0};
  4416. char sLineWord[1060]={0};
  4417. int n_chargingProfile=0;
  4418. ChargePointMaxProfileIsNull=TRUE;
  4419. if((access(fname,F_OK))!=-1)
  4420. {
  4421. fptr1 = fopen(fname, "r");
  4422. int c;
  4423. c = fgetc(fptr1);
  4424. //DEBUG_INFO("c:%d\n",c);
  4425. rewind(fptr1);
  4426. if(c == EOF)
  4427. {
  4428. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4429. ChargePointMaxProfileIsNull=TRUE;
  4430. fclose(fptr1);
  4431. }
  4432. else
  4433. {
  4434. ChargePointMaxProfileIsNull=FALSE;
  4435. while(fscanf(fptr1, "%s", word) != EOF)
  4436. {
  4437. if(strcmp(word, "chargingProfileId") == 0)
  4438. {
  4439. n_chargingProfile = n_chargingProfile + 1;
  4440. printf("Found\n");
  4441. }
  4442. }
  4443. rewind(fptr1);
  4444. //search Charging Profile Element
  4445. int i= 0;
  4446. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4447. #if 0
  4448. /***********connectorId****************/
  4449. c = 0;
  4450. loc = strstr(sLineWord, "connectorId");
  4451. // printf("loc=%s\n",loc);
  4452. memset(sstr ,0, sizeof(sstr) );
  4453. while (loc[strlen("connectorId")+2+c] != ',')
  4454. {
  4455. sstr[c] = loc[strlen("connectorId")+2+c];
  4456. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4457. c++;
  4458. }
  4459. sstr[c] = '\0';
  4460. tempconnectorIdInt = atoi(sstr);
  4461. #endif
  4462. //***********validFrom**************/
  4463. c = 0;
  4464. loc = strstr(sLineWord, "validFrom");
  4465. //DEBUG_INFO("loc=%s\n",loc);
  4466. memset(sstr ,0, sizeof(sstr) );
  4467. if(loc != NULL)
  4468. {
  4469. while (loc[3+strlen("validFrom")+c] != '\"')
  4470. {
  4471. sstr[c] = loc[3+strlen("validFrom")+c];
  4472. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4473. c++;
  4474. }
  4475. sstr[c] = '\0';
  4476. DEBUG_INFO("validFrom=%s\n",sstr);
  4477. strcpy(tempvalidFromStr,sstr);
  4478. }
  4479. else
  4480. {
  4481. strcpy(tempvalidFromStr,"");
  4482. }
  4483. //**********startSchedule**********/
  4484. c = 0;
  4485. loc = strstr(sLineWord, "startSchedule");
  4486. //DEBUG_INFO("loc=%s\n",loc);
  4487. memset(sstr ,0, sizeof(sstr) );
  4488. while (loc[3+strlen("startSchedule")+c] != '\"')
  4489. {
  4490. sstr[c] = loc[3+strlen("startSchedule")+c];
  4491. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4492. c++;
  4493. }
  4494. sstr[c] = '\0';
  4495. strcpy(tempstartScheduleStr, sstr);
  4496. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4497. //**********chargingRateUnit**********/
  4498. c = 0;
  4499. loc = strstr(sLineWord, "chargingRateUnit");
  4500. memset(sstr ,0, sizeof(sstr) );
  4501. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4502. {
  4503. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4504. c++;
  4505. }
  4506. sstr[c] = '\0';
  4507. strcpy(tempchargingRateUnitStr, sstr);
  4508. //**********minChargingRate*******/
  4509. c = 0;
  4510. loc = strstr(sLineWord, "minChargingRate");
  4511. //printf("loc=%s\n",loc);
  4512. if(loc != NULL)
  4513. {
  4514. memset(sstr ,0, sizeof(sstr) );
  4515. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4516. {
  4517. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4518. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4519. c++;
  4520. }
  4521. sstr[c] = '\0';
  4522. tempminChargingRateFloat = atof(sstr);
  4523. }
  4524. else
  4525. {
  4526. tempminChargingRateFloat = 0.0;
  4527. }
  4528. //
  4529. #if 0
  4530. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4531. tp.tm_isdst = -1;
  4532. time_t utc = mktime(&tp);
  4533. // current time
  4534. time_t t = time(NULL);
  4535. #endif
  4536. //diff_t = difftime(t, utc);
  4537. //parsing strings to words
  4538. i = 0;
  4539. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4540. loc = loc+3+strlen("chargingSchedulePeriod");
  4541. pch = strtok(loc ,"{");
  4542. while (pch != NULL)
  4543. {
  4544. strcpy(SchedulePeriodList[i], pch);
  4545. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4546. //printf ("%s\n",pch);
  4547. pch = strtok (NULL, "{");
  4548. i = i + 1;
  4549. }
  4550. n_SchedulePeriods = i;
  4551. for(int i=0;i<n_SchedulePeriods;i++)
  4552. {
  4553. //*************startPeriod****************/
  4554. c = 0;
  4555. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4556. memset(sstr ,0, sizeof(sstr) );
  4557. while (loc[strlen("startPeriod")+2+c] != ',')
  4558. {
  4559. sstr[c] = loc[strlen("startPeriod")+2+c];
  4560. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4561. c++;
  4562. }
  4563. sstr[c] = '\0';
  4564. tempStartPeriodInt = atoi(sstr);
  4565. //*************limit****************/
  4566. c = 0;
  4567. loc = strstr(SchedulePeriodList[i], "limit");
  4568. memset(sstr ,0, sizeof(sstr) );
  4569. while (loc[strlen("limit")+2+c] != ',')
  4570. {
  4571. sstr[c] = loc[strlen("limit")+2+c];
  4572. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4573. c++;
  4574. }
  4575. sstr[c] = '\0';
  4576. tempLimitInt = atof(sstr);
  4577. //*************numberPhases****************/
  4578. c = 0;
  4579. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4580. memset(sstr ,0, sizeof(sstr) );
  4581. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4582. {
  4583. sstr[c] = loc[strlen("numberPhases")+2+c];
  4584. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4585. c++;
  4586. }
  4587. sstr[c] = '\0';
  4588. tempNumberPhasesInt = atoi(sstr);
  4589. ChargePointMaxProfile.Duration = durationInt;
  4590. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4591. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4592. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4593. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4594. }
  4595. if(MinChargingRate < tempminChargingRateFloat)
  4596. MinChargingRate = tempminChargingRateFloat;
  4597. }
  4598. }// End of file ChargingProfile
  4599. } //THE END OF ACCESS ChargePointMaxProfile
  4600. //******************************TxDefaultProfile***********************************************/
  4601. strcpy(fname, TxDefaultProfile_0_JSON);
  4602. memset(word, 0, 30);
  4603. memset(sLineWord, 0, 1060);
  4604. //char word[30]={0};
  4605. //char sLineWord[1060]={0};
  4606. n_chargingProfile=0;
  4607. TxDefaultProfileFileIsNull=TRUE;
  4608. if((access(fname,F_OK))!=-1)
  4609. {
  4610. fptr1 = fopen(fname, "r");
  4611. c = 0;
  4612. c = fgetc(fptr1);
  4613. //DEBUG_INFO("c:%d\n",c);
  4614. rewind(fptr1);
  4615. if(c == EOF)
  4616. {
  4617. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4618. TxDefaultProfileFileIsNull=TRUE;
  4619. fclose(fptr1);
  4620. }
  4621. else
  4622. {
  4623. TxDefaultProfileFileIsNull=FALSE;
  4624. while(fscanf(fptr1, "%s", word) != EOF)
  4625. {
  4626. if(strcmp(word, "chargingProfileId") == 0)
  4627. {
  4628. n_chargingProfile = n_chargingProfile + 1;
  4629. printf("Found\n");
  4630. }
  4631. }
  4632. rewind(fptr1);
  4633. //search Charging Profile Element
  4634. int i= 0;
  4635. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4636. #if 0
  4637. /***********connectorId****************/
  4638. c = 0;
  4639. loc = strstr(sLineWord, "connectorId");
  4640. // printf("loc=%s\n",loc);
  4641. memset(sstr ,0, sizeof(sstr) );
  4642. while (loc[strlen("connectorId")+2+c] != ',')
  4643. {
  4644. sstr[c] = loc[strlen("connectorId")+2+c];
  4645. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4646. c++;
  4647. }
  4648. sstr[c] = '\0';
  4649. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4650. tempconnectorIdInt = atoi(sstr);
  4651. #endif
  4652. //***********validFrom**************/
  4653. c = 0;
  4654. loc = strstr(sLineWord, "validFrom");
  4655. //DEBUG_INFO("loc=%s\n",loc);
  4656. memset(sstr ,0, sizeof(sstr) );
  4657. if(loc != NULL)
  4658. {
  4659. while (loc[3+strlen("validFrom")+c] != '\"')
  4660. {
  4661. sstr[c] = loc[3+strlen("validFrom")+c];
  4662. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4663. c++;
  4664. }
  4665. sstr[c] = '\0';
  4666. DEBUG_INFO("validFrom=%s\n",sstr);
  4667. strcpy(tempvalidFromStr,sstr);
  4668. }
  4669. else
  4670. {
  4671. strcpy(tempvalidFromStr,"");
  4672. }
  4673. //**********startSchedule**********/
  4674. c = 0;
  4675. loc = strstr(sLineWord, "startSchedule");
  4676. //DEBUG_INFO("loc=%s\n",loc);
  4677. memset(sstr ,0, sizeof(sstr) );
  4678. while (loc[3+strlen("startSchedule")+c] != '\"')
  4679. {
  4680. sstr[c] = loc[3+strlen("startSchedule")+c];
  4681. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4682. c++;
  4683. }
  4684. sstr[c] = '\0';
  4685. strcpy(tempstartScheduleStr, sstr);
  4686. strcpy(TxDefaultProfileScheduleStr, sstr);
  4687. //**********chargingRateUnit**********/
  4688. c = 0;
  4689. loc = strstr(sLineWord, "chargingRateUnit");
  4690. memset(sstr ,0, sizeof(sstr) );
  4691. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4692. {
  4693. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4694. c++;
  4695. }
  4696. sstr[c] = '\0';
  4697. strcpy(tempchargingRateUnitStr, sstr);
  4698. //**********minChargingRate*******/
  4699. c = 0;
  4700. loc = strstr(sLineWord, "minChargingRate");
  4701. //printf("loc=%s\n",loc);
  4702. if(loc != NULL)
  4703. {
  4704. memset(sstr ,0, sizeof(sstr) );
  4705. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4706. {
  4707. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4708. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4709. c++;
  4710. }
  4711. sstr[c] = '\0';
  4712. tempminChargingRateFloat = atof(sstr);
  4713. }
  4714. else
  4715. {
  4716. tempminChargingRateFloat = 0.0;
  4717. }
  4718. #if 0
  4719. //
  4720. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4721. tp.tm_isdst = -1;
  4722. time_t utc = mktime(&tp);
  4723. // current time
  4724. time_t t = time(NULL);
  4725. //diff_t = difftime(t, utc);
  4726. #endif
  4727. //parsing strings to words
  4728. i = 0;
  4729. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4730. loc = loc+3+strlen("chargingSchedulePeriod");
  4731. pch = strtok(loc ,"{");
  4732. while (pch != NULL)
  4733. {
  4734. strcpy(SchedulePeriodList[i], pch);
  4735. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4736. //printf ("%s\n",pch);
  4737. pch = strtok (NULL, "{");
  4738. i = i + 1;
  4739. }
  4740. n_SchedulePeriods = i;
  4741. for(int i=0;i<n_SchedulePeriods;i++)
  4742. {
  4743. //*************startPeriod****************/
  4744. c = 0;
  4745. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4746. memset(sstr ,0, sizeof(sstr) );
  4747. while (loc[strlen("startPeriod")+2+c] != ',')
  4748. {
  4749. sstr[c] = loc[strlen("startPeriod")+2+c];
  4750. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4751. c++;
  4752. }
  4753. sstr[c] = '\0';
  4754. tempStartPeriodInt = atoi(sstr);
  4755. //*************limit****************/
  4756. c = 0;
  4757. loc = strstr(SchedulePeriodList[i], "limit");
  4758. memset(sstr ,0, sizeof(sstr) );
  4759. while (loc[strlen("limit")+2+c] != ',')
  4760. {
  4761. sstr[c] = loc[strlen("limit")+2+c];
  4762. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4763. c++;
  4764. }
  4765. sstr[c] = '\0';
  4766. tempLimitInt = atof(sstr);
  4767. //*************numberPhases****************/
  4768. c = 0;
  4769. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4770. memset(sstr ,0, sizeof(sstr) );
  4771. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4772. {
  4773. sstr[c] = loc[strlen("numberPhases")+2+c];
  4774. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4775. c++;
  4776. }
  4777. sstr[c] = '\0';
  4778. tempNumberPhasesInt = atoi(sstr);
  4779. TxDefaultProfile.Duration = durationInt;
  4780. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4781. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4782. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4783. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4784. }
  4785. if(MinChargingRate < tempminChargingRateFloat)
  4786. MinChargingRate = tempminChargingRateFloat;
  4787. }
  4788. }
  4789. }// the end of ACCESS TxDefaultProfile
  4790. //--------------------- Composite Schedule-----------------------------//
  4791. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4792. {
  4793. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4794. struct tm tp;
  4795. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4796. tp.tm_isdst = -1;
  4797. time_t utc = mktime(&tp);
  4798. time_t t = time(NULL);
  4799. double diff_f = difftime(t, utc);
  4800. int diff_i; //= (int)diff_f;
  4801. int quotient; //= diff_i / 86400;//86400 seconds/day
  4802. int period = 0;
  4803. if(diff_f >= 0)
  4804. {
  4805. diff_i = (int)diff_f;
  4806. quotient = diff_i / 86400;
  4807. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4808. {
  4809. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4810. {
  4811. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4812. {
  4813. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4814. }
  4815. else
  4816. {
  4817. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  4818. }
  4819. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4820. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4821. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4822. period = period + 1;
  4823. }
  4824. }
  4825. }
  4826. confirmPeriods = period;
  4827. }
  4828. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  4829. {
  4830. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4831. struct tm tp;
  4832. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4833. tp.tm_isdst = -1;
  4834. time_t utc = mktime(&tp);
  4835. time_t t = time(NULL);
  4836. double diff_f = difftime(t, utc);
  4837. int diff_i; // = (int)diff_f;
  4838. int quotient; // = diff_i / 86400;//86400 seconds/day
  4839. int period = 0;
  4840. if(diff_f >= 0)
  4841. {
  4842. diff_i = (int)diff_f;
  4843. quotient = diff_i / 86400;//86400 seconds/day
  4844. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4845. {
  4846. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4847. {
  4848. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4849. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4850. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4851. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4852. period = period + 1;
  4853. }
  4854. }
  4855. }
  4856. confirmPeriods = period;
  4857. }
  4858. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  4859. {
  4860. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  4861. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  4862. {
  4863. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  4864. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  4865. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  4866. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4867. }
  4868. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  4869. }
  4870. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  4871. {
  4872. confirmPeriods = 0;
  4873. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  4874. goto end;
  4875. }
  4876. //* Define temporary variables */
  4877. struct tm *gtime;
  4878. time_t now;
  4879. char buf[28];
  4880. /* Read the current system time */
  4881. time(&now);
  4882. /* Convert the system time to GMT (now UTC) */
  4883. gtime = gmtime(&now);
  4884. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4885. // make .conf
  4886. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4887. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  4888. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  4889. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4890. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4891. }
  4892. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4893. {
  4894. //*****************************ChargePointMaxProfile******************************************/
  4895. strcpy(fname, ChargePointMaxProfile_JSON);
  4896. ChargePointMaxProfileIsNull=TRUE;
  4897. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4898. {
  4899. fptr1 = fopen(fname, "r");
  4900. int c;
  4901. c = fgetc(fptr1);
  4902. //DEBUG_INFO("c:%d\n",c);
  4903. rewind(fptr1);
  4904. if(c == EOF)
  4905. {
  4906. DEBUG_INFO("\n End of file reached.");
  4907. ChargePointMaxProfileIsNull=TRUE;
  4908. fclose(fptr1);
  4909. }
  4910. else
  4911. {
  4912. ChargePointMaxProfileIsNull=FALSE;
  4913. while(fscanf(fptr1, "%s", word) != EOF)
  4914. {
  4915. if(strcmp(word, "chargingProfileId") == 0)
  4916. {
  4917. n_chargingProfile = n_chargingProfile + 1;
  4918. }
  4919. }
  4920. rewind(fptr1);
  4921. //search Charging Profile Element
  4922. int i = 0;
  4923. int j = 0;
  4924. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4925. #if 0
  4926. /***********connectorId****************/
  4927. c = 0;
  4928. loc = strstr(sLineWord, "connectorId");
  4929. memset(sstr ,0, sizeof(sstr) );
  4930. while (loc[strlen("connectorId")+2+c] != ',')
  4931. {
  4932. sstr[c] = loc[strlen("connectorId")+2+c];
  4933. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4934. c++;
  4935. }
  4936. sstr[c] = '\0';
  4937. tempconnectorIdInt = atoi(sstr);
  4938. #endif
  4939. //***********validFrom**************/
  4940. c = 0;
  4941. loc = strstr(sLineWord, "validFrom");
  4942. if(loc != NULL)
  4943. {
  4944. memset(sstr ,0, sizeof(sstr) );
  4945. while (loc[3+strlen("validFrom")+c] != '\"')
  4946. {
  4947. sstr[c] = loc[3+strlen("validFrom")+c];
  4948. c++;
  4949. }
  4950. sstr[c] = '\0';
  4951. strcpy(tempvalidFromStr,sstr);
  4952. }
  4953. else
  4954. {
  4955. strcpy(tempvalidFromStr,"");
  4956. }
  4957. //***********validFrom**************/
  4958. c = 0;
  4959. loc = strstr(sLineWord, "duration");
  4960. if(loc != NULL)
  4961. {
  4962. memset(sstr ,0, sizeof(sstr) );
  4963. while (loc[2+strlen("duration")+c] != ',')
  4964. {
  4965. sstr[c] = loc[2+strlen("duration")+c];
  4966. c++;
  4967. }
  4968. sstr[c] = '\0';
  4969. tempdurationInt = atoi(sstr);
  4970. }
  4971. else
  4972. {
  4973. tempdurationInt = 0;
  4974. }
  4975. //**********startSchedule**********/
  4976. c = 0;
  4977. loc = strstr(sLineWord, "startSchedule");
  4978. memset(sstr ,0, sizeof(sstr) );
  4979. while (loc[3+strlen("startSchedule")+c] != '\"')
  4980. {
  4981. sstr[c] = loc[3+strlen("startSchedule")+c];
  4982. c++;
  4983. }
  4984. sstr[c] = '\0';
  4985. strcpy(tempstartScheduleStr, sstr);
  4986. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4987. //**********chargingRateUnit**********/
  4988. c = 0;
  4989. loc = strstr(sLineWord, "chargingRateUnit");
  4990. memset(sstr ,0, sizeof(sstr) );
  4991. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4992. {
  4993. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4994. c++;
  4995. }
  4996. sstr[c] = '\0';
  4997. strcpy(tempchargingRateUnitStr, sstr);
  4998. //**********minChargingRate*******/
  4999. c = 0;
  5000. loc = strstr(sLineWord, "minChargingRate");
  5001. if(loc != NULL)
  5002. {
  5003. memset(sstr ,0, sizeof(sstr) );
  5004. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5005. {
  5006. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5007. c++;
  5008. }
  5009. sstr[c] = '\0';
  5010. tempminChargingRateFloat = atof(sstr);
  5011. }
  5012. else
  5013. {
  5014. tempminChargingRateFloat = 0.0;
  5015. }
  5016. #if 0
  5017. //
  5018. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5019. tp.tm_isdst = -1;
  5020. time_t utc = mktime(&tp);
  5021. time_t t = time(NULL);
  5022. //diff_t = difftime(t, utc);
  5023. #endif
  5024. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5025. //DEBUG_INFO(" debug 5 -1\n");
  5026. //parsing strings to words
  5027. i = 0;
  5028. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5029. loc = loc+3+strlen("chargingSchedulePeriod");
  5030. pch = strtok(loc ,"{");
  5031. while (pch != NULL)
  5032. {
  5033. strcpy(SchedulePeriodList[i], pch);
  5034. pch = strtok (NULL, "{");
  5035. i = i + 1;
  5036. }
  5037. n_SchedulePeriods = i;
  5038. for(int i=0;i<n_SchedulePeriods;i++)
  5039. {
  5040. //*************startPeriod****************/
  5041. c = 0;
  5042. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5043. memset(sstr ,0, sizeof(sstr) );
  5044. while (loc[strlen("startPeriod")+2+c] != ',')
  5045. {
  5046. sstr[c] = loc[strlen("startPeriod")+2+c];
  5047. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5048. c++;
  5049. }
  5050. sstr[c] = '\0';
  5051. tempStartPeriodInt = atoi(sstr);
  5052. //*************limit****************/
  5053. c = 0;
  5054. loc = strstr(SchedulePeriodList[i], "limit");
  5055. memset(sstr ,0, sizeof(sstr) );
  5056. while (loc[strlen("limit")+2+c] != ',')
  5057. {
  5058. sstr[c] = loc[strlen("limit")+2+c];
  5059. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5060. c++;
  5061. }
  5062. sstr[c] = '\0';
  5063. tempLimitInt = atof(sstr);
  5064. //*************numberPhases****************/
  5065. c = 0;
  5066. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5067. memset(sstr ,0, sizeof(sstr) );
  5068. while (loc[strlen("numberPhases")+2+c] != '}')
  5069. {
  5070. sstr[c] = loc[strlen("numberPhases")+2+c];
  5071. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5072. c++;
  5073. }
  5074. sstr[c] = '\0';
  5075. tempNumberPhasesInt = atoi(sstr);
  5076. if(j == 0)
  5077. {
  5078. ChargePointMaxProfile.Duration = tempdurationInt;
  5079. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5080. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5081. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5082. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5083. }
  5084. }
  5085. if(MinChargingRate < tempminChargingRateFloat)
  5086. {
  5087. MinChargingRate = tempminChargingRateFloat;
  5088. }
  5089. if(confirmPeriods < n_SchedulePeriods)
  5090. {
  5091. confirmPeriods = n_SchedulePeriods;
  5092. }
  5093. j = j + 1;
  5094. }
  5095. fclose(fptr1);
  5096. }
  5097. }// the end of access file ChargePointMaxProfile
  5098. //****************************TxDefaultProfile************************************************/
  5099. #if 0
  5100. switch(connectorIdInt)
  5101. {
  5102. case 0:
  5103. break;
  5104. case 1:
  5105. strcpy(fname, TxDefaultProfile_1_JSON );
  5106. break;
  5107. case 2:
  5108. strcpy(fname, TxDefaultProfile_2_JSON );
  5109. break;
  5110. default:
  5111. strcpy(fname, TxDefaultProfile_1_JSON );
  5112. break;
  5113. }
  5114. #endif
  5115. memset(fname, 0, sizeof fname);
  5116. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5117. TxDefaultProfileFileIsNull=TRUE;
  5118. if((access(fname,F_OK))!=-1)
  5119. {
  5120. fptr1 = fopen(fname, "r");
  5121. c = 0;
  5122. c = fgetc(fptr1);
  5123. //DEBUG_INFO("c:%d\n",c);
  5124. rewind(fptr1);
  5125. if(c == EOF)
  5126. {
  5127. DEBUG_INFO("\n End of file reached.");
  5128. TxDefaultProfileFileIsNull=TRUE;
  5129. fclose(fptr1);
  5130. }
  5131. else
  5132. {
  5133. TxDefaultProfileFileIsNull=FALSE;
  5134. while(fscanf(fptr1, "%s", word) != EOF)
  5135. {
  5136. if(strcmp(word, "chargingProfileId") == 0)
  5137. {
  5138. n_chargingProfile = n_chargingProfile + 1;
  5139. }
  5140. }
  5141. rewind(fptr1);
  5142. //search Charging Profile Element
  5143. int i = 0;
  5144. int j = 0;
  5145. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5146. //DEBUG_INFO(" 1-1\n");
  5147. #if 0
  5148. /***********connectorId****************/
  5149. c = 0;
  5150. loc = strstr(sLineWord, "connectorId");
  5151. memset(sstr ,0, sizeof(sstr) );
  5152. while (loc[strlen("connectorId")+2+c] != ',')
  5153. {
  5154. sstr[c] = loc[strlen("connectorId")+2+c];
  5155. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5156. c++;
  5157. }
  5158. sstr[c] = '\0';
  5159. tempconnectorIdInt = atoi(sstr);
  5160. #endif
  5161. //***********validFrom**************/
  5162. c = 0;
  5163. loc = strstr(sLineWord, "validFrom");
  5164. if(loc != NULL)
  5165. {
  5166. memset(sstr ,0, sizeof(sstr) );
  5167. while (loc[3+strlen("validFrom")+c] != '\"')
  5168. {
  5169. sstr[c] = loc[3+strlen("validFrom")+c];
  5170. c++;
  5171. }
  5172. sstr[c] = '\0';
  5173. strcpy(tempvalidFromStr,sstr);
  5174. }
  5175. else
  5176. {
  5177. strcpy(tempvalidFromStr,"");
  5178. }
  5179. //***********validFrom**************/
  5180. c = 0;
  5181. loc = strstr(sLineWord, "duration");
  5182. if(loc != NULL)
  5183. {
  5184. memset(sstr ,0, sizeof(sstr) );
  5185. while (loc[2+strlen("duration")+c] != ',')
  5186. {
  5187. sstr[c] = loc[2+strlen("duration")+c];
  5188. c++;
  5189. }
  5190. sstr[c] = '\0';
  5191. tempdurationInt = atoi(sstr);
  5192. }
  5193. else
  5194. {
  5195. tempdurationInt = 0;
  5196. }
  5197. //**********startSchedule**********/
  5198. c = 0;
  5199. loc = strstr(sLineWord, "startSchedule");
  5200. memset(sstr ,0, sizeof(sstr) );
  5201. while (loc[3+strlen("startSchedule")+c] != '\"')
  5202. {
  5203. sstr[c] = loc[3+strlen("startSchedule")+c];
  5204. c++;
  5205. }
  5206. sstr[c] = '\0';
  5207. strcpy(tempstartScheduleStr, sstr);
  5208. strcpy(TxDefaultProfileScheduleStr, sstr);
  5209. //**********chargingRateUnit**********/
  5210. c = 0;
  5211. loc = strstr(sLineWord, "chargingRateUnit");
  5212. memset(sstr ,0, sizeof(sstr) );
  5213. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5214. {
  5215. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5216. c++;
  5217. }
  5218. sstr[c] = '\0';
  5219. strcpy(tempchargingRateUnitStr, sstr);
  5220. //**********minChargingRate*******/
  5221. c = 0;
  5222. loc = strstr(sLineWord, "minChargingRate");
  5223. if(loc != NULL)
  5224. {
  5225. memset(sstr ,0, sizeof(sstr) );
  5226. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5227. {
  5228. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5229. c++;
  5230. }
  5231. sstr[c] = '\0';
  5232. tempminChargingRateFloat = atof(sstr);
  5233. }
  5234. else
  5235. {
  5236. tempminChargingRateFloat = 0.0;
  5237. }
  5238. #if 0
  5239. //
  5240. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5241. tp.tm_isdst = -1;
  5242. time_t utc = mktime(&tp);
  5243. time_t t = time(NULL);
  5244. //diff_t = difftime(t, utc);
  5245. #endif
  5246. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5247. //parsing strings to words
  5248. i = 0;
  5249. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5250. loc = loc+3+strlen("chargingSchedulePeriod");
  5251. pch = strtok(loc ,"{");
  5252. while (pch != NULL)
  5253. {
  5254. strcpy(SchedulePeriodList[i], pch);
  5255. pch = strtok (NULL, "{");
  5256. i = i + 1;
  5257. }
  5258. n_SchedulePeriods = i;
  5259. for(int i=0;i<n_SchedulePeriods;i++)
  5260. {
  5261. //*************startPeriod****************/
  5262. c = 0;
  5263. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5264. memset(sstr ,0, sizeof(sstr) );
  5265. while (loc[strlen("startPeriod")+2+c] != ',')
  5266. {
  5267. sstr[c] = loc[strlen("startPeriod")+2+c];
  5268. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5269. c++;
  5270. }
  5271. sstr[c] = '\0';
  5272. tempStartPeriodInt = atoi(sstr);
  5273. //*************limit****************/
  5274. c = 0;
  5275. loc = strstr(SchedulePeriodList[i], "limit");
  5276. memset(sstr ,0, sizeof(sstr) );
  5277. while (loc[strlen("limit")+2+c] != ',')
  5278. {
  5279. sstr[c] = loc[strlen("limit")+2+c];
  5280. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5281. c++;
  5282. }
  5283. sstr[c] = '\0';
  5284. tempLimitInt = atof(sstr);
  5285. //*************numberPhases****************/
  5286. c = 0;
  5287. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5288. memset(sstr ,0, sizeof(sstr) );
  5289. while (loc[strlen("numberPhases")+2+c] != '}')
  5290. {
  5291. sstr[c] = loc[strlen("numberPhases")+2+c];
  5292. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5293. c++;
  5294. }
  5295. sstr[c] = '\0';
  5296. tempNumberPhasesInt = atoi(sstr);
  5297. if(j == 0)
  5298. {
  5299. TxDefaultProfile.Duration = tempdurationInt;
  5300. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5301. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5302. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5303. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5304. }
  5305. else
  5306. {
  5307. //other stack level charging Profile
  5308. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5309. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5310. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5311. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5312. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5313. }
  5314. }
  5315. if(MinChargingRate < tempminChargingRateFloat)
  5316. MinChargingRate = tempminChargingRateFloat;
  5317. if(confirmPeriods < n_SchedulePeriods)
  5318. confirmPeriods = n_SchedulePeriods;
  5319. j = j + 1;
  5320. //DEBUG_INFO(" 1-2\n");
  5321. }
  5322. fclose(fptr1);
  5323. //Stacking Charging Profiles
  5324. for(int l=0; l <(j-1) ;l++)
  5325. {
  5326. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5327. {
  5328. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5329. {
  5330. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5331. {
  5332. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5333. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5334. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5335. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5336. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5337. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5338. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5339. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5340. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5341. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5342. }
  5343. else
  5344. {
  5345. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5346. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5347. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5348. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5349. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5350. }
  5351. }
  5352. }
  5353. }
  5354. //end of Stacking Charging Profiles
  5355. }
  5356. }// the end of ACCESS TxDefaultProfile
  5357. //****************************TxProfile************************************************/
  5358. #if 0
  5359. switch(connectorIdInt)
  5360. {
  5361. case 0:
  5362. break;
  5363. case 1:
  5364. strcpy(fname, TxProfile_1_JSON );
  5365. break;
  5366. case 2:
  5367. strcpy(fname, TxProfile_2_JSON );
  5368. break;
  5369. default:
  5370. strcpy(fname, TxProfile_1_JSON );
  5371. break;
  5372. }
  5373. #endif
  5374. memset(fname, 0, sizeof fname);
  5375. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5376. TxProfileIsNull=TRUE;
  5377. if((access(fname,F_OK))!=-1)
  5378. {
  5379. fptr1 = fopen(fname, "r");
  5380. c = 0;
  5381. c = fgetc(fptr1);
  5382. //DEBUG_INFO("c:%d\n",c);
  5383. rewind(fptr1);
  5384. if(c == EOF)
  5385. {
  5386. DEBUG_INFO("\n End of file reached.");
  5387. TxProfileIsNull=TRUE;
  5388. fclose(fptr1);
  5389. }
  5390. else
  5391. {
  5392. TxProfileIsNull=FALSE;
  5393. while(fscanf(fptr1, "%s", word) != EOF)
  5394. {
  5395. if(strcmp(word, "chargingProfileId") == 0)
  5396. {
  5397. n_chargingProfile = n_chargingProfile + 1;
  5398. }
  5399. }
  5400. rewind(fptr1);
  5401. //search Charging Profile Element
  5402. int i= 0;
  5403. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5404. #if 0
  5405. /***********connectorId****************/
  5406. c = 0;
  5407. loc = strstr(sLineWord, "connectorId");
  5408. memset(sstr ,0, sizeof(sstr) );
  5409. while (loc[strlen("connectorId")+2+c] != ',')
  5410. {
  5411. sstr[c] = loc[strlen("connectorId")+2+c];
  5412. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5413. c++;
  5414. }
  5415. sstr[c] = '\0';
  5416. tempconnectorIdInt = atoi(sstr);
  5417. #endif
  5418. //***********validFrom**************/
  5419. c = 0;
  5420. loc = strstr(sLineWord, "validFrom");
  5421. if(loc != NULL)
  5422. {
  5423. memset(sstr ,0, sizeof(sstr) );
  5424. while (loc[3+strlen("validFrom")+c] != '\"')
  5425. {
  5426. sstr[c] = loc[3+strlen("validFrom")+c];
  5427. c++;
  5428. }
  5429. sstr[c] = '\0';
  5430. strcpy(tempvalidFromStr,sstr);
  5431. }
  5432. else
  5433. {
  5434. strcpy(tempvalidFromStr,"");
  5435. }
  5436. //**********startSchedule**********/
  5437. c = 0;
  5438. loc = strstr(sLineWord, "startSchedule");
  5439. memset(sstr ,0, sizeof(sstr) );
  5440. while (loc[3+strlen("startSchedule")+c] != '\"')
  5441. {
  5442. sstr[c] = loc[3+strlen("startSchedule")+c];
  5443. c++;
  5444. }
  5445. sstr[c] = '\0';
  5446. strcpy(tempstartScheduleStr, sstr);
  5447. strcpy(TxProfileScheduleStr, sstr);
  5448. //**********chargingRateUnit**********/
  5449. c = 0;
  5450. loc = strstr(sLineWord, "chargingRateUnit");
  5451. memset(sstr ,0, sizeof(sstr) );
  5452. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5453. {
  5454. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5455. c++;
  5456. }
  5457. sstr[c] = '\0';
  5458. strcpy(tempchargingRateUnitStr, sstr);
  5459. //**********minChargingRate*******/
  5460. c = 0;
  5461. loc = strstr(sLineWord, "minChargingRate");
  5462. if(loc != NULL)
  5463. {
  5464. memset(sstr ,0, sizeof(sstr) );
  5465. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5466. {
  5467. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5468. c++;
  5469. }
  5470. sstr[c] = '\0';
  5471. tempminChargingRateFloat = atof(sstr);
  5472. }
  5473. else
  5474. {
  5475. tempminChargingRateFloat = 0.0;
  5476. }
  5477. #if 0
  5478. //
  5479. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5480. tp.tm_isdst = -1;
  5481. time_t utc = mktime(&tp);
  5482. time_t t = time(NULL);
  5483. //diff_t = difftime(t, utc);
  5484. #endif
  5485. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5486. //parsing strings to words
  5487. i = 0;
  5488. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5489. loc = loc+3+strlen("chargingSchedulePeriod");
  5490. pch = strtok(loc ,"{");
  5491. while (pch != NULL)
  5492. {
  5493. strcpy(SchedulePeriodList[i], pch);
  5494. pch = strtok (NULL, "{");
  5495. i = i + 1;
  5496. }
  5497. n_SchedulePeriods = i;
  5498. for(int i=0;i<n_SchedulePeriods;i++)
  5499. {
  5500. //*************startPeriod****************/
  5501. c = 0;
  5502. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5503. memset(sstr ,0, sizeof(sstr) );
  5504. while (loc[strlen("startPeriod")+2+c] != ',')
  5505. {
  5506. sstr[c] = loc[strlen("startPeriod")+2+c];
  5507. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5508. c++;
  5509. }
  5510. sstr[c] = '\0';
  5511. tempStartPeriodInt = atoi(sstr);
  5512. //*************limit****************/
  5513. c = 0;
  5514. loc = strstr(SchedulePeriodList[i], "limit");
  5515. memset(sstr ,0, sizeof(sstr) );
  5516. while (loc[strlen("limit")+2+c] != ',')
  5517. {
  5518. sstr[c] = loc[strlen("limit")+2+c];
  5519. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5520. c++;
  5521. }
  5522. sstr[c] = '\0';
  5523. tempLimitInt = atof(sstr);
  5524. //*************numberPhases****************/
  5525. c = 0;
  5526. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5527. memset(sstr ,0, sizeof(sstr) );
  5528. while (loc[strlen("numberPhases")+2+c] != '}')
  5529. {
  5530. sstr[c] = loc[strlen("numberPhases")+2+c];
  5531. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5532. c++;
  5533. }
  5534. sstr[c] = '\0';
  5535. tempNumberPhasesInt = atoi(sstr);
  5536. TxProfile.Duration = durationInt;
  5537. TxProfile.TotalPeriod = n_SchedulePeriods;
  5538. TxProfile.Period[i].Limit = tempLimitInt;
  5539. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5540. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5541. }
  5542. if(MinChargingRate < tempminChargingRateFloat)
  5543. MinChargingRate = tempminChargingRateFloat;
  5544. if(confirmPeriods < n_SchedulePeriods)
  5545. confirmPeriods = n_SchedulePeriods;
  5546. }
  5547. fclose(fptr1);
  5548. }
  5549. }// the end of ACCESS TxProfile
  5550. //CompositeSchedule
  5551. int period=0;
  5552. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5553. {
  5554. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5555. struct tm tp;
  5556. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5557. tp.tm_isdst = -1;
  5558. time_t utc = mktime(&tp);
  5559. time_t t = time(NULL);
  5560. double diff_f = difftime(t, utc);
  5561. int diff_i; // = (int)diff_f;
  5562. int quotient; // = diff_i / 86400;//86400 seconds/day
  5563. //int remainder = diff_i % 86400;
  5564. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5565. {
  5566. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5567. {
  5568. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5569. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5570. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5571. period = period + 1;
  5572. }
  5573. else
  5574. {
  5575. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5576. {
  5577. }
  5578. else
  5579. {
  5580. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5581. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5582. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5583. period = period + 1;
  5584. }
  5585. }
  5586. }
  5587. if( diff_f >= 0)
  5588. {
  5589. diff_i = (int)diff_f;
  5590. quotient = diff_i / 86400;//86400 seconds/day
  5591. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5592. {
  5593. 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))
  5594. {
  5595. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5596. {
  5597. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5598. }
  5599. else
  5600. {
  5601. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5602. }
  5603. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5604. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  5605. period = period + 1;
  5606. }
  5607. }
  5608. // Check Last Period
  5609. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5610. {
  5611. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5612. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5613. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5614. period = period + 1;
  5615. }
  5616. } // diff_f >= 0
  5617. }
  5618. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5619. {
  5620. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5621. struct tm tp;
  5622. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5623. tp.tm_isdst = -1;
  5624. time_t utc = mktime(&tp);
  5625. time_t t = time(NULL);
  5626. double diff_f = difftime(t, utc);
  5627. int diff_i;// = (int)diff_f;
  5628. int quotient; // = diff_i / 86400;//86400 seconds/day
  5629. //int remainder = diff_i % 86400;
  5630. if(diff_f >= 0)
  5631. {
  5632. diff_i = (int)diff_f;
  5633. quotient = diff_i / 86400;//86400 seconds/day
  5634. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5635. {
  5636. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5637. {
  5638. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5639. {
  5640. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5641. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5642. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5643. period = period + 1;
  5644. }
  5645. else
  5646. {
  5647. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5648. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5649. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5650. period = period + 1;
  5651. }
  5652. }
  5653. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5654. {
  5655. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5656. {
  5657. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5658. {
  5659. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5660. {
  5661. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5662. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5663. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5664. period = period + 1;
  5665. }
  5666. else
  5667. {
  5668. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5669. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5670. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5671. period = period + 1;
  5672. }
  5673. }
  5674. }
  5675. }
  5676. }
  5677. } // end diff_f >= 0
  5678. }
  5679. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5680. {
  5681. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5682. struct tm tp;
  5683. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5684. tp.tm_isdst = -1;
  5685. time_t utc = mktime(&tp);
  5686. time_t t = time(NULL);
  5687. double diff_f = difftime(t, utc);
  5688. int diff_i; // = (int)diff_f;
  5689. int quotient; // = diff_i / 86400;//86400 seconds/day
  5690. //int remainder = diff_i % 86400;
  5691. if(diff_f >= 0)
  5692. {
  5693. diff_i = (int)diff_f;
  5694. quotient = diff_i / 86400;//86400 seconds/day
  5695. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5696. {
  5697. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5698. {
  5699. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5700. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5701. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5702. period = period + 1;
  5703. }
  5704. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5705. {
  5706. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5707. {
  5708. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5709. {
  5710. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5711. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5712. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5713. period = period + 1;
  5714. }
  5715. }
  5716. }
  5717. }
  5718. } // diff_f >= 0
  5719. }
  5720. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  5721. {
  5722. confirmPeriods = 0;
  5723. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5724. goto end;
  5725. }
  5726. confirmPeriods = period;
  5727. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5728. //---- Define StartSchedule----/
  5729. struct tm *gtime;
  5730. time_t now;
  5731. char buf[28];
  5732. //---Read the current system time---/
  5733. time(&now);
  5734. //---Convert the system time to GMT (now UTC)---/
  5735. gtime = gmtime(&now);
  5736. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5737. // make .conf
  5738. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5739. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5740. //DEBUG_INFO(" debug 11\n");
  5741. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5742. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5743. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5744. }
  5745. else
  5746. {
  5747. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5748. }
  5749. end:
  5750. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5751. return result;
  5752. }
  5753. int handleGetConfigurationRequest(char *uuid, char *payload)
  5754. {
  5755. mtrace();
  5756. int result = FAIL;
  5757. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5758. //struct json_object *jsonitem;
  5759. int MaxKeySupported = 0;
  5760. int n_keys = 0;
  5761. char requestKey[43][50]={0};
  5762. char search[]="[";
  5763. char sstr[500]={ 0 };
  5764. //int pos;
  5765. int l, c = 0;
  5766. int i = 0;
  5767. char *delim = "\",\"";
  5768. char * pch;
  5769. char *loc = strstr(payload, search);
  5770. //********************* Parsing String ***********************************/
  5771. if(loc == NULL) {
  5772. DEBUG_INFO("no key match in Configuration \n");
  5773. }
  5774. else {
  5775. //pos = loc - payload;
  5776. l = strlen(loc)-4;
  5777. while (c < l)
  5778. {
  5779. sstr[c] = loc[c+2];
  5780. c++;
  5781. }
  5782. sstr[c] = '\0';
  5783. //parsing strings to words
  5784. pch = strtok(sstr,delim);
  5785. if(pch == NULL)
  5786. {
  5787. strcpy(requestKey[0], sstr);
  5788. }
  5789. else
  5790. {
  5791. while (pch != NULL)
  5792. {
  5793. strcpy(requestKey[i], pch);
  5794. pch = strtok (NULL, delim);
  5795. i = i + 1;
  5796. }
  5797. n_keys = i;
  5798. }
  5799. }
  5800. UnknownKeynum = 0;
  5801. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5802. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5803. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5804. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5805. if(n_keys != 0)
  5806. {
  5807. for(int i=0;i<n_keys;i++)
  5808. {
  5809. getKeyValue(requestKey[i]);
  5810. //json_object_put(jsonitem);
  5811. }
  5812. }
  5813. else
  5814. {
  5815. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5816. getKeyValue("");
  5817. }
  5818. processUnkownKey();
  5819. sendGetConfigurationConfirmation(uuid);
  5820. return result;
  5821. }
  5822. static char fnamePlusPath[100]={0};
  5823. static char fnamePWithNoPath[60]={0};
  5824. void checkUploadLog(void)
  5825. {
  5826. FILE *fp;
  5827. /* Open the command for reading. */
  5828. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5829. if (fp == NULL) {
  5830. printf("Failed to run command\n" );
  5831. exit(1);
  5832. }
  5833. int ftppathlen = 0;
  5834. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5835. int i = 0;
  5836. /* Read the output a line at a time - output it. */
  5837. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5838. if(i==0)
  5839. {
  5840. ftppathlen = strlen(fnamePlusPath);
  5841. printf("%s\n", fnamePlusPath);
  5842. fnamePlusPath[ftppathlen]='\0';
  5843. break;
  5844. }
  5845. i= i+1;
  5846. }
  5847. /* close */
  5848. pclose(fp);
  5849. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5850. {
  5851. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5852. {
  5853. fnamePlusPath[k]='\0';
  5854. }
  5855. }
  5856. i=1;
  5857. //char fname[60]={0};
  5858. while(i < ftppathlen)
  5859. {
  5860. int len=ftppathlen-i;
  5861. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5862. {
  5863. printf("compare '/' all right\n");
  5864. break;
  5865. }
  5866. i=i+1;
  5867. }
  5868. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5869. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5870. fnamePWithNoPath[i+1] = '\0';
  5871. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5872. {
  5873. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5874. {
  5875. fnamePWithNoPath[j]='\0';
  5876. }
  5877. }
  5878. FILE* fp1 = fopen(fnamePlusPath, "r");
  5879. if (fp1)
  5880. {
  5881. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5882. // file exists
  5883. fclose(fp1);
  5884. }
  5885. else
  5886. {
  5887. // file doesn't exist
  5888. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5889. }
  5890. }
  5891. static char GetDiagnosticspayloadData[300]={0};
  5892. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5893. {
  5894. mtrace();
  5895. int result = FAIL;
  5896. pthread_t t; // pthread 變數
  5897. system("exec /root/logPackTools 'log' 6");
  5898. #if 0
  5899. //char buffer [128];
  5900. time (&rawtime);
  5901. //printf("%ld\n", rawtime);
  5902. timeinfo = localtime (&rawtime);
  5903. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5904. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5905. if((access(fnamePlusPath,F_OK))!=-1)
  5906. {
  5907. DEBUG_INFO("fnamePlusPath exist.\n");
  5908. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5909. }
  5910. else
  5911. {
  5912. DEBUG_INFO("fnamePlusPath not exist!\n");
  5913. }
  5914. #endif
  5915. checkUploadLog();
  5916. memset(GetDiagnosticspayloadData, 0, 300);
  5917. strcpy(GetDiagnosticspayloadData, payload);
  5918. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5919. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5920. return result;
  5921. }
  5922. void* GetDiagnosticsProcess(void* data)
  5923. {
  5924. pthread_detach(pthread_self());
  5925. mtrace();
  5926. int retriesInt=0, retryIntervalInt=0;
  5927. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5928. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5929. 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};
  5930. int port=0;
  5931. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5932. int c = 0;
  5933. char *loc;
  5934. int isSuccess = FALSE;
  5935. char ftpbuf[200]={0};
  5936. //char temp[100]={0};
  5937. char * pch;
  5938. // [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"}]
  5939. char str[300]={ 0 };
  5940. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5941. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5942. DEBUG_INFO("GetDiagnosticsProcess\n");
  5943. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5944. //****************location*******************/
  5945. c = 0;
  5946. memset(sstr ,0, sizeof(sstr) );
  5947. loc = strstr(str, "location");
  5948. while (loc[3+strlen("location")+c] != '\"')
  5949. {
  5950. sstr[c] = loc[3+strlen("location")+c];
  5951. c++;
  5952. }
  5953. sstr[c] = '\0';
  5954. strcpy(locationstr,sstr);
  5955. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5956. if(strcmp(locationstr,"")==0)
  5957. {
  5958. DEBUG_INFO("location is <Empty>!\n");
  5959. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5960. goto end;
  5961. }
  5962. //****************retries*******************/
  5963. c = 0;
  5964. loc = strstr(str, "retries");
  5965. if(loc == NULL)
  5966. {
  5967. retriesIsNULL = TRUE;
  5968. }
  5969. else
  5970. {
  5971. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5972. {
  5973. sstr[c] = loc[strlen("retries")+2+c];
  5974. c++;
  5975. }
  5976. sstr[c] = '\0';
  5977. retriesInt = atoi(sstr);
  5978. }
  5979. if(retriesIsNULL == TRUE)
  5980. {
  5981. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5982. }
  5983. //****************retryInterval*******************/
  5984. c = 0;
  5985. loc = strstr(str, "retryInterval");
  5986. if(loc == NULL)
  5987. {
  5988. retryIntervalIsNULL = TRUE;
  5989. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5990. }
  5991. else
  5992. {
  5993. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5994. {
  5995. sstr[c] = loc[strlen("retryInterval")+2+c];
  5996. c++;
  5997. }
  5998. sstr[c] = '\0';
  5999. retryIntervalInt = atoi(sstr);
  6000. }
  6001. //****************startTime*******************/
  6002. c = 0;
  6003. memset(sstr ,0, sizeof(sstr) );
  6004. loc = strstr(str, "startTime");
  6005. if(loc == NULL)
  6006. {
  6007. startTimeIsNULL = TRUE;
  6008. }
  6009. else
  6010. {
  6011. while (loc[3+strlen("startTime")+c] != '\"')
  6012. {
  6013. sstr[c] = loc[3+strlen("startTime")+c];
  6014. c++;
  6015. }
  6016. sstr[c] = '\0';
  6017. strcpy(startTimestr,sstr);
  6018. }
  6019. //****************stopTime*******************/
  6020. c = 0;
  6021. memset(sstr ,0, sizeof(sstr) );
  6022. loc = strstr(str, "stopTime");
  6023. if(loc == NULL)
  6024. {
  6025. stopTimeIsNULL = TRUE;
  6026. }
  6027. else
  6028. {
  6029. while (loc[3+strlen("stopTime")+c] != '\"')
  6030. {
  6031. sstr[c] = loc[3+strlen("stopTime")+c];
  6032. c++;
  6033. }
  6034. sstr[c] = '\0';
  6035. strcpy(stopTimestr,sstr);
  6036. }
  6037. memset(protocol, 0, sizeof(protocol));
  6038. memset(user, 0, sizeof(user) );
  6039. memset(password, 0, sizeof(password));
  6040. memset(host, 0, sizeof(host));
  6041. memset(path, 0, sizeof(path));
  6042. memset(ftppath, 0, sizeof(ftppath));
  6043. memset(host1, 0, sizeof(host1));
  6044. memset(path1, 0, sizeof(path1));
  6045. /*location: ftp://user:password@host:port/path*/
  6046. #if 0
  6047. time_t rawtime;
  6048. struct tm * timeinfo;
  6049. //char buffer [128];
  6050. time (&rawtime);
  6051. //printf("%ld\n", rawtime);
  6052. timeinfo = localtime (&rawtime);
  6053. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6054. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6055. #endif
  6056. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6057. if((access(fnamePlusPath,F_OK))!=-1)
  6058. {
  6059. DEBUG_INFO("fnamePlusPath exist.\n");
  6060. }
  6061. else
  6062. {
  6063. DEBUG_INFO("fnamePlusPath not exist!\n");
  6064. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6065. goto end;
  6066. }
  6067. pch=strchr(locationstr,'@');
  6068. if(pch==NULL)
  6069. {
  6070. sscanf(locationstr,
  6071. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6072. protocol, host, &port, path);
  6073. strcpy(user,"anonymous");
  6074. strcpy(password,"");
  6075. }
  6076. else
  6077. {
  6078. //DEBUG_INFO("pch=%s\n", pch);
  6079. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6080. protocol, user, password, host, &port, path);
  6081. }
  6082. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6083. {
  6084. DEBUG_INFO("protocol is not ftp/http ! \n");
  6085. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6086. goto end;
  6087. }
  6088. if(strncmp(locationstr,"http", 4) == 0)
  6089. {
  6090. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6091. sprintf(ftppath,"/%s", path);
  6092. do{
  6093. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6094. sleep(retryIntervalInt);
  6095. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6096. if(!isSuccess)
  6097. {
  6098. DEBUG_INFO("Diagnostics fail.\n");
  6099. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6100. }
  6101. else
  6102. {
  6103. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6104. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6105. }
  6106. }
  6107. else
  6108. {
  6109. sscanf(host,"%[^/]%s",host1, path1);
  6110. sprintf(ftppath,"%s", path1);
  6111. int ftppathlen=strlen(ftppath);
  6112. int i=1;
  6113. char filenametemp[50];
  6114. while(i < ftppathlen)
  6115. {
  6116. int len=ftppathlen-i;
  6117. if(ftppath[len]== 47) // '/' ascll code: 47
  6118. {
  6119. DEBUG_INFO("find '/' all right\n");
  6120. break;
  6121. }
  6122. i=i+1;
  6123. }
  6124. memset(filenametemp, 0, sizeof(filenametemp));
  6125. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6126. filenametemp[i+1] = 0;
  6127. memset(ftpbuf, 0, sizeof(ftpbuf));
  6128. if(port == 0)
  6129. port = 21;
  6130. do{
  6131. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6132. sleep(retryIntervalInt);
  6133. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6134. if(!isSuccess)
  6135. {
  6136. DEBUG_INFO("Diagnostics fail.\n");
  6137. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6138. }
  6139. else
  6140. {
  6141. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6142. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6143. }
  6144. }
  6145. end:
  6146. DiagnosticsStatusNotificationStatus = 0; //Idle
  6147. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6148. }
  6149. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6150. {
  6151. mtrace();
  6152. int result = FAIL;
  6153. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6154. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6155. {
  6156. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6157. localversion = -1;
  6158. }
  6159. else
  6160. {
  6161. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6162. OCPP_getListVerion();
  6163. }
  6164. //from db.OCPP_getListVerion
  6165. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6166. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6167. sendGetLocalListVersionConfirmation(uuid,"");
  6168. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6169. return result;
  6170. }
  6171. int handleRemoteStartRequest(char *uuid, char *payload)
  6172. {
  6173. mtrace();
  6174. int result = FAIL;
  6175. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6176. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6177. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6178. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6179. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6180. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6181. int chargingSchedulePeriodCount = 0;
  6182. char sstr[30]={ 0 };//sstr[200]={ 0 };
  6183. int c = 0;
  6184. char *loc;
  6185. char comfirmstr[20]={0};
  6186. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6187. if(server_pending == TRUE)
  6188. {
  6189. return 0;
  6190. }
  6191. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6192. //**********connectorId****************/
  6193. c = 0;
  6194. memset(sstr ,0, sizeof(sstr) );
  6195. loc = strstr(payload, "connectorId");
  6196. if(loc == NULL)
  6197. {
  6198. connectorIdIsNULL = TRUE;
  6199. }
  6200. else
  6201. {
  6202. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6203. {
  6204. sstr[c] = loc[strlen("connectorId")+2+c];
  6205. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6206. c++;
  6207. }
  6208. sstr[c] = '\0';
  6209. connectorIdInt = atoi(sstr);
  6210. }
  6211. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6212. {
  6213. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6214. goto end;
  6215. }
  6216. //****************idTag*******************/
  6217. c = 0;
  6218. memset(sstr ,0, sizeof(sstr) );
  6219. loc = strstr(payload, "idTag");
  6220. while (loc[3+strlen("idTag")+c] != '\"')
  6221. {
  6222. sstr[c] = loc[3+strlen("idTag")+c];
  6223. c++;
  6224. }
  6225. sstr[c] = '\0';
  6226. strcpy(idTagstr,sstr);
  6227. //****************chargingProfile*******************/
  6228. c = 0;
  6229. memset(sstr ,0, sizeof(sstr) );
  6230. loc = strstr(payload, "chargingProfile");
  6231. if(loc == NULL)
  6232. {
  6233. chargingProfileIsNULL = TRUE;
  6234. }
  6235. else
  6236. {
  6237. //****************chargingProfileId*******************/
  6238. c=0;
  6239. loc = strstr(payload, "chargingProfileId");
  6240. memset(sstr ,0, sizeof(sstr) );
  6241. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6242. {
  6243. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6244. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6245. c++;
  6246. }
  6247. sstr[c] = '\0';
  6248. chargingProfileIdInt = atoi(sstr);
  6249. //****************transactionId*******************/
  6250. loc = strstr(payload, "transactionId");
  6251. if(loc == NULL)
  6252. {
  6253. transactionIdIsNULL = TRUE;
  6254. }
  6255. else
  6256. {
  6257. c=0;
  6258. memset(sstr ,0, sizeof(sstr) );
  6259. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6260. {
  6261. sstr[c] = loc[strlen("transactionId")+2+c];
  6262. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6263. c++;
  6264. }
  6265. sstr[c] = '\0';
  6266. transactionIdInt = atoi(sstr);
  6267. }
  6268. //****************stackLevel*******************/
  6269. c=0;
  6270. loc = strstr(payload, "stackLevel");
  6271. memset(sstr ,0, sizeof(sstr) );
  6272. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6273. {
  6274. sstr[c] = loc[strlen("stackLevel")+2+c];
  6275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6276. c++;
  6277. }
  6278. sstr[c] = '\0';
  6279. stackLevelInt = atoi(sstr);
  6280. //****************chargingProfilePurpose*******************/
  6281. c = 0;
  6282. memset(sstr ,0, sizeof(sstr) );
  6283. loc = strstr(payload, "chargingProfilePurpose");
  6284. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6285. {
  6286. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6287. c++;
  6288. }
  6289. sstr[c] = '\0';
  6290. strcpy(chargingProfilePurposestr,sstr);
  6291. //****************chargingProfileKind*******************/
  6292. c = 0;
  6293. memset(sstr ,0, sizeof(sstr) );
  6294. loc = strstr(payload, "chargingProfileKind");
  6295. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6296. {
  6297. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6298. c++;
  6299. }
  6300. sstr[c] = '\0';
  6301. strcpy(chargingProfileKindstr,sstr);
  6302. //****************recurrencyKind*******************/
  6303. loc = strstr(payload, "recurrencyKind");
  6304. if(loc == NULL)
  6305. {
  6306. recurrencyKindIsNULL = TRUE;
  6307. }
  6308. else
  6309. {
  6310. c = 0;
  6311. memset(sstr ,0, sizeof(sstr) );
  6312. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6313. {
  6314. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6315. c++;
  6316. }
  6317. sstr[c] = '\0';
  6318. strcpy(recurrencyKindstr,sstr);
  6319. }
  6320. //****************validFrom*******************/
  6321. loc = strstr(payload, "validFrom");
  6322. if(loc == NULL)
  6323. {
  6324. validFromIsNULL = TRUE;
  6325. }
  6326. else
  6327. {
  6328. c = 0;
  6329. memset(sstr ,0, sizeof(sstr) );
  6330. while (loc[3+strlen("validFrom")+c] != '\"')
  6331. {
  6332. sstr[c] = loc[3+strlen("validFrom")+c];
  6333. c++;
  6334. }
  6335. sstr[c] = '\0';
  6336. strcpy(validFromstr,sstr);
  6337. }
  6338. //****************validTo*******************/
  6339. loc = strstr(payload, "validTo");
  6340. if(loc == NULL)
  6341. {
  6342. validToIsNULL = TRUE;
  6343. }
  6344. else
  6345. {
  6346. c = 0;
  6347. memset(sstr ,0, sizeof(sstr) );
  6348. while (loc[3+strlen("validTo")+c] != '\"')
  6349. {
  6350. sstr[c] = loc[3+strlen("validTo")+c];
  6351. c++;
  6352. }
  6353. sstr[c] = '\0';
  6354. strcpy(validTostr,sstr);
  6355. }
  6356. //****************chargingSchedule*******************/
  6357. loc = strstr(payload, "chargingSchedule");
  6358. if(loc != NULL)
  6359. {
  6360. //****************duration*******************/
  6361. loc = strstr(payload, "duration");
  6362. if(loc == NULL)
  6363. {
  6364. durationIsNULL = TRUE;
  6365. }
  6366. else
  6367. {
  6368. c=0;
  6369. memset(sstr ,0, sizeof(sstr) );
  6370. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6371. {
  6372. sstr[c] = loc[strlen("duration")+2+c];
  6373. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6374. c++;
  6375. }
  6376. sstr[c] = '\0';
  6377. durationInt = atoi(sstr);
  6378. }
  6379. //****************startSchedule******************/
  6380. loc = strstr(payload, "startSchedule");
  6381. if(loc == NULL)
  6382. {
  6383. startScheduleIsNULL = TRUE;
  6384. }
  6385. else
  6386. {
  6387. c = 0;
  6388. memset(sstr ,0, sizeof(sstr) );
  6389. while (loc[3+strlen("startSchedule")+c] != '\"')
  6390. {
  6391. sstr[c] = loc[3+strlen("startSchedule")+c];
  6392. c++;
  6393. }
  6394. sstr[c] = '\0';
  6395. strcpy(startSchedulestr,sstr);
  6396. }
  6397. //****************chargingRateUnit*******************/
  6398. c = 0;
  6399. memset(sstr ,0, sizeof(sstr) );
  6400. loc = strstr(payload, "chargingRateUnit");
  6401. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6402. {
  6403. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6404. c++;
  6405. }
  6406. sstr[c] = '\0';
  6407. strcpy(chargingRateUnitstr,sstr);
  6408. //****************minChargingRate*******************/
  6409. loc = strstr(payload, "minChargingRate");
  6410. if(loc == NULL)
  6411. {
  6412. minChargingRateIsNULL = TRUE;
  6413. }
  6414. else
  6415. {
  6416. c=0;
  6417. memset(sstr ,0, sizeof(sstr) );
  6418. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6419. {
  6420. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6421. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6422. c++;
  6423. }
  6424. sstr[c] = '\0';
  6425. minChargingRateflaot = atof(sstr);
  6426. }
  6427. //****************chargingSchedulePeriod count*******************/
  6428. int what_len = strlen("startPeriod");
  6429. char *where = payload;
  6430. while ((where = strstr(where, "startPeriod"))) {
  6431. where += what_len;
  6432. chargingSchedulePeriodCount++;
  6433. }
  6434. where = payload;
  6435. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6436. {
  6437. //****************startPeriod*******************/
  6438. c=0;
  6439. loc = strstr(where, "startPeriod");
  6440. memset(sstr ,0, sizeof(sstr) );
  6441. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6442. {
  6443. sstr[c] = loc[strlen("startPeriod")+2+c];
  6444. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6445. c++;
  6446. }
  6447. sstr[c] = '\0';
  6448. startPeriodInt[periodNums] = atoi(sstr);
  6449. //****************limit*******************/
  6450. c=0;
  6451. loc = strstr(where, "limit");
  6452. memset(sstr ,0, sizeof(sstr) );
  6453. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6454. {
  6455. sstr[c] = loc[strlen("limit")+2+c];
  6456. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6457. c++;
  6458. }
  6459. sstr[c] = '\0';
  6460. limitflaot[periodNums] = atof(sstr);
  6461. //****************numberPhases*******************/
  6462. loc = strstr(where, "numberPhases");
  6463. if(loc == NULL)
  6464. {
  6465. numberPhasesIsNULL = TRUE;
  6466. }
  6467. else
  6468. {
  6469. c=0;
  6470. memset(sstr ,0, sizeof(sstr) );
  6471. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6472. {
  6473. sstr[c] = loc[strlen("numberPhases")+2+c];
  6474. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6475. c++;
  6476. }
  6477. sstr[c] = '\0';
  6478. numberPhasesInt[periodNums] = atoi(sstr);
  6479. }
  6480. where = loc;
  6481. }
  6482. }
  6483. }
  6484. /*
  6485. enum _SYSTEM_STATUS
  6486. {
  6487. S_BOOTING = 0,
  6488. S_IDLE, = 1
  6489. S_AUTHORIZING, =2
  6490. S_REASSIGN_CHECK, =3
  6491. S_REASSIGN, =4
  6492. S_PRECHARGE, =5
  6493. S_PREPARING_FOR_EV, =6
  6494. S_PREPARING_FOR_EVSE, =7
  6495. S_CHARGING, =8
  6496. S_TERMINATING, =9
  6497. S_COMPLETE, =10
  6498. S_ALARM, =11
  6499. S_FAULT =12
  6500. }
  6501. */
  6502. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6503. {
  6504. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6505. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6506. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6507. //check Transaction active
  6508. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6509. {
  6510. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6511. {
  6512. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6513. {
  6514. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6515. {
  6516. //Reserved
  6517. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6518. }
  6519. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6520. {
  6521. //Reserved
  6522. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6523. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6524. goto end;
  6525. }
  6526. else
  6527. {
  6528. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6529. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6530. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6531. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6532. {
  6533. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6534. goto end;
  6535. }
  6536. }//END FOR ELSE
  6537. }
  6538. }// END FOR CHAdeMO_QUANTITY
  6539. for (int index = 0; index < CCS_QUANTITY; index++)
  6540. {
  6541. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6542. {
  6543. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6544. {
  6545. //Reserved
  6546. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6547. }
  6548. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6549. {
  6550. //Reserved
  6551. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6552. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6553. goto end;
  6554. }
  6555. else
  6556. {
  6557. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6558. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6559. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6560. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6561. {
  6562. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6563. goto end;
  6564. }
  6565. }// END FOR ELSE
  6566. }
  6567. }// END FOR CCS_QUANTITY
  6568. for (int index = 0; index < GB_QUANTITY; index++)
  6569. {
  6570. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6571. {
  6572. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6573. {
  6574. //Reserved
  6575. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6576. }
  6577. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6578. {
  6579. //Reserved
  6580. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6581. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6582. goto end;
  6583. }
  6584. else
  6585. {
  6586. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6587. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6588. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6589. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6590. {
  6591. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6592. goto end;
  6593. }
  6594. }// END FOR ELSE
  6595. }
  6596. } // END FOR GB_QUANTITY
  6597. }
  6598. else
  6599. {
  6600. for (int index = 0; index < AC_QUANTITY; index++)
  6601. {
  6602. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6603. {
  6604. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6605. {
  6606. //Reserved
  6607. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6608. }
  6609. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6610. {
  6611. //Reserved
  6612. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6613. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6614. goto end;
  6615. }
  6616. else
  6617. {
  6618. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6619. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6620. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6621. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6622. {
  6623. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6624. goto end;
  6625. }
  6626. }//END FOR ELSE
  6627. }
  6628. }// END FOR AC_QUANTITY
  6629. }
  6630. if(chargingProfileIsNULL == FALSE)
  6631. {
  6632. //ChargingProfile
  6633. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6634. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6635. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6636. if(recurrencyKindIsNULL == FALSE) //OPTION
  6637. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6638. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6639. if(transactionIdIsNULL == FALSE) // OPTION
  6640. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6641. if(validFromIsNULL == FALSE) // OPTION
  6642. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6643. if(validToIsNULL == FALSE) //OPTION
  6644. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6645. //ChargingSchedule
  6646. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6647. if(durationIsNULL == FALSE) //OPTION
  6648. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6649. if(minChargingRateIsNULL == FALSE) //OPTION
  6650. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6651. if(startScheduleIsNULL == FALSE) //OPTION
  6652. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6653. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6654. {
  6655. //ChargingSchedulePeriod
  6656. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6657. if(numberPhasesIsNULL == FALSE)
  6658. {
  6659. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6660. }
  6661. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6662. }
  6663. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6664. {
  6665. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6666. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6667. //memset idTag
  6668. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6669. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6670. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6671. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6672. }
  6673. else
  6674. {
  6675. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6676. }
  6677. }
  6678. else
  6679. {
  6680. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6681. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6682. //memset idTag
  6683. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6684. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6685. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6686. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6687. }
  6688. }
  6689. else
  6690. {
  6691. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6692. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6693. }
  6694. end:
  6695. if(connectorIdIsNULL == FALSE)
  6696. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6697. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6698. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6699. //OCPP send RemoteStartConfirmation by first.
  6700. sendRemoteStartConfirmation(uuid, comfirmstr);
  6701. return result;
  6702. }
  6703. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6704. {
  6705. mtrace();
  6706. int result = FAIL;
  6707. int match = FALSE;
  6708. int GunNO = 0;
  6709. int transactionIdInt=0;
  6710. int transactionIdIsNULL= FALSE;
  6711. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6712. int c = 0;
  6713. char *loc;
  6714. char comfirmstr[20];
  6715. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6716. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6717. if(server_pending == TRUE)
  6718. {
  6719. return 0;
  6720. }
  6721. c=0;
  6722. loc = strstr(payload, "transactionId");
  6723. if(loc == NULL)
  6724. {
  6725. transactionIdIsNULL= TRUE;
  6726. }
  6727. else
  6728. {
  6729. memset(sstr ,0, sizeof(sstr) );
  6730. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6731. {
  6732. sstr[c] = loc[strlen("transactionId")+2+c];
  6733. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6734. c++;
  6735. }
  6736. sstr[c] = '\0';
  6737. transactionIdInt = atoi(sstr);
  6738. }
  6739. if(transactionIdIsNULL == FALSE)
  6740. {
  6741. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6742. {
  6743. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6744. {
  6745. //check Transaction active
  6746. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6747. {
  6748. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6749. {
  6750. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6751. {
  6752. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6753. {
  6754. match = TRUE;
  6755. GunNO = gun_index;
  6756. }
  6757. }
  6758. }// END FOR CHAdeMO_QUANTITY
  6759. for (int index = 0; index < CCS_QUANTITY; index++)
  6760. {
  6761. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6762. {
  6763. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6764. {
  6765. match = TRUE;
  6766. GunNO = gun_index;
  6767. }
  6768. }
  6769. }// END FOR CCS_QUANTITY
  6770. for (int index = 0; index < GB_QUANTITY; index++)
  6771. {
  6772. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6773. {
  6774. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6775. {
  6776. match = TRUE;
  6777. GunNO = gun_index;
  6778. }
  6779. }
  6780. }// END FOR GB_QUANTITY
  6781. }
  6782. else
  6783. {
  6784. for (int index = 0; index < AC_QUANTITY; index++)
  6785. {
  6786. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6787. {
  6788. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6789. {
  6790. match = TRUE;
  6791. GunNO = gun_index;
  6792. }
  6793. }
  6794. }// END FOR CHAdeMO_QUANTITY
  6795. }// END FOR AC ELSE
  6796. }// CHECK IF ResponseTransactionId == transactionIdInt
  6797. }//END FOR
  6798. if( match == TRUE)
  6799. {
  6800. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6801. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6802. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6803. }
  6804. else
  6805. {
  6806. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6807. }
  6808. }
  6809. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6810. return result;
  6811. }
  6812. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6813. {
  6814. mtrace();
  6815. int result = FAIL;
  6816. int connectorIdInt=0, reservationIdInt=0;
  6817. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6818. char comfirmstr[20]={0};
  6819. char sstr[180]={ 0 };
  6820. int c = 0;
  6821. char *loc;
  6822. //char *ptr;
  6823. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6824. //***(1)connectorId ****/
  6825. c=0;
  6826. loc = strstr(payload, "connectorId");
  6827. memset(sstr ,0, sizeof(sstr) );
  6828. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6829. {
  6830. sstr[c] = loc[strlen("connectorId")+2+c];
  6831. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6832. c++;
  6833. }
  6834. sstr[c] = '\0';
  6835. connectorIdInt = atoi(sstr);
  6836. //***(2)expiryDate ****/
  6837. loc = strstr(payload, "expiryDate");
  6838. memset(sstr ,0, sizeof(sstr) );
  6839. c = 0;
  6840. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6841. {
  6842. sstr[c] = loc[3+strlen("expiryDate")+c];
  6843. c++;
  6844. }
  6845. sstr[c] = '\0';
  6846. strcpy(expiryDatestr, sstr);
  6847. //***(3)idTag ****/
  6848. loc = strstr(payload, "idTag");
  6849. memset(sstr ,0, sizeof(sstr) );
  6850. c = 0;
  6851. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6852. {
  6853. sstr[c] = loc[3+strlen("idTag")+c];
  6854. c++;
  6855. }
  6856. sstr[c] = '\0';
  6857. strcpy(idTagstr, sstr);
  6858. //***(4)parentIdTag ****/
  6859. loc = strstr(payload, "parentIdTag");
  6860. memset(sstr ,0, sizeof(sstr) );
  6861. c = 0;
  6862. if(loc == NULL)
  6863. {
  6864. strcpy(parentIdTagstr, "");
  6865. }
  6866. else
  6867. {
  6868. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6869. {
  6870. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6871. c++;
  6872. }
  6873. sstr[c] = '\0';
  6874. strcpy(parentIdTagstr, sstr);
  6875. }
  6876. //***(5)reservationId ****/
  6877. c=0;
  6878. loc = strstr(payload, "reservationId");
  6879. memset(sstr ,0, sizeof(sstr) );
  6880. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6881. {
  6882. sstr[c] = loc[strlen("reservationId")+2+c];
  6883. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6884. c++;
  6885. }
  6886. sstr[c] = '\0';
  6887. reservationIdInt = atoi(sstr);
  6888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6889. /*
  6890. enum SYSTEM_STATUS
  6891. {
  6892. SYS_MODE_BOOTING = 0,
  6893. SYS_MODE_IDLE = 1,
  6894. SYS_MODE_AUTHORIZING = 2,
  6895. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6896. SYS_MODE_REASSIGN = 4,
  6897. SYS_MODE_PREPARING = 5,
  6898. SYS_MODE_PREPARE_FOR_EV = 6,
  6899. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6900. SYS_MODE_CHARGING = 8,
  6901. SYS_MODE_TERMINATING = 9,
  6902. SYS_MODE_COMPLETE = 10,
  6903. SYS_MODE_ALARM = 11,
  6904. SYS_MODE_FAULT = 12,
  6905. SYS_MODE_RESERVATION = 13,
  6906. SYS_MODE_BOOKING = 14,
  6907. SYS_MODE_MAINTAIN = 15,
  6908. SYS_MODE_DEBUG = 16,
  6909. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6910. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6911. SYS_MODE_UPDATE = 19
  6912. };
  6913. */
  6914. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6915. {
  6916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6917. goto end;
  6918. }
  6919. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6920. {
  6921. //check Transaction active
  6922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6923. {
  6924. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6925. {
  6926. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6927. {
  6928. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6929. {
  6930. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6931. {
  6932. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6933. {
  6934. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6936. }
  6937. 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'))
  6938. {
  6939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6940. }
  6941. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6942. {
  6943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6944. }
  6945. else
  6946. {
  6947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6948. }
  6949. }
  6950. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6951. {
  6952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6953. }
  6954. }
  6955. else
  6956. {
  6957. //replace reservation
  6958. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6959. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6960. }
  6961. }
  6962. } // END FOR CHAdeMO_QUANTITY
  6963. for (int index = 0; index < CCS_QUANTITY; index++)
  6964. {
  6965. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6966. {
  6967. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6968. {
  6969. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6970. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6971. {
  6972. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6973. {
  6974. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6976. }
  6977. 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'))
  6978. {
  6979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6980. }
  6981. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6982. {
  6983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6984. }
  6985. else
  6986. {
  6987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6988. }
  6989. }
  6990. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6991. {
  6992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6993. }
  6994. }
  6995. else
  6996. {
  6997. //replace reservation
  6998. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7000. }
  7001. }
  7002. } // END FOR CCS_QUANTITY
  7003. for (int index = 0; index < GB_QUANTITY; index++)
  7004. {
  7005. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  7006. {
  7007. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7008. {
  7009. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7010. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7011. {
  7012. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7013. {
  7014. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7016. }
  7017. 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'))
  7018. {
  7019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7020. }
  7021. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7022. {
  7023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7024. }
  7025. else
  7026. {
  7027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7028. }
  7029. }
  7030. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7031. {
  7032. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7033. }
  7034. }
  7035. else
  7036. {
  7037. //replace reservation
  7038. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7040. }
  7041. }
  7042. }// END FOR GB_QUANTITY
  7043. }
  7044. else
  7045. {
  7046. for (int index = 0; index < AC_QUANTITY; index++)
  7047. {
  7048. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  7049. {
  7050. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7051. {
  7052. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7053. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7054. {
  7055. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7056. {
  7057. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7059. }
  7060. 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'))
  7061. {
  7062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7063. }
  7064. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7065. {
  7066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7067. }
  7068. else
  7069. {
  7070. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7071. }
  7072. }
  7073. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7074. {
  7075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7076. }
  7077. }
  7078. else
  7079. {
  7080. //replace reservation
  7081. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7082. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7083. }
  7084. }
  7085. } // END FOR AC_QUANTITY
  7086. }//END FOR AC ELSE
  7087. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7088. }
  7089. else if(connectorIdInt == 0)
  7090. {
  7091. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7092. {
  7093. //check Transaction active
  7094. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7095. {
  7096. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7097. {
  7098. 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'))
  7099. {
  7100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7101. goto end;
  7102. }
  7103. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7104. {
  7105. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7106. goto end;
  7107. }
  7108. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7109. {
  7110. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7111. goto end;
  7112. }
  7113. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7114. {
  7115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7116. goto end;
  7117. }
  7118. }
  7119. }// END FOR CHAdeMO_QUANTITY
  7120. for (int index = 0; index < CCS_QUANTITY; index++)
  7121. {
  7122. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7123. {
  7124. 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'))
  7125. {
  7126. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7127. }
  7128. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7129. {
  7130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7131. }
  7132. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7133. {
  7134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7135. }
  7136. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7137. {
  7138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7139. }
  7140. }
  7141. } // END FOR CCS_QUANTITY
  7142. for (int index = 0; index < GB_QUANTITY; index++)
  7143. {
  7144. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7145. {
  7146. 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'))
  7147. {
  7148. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7149. }
  7150. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7151. {
  7152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7153. }
  7154. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7155. {
  7156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7157. }
  7158. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7159. {
  7160. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7161. }
  7162. }
  7163. } // END FOR GB_QUANTITY
  7164. }
  7165. else
  7166. {
  7167. for (int index = 0; index < AC_QUANTITY; index++)
  7168. {
  7169. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7170. {
  7171. 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'))
  7172. {
  7173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7174. goto end;
  7175. }
  7176. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7177. {
  7178. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7179. goto end;
  7180. }
  7181. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7182. {
  7183. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7184. goto end;
  7185. }
  7186. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7187. {
  7188. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7189. goto end;
  7190. }
  7191. }
  7192. }// END FOR AC_QUANTITY
  7193. }
  7194. //The connectorId is 0
  7195. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7196. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7197. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7198. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7199. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7200. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7201. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7202. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7203. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7204. result = TRUE;
  7205. return result;
  7206. }
  7207. else
  7208. {
  7209. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7210. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7211. }
  7212. if(strcmp(comfirmstr,"Accepted") == 0)
  7213. {
  7214. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7215. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7216. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7217. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7218. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7219. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7220. result = TRUE;
  7221. return result;
  7222. }
  7223. end:
  7224. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7225. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7226. return result;
  7227. }
  7228. int handleResetRequest(char *uuid, char *payload)
  7229. {
  7230. mtrace();
  7231. int result = FAIL;
  7232. char sstr[10]={0};
  7233. char typestr[10]={0};
  7234. char comfirmstr[20]={0};
  7235. int c = 0;
  7236. char *loc;
  7237. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7238. DEBUG_INFO("handleResetRequest ...\n");
  7239. loc = strstr(payload, "type");
  7240. memset(sstr ,0, sizeof(sstr) );
  7241. c = 0;
  7242. while (loc[3+strlen("type")+c] != '\"')
  7243. {
  7244. sstr[c] = loc[3+strlen("type")+c];
  7245. c++;
  7246. }
  7247. sstr[c] = '\0';
  7248. strcpy(typestr,sstr);
  7249. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7250. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7251. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7252. {
  7253. //check Transaction active
  7254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7255. {
  7256. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7257. {
  7258. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7259. {
  7260. //0: unplug, 1: Plug-in
  7261. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7262. }
  7263. }
  7264. for (int index = 0; index < CCS_QUANTITY; index++)
  7265. {
  7266. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7267. {
  7268. //0: unplug, 1: Plug-in
  7269. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7270. }
  7271. }
  7272. for (int index = 0; index < GB_QUANTITY; index++)
  7273. {
  7274. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7275. {
  7276. //0: unplug, 1: Plug-in
  7277. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7278. }
  7279. }
  7280. }
  7281. else
  7282. {
  7283. for (int index = 0; index < AC_QUANTITY; index++)
  7284. {
  7285. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7286. {
  7287. //0: unplug, 1: Plug-in
  7288. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7289. }
  7290. }
  7291. }// END FOR AC ELSE
  7292. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7293. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7294. result = TRUE;
  7295. return result;
  7296. }
  7297. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7298. {
  7299. //check Transaction active
  7300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7301. {
  7302. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7303. {
  7304. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7305. {
  7306. //0: unplug, 1: Plug-in
  7307. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7308. }
  7309. }
  7310. for (int index = 0; index < CCS_QUANTITY; index++)
  7311. {
  7312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7313. {
  7314. //0: unplug, 1: Plug-in
  7315. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7316. }
  7317. }
  7318. for (int index = 0; index < GB_QUANTITY; index++)
  7319. {
  7320. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7321. {
  7322. //0: unplug, 1: Plug-in
  7323. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7324. }
  7325. }
  7326. }
  7327. else
  7328. {
  7329. for (int index = 0; index < AC_QUANTITY; index++)
  7330. {
  7331. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7332. {
  7333. //0: unplug, 1: Plug-in
  7334. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7335. }
  7336. }
  7337. }// END FOR AC ELSE
  7338. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7339. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7340. result = TRUE;
  7341. return result;
  7342. }
  7343. else
  7344. {
  7345. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7346. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7347. goto errorend;
  7348. }
  7349. errorend:
  7350. sendResetConfirmation(uuid, comfirmstr);
  7351. return result;
  7352. }
  7353. int handleSendLocalListRequest(char *uuid, char *payload)
  7354. {
  7355. mtrace();
  7356. int result = FAIL;
  7357. int listVersionInt;
  7358. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7359. char listsearch[]="listVersion";
  7360. char updateTypesearch[]="updateType";
  7361. char localAuthorizationListsearch[]="localAuthorizationList";
  7362. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7363. char CardList[500][160]={0};
  7364. char updateTypestr[15]={0};
  7365. char idTagstr[20]={0};
  7366. char parentIdTag[20]={0};
  7367. char expiryDate[30]={0};
  7368. char idTagstatus[16]={0};
  7369. int c = 0;
  7370. int i = 0;
  7371. char *delim1 = "}";
  7372. char * pch;
  7373. char *loc;
  7374. //char *ptr;
  7375. char comfirmstr[20];
  7376. //int n_localAuthorizations = 0;
  7377. int checkState_Faulted = FALSE;
  7378. DEBUG_INFO("handleSendLocalListRequest\n");
  7379. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7380. {
  7381. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7382. goto end;
  7383. }
  7384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7385. {
  7386. //check Charge Point state
  7387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7388. {
  7389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7390. {
  7391. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7392. }
  7393. }
  7394. for (int index = 0; index < CCS_QUANTITY; index++)
  7395. {
  7396. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7397. {
  7398. checkState_Faulted = TRUE; //OCPP Status
  7399. }
  7400. }
  7401. for (int index = 0; index < GB_QUANTITY; index++)
  7402. {
  7403. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7404. {
  7405. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7406. }
  7407. }
  7408. }
  7409. else
  7410. {
  7411. //check Charge Point state
  7412. for (int index = 0; index < AC_QUANTITY; index++)
  7413. {
  7414. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7415. {
  7416. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7417. }
  7418. }
  7419. }// END FOR AC ELSE
  7420. if(checkState_Faulted == TRUE)
  7421. {
  7422. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7423. goto end;
  7424. }
  7425. //listVersion
  7426. c = 0;
  7427. loc = strstr(payload, listsearch);
  7428. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7429. {
  7430. sstr[c] = loc[strlen("listVersion")+2+c];
  7431. c++;
  7432. }
  7433. sstr[c] = '\0';
  7434. listVersionInt = atoi(sstr);
  7435. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7436. //updateType
  7437. loc = strstr(payload, updateTypesearch);
  7438. c = 0;
  7439. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7440. {
  7441. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7442. c++;
  7443. }
  7444. sstr[c] = '\0';
  7445. strcpy(updateTypestr, sstr);
  7446. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7447. //localAuthorizationList
  7448. memset(sstr ,0, sizeof(sstr) );
  7449. loc = strstr(payload, localAuthorizationListsearch);
  7450. if(loc != NULL) // localAuthorizationList is not NULL
  7451. {
  7452. //Check UpdateType
  7453. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7454. {
  7455. //Local list full update
  7456. printf("Local list full update.\n");
  7457. OCPP_cleanLocalList();
  7458. }
  7459. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7460. {
  7461. //Local list different update
  7462. printf("Local list different update.\n");
  7463. OCPP_getListVerion();
  7464. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7465. {
  7466. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7467. goto end;
  7468. }
  7469. }
  7470. else
  7471. {
  7472. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7473. goto end;
  7474. }
  7475. c = 0;
  7476. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7477. {
  7478. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7479. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7480. c++;
  7481. }
  7482. sstr[c] = '\0';
  7483. //DEBUG_INFO("sstr=%s\n", sstr);
  7484. //parsing strings to words
  7485. i = 0;
  7486. pch = strtok(sstr,delim1);
  7487. while (pch != NULL)
  7488. {
  7489. strcpy(CardList[i], pch);
  7490. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7491. pch = strtok (NULL, delim1);
  7492. i = i + 1;
  7493. }
  7494. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7495. //local Authorizations List Numbers
  7496. //n_localAuthorizations = i;
  7497. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7498. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7499. c= 0;
  7500. while(c < i) // i is CardList Number
  7501. {
  7502. //Search "IdToken"
  7503. memset(sstr ,0, sizeof(sstr) );
  7504. loc = strstr(CardList[c], "idTag");
  7505. int j = 0;
  7506. while (loc[3+strlen("idTag")+j] != '\"')
  7507. {
  7508. sstr[j] = loc[3+strlen("idTag")+j];
  7509. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7510. j++;
  7511. }
  7512. sstr[j] = '\0';
  7513. strcpy(idTagstr, sstr);
  7514. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7515. //Search "expiryDate"
  7516. memset(sstr ,0, sizeof(sstr) );
  7517. loc = strstr(CardList[c], "expiryDate");
  7518. j = 0;
  7519. if(loc != NULL)
  7520. {
  7521. while (loc[3+strlen("expiryDate")+j] != '\"')
  7522. {
  7523. sstr[j] = loc[3+strlen("expiryDate")+j];
  7524. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7525. j++;
  7526. }
  7527. sstr[j] = '\0';
  7528. strcpy(expiryDate, sstr);
  7529. }
  7530. else
  7531. {
  7532. strcpy(expiryDate, "");
  7533. }
  7534. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7535. //Search "parentIdTag"
  7536. memset(sstr ,0, sizeof(sstr) );
  7537. loc = strstr(CardList[c], "parentIdTag");
  7538. j = 0;
  7539. if(loc != NULL)
  7540. {
  7541. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7542. {
  7543. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7544. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7545. j++;
  7546. }
  7547. sstr[j] = '\0';
  7548. strcpy(parentIdTag, sstr);
  7549. }
  7550. else
  7551. {
  7552. strcpy(parentIdTag, "");
  7553. }
  7554. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7555. //Search "status"
  7556. memset(sstr ,0, sizeof(sstr) );
  7557. loc = strstr(CardList[c], "status");
  7558. j = 0;
  7559. while (loc[3+strlen("status")+j] != '\"')
  7560. {
  7561. sstr[j] = loc[3+strlen("status")+j];
  7562. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7563. j++;
  7564. }
  7565. sstr[j] = '\0';
  7566. strcpy(idTagstatus, sstr);
  7567. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7568. OCPP_getIdTag(idTagstr);
  7569. //OCPP_getIdTag("test"); For Test
  7570. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7571. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7572. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7573. {
  7574. //Local list full update
  7575. DEBUG_INFO("Local list full update.\n");
  7576. // update list
  7577. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7578. //DEBUG_INFO("Local list full update. 1\n");
  7579. //OCPP_get_TableAuthlocalAllData();
  7580. //DEBUG_INFO("Local list full update. 2\n");
  7581. }
  7582. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7583. {
  7584. #if 0
  7585. if(strcmp(idTagstr, idTagAuthorization) == 0)
  7586. {
  7587. //OCPP_deleteIdTag(idTagstr);
  7588. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7589. }
  7590. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  7591. {
  7592. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7593. }
  7594. #endif
  7595. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7596. }
  7597. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7598. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7599. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7600. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7601. c++;
  7602. }
  7603. }
  7604. else
  7605. {
  7606. //Check UpdateType
  7607. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7608. {
  7609. //Local list full update
  7610. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7611. OCPP_cleanLocalList();
  7612. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7613. goto end;
  7614. }
  7615. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7616. {
  7617. //Local list different update
  7618. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7619. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7620. goto end;
  7621. }
  7622. }
  7623. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7624. end:
  7625. sendSendLocalListConfirmation(uuid, comfirmstr);
  7626. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7627. return result;
  7628. }
  7629. #define MAX 200
  7630. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7631. {
  7632. mtrace();
  7633. int result = FAIL;
  7634. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7635. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7636. char chargingProfilePurposeStr[30]={0};
  7637. char chargingProfileKindStr[16]={0};
  7638. char recurrencyKindStr[10]={0};
  7639. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7640. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7641. int chargingSchedulePeriodCount = 0;
  7642. //int updateflag = FALSE;
  7643. char comfirmstr[20]={0};
  7644. int meet= FALSE;
  7645. char sstr[10]={0};
  7646. int c = 0;
  7647. char *loc;
  7648. FILE *fptr1;//, *fptr2;
  7649. //int lno=0;//, linectr = 0;
  7650. //int modifyflag = FALSE;
  7651. char filename[MAX]={0};
  7652. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  7653. //int resultRename=0;
  7654. char rmFileCmd[50]={0};
  7655. char tempchargingProfilePurposeStr[30]={0};
  7656. char word[1600]={0};
  7657. int n_chargingProfile = 0;
  7658. //[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}}}]
  7659. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7660. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7661. //*********************connectorId***************************/
  7662. loc = strstr(payload, "connectorId");
  7663. c = 0;
  7664. memset(sstr ,0, sizeof(sstr) );
  7665. while (loc[strlen("connectorId")+2+c] != ',')
  7666. {
  7667. sstr[c] = loc[strlen("connectorId")+2+c];
  7668. c++;
  7669. }
  7670. sstr[c] = '\0';
  7671. connectorIdInt = atoi(sstr);
  7672. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7673. {
  7674. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7675. }
  7676. else
  7677. {
  7678. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7679. }
  7680. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7681. //*********************chargingProfileId***************************/
  7682. loc = strstr(payload, "chargingProfileId");
  7683. c = 0;
  7684. memset(sstr ,0, sizeof(sstr) );
  7685. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7686. {
  7687. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7688. c++;
  7689. }
  7690. sstr[c] = '\0';
  7691. chargingProfileIdInt = atoi(sstr);
  7692. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7693. {
  7694. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7695. }
  7696. else
  7697. {
  7698. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7699. }
  7700. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7701. //*********************transactionId***************************/
  7702. loc = strstr(payload, "transactionId");
  7703. if(loc != NULL)
  7704. {
  7705. c = 0;
  7706. memset(sstr ,0, sizeof(sstr) );
  7707. while (loc[strlen("transactionId")+2+c] != ',')
  7708. {
  7709. sstr[c] = loc[strlen("transactionId")+2+c];
  7710. c++;
  7711. }
  7712. sstr[c] = '\0';
  7713. transactionIdInt = atoi(sstr);
  7714. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7715. {
  7716. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7717. }
  7718. else
  7719. {
  7720. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7721. }
  7722. }
  7723. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7724. //*********************stackLevel***************************/
  7725. loc = strstr(payload, "stackLevel");
  7726. c = 0;
  7727. memset(sstr ,0, sizeof(sstr) );
  7728. while (loc[strlen("stackLevel")+2+c] != ',')
  7729. {
  7730. sstr[c] = loc[strlen("stackLevel")+2+c];
  7731. c++;
  7732. }
  7733. sstr[c] = '\0';
  7734. stackLevelInt = atoi(sstr);
  7735. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7736. {
  7737. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7738. }
  7739. else
  7740. {
  7741. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7742. }
  7743. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7744. //*********************chargingProfilePurpose***************************/
  7745. loc = strstr(payload, "chargingProfilePurpose");
  7746. c = 0;
  7747. memset(sstr ,0, sizeof(sstr) );
  7748. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7749. {
  7750. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7751. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7752. c++;
  7753. }
  7754. sstr[c] = '\0';
  7755. strcpy(chargingProfilePurposeStr,sstr);
  7756. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7757. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7758. {
  7759. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7760. }
  7761. else
  7762. {
  7763. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7764. }
  7765. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7766. //*********************chargingProfileKind***************************/
  7767. loc = strstr(payload, "chargingProfileKind");
  7768. c = 0;
  7769. memset(sstr ,0, sizeof(sstr) );
  7770. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7771. {
  7772. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7773. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7774. c++;
  7775. }
  7776. sstr[c] = '\0';
  7777. strcpy(chargingProfileKindStr,sstr);
  7778. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7779. {
  7780. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7781. }
  7782. else
  7783. {
  7784. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7785. }
  7786. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7787. //*********************recurrencyKind***************************/
  7788. loc = strstr(payload, "recurrencyKind");
  7789. if(loc != NULL)
  7790. {
  7791. c = 0;
  7792. memset(sstr ,0, sizeof(sstr) );
  7793. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7794. {
  7795. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7796. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7797. c++;
  7798. }
  7799. sstr[c] = '\0';
  7800. strcpy(recurrencyKindStr,sstr);
  7801. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7802. {
  7803. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7804. }
  7805. else
  7806. {
  7807. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7808. }
  7809. }
  7810. else
  7811. {
  7812. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7813. {
  7814. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7815. }
  7816. else
  7817. {
  7818. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7819. }
  7820. }
  7821. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7822. //*********************validFrom***************************/
  7823. loc = strstr(payload, "validFrom");
  7824. if(loc != NULL)
  7825. {
  7826. c = 0;
  7827. memset(sstr ,0, sizeof(sstr) );
  7828. while (loc[3+strlen("validFrom")+c] != '\"')
  7829. {
  7830. sstr[c] = loc[3+strlen("validFrom")+c];
  7831. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7832. c++;
  7833. }
  7834. sstr[c] = '\0';
  7835. strcpy(validFromStr,sstr);
  7836. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7837. {
  7838. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7839. }
  7840. else
  7841. {
  7842. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7843. }
  7844. }
  7845. else
  7846. {
  7847. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7848. {
  7849. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7850. }
  7851. else
  7852. {
  7853. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7854. }
  7855. }
  7856. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7857. //*********************validTo***************************/
  7858. loc = strstr(payload, "validTo");
  7859. if(loc != NULL)
  7860. {
  7861. c = 0;
  7862. memset(sstr ,0, sizeof(sstr) );
  7863. while (loc[3+strlen("validTo")+c] != '\"')
  7864. {
  7865. sstr[c] = loc[3+strlen("validTo")+c];
  7866. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7867. c++;
  7868. }
  7869. sstr[c] = '\0';
  7870. strcpy(validToStr,sstr);
  7871. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7872. {
  7873. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7874. }
  7875. else
  7876. {
  7877. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7878. }
  7879. }
  7880. else
  7881. {
  7882. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7883. {
  7884. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7885. }
  7886. else
  7887. {
  7888. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7889. }
  7890. }
  7891. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7892. //*********************duration***************************/
  7893. loc = strstr(payload, "duration");
  7894. if(loc != NULL)
  7895. {
  7896. c = 0;
  7897. memset(sstr ,0, sizeof(sstr) );
  7898. while (loc[strlen("duration")+2+c] != ',')
  7899. {
  7900. sstr[c] = loc[strlen("duration")+2+c];
  7901. c++;
  7902. }
  7903. sstr[c] = '\0';
  7904. durationInt = atoi(sstr);
  7905. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7906. {
  7907. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7908. }
  7909. else
  7910. {
  7911. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7912. }
  7913. }
  7914. else
  7915. {
  7916. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7917. {
  7918. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7919. }
  7920. else
  7921. {
  7922. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7923. }
  7924. }
  7925. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7926. //*********************startSchedule***************************/
  7927. loc = strstr(payload, "startSchedule");
  7928. if(loc != NULL)
  7929. {
  7930. c = 0;
  7931. memset(sstr ,0, sizeof(sstr) );
  7932. while (loc[3+strlen("startSchedule")+c] != '\"')
  7933. {
  7934. sstr[c] = loc[3+strlen("startSchedule")+c];
  7935. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7936. c++;
  7937. }
  7938. sstr[c] = '\0';
  7939. strcpy(startScheduleStr,sstr);
  7940. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7941. {
  7942. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7943. }
  7944. else
  7945. {
  7946. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7947. }
  7948. }
  7949. else
  7950. {
  7951. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7952. {
  7953. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7954. }
  7955. else
  7956. {
  7957. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7958. }
  7959. }
  7960. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7961. //*********************chargingRateUnit***************************/
  7962. loc = strstr(payload, "chargingRateUnit");
  7963. if(loc != NULL)
  7964. {
  7965. c = 0;
  7966. memset(sstr ,0, sizeof(sstr) );
  7967. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7968. {
  7969. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7970. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7971. c++;
  7972. }
  7973. sstr[c] = '\0';
  7974. strcpy(chargingRateUnitStr,sstr);
  7975. #if 0
  7976. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  7977. {
  7978. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7979. goto end;
  7980. }
  7981. #endif
  7982. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7983. {
  7984. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7985. }
  7986. else
  7987. {
  7988. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7989. }
  7990. }
  7991. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7992. //****************chargingSchedulePeriod count start*******************/
  7993. int what_len = strlen("startPeriod");
  7994. char tempChargingProfile[1000]={0};
  7995. strcpy(tempChargingProfile,(const char*)payload);
  7996. char *where = tempChargingProfile;
  7997. if (what_len)
  7998. {
  7999. while ((where = strstr(where, "startPeriod"))) {
  8000. where += what_len;
  8001. chargingSchedulePeriodCount++;
  8002. }
  8003. }
  8004. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8005. {
  8006. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8007. goto end;
  8008. }
  8009. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8010. //where = payload;
  8011. int templength = 0;
  8012. //int searchstart = 0;
  8013. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8014. {
  8015. //****************startPeriod*******************/
  8016. c=0;
  8017. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8018. memset(sstr ,0, sizeof(sstr) );
  8019. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8020. {
  8021. sstr[c] = loc[strlen("startPeriod")+2+c];
  8022. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8023. c++;
  8024. }
  8025. sstr[c] = '\0';
  8026. startPeriodInt[periodNums] = atoi(sstr);
  8027. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8028. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8029. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8030. {
  8031. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8032. }
  8033. else
  8034. {
  8035. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8036. }
  8037. templength = strlen("startPeriod")+2+c;
  8038. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8039. //****************limit*******************/
  8040. c=0;
  8041. loc = strstr(tempChargingProfile + templength, "limit");
  8042. memset(sstr ,0, sizeof(sstr) );
  8043. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8044. {
  8045. sstr[c] = loc[strlen("limit")+2+c];
  8046. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8047. c++;
  8048. }
  8049. sstr[c] = '\0';
  8050. limitflaot[periodNums] = atof(sstr);
  8051. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8052. {
  8053. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8054. }
  8055. else
  8056. {
  8057. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8058. }
  8059. templength = templength + strlen("limit")+2+c;
  8060. //****************numberPhases*******************/
  8061. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8062. if(loc != NULL)
  8063. {
  8064. c=0;
  8065. memset(sstr ,0, sizeof(sstr) );
  8066. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8067. {
  8068. sstr[c] = loc[strlen("numberPhases")+2+c];
  8069. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8070. c++;
  8071. }
  8072. sstr[c] = '\0';
  8073. numberPhasesInt[periodNums] = atoi(sstr);
  8074. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8075. {
  8076. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8077. }
  8078. else
  8079. {
  8080. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8081. }
  8082. templength = templength + strlen("numberPhases")+2+c;
  8083. }
  8084. //where = loc;
  8085. }
  8086. //****************chargingSchedulePeriod count end*******************/
  8087. //*********************minChargingRate***************************/
  8088. loc = strstr(payload, "minChargingRate");
  8089. if(loc != NULL)
  8090. {
  8091. c = 0;
  8092. memset(sstr ,0, sizeof(sstr) );
  8093. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8094. {
  8095. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8096. c++;
  8097. }
  8098. sstr[c] = '\0';
  8099. minChargingRateFloat = atof(sstr);
  8100. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8101. {
  8102. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8103. }
  8104. else
  8105. {
  8106. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8107. }
  8108. }
  8109. else
  8110. {
  8111. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8112. {
  8113. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8114. }
  8115. else
  8116. {
  8117. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8118. }
  8119. }
  8120. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8121. {
  8122. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8123. if(connectorIdInt != 0)
  8124. {
  8125. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8126. goto end;
  8127. }
  8128. strcpy(filename, ChargePointMaxProfile_JSON );
  8129. fptr1 = fopen(filename, "r");
  8130. if (!fptr1)
  8131. {
  8132. //file not exist
  8133. DEBUG_INFO("Unable to open the input file!!\n");
  8134. fptr1 = fopen(filename, "w+");
  8135. }
  8136. else
  8137. {
  8138. //Check Charging Profile Count
  8139. while(fscanf(fptr1, "%s", word) != EOF)
  8140. {
  8141. //DEBUG_INFO("word=%s\n",word);
  8142. if(strstr(word, "chargingProfileId")!= NULL)
  8143. {
  8144. //DEBUG_INFO("test chargingProfileId \n");
  8145. n_chargingProfile = n_chargingProfile + 1;
  8146. //DEBUG_INFO("chargingProfileId Found\n");
  8147. }
  8148. }
  8149. }
  8150. fclose(fptr1);
  8151. }
  8152. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8153. {
  8154. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8155. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8156. {
  8157. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8158. goto end;
  8159. }
  8160. #if 0
  8161. switch(connectorIdInt)
  8162. {
  8163. case 0:
  8164. strcpy(filename, TxDefaultProfile_0_JSON );
  8165. break;
  8166. case 1:
  8167. strcpy(filename, TxDefaultProfile_1_JSON );
  8168. break;
  8169. case 2:
  8170. strcpy(filename, TxDefaultProfile_2_JSON );
  8171. break;
  8172. default:
  8173. strcpy(filename, TxDefaultProfile_0_JSON );
  8174. break;
  8175. }
  8176. #endif
  8177. memset(filename, 0, sizeof filename);
  8178. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8179. fptr1 = fopen(filename, "r");
  8180. if (!fptr1)
  8181. {
  8182. //file not exist
  8183. //DEBUG_INFO("Unable to open the input file!!\n");
  8184. fptr1 = fopen(filename, "w+");
  8185. }
  8186. else
  8187. {
  8188. //Check Charging Profile Count
  8189. while(fscanf(fptr1, "%s", word) != EOF)
  8190. {
  8191. //DEBUG_INFO("word=%s\n",word);
  8192. if(strstr(word, "chargingProfileId")!= NULL)
  8193. {
  8194. //DEBUG_INFO("test chargingProfileId \n");
  8195. n_chargingProfile = n_chargingProfile + 1;
  8196. //DEBUG_INFO("chargingProfileId Found\n");
  8197. }
  8198. }
  8199. }
  8200. fclose(fptr1);
  8201. }
  8202. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8203. {
  8204. //printf("set chargingProfile 1-4\n");
  8205. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8206. //check Transaction active
  8207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8208. {
  8209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8210. {
  8211. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8212. {
  8213. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8214. {
  8215. meet = TRUE;
  8216. break;
  8217. }
  8218. }
  8219. }
  8220. }
  8221. for (int index = 0; index < CCS_QUANTITY; index++)
  8222. {
  8223. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8224. {
  8225. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8226. {
  8227. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8228. {
  8229. meet = TRUE;
  8230. break;
  8231. }
  8232. }
  8233. }
  8234. }
  8235. for (int index = 0; index < GB_QUANTITY; index++)
  8236. {
  8237. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8238. {
  8239. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8240. {
  8241. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8242. {
  8243. meet = TRUE;
  8244. break;
  8245. }
  8246. }
  8247. }
  8248. }
  8249. if(meet == FALSE)
  8250. {
  8251. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8252. goto end;
  8253. }
  8254. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8255. {
  8256. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8257. goto end;
  8258. }
  8259. #if 0
  8260. switch(connectorIdInt)
  8261. {
  8262. case 0:
  8263. break;
  8264. case 1:
  8265. strcpy(filename, TxProfile_1_JSON);
  8266. break;
  8267. case 2:
  8268. strcpy(filename, TxProfile_2_JSON);
  8269. break;
  8270. default:
  8271. strcpy(filename, TxProfile_1_JSON);
  8272. break;
  8273. }
  8274. #endif
  8275. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8276. fptr1 = fopen(filename, "r");
  8277. if (!fptr1)
  8278. {
  8279. //file not exist
  8280. DEBUG_INFO("Unable to open the input file!!\n");
  8281. fptr1 = fopen(filename, "w+");
  8282. }
  8283. else
  8284. {
  8285. //Check Charging Profile Count
  8286. while(fscanf(fptr1, "%s", word) != EOF)
  8287. {
  8288. //DEBUG_INFO("word=%s\n",word);
  8289. if(strstr(word, "chargingProfileId")!= NULL)
  8290. {
  8291. //DEBUG_INFO("test chargingProfileId \n");
  8292. n_chargingProfile = n_chargingProfile + 1;
  8293. //DEBUG_INFO("chargingProfileId Found\n");
  8294. }
  8295. }
  8296. }
  8297. fclose(fptr1);
  8298. DEBUG_INFO("n_chargingProfile_3=%d\n",n_chargingProfile);
  8299. }
  8300. // Check ChargeProfileMaxStackLevel
  8301. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8302. {
  8303. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8304. goto end;
  8305. }
  8306. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8307. {
  8308. int i = 0;
  8309. char fnametemp[200]={0};
  8310. n_chargingProfile = 0;
  8311. //Check ChargePointMaxProfile.json exit
  8312. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8313. {
  8314. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8315. //Check Charging Profile Count
  8316. while(fscanf(fptr1, "%s", word) != EOF)
  8317. {
  8318. //DEBUG_INFO("word=%s\n",word);
  8319. if(strstr(word, "chargingProfileId")!= NULL)
  8320. {
  8321. //DEBUG_INFO("test chargingProfileId \n");
  8322. n_chargingProfile = n_chargingProfile + 1;
  8323. i = i + 1;
  8324. //DEBUG_INFO("chargingProfileId Found\n");
  8325. }
  8326. memset(word, 0, sizeof word);
  8327. }
  8328. fclose(fptr1);
  8329. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8330. }
  8331. //Check TxDefaultProfile_0.json exit
  8332. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8333. {
  8334. i = 0;
  8335. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8336. //Check Charging Profile Count
  8337. while(fscanf(fptr1, "%s", word) != EOF)
  8338. {
  8339. //DEBUG_INFO("word=%s\n",word);
  8340. if(strstr(word, "chargingProfileId")!= NULL)
  8341. {
  8342. //DEBUG_INFO("test chargingProfileId \n");
  8343. n_chargingProfile = n_chargingProfile + 1;
  8344. i = i + 1;
  8345. //DEBUG_INFO("chargingProfileId Found\n");
  8346. }
  8347. memset(word, 0, sizeof word);
  8348. }
  8349. fclose(fptr1);
  8350. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8351. }
  8352. //Check TxDefaultProfile_%d.json
  8353. for(int j=1; j <= gunTotalNumber; j++)
  8354. {
  8355. memset(fnametemp, 0, sizeof fnametemp);
  8356. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8357. if((access(fnametemp,F_OK))!=-1)
  8358. {
  8359. i = 0;
  8360. fptr1 = fopen(fnametemp, "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("%s has %d charging Profile\n",fnametemp, i);
  8376. }
  8377. }
  8378. //Check TxProfile_%d.json
  8379. for(int j=1; j <= gunTotalNumber; j++)
  8380. {
  8381. memset(fnametemp, 0, sizeof fnametemp);
  8382. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8383. if((access(fnametemp,F_OK))!=-1)
  8384. {
  8385. i = 0;
  8386. fptr1 = fopen(fnametemp, "r");
  8387. //Check Charging Profile Count
  8388. while(fscanf(fptr1, "%s", word) != EOF)
  8389. {
  8390. //DEBUG_INFO("word=%s\n",word);
  8391. if(strstr(word, "chargingProfileId")!= NULL)
  8392. {
  8393. //DEBUG_INFO("test chargingProfileId \n");
  8394. n_chargingProfile = n_chargingProfile + 1;
  8395. i = i + 1;
  8396. //DEBUG_INFO("chargingProfileId Found\n");
  8397. }
  8398. memset(word, 0, sizeof word);
  8399. }
  8400. fclose(fptr1);
  8401. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8402. }
  8403. }
  8404. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8405. {
  8406. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8407. goto end;
  8408. }
  8409. }
  8410. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8411. //**********************************Write to File********************************************************/
  8412. FILE *infile;
  8413. FILE *outfile;
  8414. // open file for writing
  8415. infile = fopen (filename, "r");
  8416. outfile = fopen (tempfile, "w");
  8417. int d =0;
  8418. d = fgetc(infile);
  8419. //DEBUG_INFO("d:%d\n",d);
  8420. rewind(infile);
  8421. //*检测到文件结束标识返回1,否则返回0。*/
  8422. if(d == EOF)
  8423. {
  8424. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8425. fprintf(outfile,"%s\n",payload);
  8426. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8427. fclose(infile);
  8428. fclose(outfile);
  8429. sprintf(rmFileCmd,"rm -f %s",filename);
  8430. system(rmFileCmd);
  8431. rename(tempfile, filename);
  8432. #if 0
  8433. resultRename = rename(tempfile, filename);
  8434. if(resultRename == 0)
  8435. {
  8436. DEBUG_INFO("File chargingProfile renamed successfully");
  8437. }
  8438. else
  8439. {
  8440. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8441. }
  8442. #endif
  8443. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8444. //system(rmFileCmd);
  8445. }
  8446. else
  8447. {
  8448. char buf[1000]={0};
  8449. int ChargingProfileAdded = FALSE;
  8450. while (fgets(buf, sizeof(buf), infile) != NULL)
  8451. {
  8452. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8453. //*************************tempconnectorIdInt*********************************/
  8454. loc = strstr(buf, "connectorId");
  8455. c = 0;
  8456. memset(sstr ,0, sizeof(sstr) );
  8457. while (loc[strlen("connectorId")+2+c] != ',')
  8458. {
  8459. sstr[c] = loc[strlen("connectorId")+2+c];
  8460. c++;
  8461. }
  8462. sstr[c] = '\0';
  8463. tempconnectorIdInt = atoi(sstr);
  8464. //*************************tempchargingProfileIdInt*********************************/
  8465. loc = strstr(buf, "chargingProfileId");
  8466. c = 0;
  8467. memset(sstr ,0, sizeof(sstr) );
  8468. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8469. {
  8470. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8471. c++;
  8472. }
  8473. sstr[c] = '\0';
  8474. tempchargingProfileIdInt = atoi(sstr);
  8475. //*************************tempstackLevelInt*********************************/
  8476. loc = strstr(buf, "stackLevel");
  8477. c = 0;
  8478. memset(sstr ,0, sizeof(sstr) );
  8479. while (loc[strlen("stackLevel")+2+c] != ',')
  8480. {
  8481. sstr[c] = loc[strlen("stackLevel")+2+c];
  8482. c++;
  8483. }
  8484. sstr[c] = '\0';
  8485. tempstackLevelInt = atoi(sstr);
  8486. //*************************tempchargingProfilePurposeStr*********************************/
  8487. loc = strstr(payload, "chargingProfilePurpose");
  8488. c = 0;
  8489. memset(sstr ,0, sizeof(sstr) );
  8490. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8491. {
  8492. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8494. c++;
  8495. }
  8496. sstr[c] = '\0';
  8497. strcpy(tempchargingProfilePurposeStr,sstr);
  8498. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8499. {
  8500. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8501. {
  8502. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8503. if(ChargingProfileAdded == FALSE)
  8504. {
  8505. fprintf(outfile,"%s\n",payload);
  8506. ChargingProfileAdded = TRUE;
  8507. }
  8508. }
  8509. else
  8510. {
  8511. if(tempstackLevelInt < stackLevelInt)
  8512. {
  8513. if(ChargingProfileAdded == FALSE)
  8514. {
  8515. fprintf(outfile,"%s\n",payload);
  8516. ChargingProfileAdded = TRUE;
  8517. fprintf(outfile,"%s\n",buf);
  8518. }
  8519. else
  8520. {
  8521. fprintf(outfile,"%s\n",buf);
  8522. }
  8523. }
  8524. else
  8525. {
  8526. if(ChargingProfileAdded == FALSE)
  8527. {
  8528. fprintf(outfile,"%s\n",buf);
  8529. fprintf(outfile,"%s\n",payload);
  8530. ChargingProfileAdded = TRUE;
  8531. }
  8532. else
  8533. {
  8534. fprintf(outfile,"%s\n",buf);
  8535. }
  8536. }
  8537. }
  8538. }
  8539. else
  8540. {
  8541. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8542. {
  8543. if(ChargingProfileAdded == FALSE)
  8544. {
  8545. fprintf(outfile,"%s\n",payload);
  8546. ChargingProfileAdded = TRUE;
  8547. fprintf(outfile,"%s\n",buf);
  8548. }
  8549. else
  8550. {
  8551. fprintf(outfile,"%s\n",buf);
  8552. }
  8553. }
  8554. else if(tempstackLevelInt < stackLevelInt)
  8555. {
  8556. if(ChargingProfileAdded == FALSE)
  8557. {
  8558. fprintf(outfile,"%s\n",payload);
  8559. ChargingProfileAdded = TRUE;
  8560. fprintf(outfile,"%s\n",buf);
  8561. }
  8562. else
  8563. {
  8564. fprintf(outfile,"%s\n",buf);
  8565. }
  8566. }
  8567. else
  8568. {
  8569. if(ChargingProfileAdded == FALSE)
  8570. {
  8571. fprintf(outfile,"%s\n",buf);
  8572. fprintf(outfile,"%s\n",payload);
  8573. ChargingProfileAdded = TRUE;
  8574. }
  8575. else
  8576. {
  8577. fprintf(outfile,"%s\n",buf);
  8578. }
  8579. }
  8580. }
  8581. } // end of while loop
  8582. fclose(infile);
  8583. fclose(outfile);
  8584. sprintf(rmFileCmd,"rm -f %s",filename);
  8585. system(rmFileCmd);
  8586. rename(tempfile, filename);
  8587. #if 0
  8588. resultRename = rename(tempfile, filename);
  8589. if(resultRename == 0)
  8590. {
  8591. DEBUG_INFO("File chargingProfile renamed successfully");
  8592. }
  8593. else
  8594. {
  8595. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8596. }
  8597. #endif
  8598. result = TRUE;
  8599. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8600. }
  8601. end:
  8602. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8603. return result;
  8604. return result;
  8605. }
  8606. int handleTriggerMessageRequest(char *uuid, char *payload)
  8607. {
  8608. mtrace();
  8609. int result = FAIL;
  8610. int connectorIdIsNULL = FALSE;
  8611. int connectorIdInt =0;
  8612. char sstr[40]={0};
  8613. char requestedMessagestr[40]={0};
  8614. char comfirmstr[20]={0};
  8615. int c = 0;
  8616. char *loc;
  8617. DEBUG_INFO("handleTriggerMessageRequest\n");
  8618. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8619. c = 0;
  8620. loc = strstr(payload, "requestedMessage");
  8621. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8622. {
  8623. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8624. c++;
  8625. }
  8626. sstr[c] = '\0';
  8627. strcpy(requestedMessagestr, sstr);
  8628. c = 0;
  8629. loc = strstr(payload, "connectorId");
  8630. if(loc == NULL)
  8631. {
  8632. connectorIdIsNULL = TRUE;
  8633. }
  8634. else
  8635. {
  8636. memset(sstr ,0, sizeof(sstr) );
  8637. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8638. {
  8639. sstr[c] = loc[strlen("connectorId")+2+c];
  8640. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8641. c++;
  8642. }
  8643. sstr[c] = '\0';
  8644. connectorIdInt = atoi(sstr);
  8645. }
  8646. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8647. {
  8648. //connectorIdInt = json_object_get_int(connectorId);
  8649. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8650. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8651. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8652. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8653. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8654. }
  8655. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8656. {
  8657. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8658. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8659. return TRUE;
  8660. }
  8661. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8662. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8663. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8664. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8665. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8666. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8667. {
  8668. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8669. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8670. return TRUE;
  8671. }
  8672. else
  8673. {
  8674. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8675. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8676. }
  8677. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8678. {
  8679. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8680. {
  8681. FirmwareStatusNotificationStatus = 3;
  8682. }
  8683. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8684. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8685. }
  8686. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8687. {
  8688. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8689. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8690. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8691. }
  8692. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8693. {
  8694. sendBootNotificationRequest();
  8695. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8696. }
  8697. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8698. {
  8699. sendHeartbeatRequest(connectorIdInt);
  8700. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8701. }
  8702. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8703. {
  8704. if(connectorIdIsNULL == FALSE)
  8705. {
  8706. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8707. {
  8708. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8709. sendMeterValuesRequest(connectorIdInt -1);
  8710. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8711. }
  8712. }
  8713. else
  8714. {
  8715. for(int idx=0;idx< gunTotalNumber;idx++)
  8716. {
  8717. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8718. sendMeterValuesRequest(idx);
  8719. }
  8720. }
  8721. }
  8722. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8723. {
  8724. if(connectorIdIsNULL == FALSE)
  8725. {
  8726. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8727. {
  8728. sendStatusNotificationRequest(connectorIdInt -1);
  8729. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8730. }
  8731. }
  8732. else
  8733. {
  8734. for(int idx=0;idx< gunTotalNumber;idx++)
  8735. sendStatusNotificationRequest(idx);
  8736. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8737. }
  8738. }
  8739. return result;
  8740. }
  8741. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8742. {
  8743. mtrace();
  8744. int result = FAIL;
  8745. char sstr[6]={0};
  8746. int connectorIdInt =0;
  8747. char comfirmstr[20]={0};
  8748. int c = 0;
  8749. char *loc;
  8750. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8751. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8752. c = 0;
  8753. loc = strstr(payload, "connectorId");
  8754. memset(sstr ,0, sizeof(sstr) );
  8755. while (loc[strlen("connectorId")+2+c] != '}')
  8756. {
  8757. sstr[c] = loc[strlen("connectorId")+2+c];
  8758. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8759. c++;
  8760. }
  8761. sstr[c] = '\0';
  8762. connectorIdInt = atoi(sstr);
  8763. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8764. if(gunTotalNumber == 0)
  8765. {
  8766. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8767. goto end;
  8768. }
  8769. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8770. {
  8771. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8772. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8773. goto end;
  8774. }
  8775. else
  8776. {
  8777. //check Transaction active
  8778. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8779. {
  8780. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8781. {
  8782. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8783. {
  8784. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8785. }
  8786. }
  8787. for (int index = 0; index < CCS_QUANTITY; index++)
  8788. {
  8789. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8790. {
  8791. //stop Transaction
  8792. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8793. }
  8794. }
  8795. for (int index = 0; index < GB_QUANTITY; index++)
  8796. {
  8797. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8798. {
  8799. //stop Transaction
  8800. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8801. }
  8802. }
  8803. }
  8804. else
  8805. {
  8806. for (int index = 0; index < AC_QUANTITY; index++)
  8807. {
  8808. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8809. {
  8810. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8811. }
  8812. }
  8813. }// END FOR AC ELSE
  8814. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8815. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8816. result = TRUE;
  8817. return result;
  8818. }
  8819. end:
  8820. //json_object_put(obj); --- remove temporally
  8821. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8822. return result;
  8823. }
  8824. static char UpdateFirmwarepayloadData[300]={0};
  8825. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8826. {
  8827. mtrace();
  8828. int result = FAIL;
  8829. pthread_t t;
  8830. sendUpdateFirmwareConfirmation(uuid);
  8831. memset(UpdateFirmwarepayloadData, 0, 300);
  8832. strcpy(UpdateFirmwarepayloadData, payload);
  8833. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8834. ////pthread_join(t, NULL); //
  8835. //pthread_detach(t);
  8836. //sendUpdateFirmwareConfirmation(uuid);
  8837. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8838. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8839. return result;
  8840. }
  8841. void *UpdateFirmwareProcess(void *data)
  8842. {
  8843. pthread_detach(pthread_self());
  8844. mtrace();
  8845. int retriesInt =0, retryIntervalInt=0;
  8846. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8847. int port=0;
  8848. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8849. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8850. //char comfirmstr[20];
  8851. int isSuccess = 0;
  8852. char ftpbuf[200];
  8853. char temp[100];
  8854. char * pch;
  8855. int retriesISNULL=FALSE;
  8856. int retryInterval=FALSE;
  8857. int c = 0;
  8858. //int i = 0;
  8859. char *loc;
  8860. char sstr[300]={ 0 };
  8861. char str[300]={ 0 };
  8862. //char *str = (char*) data; // ? ?輸入資 ?
  8863. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8864. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8865. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8866. //***************location **************/
  8867. loc = strstr(str, "location");
  8868. memset(sstr ,0, sizeof(sstr) );
  8869. c = 0;
  8870. while (loc[3+strlen("location")+c] != '\"')
  8871. {
  8872. sstr[c] = loc[3+strlen("location")+c];
  8873. c++;
  8874. }
  8875. sstr[c] = '\0';
  8876. strcpy(locationstr, sstr);
  8877. //***************retries**************/
  8878. c = 0;
  8879. loc = strstr(str, "retries");
  8880. if(loc == NULL)
  8881. {
  8882. retriesISNULL=TRUE;
  8883. }
  8884. else
  8885. {
  8886. memset(sstr ,0, sizeof(sstr) );
  8887. while (loc[strlen("retries")+2+c] != ',')
  8888. {
  8889. sstr[c] = loc[strlen("retries")+2+c];
  8890. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8891. c++;
  8892. }
  8893. sstr[c] = '\0';
  8894. }
  8895. if(retriesISNULL == FALSE)
  8896. {
  8897. retriesInt = atoi(sstr);
  8898. }
  8899. //***************retrieveDate **************/
  8900. loc = strstr(str, "retrieveDate");
  8901. memset(sstr ,0, sizeof(sstr) );
  8902. c = 0;
  8903. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8904. {
  8905. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8906. c++;
  8907. }
  8908. sstr[c] = '\0';
  8909. strcpy(retrieveDatestr, sstr);
  8910. //***************retryInterval **************/
  8911. c = 0;
  8912. loc = strstr(str, "retryInterval");
  8913. memset(sstr ,0, sizeof(sstr) );
  8914. if(loc == NULL)
  8915. {
  8916. retryInterval=TRUE;
  8917. }
  8918. else
  8919. {
  8920. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8921. {
  8922. sstr[c] = loc[strlen("retryInterval")+2+c];
  8923. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8924. c++;
  8925. }
  8926. sstr[c] = '\0';
  8927. }
  8928. if(retryInterval==FALSE)
  8929. {
  8930. retryIntervalInt = atoi(sstr);
  8931. }
  8932. memset(ftppath, 0, sizeof(ftppath));
  8933. memset(path, 0, sizeof(path));
  8934. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8935. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8936. if(strncmp(locationstr,"http", 4) == 0)
  8937. {
  8938. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8939. protocol, host, path);
  8940. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8941. // protocol, user, password, host, path);
  8942. sprintf(ftppath,"/%s", path);
  8943. //DEBUG_INFO("protocol =%s\n",protocol);
  8944. //DEBUG_INFO("host =%s\n",host);
  8945. //DEBUG_INFO("path =%s\n",path);
  8946. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8947. int ftppathlen=strlen(ftppath);
  8948. int i=1;
  8949. char filenametemp[50];
  8950. while(i < ftppathlen)
  8951. {
  8952. int len=ftppathlen-i;
  8953. if(ftppath[len]== 47) // '/' ascll code: 47
  8954. {
  8955. DEBUG_INFO("compare '/' all right\n");
  8956. break;
  8957. }
  8958. i=i+1;
  8959. }
  8960. memset(filenametemp, 0, sizeof(filenametemp));
  8961. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8962. filenametemp[i+1] = 0;
  8963. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8964. do{
  8965. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8966. sleep(retryIntervalInt);
  8967. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8968. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8969. if(!isSuccess)
  8970. {
  8971. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8972. }
  8973. else
  8974. {
  8975. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8976. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8977. isUpdateRequest = TRUE;
  8978. }
  8979. }
  8980. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8981. {
  8982. memset(ftpbuf, 0, sizeof(ftpbuf));
  8983. memset(temp, 0, sizeof(temp));
  8984. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8985. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8986. int ftppathlen=strlen(ftpbuf);
  8987. int i=1;
  8988. char filenametemp[50];
  8989. while(i < ftppathlen)
  8990. {
  8991. int len=ftppathlen-i;
  8992. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8993. {
  8994. DEBUG_INFO(" compare '/' all right\n");
  8995. break;
  8996. }
  8997. i=i+1;
  8998. }
  8999. memset(filenametemp, 0, sizeof(filenametemp));
  9000. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9001. filenametemp[i+1] = 0;
  9002. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9003. pch=strchr(temp,'@');
  9004. if(pch==NULL)
  9005. {
  9006. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9007. protocol, host, &port, path);
  9008. strcpy(user,"anonymous");
  9009. strcpy(password,"");
  9010. }
  9011. else
  9012. {
  9013. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9014. protocol, user, password, host, &port, path);
  9015. }
  9016. sscanf(host,"%[^/]%s",host1, path1);
  9017. sprintf(ftppath,"%s", path1);
  9018. //DEBUG_INFO("protocol =%s\n",protocol);
  9019. //DEBUG_INFO("user =%s\n",user);
  9020. //DEBUG_INFO("password =%s\n",password);
  9021. //DEBUG_INFO("host1 =%s\n",host1);
  9022. //DEBUG_INFO("port =%d\n",port);
  9023. //DEBUG_INFO("path1 =%s\n",path1);
  9024. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9025. //ftpFile(host, user, password, port, ftppath, fname);
  9026. //download firmware pthred
  9027. if(port == 0)
  9028. {
  9029. port = 21;
  9030. }
  9031. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9032. do{
  9033. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9034. sleep(retryIntervalInt);
  9035. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9036. if(!isSuccess)
  9037. {
  9038. //BulldogUtil.sleepMs(interval*1000);
  9039. DEBUG_INFO("Update firmware request and download file fail.\n");
  9040. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9041. }
  9042. else
  9043. {
  9044. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9045. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9046. isUpdateRequest = TRUE;
  9047. }
  9048. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9049. }
  9050. else
  9051. {
  9052. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9053. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9054. }
  9055. pthread_exit(NULL);
  9056. }
  9057. //==========================================
  9058. // Handle server response routine
  9059. //==========================================
  9060. void handleAuthorizeResponse(char *payload, int gun_index)
  9061. {
  9062. mtrace();
  9063. char expiryDatestr[30]={0};
  9064. char parentIdTagstr[20]={0};
  9065. char statusstr[20]={0};
  9066. char expiryDatestrtemp[30]={0};
  9067. char parentIdTagstrtemp[20]={0};
  9068. char IdTagstrtemp[20]={0};
  9069. char statusstrtemp[20]={0};
  9070. int expiryDateISNULL=FALSE;
  9071. int parentIdTagISNULL=FALSE;
  9072. char sstr[160]={ 0 };
  9073. char* filename = AuthorizationCache_JSON;
  9074. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9075. int c = 0;
  9076. char *loc;
  9077. int resultRename=0;
  9078. int responseIdTagInfoAsZero= 0;
  9079. char rmFileCmd[50]={0};
  9080. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9081. //***********expiryDate*************/
  9082. loc = strstr(payload, "expiryDate");
  9083. memset(sstr ,0, sizeof(sstr) );
  9084. c = 0;
  9085. if(loc == NULL)
  9086. {
  9087. expiryDateISNULL = TRUE;
  9088. }
  9089. else
  9090. {
  9091. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9092. {
  9093. sstr[c] = loc[3+strlen("expiryDate")+c];
  9094. c++;
  9095. }
  9096. sstr[c] = '\0';
  9097. strcpy(expiryDatestr, sstr);
  9098. }
  9099. //***********parentIdTag*************/
  9100. loc = strstr(payload, "parentIdTag");
  9101. memset(sstr ,0, sizeof(sstr) );
  9102. c = 0;
  9103. if(loc == NULL)
  9104. {
  9105. parentIdTagISNULL = TRUE;
  9106. }
  9107. else
  9108. {
  9109. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9110. {
  9111. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9112. c++;
  9113. }
  9114. sstr[c] = '\0';
  9115. strcpy(parentIdTagstr, sstr);
  9116. }
  9117. //***********status*************/
  9118. loc = strstr(payload, "status");
  9119. memset(sstr ,0, sizeof(sstr) );
  9120. c = 0;
  9121. while (loc[3+strlen("status")+c] != '\"')
  9122. {
  9123. sstr[c] = loc[3+strlen("status")+c];
  9124. c++;
  9125. }
  9126. sstr[c] = '\0';
  9127. strcpy(statusstr, sstr);
  9128. if(expiryDateISNULL == FALSE)
  9129. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9130. if(parentIdTagISNULL == FALSE)
  9131. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9132. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9133. //Update idTag information to authorization cache if supproted
  9134. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9135. {
  9136. if((access(filename,F_OK))!=-1)
  9137. {
  9138. printf("AuthorizationCache exist.\n");
  9139. }
  9140. else
  9141. {
  9142. printf("AuthorizationCache not exist\n");
  9143. FILE *log = fopen(filename, "w+");
  9144. if(log == NULL)
  9145. {
  9146. printf("log is NULL\n");
  9147. goto out;
  9148. }
  9149. else
  9150. {
  9151. fclose(log);
  9152. }
  9153. }
  9154. FILE *infile;
  9155. FILE *outfile;
  9156. // open file for writing
  9157. infile = fopen (filename, "r");
  9158. outfile = fopen (tempfile, "w");
  9159. //*检测到文件结束标识返回1,否则返回0。*/
  9160. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9161. int c;
  9162. c = fgetc(infile);
  9163. //DEBUG_INFO("c:%d\n",c);
  9164. rewind(infile);
  9165. if(c == EOF)
  9166. {
  9167. DEBUG_INFO("Orignal File is NULL\n");
  9168. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9169. {
  9170. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9171. }
  9172. else
  9173. {
  9174. strcpy(expiryDatestrtemp, "");
  9175. }
  9176. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9177. {
  9178. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9179. }
  9180. else
  9181. {
  9182. //write Authorize IdTag
  9183. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9184. }
  9185. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9186. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9187. fclose(infile);
  9188. fclose(outfile);
  9189. sprintf(rmFileCmd,"rm -f %s",filename);
  9190. system(rmFileCmd);
  9191. resultRename = rename(tempfile, filename);
  9192. if(resultRename == 0)
  9193. {
  9194. printf("File renamed successfully");
  9195. }
  9196. else
  9197. {
  9198. printf("Error: unable to rename the file");
  9199. }
  9200. }
  9201. else
  9202. {
  9203. char buf[160]={0};
  9204. while (fgets(buf, sizeof(buf), infile) != NULL)
  9205. {
  9206. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9207. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9208. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9209. memset(statusstr, 0, sizeof(statusstrtemp));
  9210. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9211. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9212. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9213. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9214. //------------------IdTag-----------------------
  9215. loc = strstr(buf, "idTag");
  9216. memset(sstr ,0, sizeof(sstr) );
  9217. c = 0;
  9218. while (loc[3+strlen("idTag")+c] != '\"')
  9219. {
  9220. sstr[c] = loc[3+strlen("idTag")+c];
  9221. c++;
  9222. }
  9223. sstr[c] = '\0';
  9224. strcpy(IdTagstrtemp,sstr);
  9225. //*********************expiryDate***************/
  9226. loc = strstr(buf, "expiryDate");
  9227. memset(sstr ,0, sizeof(sstr) );
  9228. c = 0;
  9229. while (loc[3+strlen("expiryDate")+c] != '\"')
  9230. {
  9231. sstr[c] = loc[3+strlen("expiryDate")+c];
  9232. c++;
  9233. }
  9234. sstr[c] = '\0';
  9235. strcpy(expiryDatestr,sstr);
  9236. //*********************parentIdTag***************/
  9237. loc = strstr(buf, "parentIdTag");
  9238. memset(sstr ,0, sizeof(sstr) );
  9239. c = 0;
  9240. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9241. {
  9242. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9243. c++;
  9244. }
  9245. sstr[c] = '\0';
  9246. strcpy(parentIdTagstr,sstr);
  9247. //*********************status***************/
  9248. loc = strstr(buf, "status");
  9249. memset(sstr ,0, sizeof(sstr) );
  9250. c = 0;
  9251. while (loc[3+strlen("status")+c] != '\"')
  9252. {
  9253. sstr[c] = loc[3+strlen("status")+c];
  9254. c++;
  9255. }
  9256. sstr[c] = '\0';
  9257. strcpy(statusstr,sstr);
  9258. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9259. {
  9260. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9261. responseIdTagInfoAsZero = 1;
  9262. }
  9263. else
  9264. {
  9265. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9266. }
  9267. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9268. {
  9269. //modify item
  9270. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9271. {
  9272. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9273. }
  9274. else
  9275. {
  9276. strcpy(expiryDatestrtemp, "");
  9277. }
  9278. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9279. {
  9280. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9281. }
  9282. else
  9283. {
  9284. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9285. }
  9286. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9287. }
  9288. else
  9289. {
  9290. //wrie original item
  9291. strcpy(expiryDatestrtemp, expiryDatestr);
  9292. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9293. strcpy(statusstrtemp, statusstr);
  9294. }
  9295. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9296. }
  9297. fclose(infile);
  9298. fclose(outfile);
  9299. sprintf(rmFileCmd,"rm -f %s",filename);
  9300. system(rmFileCmd);
  9301. resultRename = rename(tempfile, filename);
  9302. if(resultRename == 0)
  9303. {
  9304. DEBUG_INFO("File renamed successfully");
  9305. }
  9306. else
  9307. {
  9308. DEBUG_INFO("Error: unable to rename the file");
  9309. }
  9310. }
  9311. }
  9312. out:
  9313. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9314. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9315. authorizeRetryTimes = 0;
  9316. }
  9317. void handleBootNotificationResponse(char *payload, int gun_index)
  9318. {
  9319. mtrace();
  9320. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9321. char statusStr[12]={0};
  9322. char currentTimeStr[30]={0};
  9323. char *loc;
  9324. int intervalInt = 0;
  9325. int c = 0;
  9326. //double diff_t;
  9327. struct tm tp;
  9328. char buf[28]={0};
  9329. char timebuf[50]={0};
  9330. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9331. //*** interval ****/
  9332. c = 0;
  9333. loc = strstr(payload, "interval");
  9334. //printf("loc=%s\n",loc);
  9335. memset(sstr ,0, sizeof(sstr) );
  9336. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9337. {
  9338. sstr[c] = loc[strlen("interval")+2+c];
  9339. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9340. c++;
  9341. }
  9342. sstr[c] = '\0';
  9343. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9344. intervalInt = atoi(sstr);
  9345. //***status ****/
  9346. loc = strstr(payload, "status");
  9347. memset(sstr ,0, sizeof(sstr) );
  9348. c = 0;
  9349. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9350. {
  9351. sstr[c] = loc[3+strlen("status")+c];
  9352. c++;
  9353. }
  9354. sstr[c] = '\0';
  9355. strcpy(statusStr, sstr);
  9356. //***currentTime ****/
  9357. loc = strstr(payload, "currentTime");
  9358. //printf("loc=%s\n",loc);
  9359. memset(sstr ,0, sizeof(sstr) );
  9360. c = 0;
  9361. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9362. {
  9363. sstr[c] = loc[3+strlen("currentTime")+c];
  9364. c++;
  9365. }
  9366. sstr[c] = '\0';
  9367. strcpy(currentTimeStr, sstr);
  9368. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9369. HeartBeatWaitTime = BootNotificationInterval;
  9370. clientTime.Heartbeat=time((time_t*)NULL);
  9371. //write back to ShmOCPP16Data->BootNotification
  9372. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9373. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9374. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9375. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9376. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9377. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9378. {
  9379. server_sign = TRUE;
  9380. server_pending =FALSE;
  9381. }
  9382. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9383. {
  9384. server_pending = TRUE;
  9385. }
  9386. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9387. tp.tm_isdst = -1;
  9388. //time_t utc = mktime(&tp);
  9389. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9390. memset(timebuf, 0, sizeof timebuf);
  9391. sprintf(timebuf,"date -s '%s'",buf);
  9392. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9393. system(timebuf);
  9394. //==============================================
  9395. // RTC sync
  9396. //==============================================
  9397. system("/sbin/hwclock -w --systohc");
  9398. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9399. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9400. }
  9401. void handleDataTransferResponse(char *payload, int gun_index)
  9402. {
  9403. char sstr[160]={0};//sstr[200]={ 0 };
  9404. int c = 0;
  9405. char *loc;
  9406. DEBUG_INFO("handleDataTransferResponse ...\n");
  9407. loc = strstr(payload, "status");
  9408. printf("loc=%s\n",loc);
  9409. c = 0;
  9410. while (loc[3+strlen("status")+c] != '\"')
  9411. {
  9412. sstr[c] = loc[3+strlen("status")+c];
  9413. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9414. c++;
  9415. }
  9416. sstr[c] = '\0';
  9417. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9418. }
  9419. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9420. {
  9421. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9422. //struct json_object *obj;
  9423. // obj = json_tokener_parse(payload);
  9424. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9425. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9426. //No fields are defined.
  9427. }
  9428. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9429. {
  9430. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9431. //struct json_object *obj;
  9432. // obj = json_tokener_parse(payload);
  9433. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9434. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9435. //No fields are defined.
  9436. }
  9437. void handleHeartbeatResponse(char *payload, int gun_index)
  9438. {
  9439. mtrace();
  9440. //double diff_t;
  9441. struct tm tp;
  9442. char buf[28]={0};
  9443. char timebuf[50]={0};
  9444. char sstr[30]={ 0 };
  9445. int c = 0;
  9446. char *loc;
  9447. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9448. c = 0;
  9449. loc = strstr(payload, "currentTime");
  9450. memset(sstr ,0, sizeof(sstr) );
  9451. while (loc[3+strlen("currentTime")+c] != '\"')
  9452. {
  9453. sstr[c] = loc[3+strlen("currentTime")+c];
  9454. c++;
  9455. }
  9456. sstr[c] = '\0';
  9457. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9458. // #ifdef SystemLogMessage
  9459. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9460. // #endif
  9461. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9462. tp.tm_isdst = -1;
  9463. //time_t utc = mktime(&tp);
  9464. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9465. memset(timebuf, 0, sizeof timebuf);
  9466. sprintf(timebuf,"date -s '%s'",buf);
  9467. system(timebuf);
  9468. //==============================================
  9469. // RTC sync
  9470. //==============================================
  9471. system("/sbin/hwclock -w --systohc");
  9472. if(FirstHeartBeat == 0)
  9473. {
  9474. FirstHeartBeat = 1;
  9475. }
  9476. HeartBeatWithNOResponse = 0;
  9477. //--------Print Out HeartBeat log
  9478. {
  9479. double diff_t;
  9480. struct tm tp,tp1;
  9481. // BootNotification Receive Time
  9482. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9483. tp.tm_isdst = -1;
  9484. time_t BootNotificationReceiveTime = mktime(&tp);
  9485. //HeartBeat Receive Time
  9486. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9487. tp1.tm_isdst = -1;
  9488. time_t HeartBeatReceiveTime = mktime(&tp1);
  9489. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9490. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9491. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9492. {
  9493. HeartBeatCountPerHour = (int)diff_t / 3600;
  9494. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9495. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9496. }
  9497. }
  9498. }
  9499. void handleMeterValuesResponse(char *payload, int gun_index)
  9500. {
  9501. mtrace();
  9502. //struct json_object *obj;
  9503. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9504. //No fields are defined.
  9505. }
  9506. void handleStartTransactionResponse(char *payload, int gun_index)
  9507. {
  9508. mtrace();
  9509. char sstr[28]={ 0 };
  9510. int c = 0;
  9511. char *loc;
  9512. int transactionIdInt = 0;
  9513. FILE *outfile;
  9514. char data[100]={0};
  9515. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9516. DEBUG_INFO("handleStartTransactionResponse\n");
  9517. //****************expiryDate********************/
  9518. loc = strstr(payload, "expiryDate");
  9519. if(loc == NULL)
  9520. {
  9521. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9522. }
  9523. else
  9524. {
  9525. c = 0;
  9526. memset(sstr ,0, sizeof(sstr) );
  9527. while (loc[3+strlen("expiryDate")+c] != '\"')
  9528. {
  9529. sstr[c] = loc[3+strlen("expiryDate")+c];
  9530. c++;
  9531. }
  9532. sstr[c] = '\0';
  9533. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9534. }
  9535. //****************parentIdTag********************/
  9536. loc = strstr(payload, "parentIdTag");
  9537. if(loc == NULL)
  9538. {
  9539. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9540. }
  9541. else
  9542. {
  9543. c = 0;
  9544. memset(sstr ,0, sizeof(sstr) );
  9545. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9546. {
  9547. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9548. c++;
  9549. }
  9550. sstr[c] = '\0';
  9551. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9552. }
  9553. //****************status********************/
  9554. loc = strstr(payload, "status");
  9555. if(loc == NULL)
  9556. {
  9557. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9558. }
  9559. else
  9560. {
  9561. c = 0;
  9562. memset(sstr ,0, sizeof(sstr) );
  9563. while (loc[3+strlen("status")+c] != '\"')
  9564. {
  9565. sstr[c] = loc[3+strlen("status")+c];
  9566. c++;
  9567. }
  9568. sstr[c] = '\0';
  9569. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9570. }
  9571. //****************transactionId********************/
  9572. c=0;
  9573. loc = strstr(payload, "transactionId");
  9574. memset(sstr ,0, sizeof(sstr) );
  9575. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9576. {
  9577. sstr[c] = loc[strlen("transactionId")+2+c];
  9578. c++;
  9579. }
  9580. sstr[c] = '\0';
  9581. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9582. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9583. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9584. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9585. //-----------Start : write to the Queue TransactionId file -----------------//
  9586. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9587. {
  9588. //DEBUG_INFO("QueueTransactionId exist.\n");
  9589. }
  9590. else
  9591. {
  9592. //DEBUG_INFO("QueueTransactionId not exist\n");
  9593. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9594. if(log == NULL)
  9595. {
  9596. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9597. return ;
  9598. }
  9599. else
  9600. {
  9601. fclose(log);
  9602. }
  9603. }
  9604. // open file for writing
  9605. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9606. //DEBUG_INFO("data=%s\n",data);
  9607. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9608. fputs(data, outfile);
  9609. //fputs("\n", outfile);
  9610. fclose (outfile);
  9611. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9612. TransactionId[gun_index] = transactionIdInt;
  9613. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9614. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9615. #ifdef SystemLogMessage
  9616. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9617. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9618. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9619. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9620. #endif
  9621. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  9622. {
  9623. //add Charging Record
  9624. SettingChargingRecord(gun_index, transactionIdInt);
  9625. }
  9626. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  9627. }
  9628. void handleStatusNotificationResponse(char *payload, int gun_index)
  9629. {
  9630. mtrace();
  9631. printf("handleStatusNotificationResponse\n");
  9632. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9633. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9634. }
  9635. void handleStopTransactionnResponse(char *payload, int gun_index)
  9636. {
  9637. mtrace();
  9638. char sstr[30]={ 0 };
  9639. int c = 0;
  9640. char *loc;
  9641. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9642. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9643. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9644. loc = strstr(payload, "idTagInfo");
  9645. //***********************idTagInfo************************/
  9646. if(loc != NULL)
  9647. {
  9648. //***********************expiryDate************************/
  9649. loc = strstr(payload, "expiryDate");
  9650. if(loc != NULL)
  9651. {
  9652. memset(sstr ,0, sizeof(sstr) );
  9653. c = 0;
  9654. while (loc[3+strlen("expiryDate")+c] != '\"')
  9655. {
  9656. sstr[c] = loc[3+strlen("expiryDate")+c];
  9657. c++;
  9658. }
  9659. sstr[c] = '\0';
  9660. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9661. }
  9662. //***********************parentIdTag************************/
  9663. loc = strstr(payload, "parentIdTag");
  9664. if(loc != NULL)
  9665. {
  9666. memset(sstr ,0, sizeof(sstr) );
  9667. c = 0;
  9668. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9669. {
  9670. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9671. c++;
  9672. }
  9673. sstr[c] = '\0';
  9674. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9675. }
  9676. //***********************status************************/
  9677. loc = strstr(payload, "status");
  9678. memset(sstr ,0, sizeof(sstr) );
  9679. c = 0;
  9680. while (loc[3+strlen("status")+c] != '\"')
  9681. {
  9682. sstr[c] = loc[3+strlen("status")+c];
  9683. c++;
  9684. }
  9685. sstr[c] = '\0';
  9686. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9687. }
  9688. #ifdef SystemLogMessage
  9689. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9690. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9691. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9692. #endif
  9693. }
  9694. //==========================================
  9695. // Handle Error routine
  9696. //==========================================
  9697. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9698. {
  9699. mtrace();
  9700. #ifdef SystemLogMessage
  9701. DEBUG_INFO("errorCode: %s\n", errorCode);
  9702. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9703. DEBUG_INFO("errorDetails: %s\n", payload);
  9704. #endif
  9705. }
  9706. //===============================================
  9707. // Common routine
  9708. //===============================================
  9709. int initialConfigurationTable(void)
  9710. {
  9711. FILE *fp;
  9712. FILE *outfile;
  9713. char str[200]={0};
  9714. char sstr[100]={0};
  9715. int c = 0;
  9716. char *loc;
  9717. printf("initialConfigurationTable \n");
  9718. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9719. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9720. {
  9721. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9722. if(outfile == NULL) {
  9723. DEBUG_INFO("Error opening file");
  9724. return FALSE;
  9725. }
  9726. /*Core Profile*/
  9727. //AllowOfflineTxForUnknownId
  9728. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9729. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  9733. //AuthorizationCacheEnabled
  9734. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9738. //AuthorizeRemoteTxRequests
  9739. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9743. //BlinkRepeat
  9744. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9748. //ClockAlignedDataInterval
  9749. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9753. //ConnectionTimeOut
  9754. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9758. //GetConfigurationMaxKeys
  9759. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9763. // HeartbeatInterval
  9764. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9768. // LightIntensity
  9769. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9773. // LocalAuthorizeOffline
  9774. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9778. // LocalPreAuthorize
  9779. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9783. // MaxEnergyOnInvalidId
  9784. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9787. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9789. // MeterValuesAlignedData
  9790. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9794. // MeterValuesAlignedDataMaxLength
  9795. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9799. // MeterValuesSampledData
  9800. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9804. // MeterValuesSampledDataMaxLength
  9805. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9809. // MeterValueSampleInterval
  9810. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9814. // MinimumStatusDuration
  9815. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9819. // NumberOfConnectors
  9820. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9822. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9823. {
  9824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9825. }
  9826. else
  9827. {
  9828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9829. }
  9830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9831. // ResetRetries
  9832. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9836. // ConnectorPhaseRotation
  9837. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9841. // ConnectorPhaseRotationMaxLength
  9842. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9846. // StopTransactionOnEVSideDisconnect
  9847. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9851. // StopTransactionOnInvalidId
  9852. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  9853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE" );
  9855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "TRUE");
  9856. // StopTxnAlignedData
  9857. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9861. // StopTxnAlignedDataMaxLength
  9862. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9866. // StopTxnSampledData
  9867. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9871. // StopTxnSampledDataMaxLength
  9872. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9874. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9875. {
  9876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9877. }
  9878. else
  9879. {
  9880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9881. }
  9882. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9884. // SupportedFeatureProfiles
  9885. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9889. // SupportedFeatureProfilesMaxLength
  9890. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9894. // TransactionMessageAttempts
  9895. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9898. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9900. // TransactionMessageRetryInterval
  9901. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9904. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9906. // UnlockConnectorOnEVSideDisconnect
  9907. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9911. // WebSocketPingInterval
  9912. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9916. //* Local Auth List Management Profile*/
  9917. #if 0
  9918. //For OCTT Test Case
  9919. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9922. #endif
  9923. #if 1
  9924. //LocalAuthListEnabled
  9925. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9929. #endif
  9930. //LocalAuthListMaxLength
  9931. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9935. //SendLocalListMaxLength
  9936. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9940. //ReserveConnectorZeroSupported
  9941. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9945. //* Smart Charging Profile */
  9946. //ChargeProfileMaxStackLevel
  9947. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9951. // ChargingScheduleAllowedChargingRateUnit
  9952. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9956. // ChargingScheduleMaxPeriods
  9957. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9961. // ConnectorSwitch3to1PhaseSupported
  9962. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9966. // MaxChargingProfilesInstalled
  9967. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9971. fclose(outfile);
  9972. }
  9973. else
  9974. {
  9975. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9976. char keystr[60]={0};
  9977. char readonlystr[10]={0};
  9978. char valuestr[100]={0};
  9979. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9980. if(fp == NULL) {
  9981. DEBUG_INFO("Error opening file");
  9982. return FALSE;
  9983. }
  9984. while( fgets (str, sizeof(str), fp)!=NULL )
  9985. {
  9986. //DEBUG_INFO("Get Configuration \n");
  9987. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9988. //*************************key*********************************/
  9989. loc = strstr(str, "key");
  9990. c = 0;
  9991. memset(sstr ,0, sizeof(sstr) );
  9992. while (loc[strlen("key")+3+c] != '\"')
  9993. {
  9994. sstr[c] = loc[strlen("key")+3+c];
  9995. c++;
  9996. }
  9997. sstr[c] = '\0';
  9998. strcpy(keystr,sstr);
  9999. //*************************readonly*********************************/
  10000. loc = strstr(str, "readonly");
  10001. c = 0;
  10002. memset(sstr ,0, sizeof(sstr) );
  10003. while (loc[strlen("readonly")+2+c] != ',')
  10004. {
  10005. sstr[c] = loc[strlen("readonly")+2+c];
  10006. c++;
  10007. }
  10008. sstr[c] = '\0';
  10009. strcpy(readonlystr,sstr);
  10010. //*************************value*********************************/
  10011. loc = strstr(str, "value");
  10012. c = 0;
  10013. memset(sstr ,0, sizeof(sstr) );
  10014. while (loc[strlen("value")+3+c] != '\"')
  10015. {
  10016. sstr[c] = loc[strlen("value")+3+c];
  10017. c++;
  10018. }
  10019. sstr[c] = '\0';
  10020. strcpy(valuestr,sstr);
  10021. // DEBUG_INFO("keystr=%s\n",keystr);
  10022. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10023. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10024. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10025. {
  10026. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10027. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10029. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10030. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10031. }
  10032. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10033. {
  10034. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10035. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10037. }
  10038. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10039. {
  10040. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10042. }
  10043. if(strcmp(keystr, "BlinkRepeat") == 0)
  10044. {
  10045. //Charger.BlinkRepeat = Integer.parseInt(value);
  10046. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10048. }
  10049. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10050. {
  10051. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10053. }
  10054. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10055. {
  10056. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10058. }
  10059. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10060. {
  10061. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10063. }
  10064. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10065. {
  10066. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10068. HeartBeatWaitTime = atoi(valuestr);
  10069. }
  10070. if(strcmp(keystr, "LightIntensity") == 0)
  10071. {
  10072. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10074. }
  10075. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10076. {
  10077. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10079. }
  10080. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10081. {
  10082. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10084. }
  10085. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10086. {
  10087. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10089. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10090. }
  10091. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10092. {
  10093. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10095. }
  10096. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10097. {
  10098. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10100. }
  10101. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10102. {
  10103. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10105. }
  10106. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10107. {
  10108. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10110. }
  10111. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10112. {
  10113. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10115. }
  10116. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10117. {
  10118. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10120. }
  10121. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10122. {
  10123. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10125. }
  10126. if(strcmp(keystr, "ResetRetries") == 0)
  10127. {
  10128. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10130. }
  10131. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10132. {
  10133. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10135. }
  10136. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10137. {
  10138. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10140. }
  10141. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10142. {
  10143. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10145. }
  10146. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10147. {
  10148. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10150. }
  10151. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10152. {
  10153. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10155. }
  10156. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10157. {
  10158. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10160. }
  10161. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10162. {
  10163. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10165. }
  10166. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10167. {
  10168. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10170. }
  10171. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10172. {
  10173. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10175. }
  10176. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10177. {
  10178. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10180. }
  10181. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10182. {
  10183. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10185. TransactionMessageAttemptsValue = atoi(valuestr);
  10186. }
  10187. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10188. {
  10189. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10191. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10192. }
  10193. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10194. {
  10195. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10197. }
  10198. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10199. {
  10200. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10202. }
  10203. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10204. {
  10205. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10207. }
  10208. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10209. {
  10210. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10212. }
  10213. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10214. {
  10215. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10217. }
  10218. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10219. {
  10220. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10222. }
  10223. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10224. {
  10225. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10227. }
  10228. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10229. {
  10230. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10232. }
  10233. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10234. {
  10235. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10237. }
  10238. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10239. {
  10240. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10242. }
  10243. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10244. {
  10245. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10247. }
  10248. }
  10249. fclose(fp);
  10250. }
  10251. return 0;
  10252. }
  10253. void StoreConfigurationTable(void)
  10254. {
  10255. FILE *outfile;
  10256. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10257. if(outfile == NULL)
  10258. {
  10259. DEBUG_INFO("Error opening file");
  10260. return ;
  10261. }
  10262. /*Core Profile*/
  10263. //AllowOfflineTxForUnknownId
  10264. /*
  10265. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10266. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10269. */
  10270. //DEBUG_INFO("data=%s\n",data);
  10271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10272. //AuthorizationCacheEnabled
  10273. /*
  10274. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10277. */
  10278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10279. //AuthorizeRemoteTxRequests
  10280. /*
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10284. */
  10285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10286. //BlinkRepeat
  10287. /*
  10288. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10291. */
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10293. //ClockAlignedDataInterval
  10294. /*
  10295. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10298. */
  10299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10300. //ConnectionTimeOut
  10301. /*
  10302. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10305. */
  10306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10307. //GetConfigurationMaxKeys
  10308. /*
  10309. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10312. */
  10313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10314. // HeartbeatInterval
  10315. /*
  10316. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10319. */
  10320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10321. // LightIntensity
  10322. /*
  10323. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10326. */
  10327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10328. // LocalAuthorizeOffline
  10329. /*
  10330. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10333. */
  10334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10335. // LocalPreAuthorize
  10336. /*
  10337. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10340. */
  10341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10342. // MaxEnergyOnInvalidId
  10343. /*
  10344. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10347. */
  10348. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10350. // MeterValuesAlignedData
  10351. /*
  10352. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10355. */
  10356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10357. // MeterValuesAlignedDataMaxLength
  10358. /*
  10359. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10362. */
  10363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10364. // MeterValuesSampledData
  10365. /*
  10366. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10369. */
  10370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10371. // MeterValuesSampledDataMaxLength
  10372. /*
  10373. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10376. */
  10377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10378. // MeterValueSampleInterval
  10379. /*
  10380. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10383. */
  10384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10385. // MinimumStatusDuration
  10386. /*
  10387. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10390. */
  10391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10392. // NumberOfConnectors
  10393. /*
  10394. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10397. {
  10398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10399. }
  10400. else
  10401. {
  10402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10403. }
  10404. */
  10405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10406. // ResetRetries
  10407. /*
  10408. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10411. */
  10412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10413. // ConnectorPhaseRotation
  10414. /*
  10415. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10418. */
  10419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10420. // ConnectorPhaseRotationMaxLength
  10421. /*
  10422. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10425. */
  10426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10427. // StopTransactionOnEVSideDisconnect
  10428. /*
  10429. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10432. */
  10433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10434. // StopTransactionOnInvalidId
  10435. /*
  10436. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  10437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10439. */
  10440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10441. // StopTxnAlignedData
  10442. /*
  10443. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10446. */
  10447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10448. // StopTxnAlignedDataMaxLength
  10449. /*
  10450. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10453. */
  10454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10455. // StopTxnSampledData
  10456. /*
  10457. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10460. */
  10461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10462. // StopTxnSampledDataMaxLength
  10463. /*
  10464. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10467. */
  10468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10469. // SupportedFeatureProfiles
  10470. /*
  10471. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10474. */
  10475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10476. // SupportedFeatureProfilesMaxLength
  10477. /*
  10478. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10481. */
  10482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10483. // TransactionMessageAttempts
  10484. /*
  10485. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10488. */
  10489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10490. // TransactionMessageRetryInterval
  10491. /*
  10492. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10495. */
  10496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10497. // UnlockConnectorOnEVSideDisconnect
  10498. /*
  10499. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10502. */
  10503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10504. // WebSocketPingInterval
  10505. /*
  10506. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10509. */
  10510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10511. //* Local Auth List Management Profile*/
  10512. //LocalAuthListEnabled
  10513. /*
  10514. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10517. */
  10518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10519. //LocalAuthListMaxLength
  10520. /*
  10521. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10524. */
  10525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10526. //SendLocalListMaxLength
  10527. /*
  10528. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10531. */
  10532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10533. //ReserveConnectorZeroSupported
  10534. /*
  10535. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10538. */
  10539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10540. //* Smart Charging Profile */
  10541. //ChargeProfileMaxStackLevel
  10542. /*
  10543. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10546. */
  10547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10548. // ChargingScheduleAllowedChargingRateUnit
  10549. /*
  10550. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10553. */
  10554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10555. // ChargingScheduleMaxPeriods
  10556. /*
  10557. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10560. */
  10561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10562. // ConnectorSwitch3to1PhaseSupported
  10563. /*
  10564. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10567. */
  10568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10569. // MaxChargingProfilesInstalled
  10570. /*
  10571. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10574. */
  10575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10576. fclose(outfile);
  10577. }
  10578. void getKeyValue(char *keyReq)
  10579. {
  10580. int isEmpty = FALSE;
  10581. int isKnowKey = FALSE;
  10582. //int unKnowIndex = 0;
  10583. DEBUG_INFO("getKeyValue \n");
  10584. DEBUG_INFO("keyReq=%s \n",keyReq);
  10585. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10586. isEmpty = TRUE;
  10587. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10588. {
  10589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10592. {
  10593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10594. }
  10595. else
  10596. {
  10597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10598. }
  10599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10600. isKnowKey = TRUE;
  10601. }
  10602. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10603. {
  10604. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10607. {
  10608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10609. }
  10610. else
  10611. {
  10612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10613. }
  10614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10615. isKnowKey = TRUE;
  10616. }
  10617. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10618. {
  10619. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10622. {
  10623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10624. }
  10625. else
  10626. {
  10627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10628. }
  10629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10630. isKnowKey = TRUE;
  10631. }
  10632. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10633. {
  10634. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10637. {
  10638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10639. }
  10640. else
  10641. {
  10642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10643. }
  10644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10645. isKnowKey = TRUE;
  10646. }
  10647. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10648. {
  10649. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10652. {
  10653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10654. }
  10655. else
  10656. {
  10657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10658. }
  10659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10660. isKnowKey = TRUE;
  10661. }
  10662. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10663. {
  10664. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10667. {
  10668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10669. }
  10670. else
  10671. {
  10672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10673. }
  10674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10675. isKnowKey = TRUE;
  10676. }
  10677. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10678. {
  10679. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10682. {
  10683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10684. }
  10685. else
  10686. {
  10687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10688. }
  10689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10690. isKnowKey = TRUE;
  10691. }
  10692. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10693. {
  10694. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10697. {
  10698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10699. }
  10700. else
  10701. {
  10702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10703. }
  10704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10705. isKnowKey = TRUE;
  10706. }
  10707. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10708. {
  10709. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10712. {
  10713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10714. }
  10715. else
  10716. {
  10717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10718. }
  10719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10720. isKnowKey = TRUE;
  10721. }
  10722. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10723. {
  10724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10727. {
  10728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10729. }
  10730. else
  10731. {
  10732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10733. }
  10734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10735. isKnowKey = TRUE;
  10736. }
  10737. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10738. {
  10739. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10742. {
  10743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10744. }
  10745. else
  10746. {
  10747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10748. }
  10749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10750. isKnowKey = TRUE;
  10751. }
  10752. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10753. {
  10754. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10757. {
  10758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10759. }
  10760. else
  10761. {
  10762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10763. }
  10764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10765. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10766. isKnowKey = TRUE;
  10767. }
  10768. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10769. {
  10770. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10773. {
  10774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10775. }
  10776. else
  10777. {
  10778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10779. }
  10780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10781. isKnowKey = TRUE;
  10782. }
  10783. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10784. {
  10785. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10788. {
  10789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10790. }
  10791. else
  10792. {
  10793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10794. }
  10795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10796. isKnowKey = TRUE;
  10797. }
  10798. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10799. {
  10800. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10803. {
  10804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10805. }
  10806. else
  10807. {
  10808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10809. }
  10810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10811. isKnowKey = TRUE;
  10812. }
  10813. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10814. {
  10815. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10818. {
  10819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10820. }
  10821. else
  10822. {
  10823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10824. }
  10825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10826. isKnowKey = TRUE;
  10827. }
  10828. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10829. {
  10830. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10833. {
  10834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10835. }
  10836. else
  10837. {
  10838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10839. }
  10840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10841. isKnowKey = TRUE;
  10842. }
  10843. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10844. {
  10845. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10848. {
  10849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10850. }
  10851. else
  10852. {
  10853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10854. }
  10855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10856. isKnowKey = TRUE;
  10857. }
  10858. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10859. {
  10860. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10863. {
  10864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10865. }
  10866. else
  10867. {
  10868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10869. }
  10870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10871. isKnowKey = TRUE;
  10872. }
  10873. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10874. {
  10875. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10877. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10878. {
  10879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10880. }
  10881. else
  10882. {
  10883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10884. }
  10885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10886. isKnowKey = TRUE;
  10887. }
  10888. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10889. {
  10890. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10892. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10893. {
  10894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10895. }
  10896. else
  10897. {
  10898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10899. }
  10900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10901. isKnowKey = TRUE;
  10902. }
  10903. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10904. {
  10905. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10908. {
  10909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10910. }
  10911. else
  10912. {
  10913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10914. }
  10915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10916. isKnowKey = TRUE;
  10917. }
  10918. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10919. {
  10920. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10923. {
  10924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10925. }
  10926. else
  10927. {
  10928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10929. }
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10931. isKnowKey = TRUE;
  10932. }
  10933. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10934. {
  10935. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10938. {
  10939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10940. }
  10941. else
  10942. {
  10943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10944. }
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10946. isKnowKey = TRUE;
  10947. }
  10948. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10949. {
  10950. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10953. {
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10955. }
  10956. else
  10957. {
  10958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10959. }
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10961. isKnowKey = TRUE;
  10962. }
  10963. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10964. {
  10965. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10968. {
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10970. }
  10971. else
  10972. {
  10973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10974. }
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10976. isKnowKey = TRUE;
  10977. }
  10978. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10979. {
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10983. {
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10985. }
  10986. else
  10987. {
  10988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10989. }
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10991. isKnowKey = TRUE;
  10992. }
  10993. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10994. {
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10998. {
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11000. }
  11001. else
  11002. {
  11003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11004. }
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11006. isKnowKey = TRUE;
  11007. }
  11008. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11009. {
  11010. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11013. {
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11015. }
  11016. else
  11017. {
  11018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11019. }
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11021. isKnowKey = TRUE;
  11022. }
  11023. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11024. {
  11025. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11027. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11028. {
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11030. }
  11031. else
  11032. {
  11033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11034. }
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11036. isKnowKey = TRUE;
  11037. }
  11038. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11039. {
  11040. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11042. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11043. {
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11045. }
  11046. else
  11047. {
  11048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11049. }
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11051. isKnowKey = TRUE;
  11052. }
  11053. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11054. {
  11055. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11058. {
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11060. }
  11061. else
  11062. {
  11063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11064. }
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11066. isKnowKey = TRUE;
  11067. }
  11068. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11069. {
  11070. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11073. {
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11075. }
  11076. else
  11077. {
  11078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11079. }
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11081. isKnowKey = TRUE;
  11082. }
  11083. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11084. {
  11085. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11088. {
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11090. }
  11091. else
  11092. {
  11093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11094. }
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11096. isKnowKey = TRUE;
  11097. }
  11098. #if 0
  11099. //For OCTT Test Case
  11100. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11101. {
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11104. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11105. {
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11107. }
  11108. else
  11109. {
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11111. }
  11112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11113. isKnowKey = TRUE;
  11114. }
  11115. #endif
  11116. #if 1
  11117. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11118. {
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11121. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11122. {
  11123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11124. }
  11125. else
  11126. {
  11127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11128. }
  11129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11130. isKnowKey = TRUE;
  11131. }
  11132. #endif
  11133. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11134. {
  11135. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11137. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11138. {
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11140. }
  11141. else
  11142. {
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11144. }
  11145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11146. isKnowKey = TRUE;
  11147. }
  11148. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11149. {
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11152. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11155. }
  11156. else
  11157. {
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11159. }
  11160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11161. isKnowKey = TRUE;
  11162. }
  11163. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11164. {
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11167. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11170. }
  11171. else
  11172. {
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11174. }
  11175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11176. isKnowKey = TRUE;
  11177. }
  11178. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11179. {
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11182. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11185. }
  11186. else
  11187. {
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11189. }
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11191. isKnowKey = TRUE;
  11192. }
  11193. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11194. {
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11197. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11200. }
  11201. else
  11202. {
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11204. }
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11206. isKnowKey = TRUE;
  11207. }
  11208. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11209. {
  11210. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11212. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11213. {
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11215. }
  11216. else
  11217. {
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11219. }
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11221. isKnowKey = TRUE;
  11222. }
  11223. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11224. {
  11225. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11227. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11228. {
  11229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11230. }
  11231. else
  11232. {
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11234. }
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11236. isKnowKey = TRUE;
  11237. }
  11238. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11239. {
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11242. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11243. {
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11245. }
  11246. else
  11247. {
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11249. }
  11250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11251. isKnowKey = TRUE;
  11252. }
  11253. //=========================================================
  11254. if(!isEmpty && !isKnowKey)
  11255. {
  11256. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11257. strcpy(unknownkey[UnknownKeynum], keyReq);
  11258. UnknownKeynum = UnknownKeynum + 1;
  11259. }
  11260. }
  11261. void processUnkownKey(void)
  11262. {
  11263. DEBUG_INFO("processUnkownKey\n");
  11264. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11265. for(int index=0; index < UnknownKeynum; index++)
  11266. {
  11267. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11268. {
  11269. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11270. }
  11271. }
  11272. }
  11273. int setKeyValue(char *key, char *value)
  11274. {
  11275. int isSuccess = NotSupported;
  11276. int check_ascii=0;
  11277. char str[10]={0};
  11278. #ifdef Debug
  11279. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11280. #endif
  11281. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11282. {
  11283. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11285. {
  11286. strcpy(str, (const char*)value);
  11287. for(int i = 0; str[i]; i++){
  11288. str[i] = tolower(str[i]);
  11289. }
  11290. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11291. isSuccess = ConfigurationStatus_Accepted;
  11292. }
  11293. else
  11294. {
  11295. isSuccess = ConfigurationStatus_Rejected;
  11296. }
  11297. }
  11298. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11299. {
  11300. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11302. {
  11303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  11304. isSuccess = ConfigurationStatus_Accepted;
  11305. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11306. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11307. }
  11308. else
  11309. {
  11310. isSuccess = ConfigurationStatus_Rejected;
  11311. }
  11312. }
  11313. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11314. {
  11315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11316. {
  11317. strcpy(str, (const char*)value);
  11318. for(int i = 0; str[i]; i++)
  11319. {
  11320. str[i] = tolower(str[i]);
  11321. }
  11322. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11324. isSuccess = ConfigurationStatus_Accepted;
  11325. }
  11326. else
  11327. {
  11328. isSuccess = ConfigurationStatus_Rejected;
  11329. }
  11330. }
  11331. if(strcmp(key, "BlinkRepeat") == 0)
  11332. {
  11333. //Charger.BlinkRepeat = Integer.parseInt(value);
  11334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11335. {
  11336. check_ascii = value[0];
  11337. if( (check_ascii < 48) || (check_ascii > 57) )
  11338. {
  11339. isSuccess = ConfigurationStatus_Rejected;
  11340. }
  11341. else
  11342. {
  11343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11344. isSuccess = ConfigurationStatus_Accepted;
  11345. }
  11346. }
  11347. else
  11348. {
  11349. isSuccess = ConfigurationStatus_Rejected;
  11350. }
  11351. }
  11352. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11353. {
  11354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11355. {
  11356. check_ascii = value[0];
  11357. if( (check_ascii < 48) || (check_ascii > 57) )
  11358. {
  11359. isSuccess = ConfigurationStatus_Rejected;
  11360. }
  11361. else
  11362. {
  11363. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11365. isSuccess = ConfigurationStatus_Accepted;
  11366. }
  11367. }
  11368. else
  11369. {
  11370. isSuccess = ConfigurationStatus_Rejected;
  11371. }
  11372. }
  11373. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11374. {
  11375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11376. {
  11377. check_ascii = value[0];
  11378. if( (check_ascii < 48) || (check_ascii > 57) )
  11379. {
  11380. isSuccess = ConfigurationStatus_Rejected;
  11381. }
  11382. else
  11383. {
  11384. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11386. isSuccess = ConfigurationStatus_Accepted;
  11387. }
  11388. }
  11389. else
  11390. {
  11391. isSuccess = ConfigurationStatus_Rejected;
  11392. }
  11393. }
  11394. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11395. {
  11396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11397. {
  11398. check_ascii = value[0];
  11399. if( (check_ascii < 48) || (check_ascii > 57) )
  11400. {
  11401. isSuccess = ConfigurationStatus_Rejected;
  11402. }
  11403. else
  11404. {
  11405. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11407. isSuccess = ConfigurationStatus_Accepted;
  11408. }
  11409. }
  11410. else
  11411. {
  11412. isSuccess = ConfigurationStatus_Rejected;
  11413. }
  11414. }
  11415. if(strcmp(key, "HeartbeatInterval") == 0)
  11416. {
  11417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11418. {
  11419. check_ascii = value[0];
  11420. if( (check_ascii < 48) || (check_ascii > 57) )
  11421. {
  11422. isSuccess = ConfigurationStatus_Rejected;
  11423. }
  11424. else
  11425. {
  11426. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11428. HeartBeatWaitTime = atoi(value);
  11429. isSuccess = ConfigurationStatus_Accepted;
  11430. }
  11431. }
  11432. else
  11433. {
  11434. isSuccess = ConfigurationStatus_Rejected;
  11435. }
  11436. }
  11437. if(strcmp(key, "LightIntensity") == 0)
  11438. {
  11439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11440. {
  11441. check_ascii = value[0];
  11442. if( (check_ascii < 48) || (check_ascii > 57) )
  11443. {
  11444. isSuccess = ConfigurationStatus_Rejected;
  11445. }
  11446. else
  11447. {
  11448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11449. isSuccess = ConfigurationStatus_Accepted;
  11450. }
  11451. }
  11452. else
  11453. {
  11454. isSuccess = ConfigurationStatus_Rejected;
  11455. }
  11456. }
  11457. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11458. {
  11459. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11460. {
  11461. strcpy(str, (const char*)value);
  11462. for(int i = 0; str[i]; i++)
  11463. {
  11464. str[i] = tolower(str[i]);
  11465. }
  11466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11467. isSuccess = ConfigurationStatus_Accepted;
  11468. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11469. }
  11470. else
  11471. {
  11472. isSuccess = ConfigurationStatus_Rejected;
  11473. }
  11474. }
  11475. if(strcmp(key, "LocalPreAuthorize") == 0)
  11476. {
  11477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11478. {
  11479. strcpy(str, (const char*)value);
  11480. for(int i = 0; str[i]; i++)
  11481. {
  11482. str[i] = tolower(str[i]);
  11483. }
  11484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11485. isSuccess = ConfigurationStatus_Accepted;
  11486. }
  11487. else
  11488. {
  11489. isSuccess = ConfigurationStatus_Rejected;
  11490. }
  11491. }
  11492. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11493. {
  11494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11495. {
  11496. check_ascii = value[0];
  11497. if( (check_ascii < 48) || (check_ascii > 57) )
  11498. {
  11499. isSuccess = ConfigurationStatus_Rejected;
  11500. }
  11501. else
  11502. {
  11503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11504. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11505. isSuccess = ConfigurationStatus_Accepted;
  11506. }
  11507. }
  11508. else
  11509. {
  11510. isSuccess = ConfigurationStatus_Rejected;
  11511. }
  11512. }
  11513. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11514. {
  11515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11516. {
  11517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11518. isSuccess = ConfigurationStatus_Accepted;
  11519. }
  11520. else
  11521. {
  11522. isSuccess = ConfigurationStatus_Rejected;
  11523. }
  11524. }
  11525. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11526. {
  11527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11528. {
  11529. check_ascii = value[0];
  11530. if( (check_ascii < 48) || (check_ascii > 57) )
  11531. {
  11532. isSuccess = ConfigurationStatus_Rejected;
  11533. }
  11534. else
  11535. {
  11536. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11538. isSuccess = ConfigurationStatus_Accepted;
  11539. }
  11540. }
  11541. else
  11542. {
  11543. isSuccess = ConfigurationStatus_Rejected;
  11544. }
  11545. }
  11546. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11547. {
  11548. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11549. {
  11550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11551. isSuccess = ConfigurationStatus_Accepted;
  11552. }
  11553. else
  11554. {
  11555. isSuccess = ConfigurationStatus_Rejected;
  11556. }
  11557. }
  11558. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11559. {
  11560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11561. {
  11562. check_ascii = value[0];
  11563. if( (check_ascii < 48) || (check_ascii > 57) )
  11564. {
  11565. isSuccess = ConfigurationStatus_Rejected;
  11566. }
  11567. else
  11568. {
  11569. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11571. isSuccess = ConfigurationStatus_Accepted;
  11572. }
  11573. }
  11574. else
  11575. {
  11576. isSuccess = ConfigurationStatus_Rejected;
  11577. }
  11578. }
  11579. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11580. {
  11581. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11582. {
  11583. check_ascii = value[0];
  11584. if( (check_ascii < 48) || (check_ascii > 57) )
  11585. {
  11586. isSuccess = ConfigurationStatus_Rejected;
  11587. }
  11588. else
  11589. {
  11590. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11592. isSuccess = ConfigurationStatus_Accepted;
  11593. }
  11594. }
  11595. else
  11596. {
  11597. isSuccess = ConfigurationStatus_Rejected;
  11598. }
  11599. }
  11600. if(strcmp(key, "MinimumStatusDuration") == 0)
  11601. {
  11602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11603. {
  11604. check_ascii = value[0];
  11605. if( (check_ascii < 48) || (check_ascii > 57) )
  11606. {
  11607. isSuccess = ConfigurationStatus_Rejected;
  11608. }
  11609. else
  11610. {
  11611. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11613. isSuccess = ConfigurationStatus_Accepted;
  11614. }
  11615. }
  11616. else
  11617. {
  11618. isSuccess = ConfigurationStatus_Rejected;
  11619. }
  11620. }
  11621. if(strcmp(key, "NumberOfConnectors") == 0)
  11622. {
  11623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11624. {
  11625. check_ascii = value[0];
  11626. if( (check_ascii < 48) || (check_ascii > 57) )
  11627. {
  11628. isSuccess = ConfigurationStatus_Rejected;
  11629. }
  11630. else
  11631. {
  11632. //Charger.ResetRetries = Integer.parseInt(value);
  11633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11634. isSuccess = ConfigurationStatus_Accepted;
  11635. }
  11636. }
  11637. else
  11638. {
  11639. isSuccess = ConfigurationStatus_Rejected;
  11640. }
  11641. }
  11642. if(strcmp(key, "ResetRetries") == 0)
  11643. {
  11644. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11645. {
  11646. check_ascii = value[0];
  11647. if( (check_ascii < 48) || (check_ascii > 57) )
  11648. {
  11649. isSuccess = ConfigurationStatus_Rejected;
  11650. }
  11651. else
  11652. {
  11653. //Charger.ResetRetries = Integer.parseInt(value);
  11654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11655. isSuccess = ConfigurationStatus_Accepted;
  11656. }
  11657. }
  11658. else
  11659. {
  11660. isSuccess = ConfigurationStatus_Rejected;
  11661. }
  11662. }
  11663. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11664. {
  11665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11666. {
  11667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  11668. isSuccess = ConfigurationStatus_Accepted;
  11669. }
  11670. else
  11671. {
  11672. isSuccess = ConfigurationStatus_Rejected;
  11673. }
  11674. }
  11675. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11676. {
  11677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11678. {
  11679. check_ascii = value[0];
  11680. if( (check_ascii < 48) || (check_ascii > 57) )
  11681. {
  11682. isSuccess = ConfigurationStatus_Rejected;
  11683. }
  11684. else
  11685. {
  11686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11687. isSuccess = ConfigurationStatus_Accepted;
  11688. }
  11689. }
  11690. else
  11691. {
  11692. isSuccess = ConfigurationStatus_Rejected;
  11693. }
  11694. }
  11695. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11696. {
  11697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11698. {
  11699. strcpy(str, (const char*)value);
  11700. for(int i = 0; str[i]; i++)
  11701. {
  11702. str[i] = tolower(str[i]);
  11703. }
  11704. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11706. isSuccess = ConfigurationStatus_Accepted;
  11707. }
  11708. else
  11709. {
  11710. isSuccess = ConfigurationStatus_Rejected;
  11711. }
  11712. }
  11713. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11714. {
  11715. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11716. {
  11717. strcpy(str, (const char*)value);
  11718. for(int i = 0; str[i]; i++)
  11719. {
  11720. str[i] = tolower(str[i]);
  11721. }
  11722. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11724. isSuccess = ConfigurationStatus_Accepted;
  11725. }
  11726. else
  11727. {
  11728. isSuccess = ConfigurationStatus_Rejected;
  11729. }
  11730. }
  11731. if(strcmp(key, "StopTxnAlignedData") == 0)
  11732. {
  11733. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11734. {
  11735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11736. isSuccess = ConfigurationStatus_Accepted;
  11737. }
  11738. else
  11739. {
  11740. isSuccess = ConfigurationStatus_Rejected;
  11741. }
  11742. }
  11743. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11744. {
  11745. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11746. {
  11747. check_ascii = value[0];
  11748. if( (check_ascii < 48) || (check_ascii > 57) )
  11749. {
  11750. isSuccess = ConfigurationStatus_Rejected;
  11751. }
  11752. else
  11753. {
  11754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11755. isSuccess = ConfigurationStatus_Accepted;
  11756. }
  11757. }
  11758. else
  11759. {
  11760. isSuccess = ConfigurationStatus_Rejected;
  11761. }
  11762. }
  11763. if(strcmp(key, "StopTxnSampledData") == 0)
  11764. {
  11765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11766. {
  11767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11768. isSuccess = ConfigurationStatus_Accepted;
  11769. }
  11770. else
  11771. {
  11772. isSuccess = ConfigurationStatus_Rejected;
  11773. }
  11774. }
  11775. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11776. {
  11777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11778. {
  11779. check_ascii = value[0];
  11780. if( (check_ascii < 48) || (check_ascii > 57) )
  11781. {
  11782. isSuccess = ConfigurationStatus_Rejected;
  11783. }
  11784. else
  11785. {
  11786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11787. isSuccess = ConfigurationStatus_Accepted;
  11788. }
  11789. }
  11790. else
  11791. {
  11792. isSuccess = ConfigurationStatus_Rejected;
  11793. }
  11794. }
  11795. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11796. {
  11797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11798. {
  11799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11800. isSuccess = ConfigurationStatus_Accepted;
  11801. }
  11802. else
  11803. {
  11804. isSuccess = ConfigurationStatus_Rejected;
  11805. }
  11806. }
  11807. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11808. {
  11809. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11810. {
  11811. check_ascii = value[0];
  11812. if( (check_ascii < 48) || (check_ascii > 57) )
  11813. {
  11814. isSuccess = ConfigurationStatus_Rejected;
  11815. }
  11816. else
  11817. {
  11818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11819. isSuccess = ConfigurationStatus_Accepted;
  11820. }
  11821. }
  11822. else
  11823. {
  11824. isSuccess = ConfigurationStatus_Rejected;
  11825. }
  11826. }
  11827. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11828. {
  11829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11830. {
  11831. check_ascii = value[0];
  11832. if( (check_ascii < 48) || (check_ascii > 57) )
  11833. {
  11834. isSuccess = ConfigurationStatus_Rejected;
  11835. }
  11836. else
  11837. {
  11838. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11840. TransactionMessageAttemptsValue = atoi(value);
  11841. isSuccess = ConfigurationStatus_Accepted;
  11842. }
  11843. }
  11844. else
  11845. {
  11846. isSuccess = ConfigurationStatus_Rejected;
  11847. }
  11848. }
  11849. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11850. {
  11851. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11852. {
  11853. check_ascii = value[0];
  11854. if( (check_ascii < 48) || (check_ascii > 57) )
  11855. {
  11856. isSuccess = ConfigurationStatus_Rejected;
  11857. }
  11858. else
  11859. {
  11860. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11862. TransactionMessageRetryIntervalValue = atoi(value);
  11863. isSuccess = ConfigurationStatus_Accepted;
  11864. }
  11865. }
  11866. else
  11867. {
  11868. isSuccess = ConfigurationStatus_Rejected;
  11869. }
  11870. }
  11871. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11872. {
  11873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11874. {
  11875. strcpy(str, (const char*)value);
  11876. for(int i = 0; str[i]; i++)
  11877. {
  11878. str[i] = tolower(str[i]);
  11879. }
  11880. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11882. isSuccess = ConfigurationStatus_Accepted;
  11883. }
  11884. else
  11885. {
  11886. isSuccess = ConfigurationStatus_Rejected;
  11887. }
  11888. }
  11889. if(strcmp(key, "WebSocketPingInterval") == 0)
  11890. {
  11891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11892. {
  11893. check_ascii = value[0];
  11894. if( (check_ascii < 48) || (check_ascii > 57) )
  11895. {
  11896. isSuccess = ConfigurationStatus_Rejected;
  11897. }
  11898. else
  11899. {
  11900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11901. isSuccess = ConfigurationStatus_Accepted;
  11902. }
  11903. }
  11904. else
  11905. {
  11906. isSuccess = ConfigurationStatus_Rejected;
  11907. }
  11908. }
  11909. #if 0
  11910. //For OCPP Test Case
  11911. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11912. {
  11913. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11914. {
  11915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11916. isSuccess = ConfigurationStatus_Accepted;
  11917. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11918. }
  11919. else
  11920. {
  11921. isSuccess = ConfigurationStatus_Rejected;
  11922. }
  11923. }
  11924. #endif
  11925. #if 1
  11926. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11927. {
  11928. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11929. {
  11930. strcpy(str, (const char*)value);
  11931. for(int i = 0; str[i]; i++)
  11932. {
  11933. str[i] = tolower(str[i]);
  11934. }
  11935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11936. isSuccess = ConfigurationStatus_Accepted;
  11937. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11938. }
  11939. else
  11940. {
  11941. isSuccess = ConfigurationStatus_Rejected;
  11942. }
  11943. }
  11944. #endif
  11945. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11946. {
  11947. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11948. {
  11949. check_ascii = value[0];
  11950. if( (check_ascii < 48) || (check_ascii > 57) )
  11951. {
  11952. isSuccess = ConfigurationStatus_Rejected;
  11953. }
  11954. else
  11955. {
  11956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11957. isSuccess = ConfigurationStatus_Accepted;
  11958. }
  11959. }
  11960. else
  11961. {
  11962. isSuccess = ConfigurationStatus_Rejected;
  11963. }
  11964. }
  11965. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11966. {
  11967. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11968. {
  11969. check_ascii = value[0];
  11970. if( (check_ascii < 48) || (check_ascii > 57) )
  11971. {
  11972. isSuccess = ConfigurationStatus_Rejected;
  11973. }
  11974. else
  11975. {
  11976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11977. isSuccess = ConfigurationStatus_Accepted;
  11978. }
  11979. }
  11980. else
  11981. {
  11982. isSuccess = ConfigurationStatus_Rejected;
  11983. }
  11984. }
  11985. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11986. {
  11987. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11988. {
  11989. strcpy(str, (const char*)value);
  11990. for(int i = 0; str[i]; i++)
  11991. {
  11992. str[i] = tolower(str[i]);
  11993. }
  11994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11995. isSuccess = ConfigurationStatus_Accepted;
  11996. }
  11997. else
  11998. {
  11999. isSuccess = ConfigurationStatus_Rejected;
  12000. }
  12001. }
  12002. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12003. {
  12004. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12005. {
  12006. check_ascii = value[0];
  12007. if( (check_ascii < 48) || (check_ascii > 57) )
  12008. {
  12009. isSuccess = ConfigurationStatus_Rejected;
  12010. }
  12011. else
  12012. {
  12013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12014. isSuccess = ConfigurationStatus_Accepted;
  12015. }
  12016. }
  12017. else
  12018. {
  12019. isSuccess = ConfigurationStatus_Rejected;
  12020. }
  12021. }
  12022. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12023. {
  12024. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12025. {
  12026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12027. isSuccess = ConfigurationStatus_Accepted;
  12028. }
  12029. else
  12030. {
  12031. isSuccess = ConfigurationStatus_Rejected;
  12032. }
  12033. }
  12034. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12035. {
  12036. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12037. {
  12038. check_ascii = value[0];
  12039. if( (check_ascii < 48) || (check_ascii > 57) )
  12040. {
  12041. isSuccess = ConfigurationStatus_Rejected;
  12042. }
  12043. else
  12044. {
  12045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12046. isSuccess = ConfigurationStatus_Accepted;
  12047. }
  12048. }
  12049. else
  12050. {
  12051. isSuccess = ConfigurationStatus_Rejected;
  12052. }
  12053. }
  12054. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12055. {
  12056. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12057. {
  12058. strcpy(str, (const char*)value);
  12059. for(int i = 0; str[i]; i++)
  12060. {
  12061. str[i] = tolower(str[i]);
  12062. }
  12063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12064. isSuccess = ConfigurationStatus_Accepted;
  12065. }
  12066. else
  12067. {
  12068. isSuccess = ConfigurationStatus_Rejected;
  12069. }
  12070. }
  12071. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12072. {
  12073. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12074. {
  12075. check_ascii = value[0];
  12076. if( (check_ascii < 48) || (check_ascii > 57) )
  12077. {
  12078. isSuccess = ConfigurationStatus_Rejected;
  12079. }
  12080. else
  12081. {
  12082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12083. isSuccess = ConfigurationStatus_Accepted;
  12084. }
  12085. }
  12086. else
  12087. {
  12088. isSuccess = ConfigurationStatus_Rejected;
  12089. }
  12090. }
  12091. return isSuccess;
  12092. }
  12093. int updateSetting(char *key, char *value)
  12094. {
  12095. mtrace();
  12096. int isSuccess = FALSE;
  12097. char string[1000]={0}, buffer[1000]={0};
  12098. char strtemp[50]={0};
  12099. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12100. int pos, c = 0;
  12101. char *loc;
  12102. int pos1=0;
  12103. FILE *f = fopen("/var/www/settings1", "r");
  12104. if(f == NULL)
  12105. {
  12106. #ifdef Debug
  12107. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12108. #endif
  12109. return isSuccess;
  12110. }
  12111. fseek(f, 0, SEEK_END);
  12112. long fsize = ftell(f);
  12113. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12114. fread(string, 1, fsize, f);
  12115. fclose(f);
  12116. string[fsize] = 0;
  12117. loc = strstr(string, key);
  12118. if(loc != NULL)
  12119. {
  12120. DEBUG_INFO("key exist!\n");
  12121. pos = loc - string-1;
  12122. f = fopen("/var/www/settings1", "w");
  12123. strncpy(buffer, string, pos);
  12124. fprintf(f, "%s", buffer);
  12125. memset(sstr ,0, sizeof(sstr) );
  12126. c = 0;
  12127. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12128. {
  12129. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12130. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12131. c++;
  12132. }
  12133. sstr[c] = '\0';
  12134. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12135. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12136. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12137. memset(buffer ,0, sizeof(buffer) );
  12138. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12139. //printf("buffer=%s",buffer);
  12140. fprintf(f, "%s", buffer);
  12141. fclose(f);
  12142. }
  12143. else
  12144. {
  12145. printf("key not exist!\n");
  12146. f = fopen("/var/www/settings1", "w+");
  12147. fputs(string, f);
  12148. fseek(f, -1, SEEK_CUR);
  12149. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12150. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12151. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12152. fclose(f);
  12153. }
  12154. isSuccess = TRUE;
  12155. return isSuccess;
  12156. }
  12157. int TransactionMessageAttemptsGet(void)
  12158. {
  12159. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12160. }
  12161. int FirstHeartBeatResponse(void)
  12162. {
  12163. return FirstHeartBeat;
  12164. }
  12165. int TransactionMessageRetryIntervalGet(void)
  12166. {
  12167. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12168. }
  12169. #define SA struct sockaddr
  12170. #define MAXBUF 1024
  12171. //static int m_socket_data;
  12172. //static int sockfd;
  12173. int ReadHttpStatus(int sock){
  12174. //char c;
  12175. char buff[1024]="",*ptr=buff+1;
  12176. int bytes_received, status;
  12177. DEBUG_INFO("Begin Response ..\n");
  12178. while((bytes_received = recv(sock, ptr, 1, 0))){
  12179. if(bytes_received==-1){
  12180. perror("ReadHttpStatus");
  12181. exit(1);
  12182. }
  12183. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12184. ptr++;
  12185. }
  12186. *ptr=0;
  12187. ptr=buff+1;
  12188. sscanf(ptr,"%*s %d ", &status);
  12189. DEBUG_INFO("%s\n",ptr);
  12190. DEBUG_INFO("status=%d\n",status);
  12191. DEBUG_INFO("End Response ..\n");
  12192. return (bytes_received>0)?status:0;
  12193. }
  12194. //the only filed that it parsed is 'Content-Length'
  12195. int ParseHeader(int sock){
  12196. //char c;
  12197. char buff[1024]="",*ptr=buff+4;
  12198. int bytes_received;
  12199. DEBUG_INFO("Begin HEADER ..\n");
  12200. while((bytes_received = recv(sock, ptr, 1, 0))){
  12201. if(bytes_received==-1){
  12202. perror("Parse Header");
  12203. exit(1);
  12204. }
  12205. if(
  12206. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12207. (ptr[-1]=='\r') && (*ptr=='\n' )
  12208. ) break;
  12209. ptr++;
  12210. }
  12211. *ptr=0;
  12212. ptr=buff+4;
  12213. //printf("%s",ptr);
  12214. if(bytes_received){
  12215. ptr=strstr(ptr,"Content-Length:");
  12216. if(ptr){
  12217. sscanf(ptr,"%*s %d",&bytes_received);
  12218. }else
  12219. bytes_received=-1; //unknown size
  12220. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12221. }
  12222. DEBUG_INFO("End HEADER ..\n");
  12223. return bytes_received ;
  12224. }
  12225. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12226. {
  12227. char rmFileCmd[100]={0};
  12228. char FilePath[100]={0};
  12229. char ftpbuf[200];
  12230. int systemresult;
  12231. //DEBUG_INFO("filename=%s\n",filename);
  12232. //DEBUG_INFO("url=%s\n",url);
  12233. sprintf(FilePath,"/mnt/%s",filename);
  12234. if((access(FilePath,F_OK))!=-1)
  12235. {
  12236. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12237. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12238. system(rmFileCmd);
  12239. }
  12240. memset(ftpbuf, 0, sizeof(ftpbuf));
  12241. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12242. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12243. systemresult = system(ftpbuf);
  12244. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12245. if(systemresult != 0)
  12246. {
  12247. DEBUG_INFO("http DownLoad error!\n");
  12248. return FALSE;
  12249. }
  12250. return TRUE;
  12251. }
  12252. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12253. {
  12254. char rmFileCmd[100]={0};
  12255. char FilePath[100]={0};
  12256. char ftpbuf[200];
  12257. int systemresult;
  12258. //char temp[100];
  12259. #if 0
  12260. struct hostent* server;
  12261. char *IPbuffer;
  12262. server = gethostbyname(location);
  12263. // To convert an Internet network
  12264. // address into ASCII string
  12265. IPbuffer = inet_ntoa(*((struct in_addr*)
  12266. server->h_addr_list[0]));
  12267. #endif
  12268. sprintf(FilePath,"/mnt/%s",filename);
  12269. if((access(FilePath,F_OK))!=-1)
  12270. {
  12271. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12272. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12273. system(rmFileCmd);
  12274. }
  12275. memset(ftpbuf, 0, sizeof(ftpbuf));
  12276. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12277. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12278. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12279. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12280. systemresult = system(ftpbuf);
  12281. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12282. if(systemresult != 0)
  12283. {
  12284. printf("wget error!\n");
  12285. return FALSE;
  12286. }
  12287. return TRUE;
  12288. }
  12289. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12290. {
  12291. char rmFileCmd[100]={0};
  12292. char FilePath[100]={0};
  12293. char ftpbuf[200];
  12294. char filenametemp[60]={0};
  12295. int systemresult;
  12296. //DEBUG_INFO("filename=%s\n",filename);
  12297. //DEBUG_INFO("url=%s\n",url);
  12298. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12299. if((access(FilePath,F_OK))!=-1)
  12300. {
  12301. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12302. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12303. system(rmFileCmd);
  12304. }
  12305. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12306. if(fp == NULL)
  12307. {
  12308. DEBUG_INFO("log is NULL\n");
  12309. return FALSE;
  12310. }
  12311. else
  12312. {
  12313. fprintf(fp, "%s\n", url);
  12314. sscanf(filename, "%*2[.]%s", filenametemp);
  12315. fprintf(fp, "%s\n", filenametemp);
  12316. fclose(fp);
  12317. }
  12318. memset(ftpbuf, 0, sizeof(ftpbuf));
  12319. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12320. systemresult = system(ftpbuf);
  12321. DEBUG_INFO("systemresult=%d\n",systemresult);
  12322. if(systemresult != 0)
  12323. {
  12324. DEBUG_INFO("http upload error!\n");
  12325. return FALSE;
  12326. }
  12327. return TRUE;
  12328. }
  12329. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12330. {
  12331. struct hostent* server;
  12332. char *IPbuffer;
  12333. char ftpbuf[200];
  12334. int systemresult;
  12335. // To retrieve host information
  12336. server = gethostbyname(location);
  12337. // To convert an Internet network
  12338. // address into ASCII string
  12339. IPbuffer = inet_ntoa(*((struct in_addr*)
  12340. server->h_addr_list[0]));
  12341. memset(ftpbuf, 0, sizeof(ftpbuf));
  12342. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12343. /* format : ftpput -u username -p passwd IP target source*/
  12344. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12345. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12346. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12347. systemresult = system(ftpbuf);
  12348. DEBUG_INFO("systemresult=%d\n",systemresult);
  12349. if(systemresult != 0)
  12350. {
  12351. DEBUG_INFO("ftpput error!\n");
  12352. return FALSE;
  12353. }
  12354. return TRUE;
  12355. }
  12356. int SettingChargingRecord(int target, int transactionId)
  12357. {
  12358. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12359. {
  12360. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12361. {
  12362. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12363. {
  12364. addBuff(target, transactionId, 0);
  12365. return TRUE;
  12366. }
  12367. }
  12368. for (int index = 0; index < CCS_QUANTITY; index++)
  12369. {
  12370. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12371. {
  12372. addBuff(target, transactionId, 0);
  12373. return TRUE;
  12374. }
  12375. }
  12376. for (int index = 0; index < GB_QUANTITY; index++)
  12377. {
  12378. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12379. {
  12380. addBuff(target, transactionId, 0);
  12381. return TRUE;
  12382. }
  12383. }
  12384. }
  12385. else
  12386. {
  12387. for (int index = 0; index < AC_QUANTITY; index++)
  12388. {
  12389. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12390. {
  12391. addBuff(target, transactionId, 0);
  12392. return TRUE;
  12393. }
  12394. }
  12395. }
  12396. return FALSE;
  12397. }
  12398. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12399. {
  12400. int isSuccess = FALSE;
  12401. //char *query = NULL;
  12402. sqlite3_stmt *stmt;
  12403. int rc; // return code
  12404. char str[20];
  12405. sprintf(str,"%d",user_id);
  12406. 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 */
  12407. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12408. rc = sqlite3_step(stmt); /* 3 */
  12409. if (rc != SQLITE_DONE) {
  12410. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12411. goto out;
  12412. }
  12413. sqlite3_finalize(stmt);
  12414. // free(query);
  12415. out:
  12416. //----------------------
  12417. // close SQLite database
  12418. //----------------------
  12419. sqlite3_close(db);
  12420. printf("database closed.\n");
  12421. return isSuccess;
  12422. }
  12423. /**
  12424. * Place the contents of the specified file into a memory buffer
  12425. *
  12426. * @param[in] filename The path and name of the file to read
  12427. * @param[out] filebuffer A pointer to the contents in memory
  12428. * @return status 0 success, 1 on failure
  12429. */
  12430. int get_file_contents(const char* filename, char** outbuffer) {
  12431. FILE* file = NULL;
  12432. long filesize;
  12433. const int blocksize = 1;
  12434. size_t readsize;
  12435. char* filebuffer;
  12436. // Open the file
  12437. file = fopen(filename, "r");
  12438. if (NULL == file)
  12439. {
  12440. printf("'%s' not opened\n", filename);
  12441. exit(EXIT_FAILURE);
  12442. }
  12443. // Determine the file size
  12444. fseek(file, 0, SEEK_END);
  12445. filesize = ftell(file);
  12446. rewind (file);
  12447. // Allocate memory for the file contents
  12448. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12449. *outbuffer = filebuffer;
  12450. if (filebuffer == NULL)
  12451. {
  12452. fputs ("malloc out-of-memory", stderr);
  12453. exit(EXIT_FAILURE);
  12454. }
  12455. // Read in the file
  12456. readsize = fread(filebuffer, blocksize, filesize, file);
  12457. if (readsize != filesize)
  12458. {
  12459. fputs ("didn't read file completely",stderr);
  12460. exit(EXIT_FAILURE);
  12461. }
  12462. // Clean exit
  12463. fclose(file);
  12464. return EXIT_SUCCESS;
  12465. }
  12466. static int selectSqlCount = 0;
  12467. static int callback(void *data, int argc, char **argv, char **azColName){
  12468. int i;
  12469. //printf("%s: ", (const char*)data);
  12470. selectSqlCount = argc;
  12471. for(i = 0; i<argc; i++){
  12472. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12473. }
  12474. //printf("\n");
  12475. return 0;
  12476. }
  12477. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12478. //int i;
  12479. //printf("%s:\n", (const char*)data);
  12480. localversion = argv[5] ? atoi(argv[5]) : 0;
  12481. //printf("localversion=%d\n", localversion);
  12482. return 0;
  12483. }
  12484. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12485. //int i;
  12486. //printf("%s:\n", (const char*)data);
  12487. //idTag
  12488. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12489. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12490. //parentIdTag
  12491. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12492. //expir_date
  12493. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12494. //status
  12495. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12496. //version
  12497. idTagQuery.listVersionInt = atoi(argv[5]);
  12498. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12499. return 0;
  12500. }
  12501. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12502. #if 0
  12503. int i;
  12504. //printf("%s:\n", (const char*)data);
  12505. for(i=0; i<argc; i++){
  12506. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12507. }
  12508. //printf("");
  12509. #endif
  12510. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12511. // printf("localversion=%d\n", localversion);
  12512. return 0;
  12513. }
  12514. /** sqlite3_exec的回调。
  12515. *
  12516. * 向控制台打印查询的结果。
  12517. *
  12518. * @param in data 传递给回调函数的数据。
  12519. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12520. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12521. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12522. * @return 状态码。
  12523. */
  12524. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12525. {
  12526. for (int i = 0; i < n_columns; i++)
  12527. {
  12528. DEBUG_INFO("%s/t", col_values[i]);
  12529. }
  12530. DEBUG_INFO("/n");
  12531. return 0;
  12532. }
  12533. void OCPP_getListVerion()
  12534. {
  12535. int rc = 0;
  12536. // const char* data = "Callback function called";
  12537. char sql[100];
  12538. char zErrMsg[100];
  12539. memset(sql, 0, 100);
  12540. memset(zErrMsg, 0, 100);
  12541. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12542. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12543. /* Execute SQL statement */
  12544. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12545. DEBUG_INFO("rc=%d\n",rc);
  12546. if( rc != SQLITE_OK ){
  12547. DEBUG_INFO("SQL error: %s", zErrMsg);
  12548. //sqlite3_free(zErrMsg);
  12549. }
  12550. }
  12551. void OCPP_getIdTag(char idTag[])
  12552. {
  12553. int rc = 0;
  12554. // const char* data = "Callback function called";
  12555. char sql[100];
  12556. char zErrMsg[100];
  12557. memset(sql, 0, 100);
  12558. memset(zErrMsg, 0, 100);
  12559. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12560. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12561. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12562. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12563. /* Execute SQL statement */
  12564. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12565. if( rc != SQLITE_OK ){
  12566. DEBUG_INFO("SQL error: %s", zErrMsg);
  12567. //sqlite3_free(zErrMsg);
  12568. }
  12569. //return ver;
  12570. }
  12571. void OCPP_get_TableAuthlocalAllData(void)
  12572. {
  12573. int rc = 0;
  12574. // const char* data = "Callback function called";
  12575. char sql[100];
  12576. char zErrMsg[100];
  12577. memset(sql, 0, 100);
  12578. memset(zErrMsg, 0, 100);
  12579. sprintf(sql,"select * from ocpp_auth_local ");
  12580. /* Execute SQL statement */
  12581. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12582. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12583. if( rc != SQLITE_OK ){
  12584. DEBUG_INFO("SQL error: %s", zErrMsg);
  12585. //sqlite3_free(zErrMsg);
  12586. }
  12587. //return ver;
  12588. }
  12589. int OCPP_cleanLocalList()
  12590. {
  12591. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12592. char *errMsg = 0;
  12593. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12594. if (SQLITE_OK != rc)
  12595. {
  12596. DEBUG_INFO("%s\n",errMsg);
  12597. return FALSE;
  12598. }
  12599. else
  12600. {
  12601. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12602. }
  12603. return TRUE;
  12604. }
  12605. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12606. {
  12607. int isSuccess = FALSE;
  12608. int ret = 0;
  12609. //const char* data = "Callback function called";
  12610. char sql[300];
  12611. char zErrMsg[200];
  12612. memset(sql, 0, 300);
  12613. memset(zErrMsg, 0, 200);
  12614. 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);
  12615. //* Execute SQL statement */
  12616. //zErrMsg = 0;
  12617. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12618. if( ret != SQLITE_OK ){
  12619. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12620. // free(zErrMsg);
  12621. // free(sql);
  12622. return isSuccess;
  12623. }
  12624. memset(sql, 0, 300);
  12625. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12626. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12627. if( ret != SQLITE_OK ){
  12628. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12629. // free(zErrMsg);
  12630. // free(sql);
  12631. return isSuccess;
  12632. }
  12633. // DEBUG_INFO("successfully Insert records created\n");
  12634. isSuccess = TRUE;
  12635. return isSuccess;
  12636. }
  12637. void OCPP_deleteIdTag(char idTag[])
  12638. {
  12639. //int ver = 0;
  12640. //int isSuccess = FALSE;
  12641. int rc = 0;
  12642. char sql[100];
  12643. char zErrMsg[100];
  12644. memset(sql, 0, 100);
  12645. memset(zErrMsg, 0, 100);
  12646. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12647. //* Execute SQL statement */
  12648. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12649. if( rc != SQLITE_OK ){
  12650. DEBUG_INFO("SQL error: %s", zErrMsg);
  12651. //sqlite3_free(zErrMsg);
  12652. }
  12653. }
  12654. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12655. {
  12656. int isSuccess = FALSE;
  12657. int ret = 0;
  12658. const char* data = "Callback function called";
  12659. char sql[200];
  12660. char zErrMsg[100];
  12661. memset(sql, 0, 200);
  12662. memset(zErrMsg, 0, 100);
  12663. //* selectFromTable */
  12664. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12665. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12666. //* Execute SQL statement */
  12667. selectSqlCount = 0;
  12668. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12669. if( ret != SQLITE_OK ){
  12670. printf("Error SQL: %s\n", zErrMsg);
  12671. }
  12672. printf("successfully select operation done\n");
  12673. memset(sql, 0, 200);
  12674. memset(zErrMsg, 0, 100);
  12675. if(selectSqlCount == 0)
  12676. {
  12677. //Insert
  12678. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12679. 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);
  12680. DEBUG_INFO("sql:%s\n", sql);
  12681. //* Execute SQL statement */
  12682. //zErrMsg = 0;
  12683. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12684. if( ret != SQLITE_OK ){
  12685. printf("SQL error: %s\n", zErrMsg);
  12686. return isSuccess;
  12687. }
  12688. DEBUG_INFO("successfully Insert records created\n");
  12689. isSuccess = TRUE;
  12690. }
  12691. else
  12692. {
  12693. //Update
  12694. //* Create merged SQL statement */
  12695. 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);
  12696. /* Execute SQL statement */
  12697. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12698. if( ret != SQLITE_OK ){
  12699. printf("SQL error: %s\n", zErrMsg);
  12700. //sqlite3_free(zErrMsg);
  12701. //sqlite3_free(sql);
  12702. return isSuccess;
  12703. }
  12704. DEBUG_INFO("Successfully operation done \n");
  12705. isSuccess = TRUE;
  12706. }
  12707. return isSuccess;
  12708. }
  12709. int GetOcppServerURL()
  12710. {
  12711. int result = FALSE;
  12712. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12713. memset(OcppHost, 0, sizeof(OcppHost));
  12714. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12715. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12716. {
  12717. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12718. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12719. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12720. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12721. result = TRUE;
  12722. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12723. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12724. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12725. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12726. goto End;
  12727. }
  12728. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12729. {
  12730. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12731. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12732. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12733. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12734. result = TRUE;
  12735. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12736. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12737. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12738. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12739. goto End;
  12740. }
  12741. else
  12742. {
  12743. strcpy(OcppHost,"");
  12744. }
  12745. End:
  12746. return result;
  12747. }
  12748. int GetOcppPath()
  12749. {
  12750. int result = FALSE;
  12751. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12752. {
  12753. if(OcppTempPath == NULL)
  12754. {
  12755. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12756. }
  12757. else
  12758. {
  12759. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12760. }
  12761. result = TRUE;
  12762. goto End;
  12763. }
  12764. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12765. {
  12766. if(OcppTempPath == NULL)
  12767. {
  12768. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12769. }
  12770. else
  12771. {
  12772. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12773. }
  12774. result = TRUE;
  12775. goto End;
  12776. }
  12777. else
  12778. {
  12779. strcpy(OcppPath,"");
  12780. }
  12781. End:
  12782. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12783. return result;
  12784. }
  12785. int GetOcppPort()
  12786. {
  12787. return OcppPort;
  12788. }
  12789. int GetOcppConnStatus(void)
  12790. {
  12791. return ShmOCPP16Data->OcppConnStatus;
  12792. }
  12793. void SetOcppConnStatus(uint8_t status)
  12794. {
  12795. ShmOCPP16Data->OcppConnStatus = status;
  12796. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12797. if(status == FALSE)
  12798. {
  12799. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12800. {
  12801. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12802. }
  12803. else
  12804. {
  12805. SystemInitial = AC_QUANTITY;
  12806. }
  12807. }
  12808. }
  12809. int GetHeartBeatWithNOResponse(void)
  12810. {
  12811. return HeartBeatWithNOResponse;
  12812. }
  12813. void SetHeartBeatWithNOResponse(void)
  12814. {
  12815. HeartBeatWithNOResponse = 0;
  12816. }
  12817. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12818. /*
  12819. src 源字串的首地址(buf的地址)
  12820. separator 指定的分割字元
  12821. dest 接收子字串的陣列
  12822. num 分割後子字串的個數
  12823. */
  12824. char *pNext;
  12825. int count = 0;
  12826. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12827. return;
  12828. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12829. return;
  12830. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12831. while(pNext != NULL) {
  12832. *dest++ = pNext;
  12833. ++count;
  12834. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12835. }
  12836. *num = count;
  12837. }
  12838. int GetTransactionId(int gunindex, unsigned char idTag[])
  12839. {
  12840. char ch;
  12841. FILE *fptr1;
  12842. int temptransactionId;
  12843. char str[100]={0};
  12844. temptransactionId = 0;
  12845. /*------ Read the file ----------------*/
  12846. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12847. ch=fgetc(fptr1);
  12848. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12849. rewind(fptr1);
  12850. if(ch!=EOF)
  12851. {
  12852. // printf("%c",ch);
  12853. while (fgets(str, 100, fptr1) != NULL)
  12854. {
  12855. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12856. if(str[0]=='\0')
  12857. {
  12858. break;
  12859. }
  12860. char *revbuf[8] = {0}; //存放分割後的子字串
  12861. int num = 0;//分割後子字串的個數
  12862. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12863. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12864. {
  12865. temptransactionId = atoi(revbuf[2]);
  12866. break;
  12867. }
  12868. }
  12869. }
  12870. fclose(fptr1);
  12871. /*------- End of reading ---------------*/
  12872. return temptransactionId;
  12873. }
  12874. void SetTransactionIdZero(int transactionId)
  12875. {
  12876. //TransactionId[gunindex] = 0;
  12877. char ch;
  12878. FILE *fptr1, *fptr2;
  12879. int temptransactionId = 0;
  12880. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  12881. printf("\n\n Delete a specific line from a file :\n");
  12882. printf("-----------------------------------------\n");
  12883. //scanf("%s",fname);
  12884. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12885. if (!fptr1)
  12886. {
  12887. printf(" File not found or unable to open the input file!!\n");
  12888. return ;
  12889. }
  12890. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12891. if (!fptr2)
  12892. {
  12893. printf("Unable to open a temporary file to write!!\n");
  12894. fclose(fptr1);
  12895. return ;
  12896. }
  12897. ch=fgetc(fptr1);
  12898. //printf(" Now the content of the file %s is : \n",fname);
  12899. rewind(fptr1);
  12900. if(ch!=EOF)
  12901. {
  12902. // copy all contents to the temporary file except the specific line
  12903. while (fgets(str, 100, fptr1) != NULL)
  12904. {
  12905. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12906. if(str[0]=='\0')
  12907. {
  12908. break;
  12909. }
  12910. char *revbuf[8] = {0}; //存放分割後的子字串
  12911. int num = 0;//分割後子字串的個數
  12912. strcpy(strtemp, str);
  12913. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12914. if(revbuf[2][0] != '\0')
  12915. {
  12916. temptransactionId = atoi(revbuf[2]);
  12917. if(transactionId != temptransactionId)
  12918. {
  12919. fprintf(fptr2, "%s", strtemp);
  12920. }
  12921. }
  12922. }
  12923. }
  12924. fclose(fptr1);
  12925. fclose(fptr2);
  12926. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12927. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12928. /*------ Read the file ----------------*/
  12929. }
  12930. int InternetDisconnect(void)
  12931. {
  12932. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12933. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12934. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12935. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12936. }
  12937. void GetChargingProfileRequest(int gunindex)
  12938. {
  12939. mtrace();
  12940. //int connectorIdInt, durationInt;
  12941. //char chargingRateUnitStr[4]={0};
  12942. int tempdurationInt = 0;
  12943. int tempchargingProfileId = 0;
  12944. int tempstackLevel = 0;
  12945. int temptransactionId = 0;
  12946. float tempminChargingRateFloat = 0.0;
  12947. char tempchargingProfilePurposeStr[24]={0};
  12948. char tempchargingProfileKindStr[12]={0};
  12949. char temprecurrencyKindStr[8]={0};
  12950. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12951. char tempvalidToStr[28]={0};
  12952. int tempStartPeriodInt = 0;
  12953. float tempLimitInt = 0.0;//0.1;
  12954. int tempNumberPhasesInt=0;
  12955. char fname[200];
  12956. //char comfirmstr[20];
  12957. float MinChargingRate =0.0;
  12958. double diff_t;
  12959. struct tm tp;
  12960. FILE *fptr1;//, *fptr2;
  12961. int c = 0;
  12962. char * pch;
  12963. char *loc;
  12964. char sstr[200]={ 0 };
  12965. int n_chargingProfile = 0;
  12966. int n_SchedulePeriods = 0;
  12967. char SchedulePeriodList[10][200]={0};
  12968. char sLineWord[1600]={0};
  12969. char word[1000]={0};
  12970. int confirmPeriods = 0;
  12971. struct StructProfile ChargePointMaxProfile;
  12972. struct StructProfile TxDefaultProfile;
  12973. struct StructProfile TxProfile;
  12974. struct StructProfile TxDefaultProfiletemp[2]={0};
  12975. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12976. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12977. struct StructChargingProfile TxProfile_TEMP={0};
  12978. int TxDefaultProfileFileIsNull=FALSE;
  12979. int ChargePointMaxProfileIsNull=FALSE;
  12980. int TxProfileIsNull=FALSE;
  12981. // int CompositeSceduleIndex = 0;
  12982. char ChargePointMaxProfileScheduleStr[30]={0};
  12983. char TxDefaultProfileScheduleStr[30]={0};
  12984. char TxProfileScheduleStr[30]={0};
  12985. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12986. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12987. memset(&TxProfile,0,sizeof(struct StructProfile));
  12988. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  12989. DEBUG_INFO("GetChargingProfileRequest\n");
  12990. //*****************************ChargePointMaxProfile******************************************/
  12991. strcpy(fname, ChargePointMaxProfile_JSON);
  12992. ChargePointMaxProfileIsNull=TRUE;
  12993. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12994. {
  12995. fptr1 = fopen(fname, "r");
  12996. int c;
  12997. c = fgetc(fptr1);
  12998. //DEBUG_INFO("c:%d\n",c);
  12999. rewind(fptr1);
  13000. if(c == EOF)
  13001. {
  13002. DEBUG_INFO("\n End of file reached.");
  13003. ChargePointMaxProfileIsNull=TRUE;
  13004. fclose(fptr1);
  13005. }
  13006. else
  13007. {
  13008. ChargePointMaxProfileIsNull=FALSE;
  13009. while(fscanf(fptr1, "%s", word) != EOF)
  13010. {
  13011. if(strcmp(word, "chargingProfileId") == 0)
  13012. {
  13013. n_chargingProfile = n_chargingProfile + 1;
  13014. }
  13015. }
  13016. rewind(fptr1);
  13017. //search Charging Profile Element
  13018. int i = 0;
  13019. int j = 0;
  13020. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13021. //***********chargingProfileId**************/
  13022. c = 0;
  13023. loc = strstr(sLineWord, "chargingProfileId");
  13024. //DEBUG_INFO("loc=%s\n",loc);
  13025. memset(sstr ,0, sizeof(sstr) );
  13026. if(loc != NULL)
  13027. {
  13028. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13029. {
  13030. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13031. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13032. c++;
  13033. }
  13034. sstr[c] = '\0';
  13035. tempchargingProfileId = atoi(sstr);
  13036. }
  13037. else
  13038. {
  13039. tempchargingProfileId = 0;
  13040. }
  13041. //***********stackLevel**************/
  13042. c = 0;
  13043. loc = strstr(sLineWord, "stackLevel");
  13044. //DEBUG_INFO("loc=%s\n",loc);
  13045. memset(sstr ,0, sizeof(sstr) );
  13046. if(loc != NULL)
  13047. {
  13048. while (loc[2+strlen("stackLevel")+c] != '\"')
  13049. {
  13050. sstr[c] = loc[2+strlen("stackLevel")+c];
  13051. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13052. c++;
  13053. }
  13054. sstr[c] = '\0';
  13055. tempstackLevel = atoi(sstr);
  13056. }
  13057. else
  13058. {
  13059. tempstackLevel = 0;
  13060. }
  13061. //***********chargingProfilePurpose **************/
  13062. c = 0;
  13063. loc = strstr(sLineWord, "chargingProfilePurpose");
  13064. //DEBUG_INFO("loc=%s\n",loc);
  13065. memset(sstr ,0, sizeof(sstr) );
  13066. if(loc != NULL)
  13067. {
  13068. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13069. {
  13070. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13071. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13072. c++;
  13073. }
  13074. sstr[c] = '\0';
  13075. strcpy(tempchargingProfilePurposeStr,sstr);
  13076. }
  13077. else
  13078. {
  13079. strcpy(tempchargingProfilePurposeStr,"");
  13080. }
  13081. //***********chargingProfileKind **************/
  13082. c = 0;
  13083. loc = strstr(sLineWord, "chargingProfileKind");
  13084. //DEBUG_INFO("loc=%s\n",loc);
  13085. memset(sstr ,0, sizeof(sstr) );
  13086. if(loc != NULL)
  13087. {
  13088. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13089. {
  13090. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13091. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13092. c++;
  13093. }
  13094. sstr[c] = '\0';
  13095. strcpy(tempchargingProfileKindStr,sstr);
  13096. }
  13097. else
  13098. {
  13099. strcpy(tempchargingProfileKindStr,"");
  13100. }
  13101. //***********recurrencyKind **************/
  13102. c = 0;
  13103. loc = strstr(sLineWord, "recurrencyKind");
  13104. //DEBUG_INFO("loc=%s\n",loc);
  13105. memset(sstr ,0, sizeof(sstr) );
  13106. if(loc != NULL)
  13107. {
  13108. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13109. {
  13110. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13111. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13112. c++;
  13113. }
  13114. sstr[c] = '\0';
  13115. strcpy(temprecurrencyKindStr,sstr);
  13116. }
  13117. else
  13118. {
  13119. strcpy(temprecurrencyKindStr,"");
  13120. }
  13121. //***********validFrom**************/
  13122. c = 0;
  13123. loc = strstr(sLineWord, "validFrom");
  13124. //DEBUG_INFO("loc=%s\n",loc);
  13125. memset(sstr ,0, sizeof(sstr) );
  13126. if(loc != NULL)
  13127. {
  13128. while (loc[3+strlen("validFrom")+c] != '\"')
  13129. {
  13130. sstr[c] = loc[3+strlen("validFrom")+c];
  13131. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13132. c++;
  13133. }
  13134. sstr[c] = '\0';
  13135. strcpy(tempvalidFromStr,sstr);
  13136. }
  13137. else
  13138. {
  13139. strcpy(tempvalidFromStr,"");
  13140. }
  13141. //***********validTo **************/
  13142. c = 0;
  13143. loc = strstr(sLineWord, "validTo");
  13144. //DEBUG_INFO("loc=%s\n",loc);
  13145. memset(sstr ,0, sizeof(sstr) );
  13146. if(loc != NULL)
  13147. {
  13148. while (loc[3+strlen("validTo")+c] != '\"')
  13149. {
  13150. sstr[c] = loc[3+strlen("validTo")+c];
  13151. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13152. c++;
  13153. }
  13154. sstr[c] = '\0';
  13155. strcpy(tempvalidToStr,sstr);
  13156. }
  13157. else
  13158. {
  13159. strcpy(tempvalidToStr,"");
  13160. }
  13161. //***********validFrom**************/
  13162. c = 0;
  13163. loc = strstr(sLineWord, "validFrom");
  13164. if(loc != NULL)
  13165. {
  13166. memset(sstr ,0, sizeof(sstr) );
  13167. while (loc[3+strlen("validFrom")+c] != '\"')
  13168. {
  13169. sstr[c] = loc[3+strlen("validFrom")+c];
  13170. c++;
  13171. }
  13172. sstr[c] = '\0';
  13173. strcpy(tempvalidFromStr,sstr);
  13174. }
  13175. else
  13176. {
  13177. strcpy(tempvalidFromStr,"");
  13178. }
  13179. //***********validTo **************/
  13180. c = 0;
  13181. loc = strstr(sLineWord, "validTo");
  13182. if(loc != NULL)
  13183. {
  13184. memset(sstr ,0, sizeof(sstr) );
  13185. while (loc[3+strlen("validTo")+c] != '\"')
  13186. {
  13187. sstr[c] = loc[3+strlen("validTo")+c];
  13188. c++;
  13189. }
  13190. sstr[c] = '\0';
  13191. strcpy(tempvalidToStr,sstr);
  13192. }
  13193. else
  13194. {
  13195. strcpy(tempvalidToStr,"");
  13196. }
  13197. //***********duration**************/
  13198. c = 0;
  13199. loc = strstr(sLineWord, "duration");
  13200. if(loc != NULL)
  13201. {
  13202. memset(sstr ,0, sizeof(sstr) );
  13203. while (loc[2+strlen("duration")+c] != ',')
  13204. {
  13205. sstr[c] = loc[2+strlen("duration")+c];
  13206. c++;
  13207. }
  13208. sstr[c] = '\0';
  13209. tempdurationInt = atoi(sstr);
  13210. }
  13211. else
  13212. {
  13213. tempdurationInt = 0;
  13214. }
  13215. //**********startSchedule**********/
  13216. c = 0;
  13217. loc = strstr(sLineWord, "startSchedule");
  13218. memset(sstr ,0, sizeof(sstr) );
  13219. while (loc[3+strlen("startSchedule")+c] != '\"')
  13220. {
  13221. sstr[c] = loc[3+strlen("startSchedule")+c];
  13222. c++;
  13223. }
  13224. sstr[c] = '\0';
  13225. strcpy(tempstartScheduleStr, sstr);
  13226. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  13227. //**********chargingRateUnit**********/
  13228. c = 0;
  13229. loc = strstr(sLineWord, "chargingRateUnit");
  13230. memset(sstr ,0, sizeof(sstr) );
  13231. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13232. {
  13233. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13234. c++;
  13235. }
  13236. sstr[c] = '\0';
  13237. strcpy(tempchargingRateUnitStr, sstr);
  13238. //**********minChargingRate*******/
  13239. c = 0;
  13240. loc = strstr(sLineWord, "minChargingRate");
  13241. if(loc != NULL)
  13242. {
  13243. memset(sstr ,0, sizeof(sstr) );
  13244. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13245. {
  13246. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13247. c++;
  13248. }
  13249. sstr[c] = '\0';
  13250. tempminChargingRateFloat = atof(sstr);
  13251. }
  13252. else
  13253. {
  13254. tempminChargingRateFloat = 0.0;
  13255. }
  13256. //
  13257. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13258. tp.tm_isdst = -1;
  13259. time_t utc = mktime(&tp);
  13260. time_t t = time(NULL);
  13261. diff_t = difftime(t, utc);
  13262. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13263. //parsing strings to words
  13264. i = 0;
  13265. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13266. loc = loc+3+strlen("chargingSchedulePeriod");
  13267. pch = strtok(loc ,"{");
  13268. while (pch != NULL)
  13269. {
  13270. strcpy(SchedulePeriodList[i], pch);
  13271. pch = strtok (NULL, "{");
  13272. i = i + 1;
  13273. }
  13274. n_SchedulePeriods = i;
  13275. for(int i=0;i<n_SchedulePeriods;i++)
  13276. {
  13277. //*************startPeriod****************/
  13278. c = 0;
  13279. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13280. memset(sstr ,0, sizeof(sstr) );
  13281. while (loc[strlen("startPeriod")+2+c] != ',')
  13282. {
  13283. sstr[c] = loc[strlen("startPeriod")+2+c];
  13284. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13285. c++;
  13286. }
  13287. sstr[c] = '\0';
  13288. tempStartPeriodInt = atoi(sstr);
  13289. //*************limit****************/
  13290. c = 0;
  13291. loc = strstr(SchedulePeriodList[i], "limit");
  13292. memset(sstr ,0, sizeof(sstr) );
  13293. while (loc[strlen("limit")+2+c] != ',')
  13294. {
  13295. sstr[c] = loc[strlen("limit")+2+c];
  13296. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13297. c++;
  13298. }
  13299. sstr[c] = '\0';
  13300. tempLimitInt = atof(sstr);
  13301. //*************numberPhases****************/
  13302. c = 0;
  13303. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13304. memset(sstr ,0, sizeof(sstr) );
  13305. while (loc[strlen("numberPhases")+2+c] != '}')
  13306. {
  13307. sstr[c] = loc[strlen("numberPhases")+2+c];
  13308. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13309. c++;
  13310. }
  13311. sstr[c] = '\0';
  13312. tempNumberPhasesInt = atoi(sstr);
  13313. if(j == 0)
  13314. {
  13315. ChargePointMaxProfile.Duration = tempdurationInt;
  13316. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13317. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13318. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13319. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13320. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13321. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13322. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13323. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13324. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13325. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13326. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13327. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13328. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13329. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13330. }
  13331. }
  13332. if(MinChargingRate < tempminChargingRateFloat)
  13333. {
  13334. MinChargingRate = tempminChargingRateFloat;
  13335. }
  13336. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13337. if(confirmPeriods < n_SchedulePeriods)
  13338. {
  13339. confirmPeriods = n_SchedulePeriods;
  13340. }
  13341. j = j + 1;
  13342. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13343. fclose(fptr1);
  13344. }// end else
  13345. }// the end of access file ChargePointMaxProfile
  13346. //****************************TxDefaultProfile************************************************/
  13347. #if 0
  13348. switch(gunindex + 1)
  13349. {
  13350. case 0:
  13351. strcpy(fname, TxDefaultProfile_0_JSON );
  13352. break;
  13353. case 1:
  13354. strcpy(fname, TxDefaultProfile_1_JSON );
  13355. break;
  13356. case 2:
  13357. strcpy(fname, TxDefaultProfile_2_JSON );
  13358. break;
  13359. default:
  13360. strcpy(fname, TxDefaultProfile_1_JSON );
  13361. break;
  13362. }
  13363. #endif
  13364. memset(fname, 0, sizeof fname);
  13365. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13366. TxDefaultProfileFileIsNull=TRUE;
  13367. if((access(fname,F_OK))!=-1)
  13368. {
  13369. fptr1 = fopen(fname, "r");
  13370. c = 0;
  13371. c = fgetc(fptr1);
  13372. //DEBUG_INFO("c:%d\n",c);
  13373. rewind(fptr1);
  13374. if(c == EOF)
  13375. {
  13376. DEBUG_INFO("\n End of file reached.");
  13377. TxDefaultProfileFileIsNull=TRUE;
  13378. fclose(fptr1);
  13379. }
  13380. else
  13381. {
  13382. TxDefaultProfileFileIsNull=FALSE;
  13383. while(fscanf(fptr1, "%s", word) != EOF)
  13384. {
  13385. if(strcmp(word, "chargingProfileId") == 0)
  13386. {
  13387. n_chargingProfile = n_chargingProfile + 1;
  13388. }
  13389. }
  13390. rewind(fptr1);
  13391. //search Charging Profile Element
  13392. int i = 0;
  13393. int j = 0;
  13394. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13395. {
  13396. #if 0
  13397. //***********connectorId****************/
  13398. c = 0;
  13399. loc = strstr(sLineWord, "connectorId");
  13400. memset(sstr ,0, sizeof(sstr) );
  13401. while (loc[strlen("connectorId")+2+c] != ',')
  13402. {
  13403. sstr[c] = loc[strlen("connectorId")+2+c];
  13404. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13405. c++;
  13406. }
  13407. sstr[c] = '\0';
  13408. tempconnectorIdInt = atoi(sstr);
  13409. #endif
  13410. //***********chargingProfileId**************/
  13411. c = 0;
  13412. loc = strstr(sLineWord, "chargingProfileId");
  13413. //DEBUG_INFO("loc=%s\n",loc);
  13414. memset(sstr ,0, sizeof(sstr) );
  13415. if(loc != NULL)
  13416. {
  13417. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13418. {
  13419. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13420. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13421. c++;
  13422. }
  13423. sstr[c] = '\0';
  13424. tempchargingProfileId = atoi(sstr);
  13425. }
  13426. else
  13427. {
  13428. tempchargingProfileId = 0;
  13429. }
  13430. //***********stackLevel**************/
  13431. c = 0;
  13432. loc = strstr(sLineWord, "stackLevel");
  13433. //DEBUG_INFO("loc=%s\n",loc);
  13434. memset(sstr ,0, sizeof(sstr) );
  13435. if(loc != NULL)
  13436. {
  13437. while (loc[2+strlen("stackLevel")+c] != '\"')
  13438. {
  13439. sstr[c] = loc[2+strlen("stackLevel")+c];
  13440. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13441. c++;
  13442. }
  13443. sstr[c] = '\0';
  13444. tempstackLevel = atoi(sstr);
  13445. }
  13446. else
  13447. {
  13448. tempstackLevel = 0;
  13449. }
  13450. //***********chargingProfilePurpose **************/
  13451. c = 0;
  13452. loc = strstr(sLineWord, "chargingProfilePurpose");
  13453. //DEBUG_INFO("loc=%s\n",loc);
  13454. memset(sstr ,0, sizeof(sstr) );
  13455. if(loc != NULL)
  13456. {
  13457. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13458. {
  13459. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13460. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13461. c++;
  13462. }
  13463. sstr[c] = '\0';
  13464. strcpy(tempchargingProfilePurposeStr,sstr);
  13465. }
  13466. else
  13467. {
  13468. strcpy(tempchargingProfilePurposeStr,"");
  13469. }
  13470. //***********chargingProfileKind **************/
  13471. c = 0;
  13472. loc = strstr(sLineWord, "chargingProfileKind");
  13473. //DEBUG_INFO("loc=%s\n",loc);
  13474. memset(sstr ,0, sizeof(sstr) );
  13475. if(loc != NULL)
  13476. {
  13477. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13478. {
  13479. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13480. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13481. c++;
  13482. }
  13483. sstr[c] = '\0';
  13484. strcpy(tempchargingProfileKindStr,sstr);
  13485. }
  13486. else
  13487. {
  13488. strcpy(tempchargingProfileKindStr,"");
  13489. }
  13490. //***********recurrencyKind **************/
  13491. c = 0;
  13492. loc = strstr(sLineWord, "recurrencyKind");
  13493. //DEBUG_INFO("loc=%s\n",loc);
  13494. memset(sstr ,0, sizeof(sstr) );
  13495. if(loc != NULL)
  13496. {
  13497. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13498. {
  13499. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13500. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13501. c++;
  13502. }
  13503. sstr[c] = '\0';
  13504. strcpy(temprecurrencyKindStr,sstr);
  13505. }
  13506. else
  13507. {
  13508. strcpy(temprecurrencyKindStr,"");
  13509. }
  13510. //***********validFrom**************/
  13511. c = 0;
  13512. loc = strstr(sLineWord, "validFrom");
  13513. if(loc != NULL)
  13514. {
  13515. memset(sstr ,0, sizeof(sstr) );
  13516. while (loc[3+strlen("validFrom")+c] != '\"')
  13517. {
  13518. sstr[c] = loc[3+strlen("validFrom")+c];
  13519. c++;
  13520. }
  13521. sstr[c] = '\0';
  13522. strcpy(tempvalidFromStr,sstr);
  13523. }
  13524. else
  13525. {
  13526. strcpy(tempvalidFromStr,"");
  13527. }
  13528. //***********validTo **************/
  13529. c = 0;
  13530. loc = strstr(sLineWord, "validTo");
  13531. if(loc != NULL)
  13532. {
  13533. memset(sstr ,0, sizeof(sstr) );
  13534. while (loc[3+strlen("validTo")+c] != '\"')
  13535. {
  13536. sstr[c] = loc[3+strlen("validTo")+c];
  13537. c++;
  13538. }
  13539. sstr[c] = '\0';
  13540. strcpy(tempvalidToStr,sstr);
  13541. }
  13542. else
  13543. {
  13544. strcpy(tempvalidToStr,"");
  13545. }
  13546. //***********duration**************/
  13547. c = 0;
  13548. loc = strstr(sLineWord, "duration");
  13549. if(loc != NULL)
  13550. {
  13551. memset(sstr ,0, sizeof(sstr) );
  13552. while (loc[2+strlen("duration")+c] != ',')
  13553. {
  13554. sstr[c] = loc[2+strlen("duration")+c];
  13555. c++;
  13556. }
  13557. sstr[c] = '\0';
  13558. tempdurationInt = atoi(sstr);
  13559. }
  13560. else
  13561. {
  13562. tempdurationInt = 0;
  13563. }
  13564. //**********startSchedule**********/
  13565. c = 0;
  13566. loc = strstr(sLineWord, "startSchedule");
  13567. memset(sstr ,0, sizeof(sstr) );
  13568. while (loc[3+strlen("startSchedule")+c] != '\"')
  13569. {
  13570. sstr[c] = loc[3+strlen("startSchedule")+c];
  13571. c++;
  13572. }
  13573. sstr[c] = '\0';
  13574. strcpy(tempstartScheduleStr, sstr);
  13575. strcpy(TxDefaultProfileScheduleStr, sstr);
  13576. //**********chargingRateUnit**********/
  13577. c = 0;
  13578. loc = strstr(sLineWord, "chargingRateUnit");
  13579. memset(sstr ,0, sizeof(sstr) );
  13580. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13581. {
  13582. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13583. c++;
  13584. }
  13585. sstr[c] = '\0';
  13586. strcpy(tempchargingRateUnitStr, sstr);
  13587. //**********minChargingRate*******/
  13588. c = 0;
  13589. loc = strstr(sLineWord, "minChargingRate");
  13590. if(loc != NULL)
  13591. {
  13592. memset(sstr ,0, sizeof(sstr) );
  13593. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13594. {
  13595. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13596. c++;
  13597. }
  13598. sstr[c] = '\0';
  13599. tempminChargingRateFloat = atof(sstr);
  13600. }
  13601. else
  13602. {
  13603. tempminChargingRateFloat = 0.0;
  13604. }
  13605. //
  13606. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13607. tp.tm_isdst = -1;
  13608. time_t utc = mktime(&tp);
  13609. time_t t = time(NULL);
  13610. diff_t = difftime(t, utc);
  13611. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13612. //parsing strings to words
  13613. i = 0;
  13614. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13615. loc = loc+3+strlen("chargingSchedulePeriod");
  13616. pch = strtok(loc ,"{");
  13617. while (pch != NULL)
  13618. {
  13619. strcpy(SchedulePeriodList[i], pch);
  13620. pch = strtok (NULL, "{");
  13621. i = i + 1;
  13622. }
  13623. n_SchedulePeriods = i;
  13624. for(int i=0;i<n_SchedulePeriods;i++)
  13625. {
  13626. //*************startPeriod****************/
  13627. c = 0;
  13628. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13629. memset(sstr ,0, sizeof(sstr) );
  13630. while (loc[strlen("startPeriod")+2+c] != ',')
  13631. {
  13632. sstr[c] = loc[strlen("startPeriod")+2+c];
  13633. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13634. c++;
  13635. }
  13636. sstr[c] = '\0';
  13637. tempStartPeriodInt = atoi(sstr);
  13638. //*************limit****************/
  13639. c = 0;
  13640. loc = strstr(SchedulePeriodList[i], "limit");
  13641. memset(sstr ,0, sizeof(sstr) );
  13642. while (loc[strlen("limit")+2+c] != ',')
  13643. {
  13644. sstr[c] = loc[strlen("limit")+2+c];
  13645. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13646. c++;
  13647. }
  13648. sstr[c] = '\0';
  13649. tempLimitInt = atof(sstr);
  13650. //*************numberPhases****************/
  13651. c = 0;
  13652. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13653. memset(sstr ,0, sizeof(sstr) );
  13654. while (loc[strlen("numberPhases")+2+c] != '}')
  13655. {
  13656. sstr[c] = loc[strlen("numberPhases")+2+c];
  13657. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13658. c++;
  13659. }
  13660. sstr[c] = '\0';
  13661. tempNumberPhasesInt = atoi(sstr);
  13662. if(j == 0)
  13663. {
  13664. TxDefaultProfile.Duration = tempdurationInt;
  13665. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13666. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13667. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13668. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13669. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13670. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13671. TxDefaultProfile_TEMP.TransactionId = 0;
  13672. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13673. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13674. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13675. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13676. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13677. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13678. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13679. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13680. }
  13681. else
  13682. {
  13683. //other stack level charging Profile
  13684. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13685. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13686. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13687. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13688. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13689. }
  13690. }
  13691. if(MinChargingRate < tempminChargingRateFloat)
  13692. {
  13693. MinChargingRate = tempminChargingRateFloat;
  13694. }
  13695. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13696. if(confirmPeriods < n_SchedulePeriods)
  13697. confirmPeriods = n_SchedulePeriods;
  13698. j = j + 1;
  13699. }
  13700. fclose(fptr1);
  13701. //Stacking Charging Profiles
  13702. for(int l=0; l <(j-1) ;l++)
  13703. {
  13704. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13705. {
  13706. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13707. {
  13708. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13709. {
  13710. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13711. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13712. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13713. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13714. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13715. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13716. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13717. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13718. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13719. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13720. }
  13721. else
  13722. {
  13723. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13724. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13725. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13726. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13727. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13728. }
  13729. }
  13730. }
  13731. }//end of Stacking Charging Profiles
  13732. }// end else
  13733. }// the end of ACCESS TxDefaultProfile
  13734. //****************************TxProfile************************************************/
  13735. #if 0
  13736. switch(gunindex + 1)
  13737. {
  13738. case 0:
  13739. break;
  13740. case 1:
  13741. strcpy(fname, TxProfile_1_JSON );
  13742. break;
  13743. case 2:
  13744. strcpy(fname, TxProfile_2_JSON );
  13745. break;
  13746. default:
  13747. strcpy(fname, TxProfile_1_JSON );
  13748. break;
  13749. }
  13750. #endif
  13751. memset(fname, 0, sizeof fname);
  13752. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  13753. TxProfileIsNull=TRUE;
  13754. if((access(fname,F_OK))!=-1)
  13755. {
  13756. fptr1 = fopen(fname, "r");
  13757. c = 0;
  13758. c = fgetc(fptr1);
  13759. //DEBUG_INFO("c:%d\n",c);
  13760. rewind(fptr1);
  13761. if(c == EOF)
  13762. {
  13763. DEBUG_INFO("\n End of file reached.");
  13764. TxProfileIsNull=TRUE;
  13765. fclose(fptr1);
  13766. }
  13767. else
  13768. {
  13769. TxProfileIsNull=FALSE;
  13770. while(fscanf(fptr1, "%s", word) != EOF)
  13771. {
  13772. if(strcmp(word, "chargingProfileId") == 0)
  13773. {
  13774. n_chargingProfile = n_chargingProfile + 1;
  13775. }
  13776. }
  13777. rewind(fptr1);
  13778. //search Charging Profile Element
  13779. int i= 0;
  13780. int j= 0;
  13781. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13782. #if 0
  13783. /***********connectorId****************/
  13784. c = 0;
  13785. loc = strstr(sLineWord, "connectorId");
  13786. memset(sstr ,0, sizeof(sstr) );
  13787. while (loc[strlen("connectorId")+2+c] != ',')
  13788. {
  13789. sstr[c] = loc[strlen("connectorId")+2+c];
  13790. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13791. c++;
  13792. }
  13793. sstr[c] = '\0';
  13794. tempconnectorIdInt = atoi(sstr);
  13795. #endif
  13796. //***********chargingProfileId**************/
  13797. c = 0;
  13798. loc = strstr(sLineWord, "chargingProfileId");
  13799. memset(sstr ,0, sizeof(sstr) );
  13800. if(loc != NULL)
  13801. {
  13802. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13803. {
  13804. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13805. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13806. c++;
  13807. }
  13808. sstr[c] = '\0';
  13809. tempchargingProfileId = atoi(sstr);
  13810. }
  13811. else
  13812. {
  13813. tempchargingProfileId = 0;
  13814. }
  13815. //***********transactionId **************/
  13816. c = 0;
  13817. loc = strstr(sLineWord, "transactionId");
  13818. //DEBUG_INFO("loc=%s\n",loc);
  13819. memset(sstr ,0, sizeof(sstr) );
  13820. if(loc != NULL)
  13821. {
  13822. while (loc[2+strlen("transactionId")+c] != '\"')
  13823. {
  13824. sstr[c] = loc[2+strlen("transactionId")+c];
  13825. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13826. c++;
  13827. }
  13828. sstr[c] = '\0';
  13829. temptransactionId = atoi(sstr);
  13830. }
  13831. else
  13832. {
  13833. temptransactionId = 0;
  13834. }
  13835. //***********stackLevel**************/
  13836. c = 0;
  13837. loc = strstr(sLineWord, "stackLevel");
  13838. //DEBUG_INFO("loc=%s\n",loc);
  13839. memset(sstr ,0, sizeof(sstr) );
  13840. if(loc != NULL)
  13841. {
  13842. while (loc[2+strlen("stackLevel")+c] != '\"')
  13843. {
  13844. sstr[c] = loc[2+strlen("stackLevel")+c];
  13845. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13846. c++;
  13847. }
  13848. sstr[c] = '\0';
  13849. tempstackLevel = atoi(sstr);
  13850. }
  13851. else
  13852. {
  13853. tempstackLevel = 0;
  13854. }
  13855. //***********chargingProfilePurpose **************/
  13856. c = 0;
  13857. loc = strstr(sLineWord, "chargingProfilePurpose");
  13858. //DEBUG_INFO("loc=%s\n",loc);
  13859. memset(sstr ,0, sizeof(sstr) );
  13860. if(loc != NULL)
  13861. {
  13862. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13863. {
  13864. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13865. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13866. c++;
  13867. }
  13868. sstr[c] = '\0';
  13869. strcpy(tempchargingProfilePurposeStr,sstr);
  13870. }
  13871. else
  13872. {
  13873. strcpy(tempchargingProfilePurposeStr,"");
  13874. }
  13875. //***********chargingProfileKind **************/
  13876. c = 0;
  13877. loc = strstr(sLineWord, "chargingProfileKind");
  13878. //DEBUG_INFO("loc=%s\n",loc);
  13879. memset(sstr ,0, sizeof(sstr) );
  13880. if(loc != NULL)
  13881. {
  13882. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13883. {
  13884. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13885. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13886. c++;
  13887. }
  13888. sstr[c] = '\0';
  13889. strcpy(tempchargingProfileKindStr,sstr);
  13890. }
  13891. else
  13892. {
  13893. strcpy(tempchargingProfileKindStr,"");
  13894. }
  13895. //***********recurrencyKind **************/
  13896. c = 0;
  13897. loc = strstr(sLineWord, "recurrencyKind");
  13898. //DEBUG_INFO("loc=%s\n",loc);
  13899. memset(sstr ,0, sizeof(sstr) );
  13900. if(loc != NULL)
  13901. {
  13902. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13903. {
  13904. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13905. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13906. c++;
  13907. }
  13908. sstr[c] = '\0';
  13909. strcpy(temprecurrencyKindStr,sstr);
  13910. }
  13911. else
  13912. {
  13913. strcpy(temprecurrencyKindStr,"");
  13914. }
  13915. //***********validFrom**************/
  13916. c = 0;
  13917. loc = strstr(sLineWord, "validFrom");
  13918. if(loc != NULL)
  13919. {
  13920. memset(sstr ,0, sizeof(sstr) );
  13921. while (loc[3+strlen("validFrom")+c] != '\"')
  13922. {
  13923. sstr[c] = loc[3+strlen("validFrom")+c];
  13924. c++;
  13925. }
  13926. sstr[c] = '\0';
  13927. strcpy(tempvalidFromStr,sstr);
  13928. }
  13929. else
  13930. {
  13931. strcpy(tempvalidFromStr,"");
  13932. }
  13933. //***********validTo**************/
  13934. c = 0;
  13935. loc = strstr(sLineWord, "validTo");
  13936. if(loc != NULL)
  13937. {
  13938. memset(sstr ,0, sizeof(sstr) );
  13939. while (loc[3+strlen("validTo")+c] != '\"')
  13940. {
  13941. sstr[c] = loc[3+strlen("validTo")+c];
  13942. c++;
  13943. }
  13944. sstr[c] = '\0';
  13945. strcpy(tempvalidToStr,sstr);
  13946. }
  13947. else
  13948. {
  13949. strcpy(tempvalidToStr,"");
  13950. }
  13951. //***********duration**************/
  13952. c = 0;
  13953. loc = strstr(sLineWord, "duration");
  13954. //DEBUG_INFO("loc=%s\n",loc);
  13955. memset(sstr ,0, sizeof(sstr) );
  13956. if(loc != NULL)
  13957. {
  13958. while (loc[2+strlen("duration")+c] != '\"')
  13959. {
  13960. sstr[c] = loc[2+strlen("duration")+c];
  13961. c++;
  13962. }
  13963. sstr[c] = '\0';
  13964. tempdurationInt = atoi(sstr);
  13965. }
  13966. else
  13967. {
  13968. tempdurationInt = 0;
  13969. }
  13970. //**********startSchedule**********/
  13971. c = 0;
  13972. loc = strstr(sLineWord, "startSchedule");
  13973. memset(sstr ,0, sizeof(sstr) );
  13974. while (loc[3+strlen("startSchedule")+c] != '\"')
  13975. {
  13976. sstr[c] = loc[3+strlen("startSchedule")+c];
  13977. c++;
  13978. }
  13979. sstr[c] = '\0';
  13980. strcpy(tempstartScheduleStr, sstr);
  13981. strcpy(TxProfileScheduleStr, sstr);
  13982. //**********chargingRateUnit**********/
  13983. c = 0;
  13984. loc = strstr(sLineWord, "chargingRateUnit");
  13985. memset(sstr ,0, sizeof(sstr) );
  13986. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13987. {
  13988. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13989. c++;
  13990. }
  13991. sstr[c] = '\0';
  13992. strcpy(tempchargingRateUnitStr, sstr);
  13993. //**********minChargingRate*******/
  13994. c = 0;
  13995. loc = strstr(sLineWord, "minChargingRate");
  13996. if(loc != NULL)
  13997. {
  13998. memset(sstr ,0, sizeof(sstr) );
  13999. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14000. {
  14001. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14002. c++;
  14003. }
  14004. sstr[c] = '\0';
  14005. tempminChargingRateFloat = atof(sstr);
  14006. }
  14007. else
  14008. {
  14009. tempminChargingRateFloat = 0.0;
  14010. }
  14011. //
  14012. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14013. tp.tm_isdst = -1;
  14014. time_t utc = mktime(&tp);
  14015. time_t t = time(NULL);
  14016. diff_t = difftime(t, utc);
  14017. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14018. //parsing strings to words
  14019. i = 0;
  14020. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14021. loc = loc+3+strlen("chargingSchedulePeriod");
  14022. pch = strtok(loc ,"{");
  14023. while (pch != NULL)
  14024. {
  14025. strcpy(SchedulePeriodList[i], pch);
  14026. pch = strtok (NULL, "{");
  14027. i = i + 1;
  14028. }
  14029. n_SchedulePeriods = i;
  14030. for(int i=0;i<n_SchedulePeriods;i++)
  14031. {
  14032. //*************startPeriod****************/
  14033. c = 0;
  14034. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14035. memset(sstr ,0, sizeof(sstr) );
  14036. while (loc[strlen("startPeriod")+2+c] != ',')
  14037. {
  14038. sstr[c] = loc[strlen("startPeriod")+2+c];
  14039. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14040. c++;
  14041. }
  14042. sstr[c] = '\0';
  14043. tempStartPeriodInt = atoi(sstr);
  14044. //*************limit****************/
  14045. c = 0;
  14046. loc = strstr(SchedulePeriodList[i], "limit");
  14047. memset(sstr ,0, sizeof(sstr) );
  14048. while (loc[strlen("limit")+2+c] != ',')
  14049. {
  14050. sstr[c] = loc[strlen("limit")+2+c];
  14051. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14052. c++;
  14053. }
  14054. sstr[c] = '\0';
  14055. tempLimitInt = atof(sstr);
  14056. //*************numberPhases****************/
  14057. c = 0;
  14058. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14059. memset(sstr ,0, sizeof(sstr) );
  14060. while (loc[strlen("numberPhases")+2+c] != '}')
  14061. {
  14062. sstr[c] = loc[strlen("numberPhases")+2+c];
  14063. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14064. c++;
  14065. }
  14066. sstr[c] = '\0';
  14067. tempNumberPhasesInt = atoi(sstr);
  14068. //TxProfile.Duration = durationInt;
  14069. TxProfile.TotalPeriod = n_SchedulePeriods;
  14070. TxProfile.Period[i].Limit = tempLimitInt;
  14071. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14072. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14073. }
  14074. if(MinChargingRate < tempminChargingRateFloat)
  14075. {
  14076. MinChargingRate = tempminChargingRateFloat;
  14077. }
  14078. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14079. if(confirmPeriods < n_SchedulePeriods)
  14080. confirmPeriods = n_SchedulePeriods;
  14081. if(j == 0)
  14082. {
  14083. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14084. TxProfile_TEMP.StackLevel = tempstackLevel;
  14085. TxProfile_TEMP.TransactionId = 0;
  14086. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14087. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14088. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14089. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14090. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14091. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14092. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14093. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14094. }
  14095. }
  14096. fclose(fptr1);
  14097. }
  14098. }// the end of ACCESS TxProfile
  14099. //-----------------------------------------------CompositeSchedule--------------------------//
  14100. int period=0;
  14101. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14102. {
  14103. //TxProfile
  14104. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14105. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14106. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14107. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14108. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14109. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14110. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14111. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14112. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14113. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14114. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14115. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14116. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14117. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14118. {
  14119. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14120. {
  14121. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14122. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14123. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14124. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14125. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14126. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14127. period = period + 1;
  14128. }
  14129. else
  14130. {
  14131. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14132. {
  14133. }
  14134. else
  14135. {
  14136. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14137. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14138. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14139. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14140. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14141. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14142. period = period + 1;
  14143. }
  14144. }
  14145. }
  14146. struct tm tp;
  14147. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14148. tp.tm_isdst = -1;
  14149. time_t utc = mktime(&tp);
  14150. time_t t = time(NULL);
  14151. double diff_f = difftime(t, utc);
  14152. int diff_i;// = (int)diff_f;
  14153. int quotient; // = diff_i / 86400;//86400 seconds/day
  14154. if(diff_f >= 0)
  14155. {
  14156. diff_i = (int)diff_f;
  14157. quotient = diff_i / 86400;//86400 seconds/day
  14158. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14159. {
  14160. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  14161. {
  14162. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14163. {
  14164. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14165. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14166. }
  14167. else
  14168. {
  14169. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14170. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14171. }
  14172. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14173. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14174. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14175. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14176. period = period + 1;
  14177. }
  14178. }
  14179. }// end of if(diff_f >= 0)
  14180. }
  14181. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14182. {
  14183. //TxDefaultProfile
  14184. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14185. struct tm tp;
  14186. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14187. tp.tm_isdst = -1;
  14188. time_t utc = mktime(&tp);
  14189. time_t t = time(NULL);
  14190. double diff_f = difftime(t, utc);
  14191. int diff_i;// = (int)diff_f;
  14192. int quotient; // = diff_i / 86400;//86400 seconds/day
  14193. int remainder;
  14194. //---- Define StartSchedule----/
  14195. struct tm *gtime;
  14196. time_t now;
  14197. char buf[28];
  14198. //---Read the current system time---/
  14199. time(&now);
  14200. //---Convert the system time to GMT (now UTC)---/
  14201. gtime = gmtime(&now);
  14202. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14203. if(diff_f >= 0)
  14204. {
  14205. diff_i = (int)diff_f;
  14206. quotient = diff_i / 86400;//86400 seconds/day
  14207. remainder = diff_i % 86400;
  14208. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14209. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14210. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14211. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  14212. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14213. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14214. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14215. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14216. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14217. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14218. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14219. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14220. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14221. {
  14222. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14223. {
  14224. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14225. {
  14226. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14227. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14228. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14229. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14230. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14231. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14232. period = period + 1;
  14233. }
  14234. else
  14235. {
  14236. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14237. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14238. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14239. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14240. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14241. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14242. period = period + 1;
  14243. }
  14244. }
  14245. }
  14246. } // end of diff_f >= 0
  14247. }
  14248. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14249. {
  14250. //TxDefaultProfile
  14251. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14252. struct tm tp;
  14253. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14254. tp.tm_isdst = -1;
  14255. time_t utc = mktime(&tp);
  14256. time_t t = time(NULL);
  14257. double diff_f = difftime(t, utc);
  14258. int diff_i;// = (int)diff_f;
  14259. int quotient; // = diff_i / 86400;//86400 seconds/day
  14260. int remainder;
  14261. //---- Define StartSchedule----/
  14262. struct tm *gtime;
  14263. time_t now;
  14264. char buf[28];
  14265. //---Read the current system time---/
  14266. time(&now);
  14267. //---Convert the system time to GMT (now UTC)---/
  14268. gtime = gmtime(&now);
  14269. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14270. if(diff_f >= 0)
  14271. {
  14272. diff_i = (int)diff_f;
  14273. quotient = diff_i / 86400;//86400 seconds/day
  14274. remainder = diff_i % 86400;
  14275. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14276. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14277. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14278. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14279. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14280. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14281. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14282. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14283. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14284. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  14285. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14286. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14287. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14288. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14289. {
  14290. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14291. {
  14292. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14293. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14294. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14295. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14296. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14297. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14298. period = period + 1;
  14299. }
  14300. }
  14301. } //end of diff_f >= 0
  14302. }
  14303. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14304. {
  14305. //ChargePointMaxProfile
  14306. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14307. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14308. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14309. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14310. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14311. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14312. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14313. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14314. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14315. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14316. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14317. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14318. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14319. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  14320. {
  14321. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14322. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14323. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14324. period = period + 1;
  14325. }
  14326. }
  14327. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14328. {
  14329. //TxProfile Daily
  14330. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14331. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14332. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14333. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14334. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14335. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14336. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14337. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14338. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14339. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14340. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14341. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14342. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14343. for(int l=0; l< TxProfile.TotalPeriod; l++)
  14344. {
  14345. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  14346. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  14347. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  14348. }
  14349. }
  14350. confirmPeriods = period;
  14351. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14352. 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,"
  14353. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14354. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14355. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14356. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14357. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14358. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14359. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14360. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14361. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14362. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14363. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14364. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14365. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14366. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14367. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14368. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14369. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14370. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14371. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14372. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14373. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14374. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14375. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14376. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14377. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14378. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14379. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14380. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14381. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14383. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14384. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14385. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14386. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14387. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14388. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14389. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14390. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14391. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14394. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14395. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14396. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14397. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14398. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14399. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14400. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14401. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14402. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14403. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14404. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14405. }
  14406. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14407. {
  14408. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14409. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14410. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14411. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14412. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14413. }
  14414. int GetWebSocketPingInterval(void)
  14415. {
  14416. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14417. }
  14418. void LWS_Send(char * str)
  14419. {
  14420. //=====================================================
  14421. // Check InternetConn 0: disconnected, 1: connected
  14422. //====================================================
  14423. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14424. {
  14425. DEBUG_INFO("\n offline now !!!\n");
  14426. return;
  14427. }
  14428. pthread_mutex_lock(&lock);
  14429. memset(SendBuffer,0,SendBufLen);
  14430. sprintf((char *)SendBuffer, "%s", str);
  14431. pthread_mutex_unlock(&lock);
  14432. lws_callback_on_writable(wsi_client);
  14433. lws_service(context, 10000);//timeout_ms
  14434. }