MessageHandler.c 609 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "hashmap.h"
  21. #include "ShareMemory.h"
  22. #include "TransactionQueue.h"
  23. #include "define.h"
  24. #include "SystemLogMessage.h"
  25. //#include "config.h"
  26. #include <sys/socket.h>
  27. #include <netinet/in.h>
  28. #include <stdlib.h>
  29. /*for sendfile()*/
  30. #include <sys/sendfile.h>
  31. /*for O_RDONLY*/
  32. #include <fcntl.h>
  33. #include "sqlite3.h"
  34. #include <arpa/inet.h>
  35. //#define _GNU_SOURCE
  36. #include <time.h>
  37. #include "MessageHandler.h"
  38. #include <assert.h>
  39. #include <pthread.h>
  40. #include <mcheck.h>
  41. #define PASS 1
  42. #define FAIL -1
  43. #define FALSE 0
  44. #define TRUE 1 // Option 1
  45. //ChargePointMaxProfile
  46. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  47. //TxDefaultProfile
  48. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  49. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  50. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  51. //TxProfile
  52. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  53. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  54. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  55. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  56. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  57. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  58. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  59. //===================================
  60. // Define CP State constant
  61. //===================================
  62. #define CP_STATE_UNKNOWN 0
  63. #define CP_STATE_A 1
  64. #define CP_STATE_B 2
  65. #define CP_STATE_C 3
  66. #define CP_STATE_D 4
  67. #define CP_STATE_E 5
  68. #define CP_STATE_F 6
  69. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  70. struct StatusCodeData *ShmStatusCodeData;
  71. struct PsuData *ShmPsuData ;
  72. struct OCPP16Data *ShmOCPP16Data;
  73. // define Macro
  74. #define SystemLogMessage
  75. // OCPP Message Type
  76. #define MESSAGE_TYPE_CALL 2
  77. #define MESSAGE_TYPE_CALLRESULT 3
  78. #define MESSAGE_TYPE_CALLERROR 4
  79. //
  80. #define server_cycle_Status 120
  81. #define MACROSTR(k) #k
  82. //ConfigurationMaxKeys
  83. #define GetConfigurationMaxKeysNUM 43
  84. //char guid[37];
  85. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  86. char queuedata[2600]={0};
  87. //===============================
  88. // Configuration: unknownkey
  89. //===============================
  90. static char unknownkey[10][20]={0};
  91. static int UnknownKeynum = 0;
  92. //===============================
  93. // Gun Total Numbers
  94. //===============================
  95. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  96. static int gunTotalNumber=0;
  97. //===============================
  98. // Local List Version
  99. //===============================
  100. static int localversion=0;
  101. static char idTagAuthorization[32]={0};
  102. //===============================
  103. // OCPP Path
  104. //===============================
  105. extern char OcppPath[160];
  106. extern char OcppProtocol[10];
  107. extern char OcppHost[50];
  108. extern char OcppTempPath[50];
  109. int OcppPort=0;
  110. //===============================
  111. // OCPP sign variable
  112. //===============================
  113. int server_sign = FALSE;
  114. int server_pending = FALSE;
  115. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  116. int BootNotificationInterval = 0;
  117. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  118. //===============================
  119. // OCPP auth variable
  120. //===============================
  121. int authenrequest = FALSE;
  122. int authorizeRetryTimes = 0; //number of Retry times
  123. //===============================
  124. // OCPP StartTransaction transactionId variables
  125. //===============================
  126. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  127. //===============================
  128. // OCPP other variables
  129. //===============================
  130. int isUpdateRequest = FALSE;
  131. static int HeartBeatWaitTime = 10;
  132. static int FirstHeartBeat = 0;
  133. static int FirmwareStatusNotificationStatus = 3; // Idle
  134. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  135. static char CurrentChargingProfileScheduleStr[30]={0};
  136. //========================================
  137. // OCPP status/previous related variables
  138. //========================================
  139. static int GunStatusInterval = 10;
  140. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  141. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  142. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  143. static int GbPreviousSystemStatus[GB_QUANTITY];
  144. static int AcPreviousSystemStatus[AC_QUANTITY];
  145. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  146. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  147. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  148. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  149. int TransactionMessageAttemptsValue = 0;
  150. int TransactionMessageRetryIntervalValue = 0;
  151. static struct OCPPAuthLocalElemet
  152. {
  153. int listVersionInt;
  154. char idTagstr[20];
  155. char parentIdTag[20];
  156. char expiryDate[30];
  157. char idTagstatus[16];
  158. }idTagQuery;
  159. //=============================================
  160. // OCPP HeartBeat Response Not Receive Counts
  161. //============================================
  162. static int HeartBeatWithNOResponse = 0;
  163. static int HeartBeatCountPerHour = 0;
  164. extern struct lws *wsi_client;
  165. extern struct lws_context *context;
  166. extern unsigned char SendBuffer[4096];
  167. extern int SendBufLen;
  168. extern char *random_uuid( char buf[37] );
  169. extern void split(char **arr, char *str, const char *del);
  170. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  171. extern int GetTransactionQueueNum(void);
  172. extern pthread_mutex_t mutex1;
  173. extern struct Charger_Info Charger;
  174. extern sqlite3 *db;
  175. int TransactionMessageAttemptsGet(void);
  176. int TransactionMessageRetryIntervalGet(void);
  177. int GetOcppConnStatus(void);
  178. void SetOcppConnStatus(uint8_t status);
  179. int updateSetting(char *key, char *value);
  180. int setKeyValue(char *key, char *value);
  181. void OCPP_get_TableAuthlocalAllData(void);
  182. void processUnkownKey(void);
  183. struct StructOCPPMeterValue
  184. {
  185. unsigned char TimeStamp[28];
  186. struct StructSampledValue SampledValue[10];
  187. };
  188. struct ClientTime
  189. {
  190. unsigned int Heartbeat;
  191. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  192. unsigned int StartTransaction;
  193. unsigned int StopTransaction;
  194. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  195. }clientTime;
  196. typedef union
  197. {
  198. //Operations Initiated by Central System
  199. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  200. struct
  201. {
  202. //CsMsgValue[0]
  203. unsigned char StatusNotificationReq :1; //bit 0,
  204. unsigned char StatusNotificationConf :1; //bit 0,
  205. unsigned char :6; //bit 2~7
  206. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  207. }CpinitiateMsg;
  208. CpinitiateMsg cpinitateMsg;
  209. //==========================================
  210. // Init all Enumeration & Mapping String
  211. //==========================================
  212. /*ChargePointErrorCode*/
  213. typedef enum {
  214. ConnectorLockFailure,
  215. EVCommunicationError,
  216. GroundFailure,
  217. HighTemperature,
  218. InternalError,
  219. LocalListConflict,
  220. NoError,
  221. OtherError,
  222. OverCurrentFailure,
  223. OverVoltage,
  224. PowerMeterFailure,
  225. PowerSwitchFailure,
  226. ReaderFailure,
  227. ResetFailure,
  228. UnderVoltage,
  229. WeakSignal
  230. } ChargePointErrorCode;
  231. #if 0
  232. static char *ChargePointErrorCodeStr[] = {
  233. MACROSTR(ConnectorLockFailure),
  234. MACROSTR(EVCommunicationError),
  235. MACROSTR(GroundFailure),
  236. MACROSTR(HighTemperature),
  237. MACROSTR(InternalError),
  238. MACROSTR(LocalListConflict),
  239. MACROSTR(NoError),
  240. MACROSTR(OtherError),
  241. MACROSTR(OverCurrentFailure),
  242. MACROSTR(OverVoltage),
  243. MACROSTR(PowerMeterFailure),
  244. MACROSTR(PowerSwitchFailure),
  245. MACROSTR(ReaderFailure),
  246. MACROSTR(ResetFailure),
  247. MACROSTR(UnderVoltage),
  248. MACROSTR(WeakSignal)
  249. };
  250. #endif
  251. /*ChargePointStatus*/
  252. typedef enum {
  253. Available =0,
  254. Preparing,
  255. Charging,
  256. SuspendedEVSE,
  257. SuspendedEV,
  258. Finishing,
  259. Reserved,
  260. Unavailable,
  261. Faulted
  262. } ChargePointStatus;
  263. static char * ChargePointStatusStr[] = {
  264. MACROSTR(Available),
  265. MACROSTR(Preparing),
  266. MACROSTR(Charging),
  267. MACROSTR(SuspendedEVSE),
  268. MACROSTR(SuspendedEV),
  269. MACROSTR(Finishing),
  270. MACROSTR(Reserved),
  271. MACROSTR(Unavailable),
  272. MACROSTR(Faulted)
  273. };
  274. /*AvailabilityType*/
  275. typedef enum {
  276. RegistrationStatus_Accepted,
  277. RegistrationStatus_Pending,
  278. RegistrationStatus_Rejected
  279. } RegistrationStatus;
  280. static char *RegistrationStatusStr[] = {
  281. MACROSTR(Accepted),
  282. MACROSTR(Pending),
  283. MACROSTR(Rejected)
  284. };
  285. /*AvailabilityType*/
  286. typedef enum {
  287. Inoperative,
  288. Operative
  289. } AvailabilityType;
  290. static char *AvailabilityTypeStr[] = {
  291. MACROSTR(Inoperative),
  292. MACROSTR(Operative)
  293. };
  294. /*AvailabilityStatus*/
  295. typedef enum {
  296. Accepted,
  297. Rejected,
  298. Scheduled
  299. } AvailabilityStatus;
  300. static char *AvailabilityStatusStr[] = {
  301. MACROSTR(Accepted),
  302. MACROSTR(Rejected),
  303. MACROSTR(Scheduled)
  304. };
  305. /*ConfigurationStatus*/
  306. typedef enum {
  307. ConfigurationStatus_Accepted,
  308. ConfigurationStatus_Rejected,
  309. RebootRequired,
  310. NotSupported
  311. } ConfigurationStatus;
  312. static char *ConfigurationStatusStr[] = {
  313. MACROSTR(Accepted),
  314. MACROSTR(Rejected),
  315. MACROSTR(RebootRequired),
  316. MACROSTR(NotSupported)
  317. };
  318. /*ClearCacheStatus*/
  319. typedef enum {
  320. ClearCacheStatus_Accepted,
  321. ClearCacheStatus_Rejected
  322. } ClearCacheStatus;
  323. static char *ClearCacheStatusStr[] = {
  324. MACROSTR(Accepted),
  325. MACROSTR(Rejected)
  326. };
  327. /*ChargingProfilePurposeType*/
  328. typedef enum {
  329. ChargePointMaxProfile,
  330. TxDefaultProfile,
  331. TxProfile
  332. } ChargingProfilePurposeType;
  333. static char *ChargingProfilePurposeTypeStr[] = {
  334. MACROSTR(ChargePointMaxProfile),
  335. MACROSTR(TxDefaultProfile),
  336. MACROSTR(TxProfile)
  337. };
  338. /*ChargingProfileStatus*/
  339. typedef enum {
  340. ChargingProfileStatus_Accepted,
  341. ChargingProfileStatus_Rejected,
  342. ChargingProfileStatus_NotSupported
  343. } ChargingProfileStatus;
  344. static char *ChargingProfileStatusStr[] = {
  345. MACROSTR(Accepted),
  346. MACROSTR(Rejected),
  347. MACROSTR(NotSupported)
  348. };
  349. /*ClearChargingProfileStatus*/
  350. typedef enum {
  351. ClearChargingProfileStatus_Accepted,
  352. ClearChargingProfileStatus_Unknown
  353. } ClearChargingProfileStatus;
  354. static char *ClearChargingProfileStatusStr[] = {
  355. MACROSTR(Accepted),
  356. MACROSTR(Unknown)
  357. };
  358. /*GetCompositeScheduleStatus*/
  359. typedef enum {
  360. GetCompositeScheduleStatus_Accepted,
  361. GetCompositeScheduleStatus_Rejected
  362. } GetCompositeScheduleStatus;
  363. static char *GetCompositeScheduleStatusStr[] = {
  364. MACROSTR(Accepted),
  365. MACROSTR(Rejected)
  366. };
  367. /*ChargingRateUnitType*/
  368. typedef enum {
  369. ChargingRateUnitType_W,
  370. ChargingRateUnitType_A
  371. } ChargingRateUnitType;
  372. /*AuthorizationStatus*/
  373. typedef enum {
  374. AuthorizationStatus_Accepted ,
  375. AuthorizationStatus_Blocked ,
  376. AuthorizationStatus_Expired ,
  377. AuthorizationStatus_Invalid ,
  378. AuthorizationStatus_ConcurrentTx
  379. } AuthorizationStatus;
  380. /*UpdateType*/
  381. typedef enum {
  382. Differential ,
  383. Full
  384. } UpdateType;
  385. static char *UpdateTypeStr[] = {
  386. MACROSTR(Differential),
  387. MACROSTR(Full)
  388. };
  389. /*UpdateStatus*/
  390. typedef enum {
  391. UpdateStatus_Accepted ,
  392. UpdateStatus_Failed ,
  393. UpdateStatus_NotSupported ,
  394. UpdateStatus_VersionMismatch
  395. } UpdateStatus;
  396. static char *UpdateStatusStr[] = {
  397. MACROSTR(Accepted),
  398. MACROSTR(Failed),
  399. MACROSTR(NotSupported),
  400. MACROSTR(VersionMismatch)
  401. };
  402. /*RemoteStartStopStatus*/
  403. typedef enum {
  404. RemoteStartStopStatus_Accepted,
  405. RemoteStartStopStatus_Rejected
  406. } RemoteStartStopStatus;
  407. static char *RemoteStartStopStatusStr[] = {
  408. MACROSTR(Accepted),
  409. MACROSTR(Rejected)
  410. };
  411. /*ReservationStatus*/
  412. typedef enum {
  413. ReservationStatus_Accepted,
  414. ReservationStatus_Faulted,
  415. ReservationStatus_Occupied,
  416. ReservationStatus_Rejected,
  417. ReservationStatus_Unavailable
  418. } ReservationStatus;
  419. static char *ReservationStatusStr[] = {
  420. MACROSTR(Accepted),
  421. MACROSTR(Faulted),
  422. MACROSTR(Occupied),
  423. MACROSTR(Rejected),
  424. MACROSTR(Unavailable)
  425. };
  426. /*ResetType*/
  427. typedef enum {
  428. Hard,
  429. Soft
  430. } ResetType;
  431. static char *ResetTypeStr[] = {
  432. MACROSTR(Hard),
  433. MACROSTR(Soft)
  434. };
  435. /*ResetStatus*/
  436. typedef enum {
  437. ResetStatus_Accepted,
  438. ResetStatus_Rejected
  439. } ResetStatus;
  440. static char *ResetStatusStr[] = {
  441. MACROSTR(Accepted),
  442. MACROSTR(Rejected)
  443. };
  444. /*DiagnosticsStatus*/
  445. typedef enum {
  446. DiagnosticsStatus_Idle,
  447. DiagnosticsStatus_Uploaded,
  448. DiagnosticsStatus_UploadFailed,
  449. DiagnosticsStatus_Uploading
  450. } DiagnosticsStatus;
  451. static char * DiagnosticsStatusStr[] = {
  452. MACROSTR(Idle),
  453. MACROSTR(Uploaded),
  454. MACROSTR(UploadFailed),
  455. MACROSTR(Uploading)
  456. };
  457. /*FirmwareStatus*/
  458. typedef enum {
  459. FirmwareStatus_Downloaded,
  460. FirmwareStatus_DownloadFailed,
  461. FirmwareStatus_Downloading,
  462. FirmwareStatus_Idle,
  463. FirmwareStatus_InstallationFailed,
  464. FirmwareStatus_Installing,
  465. FirmwareStatus_Installed
  466. } FirmwareStatus;
  467. static char * FirmwareStatusStr[] = {
  468. MACROSTR(Downloaded),
  469. MACROSTR(DownloadFailed),
  470. MACROSTR(Downloading),
  471. MACROSTR(Idle),
  472. MACROSTR(InstallationFailed),
  473. MACROSTR(Installing),
  474. MACROSTR(Installed)
  475. };
  476. /*MessageTrigger*/
  477. typedef enum {
  478. BootNotification,
  479. DiagnosticsStatusNotification,
  480. FirmwareStatusNotification,
  481. Heartbeat,
  482. MeterValues,
  483. StatusNotification
  484. } MessageTrigger;
  485. static char * MessageTriggerStr[] = {
  486. MACROSTR(BootNotification),
  487. MACROSTR(DiagnosticsStatusNotification),
  488. MACROSTR(FirmwareStatusNotification),
  489. MACROSTR(Heartbeat),
  490. MACROSTR(MeterValues),
  491. MACROSTR(StatusNotification)
  492. };
  493. /*TriggerMessageStatus*/
  494. typedef enum {
  495. TriggerMessageStatus_Accepted ,
  496. TriggerMessageStatus_Rejected ,
  497. TriggerMessageStatus_NotImplemented
  498. } TriggerMessageStatus;
  499. static char * TriggerMessageStatusStr[] = {
  500. MACROSTR(Accepted),
  501. MACROSTR(Rejected),
  502. MACROSTR(NotImplemented)
  503. };
  504. /*UnlockStatus*/
  505. typedef enum {
  506. Unlocked,
  507. UnlockFailed,
  508. UnlockStatus_NotSupported
  509. } UnlockStatus;
  510. static char * UnlockStatusStr[] = {
  511. MACROSTR(Unlocked),
  512. MACROSTR(UnlockFailed),
  513. MACROSTR(NotSupported)
  514. };
  515. /*StopTransactionReason*/
  516. typedef enum {
  517. EmergencyStop,
  518. EVDisconnected,
  519. HardReset,
  520. Local,
  521. Other,
  522. PowerLoss,
  523. Reboot,
  524. Remote,
  525. SoftReset,
  526. UnlockCommand,
  527. DeAuthorized
  528. } StopTransactionReason;
  529. #if 0
  530. static char * StopTransactionReasonStr[] = {
  531. MACROSTR(EmergencyStop),
  532. MACROSTR(EVDisconnected),
  533. MACROSTR(HardReset),
  534. MACROSTR(Local),
  535. MACROSTR(Other),
  536. MACROSTR(PowerLoss),
  537. MACROSTR(Reboot),
  538. MACROSTR(Remote),
  539. MACROSTR(SoftReset),
  540. MACROSTR(UnlockCommand),
  541. MACROSTR(DeAuthorized)
  542. };
  543. #endif
  544. /*CancelReservationStatus*/
  545. typedef enum {
  546. CancelReservationStatus_Accepted,
  547. CancelReservationStatus_Rejected
  548. } CancelReservationStatus;
  549. static char * CancelReservationStatusStr[] = {
  550. MACROSTR(Accepted),
  551. MACROSTR(Rejected)
  552. };
  553. /*ReadingContext*/
  554. typedef enum {
  555. ReadingContext_Interruption_Begin,
  556. ReadingContext_Interruption_End,
  557. ReadingContext_Other,
  558. ReadingContext_Sample_Clock,
  559. ReadingContext_Sample_Periodic ,
  560. ReadingContext_Transaction_Begin ,
  561. ReadingContext_Transaction_End,
  562. ReadingContext_Trigger
  563. } ReadingContext;
  564. static char * ReadingContextStr[] = {
  565. MACROSTR(Interruption.Begin),
  566. MACROSTR(Interruption.End),
  567. MACROSTR(Other),
  568. MACROSTR(Sample.Clock),
  569. MACROSTR(Sample.Periodic),
  570. MACROSTR(Transaction.Begin),
  571. MACROSTR(Transaction.End),
  572. MACROSTR(Trigger)
  573. };
  574. /*ValueFormat*/
  575. typedef enum {
  576. Raw,
  577. SignedData
  578. } ValueFormat;
  579. static char * ValueFormatStr[] = {
  580. MACROSTR(Raw),
  581. MACROSTR(SignedData)
  582. };
  583. /*Measurand*/
  584. typedef enum {
  585. Current_Export ,
  586. Current_Import,
  587. Current_Offered,
  588. Energy_Active_Export_Register,
  589. Energy_Active_Import_Register,
  590. Energy_Reactive_Export_Register,
  591. Energy_Reactive_Import_Register,
  592. Energy_Active_Export_Interval,
  593. Energy_Active_Import_Interval,
  594. Energy_Reactive_Export_Interval,
  595. Energy_Reactive_Import_Interval,
  596. Frequency,
  597. Power_Active_Export ,
  598. Power_Active_Import,
  599. Power_Factor,
  600. Power_Offered,
  601. Power_Reactive_Export,
  602. Power_Reactive_Import,
  603. RPM,
  604. SoC,
  605. Temperature ,
  606. Voltage
  607. } Measurand;
  608. static char * MeasurandStr[] = {
  609. MACROSTR(Current.Export),
  610. MACROSTR(Current.Import),
  611. MACROSTR(Current.Offered),
  612. MACROSTR(Energy.Active.Export.Register),
  613. MACROSTR(Energy.Active.Import.Register),
  614. MACROSTR(Energy.Reactive.Export.Register),
  615. MACROSTR(Energy.Reactive.Import.Register),
  616. MACROSTR(Energy.Active.Export.Interval),
  617. MACROSTR(Energy.Active.Import.Interval),
  618. MACROSTR(Energy.Reactive.Export.Interval),
  619. MACROSTR(Energy.Reactive.Import.Interval),
  620. MACROSTR(Frequency),
  621. MACROSTR(Power.Active.Export),
  622. MACROSTR(Power.Active.Import),
  623. MACROSTR(Power.Factor),
  624. MACROSTR(Power.Offered),
  625. MACROSTR(Power.Reactive.ExportMACROSTR),
  626. MACROSTR(Power.Reactive.Import),
  627. MACROSTR(RPM),
  628. MACROSTR(SoC),
  629. MACROSTR(Temperature),
  630. MACROSTR(Voltage)
  631. };
  632. /*Location*/
  633. typedef enum {
  634. Location_Body,
  635. Location_Cable,
  636. Location_EV,
  637. Location_Inlet ,
  638. Location_Outlet
  639. } Location;
  640. static char * LocationStr[] = {
  641. MACROSTR(Body),
  642. MACROSTR(Cable),
  643. MACROSTR(EV),
  644. MACROSTR(Inlet),
  645. MACROSTR(Outlet)
  646. };
  647. /*Phase*/
  648. typedef enum {
  649. L1,
  650. L2,
  651. L3,
  652. N,
  653. L1_N,
  654. L2_N,
  655. L3_N,
  656. L1_L2,
  657. L2_L3,
  658. L3_L1
  659. } Phase;
  660. static char * PhaseStr[] = {
  661. MACROSTR(L1),
  662. MACROSTR(L2),
  663. MACROSTR(L3),
  664. MACROSTR(N),
  665. MACROSTR(L1-N),
  666. MACROSTR(L2-N),
  667. MACROSTR(L3-N),
  668. MACROSTR(L1-L2),
  669. MACROSTR(L2-L3),
  670. MACROSTR(L3-L1)
  671. };
  672. /*UnitOfMeasure*/
  673. typedef enum {
  674. UnitOfMeasure_Wh,
  675. UnitOfMeasure_kWh ,
  676. UnitOfMeasure_varh ,
  677. UnitOfMeasure_kvarh ,
  678. UnitOfMeasure_W ,
  679. UnitOfMeasure_kW ,
  680. UnitOfMeasure_VA ,
  681. UnitOfMeasure_kVA ,
  682. UnitOfMeasure_var ,
  683. UnitOfMeasure_kvar ,
  684. UnitOfMeasure_A ,
  685. UnitOfMeasure_V ,
  686. UnitOfMeasure_Celsius ,
  687. UnitOfMeasure_Fahrenheit ,
  688. UnitOfMeasure_K ,
  689. UnitOfMeasure_Percent
  690. } UnitOfMeasure;
  691. static char * UnitOfMeasureStr[] = {
  692. MACROSTR(Wh),
  693. MACROSTR(kWh),
  694. MACROSTR(varh),
  695. MACROSTR(kvarh),
  696. MACROSTR(W),
  697. MACROSTR(kW),
  698. MACROSTR(VA),
  699. MACROSTR(kVA),
  700. MACROSTR(var),
  701. MACROSTR(kvar),
  702. MACROSTR(A),
  703. MACROSTR(V),
  704. MACROSTR(Celsius),
  705. MACROSTR(Fahrenheit),
  706. MACROSTR(K),
  707. MACROSTR(Percent)
  708. };
  709. #if 0
  710. /*Configuration enum*/
  711. enum CoreProfile {
  712. AllowOfflineTxForUnknownId=0,
  713. AuthorizationCacheEnabled,
  714. AuthorizeRemoteTxRequests,
  715. BlinkRepeat,
  716. ClockAlignedDataInterval,
  717. ConnectionTimeOut,
  718. GetConfigurationMaxKeys,
  719. HeartbeatInterval,
  720. LightIntensity,
  721. LocalAuthorizeOffline,
  722. LocalPreAuthorize,
  723. MaxEnergyOnInvalidId,
  724. MeterValuesAlignedData,
  725. MeterValuesAlignedDataMaxLength,
  726. MeterValuesSampledData,
  727. MeterValuesSampledDataMaxLength,
  728. MeterValueSampleInterval,
  729. MinimumStatusDuration,
  730. NumberOfConnectors,
  731. ResetRetries,
  732. ConnectorPhaseRotation,
  733. ConnectorPhaseRotationMaxLength,
  734. StopTransactionOnEVSideDisconnect,
  735. StopTransactionOnInvalidId,
  736. StopTxnAlignedData,
  737. StopTxnAlignedDataMaxLength,
  738. StopTxnSampledData,
  739. StopTxnSampledDataMaxLength,
  740. SupportedFeatureProfiles,
  741. SupportedFeatureProfilesMaxLength,
  742. TransactionMessageAttempts,
  743. TransactionMessageRetryInterval,
  744. UnlockConnectorOnEVSideDisconnect,
  745. WebSocketPingInterval,
  746. _CoreProfile_CNT
  747. };
  748. #endif
  749. enum LocalAuthListManagementProfile{
  750. LocalAuthListEnabled=0,
  751. LocalAuthListMaxLength,
  752. SendLocalListMaxLength,
  753. _LocalAuthListManagementProfile_CNT
  754. };
  755. enum ReservationProfile{
  756. ReserveConnectorZeroSupported
  757. };
  758. enum SmartChargingProfile{
  759. ChargeProfileMaxStackLevel,
  760. ChargingScheduleAllowedChargingRateUnit,
  761. ChargingScheduleMaxPeriods,
  762. ConnectorSwitch3to1PhaseSupported,
  763. MaxChargingProfilesInstalled
  764. };
  765. enum ChargerSystemStatus{
  766. ChargerSystemStatus_Booting,
  767. ChargerSystemStatus_Idle,
  768. ChargerSystemStatus_Authorizing,
  769. ChargerSystemStatus_Preparing,
  770. ChargerSystemStatus_Charging,
  771. ChargerSystemStatus_Terminating,
  772. ChargerSystemStatus_Alarm,
  773. ChargerSystemStatus_Fault
  774. };
  775. enum GetConfigurationKey {
  776. GetConfiguration_AllowOfflineTxForUnknownId=0,
  777. GetConfiguration_AuthorizationCacheEnabled,
  778. GetConfiguration_AuthorizeRemoteTxRequests,
  779. GetConfiguration_BlinkRepeat,
  780. GetConfiguration_ClockAlignedDataInterval,
  781. GetConfiguration_ConnectionTimeOut,
  782. GetConfiguration_GetConfigurationMaxKeys,
  783. GetConfiguration_HeartbeatInterval,
  784. GetConfiguration_LightIntensity,
  785. GetConfiguration_LocalAuthorizeOffline,
  786. GetConfiguration_LocalPreAuthorize,
  787. GetConfiguration_MaxEnergyOnInvalidId,
  788. GetConfiguration_MeterValuesAlignedData,
  789. GetConfiguration_MeterValuesAlignedDataMaxLength,
  790. GetConfiguration_MeterValuesSampledData,
  791. GetConfiguration_MeterValuesSampledDataMaxLength,
  792. GetConfiguration_MeterValueSampleInterval,
  793. GetConfiguration_MinimumStatusDuration,
  794. GetConfiguration_NumberOfConnectors,
  795. GetConfiguration_ResetRetries,
  796. GetConfiguration_ConnectorPhaseRotation,
  797. GetConfiguration_ConnectorPhaseRotationMaxLength,
  798. GetConfiguration_StopTransactionOnEVSideDisconnect,
  799. GetConfiguration_StopTransactionOnInvalidId,
  800. GetConfiguration_StopTxnAlignedData,
  801. GetConfiguration_StopTxnAlignedDataMaxLength,
  802. GetConfiguration_StopTxnSampledData,
  803. GetConfiguration_StopTxnSampledDataMaxLength,
  804. GetConfiguration_SupportedFeatureProfiles,
  805. GetConfiguration_SupportedFeatureProfilesMaxLength,
  806. GetConfiguration_TransactionMessageAttempts,
  807. GetConfiguration_TransactionMessageRetryInterval,
  808. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  809. GetConfiguration_WebSocketPingInterval,
  810. GetConfiguration_LocalAuthListEnabled,
  811. GetConfiguration_LocalAuthListMaxLength,
  812. GetConfiguration_SendLocalListMaxLength,
  813. GetConfiguration_ReserveConnectorZeroSupported,
  814. GetConfiguration_ChargeProfileMaxStackLevel,
  815. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  816. GetConfiguration_ChargingScheduleMaxPeriods,
  817. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  818. GetConfiguration_MaxChargingProfilesInstalled,
  819. };
  820. //GetConfiguration Array
  821. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  822. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  823. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  824. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  825. //==========================================
  826. // Init all share memory
  827. //==========================================
  828. int InitShareMemory()
  829. {
  830. int result = PASS;
  831. int MeterSMId;
  832. //creat ShmSysConfigAndInfo
  833. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  834. {
  835. #ifdef SystemLogMessage
  836. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  837. #endif
  838. result = FAIL;
  839. }
  840. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  841. {
  842. #ifdef SystemLogMessage
  843. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  844. #endif
  845. result = FAIL;
  846. }
  847. else
  848. {}
  849. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  850. {
  851. #ifdef SystemLogMessage
  852. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  853. #endif
  854. result = FAIL;
  855. }
  856. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  857. {
  858. #ifdef SystemLogMessage
  859. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  860. #endif
  861. result = FAIL;
  862. }
  863. else
  864. {}
  865. //creat ShmPsuData
  866. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  867. {
  868. #ifdef SystemLogMessage
  869. DEBUG_ERROR("shmget ShmPsuData NG\n");
  870. #endif
  871. result = FAIL;
  872. }
  873. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  874. {
  875. #ifdef SystemLogMessage
  876. DEBUG_ERROR("shmat ShmPsuData NG\n");
  877. #endif
  878. result = FAIL;
  879. }
  880. else
  881. {}
  882. //creat ShmOCPP16Data
  883. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  884. {
  885. #ifdef SystemLogMessage
  886. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  887. #endif
  888. result = FAIL;
  889. }
  890. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  891. {
  892. #ifdef SystemLogMessage
  893. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  894. #endif
  895. result = FAIL;
  896. }
  897. else
  898. {}
  899. /****************************** For Initial Settings************************************************/
  900. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  901. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  902. {
  903. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  904. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  905. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  906. }
  907. // Charger PRE_SYS_MODE
  908. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  909. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  910. clientTime.Heartbeat=time((time_t*)NULL);
  911. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  912. {
  913. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  914. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  915. }
  916. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  917. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  918. // allocate Configuration memory address
  919. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  920. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  921. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  922. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  923. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  924. {
  925. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  926. DEBUG_INFO("DC ...\n");
  927. }
  928. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  929. {
  930. SystemInitial = AC_QUANTITY;
  931. DEBUG_INFO("AC ...\n");
  932. }
  933. //Status / ConnectorPlugIn Setting
  934. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  935. {
  936. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  937. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  938. }
  939. for (int index = 0; index < CCS_QUANTITY; index++)
  940. {
  941. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  942. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  943. }
  944. for (int index = 0; index < GB_QUANTITY; index++)
  945. {
  946. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  947. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  948. }
  949. for (int index = 0; index < AC_QUANTITY; index++)
  950. {
  951. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  952. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  953. }
  954. return result;
  955. }
  956. int ProcessShareMemory()
  957. {
  958. if(InitShareMemory() == FAIL)
  959. {
  960. #ifdef SystemLogMessage
  961. DEBUG_ERROR("InitShareMemory NG\n");
  962. #endif
  963. if(ShmStatusCodeData!=NULL)
  964. {
  965. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  966. }
  967. sleep(5);
  968. return FAIL;
  969. }
  970. return PASS;
  971. }
  972. //---------------------------------------------
  973. // new:
  974. // enum SYSTEM_STATUS
  975. // {
  976. // SYS_MODE_BOOTING = 0,
  977. // SYS_MODE_IDLE = 1,
  978. // SYS_MODE_AUTHORIZING = 2,
  979. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  980. // SYS_MODE_REASSIGN = 4,
  981. // SYS_MODE_PREPARING = 5,
  982. // SYS_MODE_PREPARE_FOR_EV = 6,
  983. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  984. // SYS_MODE_CHARGING = 8,
  985. // SYS_MODE_TERMINATING = 9,
  986. // SYS_MODE_COMPLETE = 10,
  987. // SYS_MODE_ALARM = 11,
  988. // SYS_MODE_FAULT = 12,
  989. // SYS_MODE_RESERVATION = 13,
  990. // SYS_MODE_BOOKING = 14,
  991. // SYS_MODE_MAINTAIN = 15,
  992. // SYS_MODE_DEBUG = 16,
  993. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  994. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  995. // SYS_MODE_UPDATE = 19
  996. // };
  997. //
  998. //
  999. //-----------------------------------------
  1000. void CheckSystemValue(void)
  1001. {
  1002. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1003. int IdleModeCnt = 0;
  1004. char filenmae[100]={0};
  1005. char str[100]={0};
  1006. //===============================
  1007. // send Heartbeat
  1008. //===============================
  1009. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1010. {
  1011. printf("Heartbeat !!!\n");
  1012. //parameter for test
  1013. sendHeartbeatRequest(0);
  1014. //==============================================
  1015. // Reset Waiting Time
  1016. //==============================================
  1017. clientTime.Heartbeat=time((time_t*)NULL);
  1018. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1019. }
  1020. //==============================================
  1021. // Update firmware request
  1022. //==============================================
  1023. if(isUpdateRequest == TRUE )
  1024. {
  1025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1026. {
  1027. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1028. {
  1029. //check SystemStatus
  1030. /*************************DC*******************************/
  1031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1032. {
  1033. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1034. {
  1035. IdleModeCnt = IdleModeCnt + 1;
  1036. }
  1037. }
  1038. for (int index = 0; index < CCS_QUANTITY; index++)
  1039. {
  1040. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1041. {
  1042. IdleModeCnt = IdleModeCnt + 1;
  1043. }
  1044. }
  1045. for (int index = 0; index < GB_QUANTITY; index++)
  1046. {
  1047. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1048. {
  1049. IdleModeCnt = IdleModeCnt + 1;
  1050. }
  1051. }
  1052. }
  1053. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1054. {
  1055. isUpdateRequest = FALSE;
  1056. }
  1057. }
  1058. else
  1059. {
  1060. /*************************AC*******************************/
  1061. for (int index = 0; index < AC_QUANTITY; index++)
  1062. {
  1063. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1064. {
  1065. IdleModeCnt = IdleModeCnt + 1;
  1066. }
  1067. }
  1068. if(IdleModeCnt == AC_QUANTITY)
  1069. {
  1070. isUpdateRequest = FALSE;
  1071. }
  1072. }
  1073. }
  1074. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1075. {
  1076. //===============================
  1077. // CSU Trigger Reset Conf
  1078. //===============================
  1079. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1080. {
  1081. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1082. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1083. {
  1084. server_sign = FALSE;
  1085. }
  1086. }
  1087. //===============================
  1088. // CSU Trigger Authorize Request
  1089. //===============================
  1090. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1091. {
  1092. sendAuthorizeRequest(0);
  1093. authorizeRetryTimes = authorizeRetryTimes + 1;
  1094. if(authorizeRetryTimes < 3)
  1095. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1096. }
  1097. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1098. {
  1099. authorizeRetryTimes = 0;
  1100. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1101. server_sign = FALSE;
  1102. }
  1103. 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))
  1104. {
  1105. sendAuthorizeRequest(0);
  1106. }
  1107. //===============================
  1108. // CSU Trigger Smart Charging Profilw
  1109. //===============================
  1110. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1111. {
  1112. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1113. GetChargingProfileRequest(gun_index);
  1114. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1115. }
  1116. //==============================================
  1117. // Charger start transaction
  1118. //==============================================
  1119. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1120. {
  1121. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1122. sendStartTransactionRequest(gun_index);
  1123. clientTime.StartTransaction = time((time_t*)NULL);
  1124. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1125. }
  1126. //==============================================
  1127. // Charger stop transaction
  1128. //==============================================
  1129. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1130. {
  1131. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1132. sendStopTransactionRequest(gun_index);
  1133. clientTime.StopTransaction = time((time_t*)NULL);
  1134. }
  1135. //==============================================
  1136. // Charger status report
  1137. //==============================================
  1138. /* Check Mode Change */
  1139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1140. {
  1141. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1142. {
  1143. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1144. {
  1145. 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]*/ )
  1146. {
  1147. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1148. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1149. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1150. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1151. statusModeChage[gun_index] = TRUE;
  1152. }
  1153. }
  1154. }
  1155. for (int index = 0; index < CCS_QUANTITY; index++)
  1156. {
  1157. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1158. {
  1159. 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]*/ )
  1160. {
  1161. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1162. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1163. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1164. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1165. statusModeChage[gun_index] = TRUE;
  1166. }
  1167. }
  1168. }
  1169. for (int index = 0; index < GB_QUANTITY; index++)
  1170. {
  1171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1172. {
  1173. 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]*/ )
  1174. {
  1175. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1176. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1177. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1178. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1179. statusModeChage[gun_index] = TRUE;
  1180. }
  1181. }
  1182. }
  1183. }
  1184. else //AC
  1185. {
  1186. for (int index = 0; index < AC_QUANTITY; index++)
  1187. {
  1188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1189. {
  1190. 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]*/ )
  1191. {
  1192. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1193. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1194. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1195. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1196. statusModeChage[gun_index] = TRUE;
  1197. }
  1198. }
  1199. }// END OF FOR
  1200. }// END OF ELSE
  1201. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1202. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1203. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1204. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1205. {
  1206. if(SystemInitial != 0)
  1207. SystemInitial = SystemInitial -1;
  1208. sendStatusNotificationRequest(gun_index);
  1209. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1210. statusModeChage[gun_index] = FALSE;
  1211. }
  1212. //==============================================
  1213. // Meter report
  1214. //==============================================
  1215. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1216. {
  1217. //check Transaction active
  1218. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1219. {
  1220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1221. {
  1222. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1223. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1224. {
  1225. meterValueSend[gun_index] =1;
  1226. }
  1227. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1228. {
  1229. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1230. if((access(filenmae,F_OK))!=-1)
  1231. {
  1232. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1233. sprintf(str,"rm -f %s",filenmae);
  1234. system(str);
  1235. }
  1236. }
  1237. }// End for CHAdeMO
  1238. for (int index = 0; index < CCS_QUANTITY; index++)
  1239. {
  1240. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1241. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1242. {
  1243. meterValueSend[gun_index] =1;
  1244. }
  1245. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1246. {
  1247. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1248. if((access(filenmae,F_OK))!=-1)
  1249. {
  1250. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1251. sprintf(str,"rm -f %s",filenmae);
  1252. system(str);
  1253. }
  1254. }
  1255. } // End for CCS
  1256. for (int index = 0; index < GB_QUANTITY; index++)
  1257. {
  1258. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1259. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1260. {
  1261. meterValueSend[gun_index] =1;
  1262. }
  1263. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1264. {
  1265. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1266. if((access(filenmae,F_OK))!=-1)
  1267. {
  1268. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1269. sprintf(str,"rm -f %s",filenmae);
  1270. system(str);
  1271. }
  1272. }
  1273. }// End for GB
  1274. }
  1275. else
  1276. {
  1277. for (int index = 0; index < AC_QUANTITY; index++)
  1278. {
  1279. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1280. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1281. {
  1282. meterValueSend[gun_index] =1;
  1283. }
  1284. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1285. {
  1286. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1287. if((access(filenmae,F_OK))!=-1)
  1288. {
  1289. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1290. sprintf(str,"rm -f %s",filenmae);
  1291. system(str);
  1292. }
  1293. }
  1294. }//End for AC
  1295. }//END OF ELSE
  1296. // sleep(1);
  1297. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1298. if(meterValueSend[gun_index] == 1)
  1299. sendMeterValuesRequest(gun_index);
  1300. }
  1301. //==============================================
  1302. // Check Connector reserved
  1303. //==============================================
  1304. //===============================
  1305. // Check if Reserve is expired
  1306. //===============================
  1307. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1308. {
  1309. double diff_t;
  1310. struct tm tp;
  1311. // current time
  1312. time_t t = time(NULL);
  1313. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1314. tp.tm_isdst = -1;
  1315. time_t utc = mktime(&tp);
  1316. diff_t = difftime(utc, t);
  1317. if(diff_t <= 0)
  1318. {
  1319. DEBUG_INFO("reserve expired !!! \n");
  1320. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1321. }
  1322. }//END OF Check if Reserve is expired
  1323. //==========================================
  1324. // csu trigger FirmwareStatusNotificationReq
  1325. //==========================================
  1326. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1327. {
  1328. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1329. }
  1330. //==========================================
  1331. // csu trigger CancelReservationConf
  1332. //==========================================
  1333. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1334. {
  1335. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1336. }
  1337. //==========================================
  1338. // csu trigger ChangeAvailabilityConf
  1339. //==========================================
  1340. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1341. {
  1342. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1343. }
  1344. //==========================================
  1345. // csu trigger UnlockConnectorConf
  1346. //==========================================
  1347. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1348. {
  1349. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1350. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1351. }
  1352. //==========================================
  1353. // csu trigger ReserveNowConf
  1354. //==========================================
  1355. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1356. {
  1357. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1358. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1359. }
  1360. //==========================================
  1361. // csu trigger DataTransferReq
  1362. //==========================================
  1363. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1364. {
  1365. sendDataTransferRequest(gun_index);
  1366. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1367. }
  1368. }
  1369. }
  1370. //==========================================
  1371. // send request routine
  1372. //==========================================
  1373. int sendAuthorizeRequest(int gun_index)
  1374. {
  1375. mtrace();
  1376. int result = FAIL;
  1377. char message[100]={0};
  1378. char guid[37];
  1379. char tempdata[65]={0};
  1380. DEBUG_INFO("sendAuthorizeRequest \n");
  1381. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1382. //Local Authorize
  1383. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1384. {
  1385. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1386. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1387. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1388. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1389. result = PASS;
  1390. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1391. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1392. authorizeRetryTimes = 0;
  1393. return result;
  1394. }
  1395. 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))||
  1396. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1397. {
  1398. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1399. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1400. {
  1401. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1402. {
  1403. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1404. }
  1405. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1406. {
  1407. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1408. }
  1409. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1410. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1411. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1412. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1413. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1414. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1415. authorizeRetryTimes = 0;
  1416. return result;
  1417. }
  1418. else
  1419. {
  1420. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1421. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1422. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1423. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1424. result = PASS;
  1425. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1426. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1427. authorizeRetryTimes = 0;
  1428. return result;
  1429. }
  1430. }
  1431. //initailize struct Authorize
  1432. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1433. //get data from shared memory
  1434. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1435. random_uuid(guid);
  1436. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1437. LWS_Send(message);
  1438. sprintf(tempdata, "Authorize,%d", gun_index);
  1439. if(hashmap_operation(0, guid, tempdata) == 1)
  1440. {
  1441. result = PASS;
  1442. DEBUG_ERROR("Authorize mapItem pass\n");
  1443. }
  1444. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1445. return result;
  1446. }
  1447. int sendBootNotificationRequest(void)
  1448. {
  1449. mtrace();
  1450. int result = FAIL;
  1451. char message[500]={0}, payload[700]={0};
  1452. char guid[37]={0};
  1453. char tempdata[65]={0};
  1454. int IsGunCharging = FALSE;
  1455. //check Transaction active
  1456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1457. {
  1458. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1459. {
  1460. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1461. {
  1462. IsGunCharging = TRUE;
  1463. }
  1464. }
  1465. for (int index = 0; index < CCS_QUANTITY; index++)
  1466. {
  1467. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1468. {
  1469. IsGunCharging = TRUE;
  1470. }
  1471. }
  1472. for (int index = 0; index < GB_QUANTITY; index++)
  1473. {
  1474. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1475. {
  1476. IsGunCharging = TRUE;
  1477. }
  1478. }
  1479. }
  1480. else
  1481. {
  1482. for (int index = 0; index < AC_QUANTITY; index++)
  1483. {
  1484. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1485. {
  1486. IsGunCharging = TRUE;
  1487. }
  1488. }
  1489. }
  1490. if(IsGunCharging == TRUE)
  1491. {
  1492. server_sign = TRUE;
  1493. return result;
  1494. }
  1495. // Fill BootNotification fields
  1496. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1497. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1498. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1499. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1500. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1501. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1502. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1503. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1504. ShmOCPP16Data->ChargeBoxId
  1505. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1506. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1507. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1508. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1509. ,ShmOCPP16Data->BootNotification.CpIccid
  1510. ,ShmOCPP16Data->BootNotification.CpImsi
  1511. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1512. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1513. random_uuid(guid);
  1514. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1515. LWS_Send(message);
  1516. sprintf(tempdata, "BootNotification,0");
  1517. 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*/)
  1518. {
  1519. result = PASS;
  1520. }
  1521. memset(queuedata, 0, sizeof(queuedata));
  1522. strcpy(queuedata,message);
  1523. return result;
  1524. }
  1525. int sendDataTransferRequest(int gun_index)
  1526. {
  1527. mtrace();
  1528. char message[1000]={0};
  1529. char guid[37]={0};
  1530. char tempdata[65]={0};
  1531. int result = FAIL;
  1532. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1533. random_uuid(guid);
  1534. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1535. MESSAGE_TYPE_CALL,
  1536. guid,
  1537. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1538. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1539. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1540. LWS_Send(message);
  1541. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1542. 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*/)
  1543. {
  1544. result = PASS;
  1545. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1546. }
  1547. return result;
  1548. }
  1549. int sendDiagnosticsStatusNotificationRequest(char *status)
  1550. {
  1551. mtrace();
  1552. int result = FAIL;
  1553. char message[110]={0};
  1554. char guid[37]={0};
  1555. char tempdata[65]={0};
  1556. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1557. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1558. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1559. random_uuid(guid);
  1560. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1561. LWS_Send(message);
  1562. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1563. if(hashmap_operation(0, guid, tempdata) == 1)
  1564. {
  1565. result = PASS;
  1566. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1567. }
  1568. //#ifdef SystemLogMessage
  1569. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1570. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1571. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1572. //#endif
  1573. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1574. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1575. //record status
  1576. if(strcmp(status,"Idle")==0)
  1577. {
  1578. DiagnosticsStatusNotificationStatus = 0;
  1579. }
  1580. else if(strcmp(status,"Uploaded")==0)
  1581. {
  1582. DiagnosticsStatusNotificationStatus = 1;
  1583. }
  1584. else if(strcmp(status,"UploadFailed")==0)
  1585. {
  1586. DiagnosticsStatusNotificationStatus = 2;
  1587. }
  1588. else if(strcmp(status,"Uploading")==0)
  1589. {
  1590. DiagnosticsStatusNotificationStatus = 3;
  1591. }
  1592. return result;
  1593. }
  1594. int sendFirmwareStatusNotificationRequest(char *status)
  1595. {
  1596. mtrace();
  1597. int result = FAIL;
  1598. char message[110]={0};
  1599. char guid[37]={0};
  1600. char tempdata[65]={0};
  1601. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1602. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1603. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1604. random_uuid(guid);
  1605. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1606. LWS_Send(message);
  1607. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1608. 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*/)
  1609. {
  1610. result = PASS;
  1611. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1612. }
  1613. //#ifdef SystemLogMessage
  1614. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1615. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1616. //#endif
  1617. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1618. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1619. //record status
  1620. if(strcmp(status,"Downloaded")==0)
  1621. {
  1622. FirmwareStatusNotificationStatus = 0;
  1623. }
  1624. else if(strcmp(status,"DownloadFailed")==0)
  1625. {
  1626. FirmwareStatusNotificationStatus = 1;
  1627. }
  1628. else if(strcmp(status,"Downloading")==0)
  1629. {
  1630. FirmwareStatusNotificationStatus = 2;
  1631. }
  1632. else if(strcmp(status,"Idle")==0)
  1633. {
  1634. FirmwareStatusNotificationStatus = 3;
  1635. }
  1636. else if(strcmp(status,"InstallationFailed")==0)
  1637. {
  1638. FirmwareStatusNotificationStatus = 4;
  1639. }
  1640. else if(strcmp(status,"Installing")==0)
  1641. {
  1642. FirmwareStatusNotificationStatus = 5;
  1643. }
  1644. else if(strcmp(status,"Installed")==0)
  1645. {
  1646. FirmwareStatusNotificationStatus = 6;
  1647. }
  1648. return result;
  1649. }
  1650. int sendHeartbeatRequest(int gun_index)
  1651. {
  1652. mtrace();
  1653. int result = FAIL;
  1654. char message[80]={0};
  1655. char guid[37]={0};
  1656. char tempdata[65]={0};
  1657. random_uuid(guid);
  1658. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1659. , MESSAGE_TYPE_CALL
  1660. , guid );
  1661. LWS_Send(message);
  1662. sprintf(tempdata, "Heartbeat,%d", 0);
  1663. 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*/)
  1664. {
  1665. result = PASS;
  1666. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1667. }
  1668. return result;
  1669. }
  1670. int sendStartTransactionRequest(int gun_index)
  1671. {
  1672. mtrace();
  1673. int result = FAIL;
  1674. char message[250]={0};
  1675. char guid[37]={0};
  1676. struct timeval tmnow;
  1677. struct tm *tm;
  1678. char buf[28];//, usec_buf[6];
  1679. char tempdata[65]={0};
  1680. DEBUG_INFO("sendStartTransactionRequest...");
  1681. gettimeofday(&tmnow, NULL);
  1682. time_t t;
  1683. t = time(NULL);
  1684. /*UTC time and date*/
  1685. tm = gmtime(&t);
  1686. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1687. #if 0 // remove temporally
  1688. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1689. strcat(buf,".");
  1690. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1691. strcat(buf,usec_buf);
  1692. #endif
  1693. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1694. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1695. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1696. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1697. {
  1698. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1699. {
  1700. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1701. {
  1702. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1703. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1704. }
  1705. }
  1706. for (int index = 0; index < CCS_QUANTITY; index++)
  1707. {
  1708. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1709. {
  1710. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1711. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1712. }
  1713. }
  1714. for (int index = 0; index < GB_QUANTITY; index++)
  1715. {
  1716. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1717. {
  1718. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1719. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1720. }
  1721. }
  1722. }
  1723. else
  1724. {
  1725. for (int index = 0; index < AC_QUANTITY; index++)
  1726. {
  1727. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1728. {
  1729. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1730. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1731. }
  1732. }
  1733. }//END OF ELSE
  1734. random_uuid(guid);
  1735. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1736. , MESSAGE_TYPE_CALL
  1737. , guid
  1738. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1739. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1740. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1741. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1742. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1743. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1744. 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*/)
  1745. {
  1746. result = PASS;
  1747. }
  1748. strcpy(queuedata, message);
  1749. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1750. if(GetTransactionQueueNum() == 1)
  1751. {
  1752. LWS_Send(message);
  1753. }
  1754. #if 0
  1755. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1756. 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*/)
  1757. {
  1758. result = PASS;
  1759. }
  1760. strcpy(queuedata, message);
  1761. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1762. #endif
  1763. //#ifdef SystemLogMessage
  1764. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1765. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1766. //#endif
  1767. return result;
  1768. }
  1769. int sendStatusNotificationRequest(int gun_index)
  1770. {
  1771. mtrace();
  1772. int result = FAIL;
  1773. char message[600]={0};
  1774. char guid[37];
  1775. int currentStatus = 0;
  1776. struct timeval tmnow;
  1777. struct tm *tm;
  1778. char buf[28];//, usec_buf[6];
  1779. char tempdata[65]={0};
  1780. gettimeofday(&tmnow, NULL);
  1781. time_t t;
  1782. t = time(NULL);
  1783. /*UTC time and date*/
  1784. tm = gmtime(&t);
  1785. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1786. #if 0 // remove temporally
  1787. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1788. strcat(buf,".");
  1789. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1790. strcat(buf,usec_buf);
  1791. #endif
  1792. printf("%s",buf);
  1793. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1794. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1795. // it's option
  1796. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1797. /*
  1798. enum _SYSTEM_STATUS
  1799. {
  1800. S_BOOTING = 0,
  1801. S_IDLE, = 1
  1802. S_AUTHORIZING, =2
  1803. S_REASSIGN_CHECK, =3
  1804. S_REASSIGN, =4
  1805. S_PRECHARGE, =5
  1806. S_PREPARING_FOR_EV, =6
  1807. S_PREPARING_FOR_EVSE, =7
  1808. S_CHARGING, =8
  1809. S_TERMINATING, =9
  1810. S_COMPLETE, =10
  1811. S_ALARM, =11
  1812. S_FAULT =12
  1813. }
  1814. */
  1815. //check Transaction active
  1816. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1817. {
  1818. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1819. {
  1820. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1821. {
  1822. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1823. {
  1824. currentStatus = 1; //OCPP Status: Preparing
  1825. }
  1826. else
  1827. {
  1828. currentStatus = 0; //OCPP Status: Available
  1829. }
  1830. }
  1831. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1832. {
  1833. currentStatus = 1; //OCPP Status: Preparing
  1834. }
  1835. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1836. {
  1837. currentStatus = 2; //OCPP Status: Charging
  1838. }
  1839. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1840. {
  1841. currentStatus = 5; //OCPP Status: Finishing
  1842. }
  1843. 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
  1844. {
  1845. currentStatus = 4; //OCPP Status: SuspendedEV
  1846. }
  1847. 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
  1848. {
  1849. currentStatus = 7; //OCPP Status: Unavailable
  1850. }
  1851. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1852. {
  1853. currentStatus = 8; //OCPP Status: Faulted
  1854. }
  1855. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1856. {
  1857. currentStatus = 6; //OCPP Status: Reserved
  1858. }
  1859. }//end of for CHAdeMO_QUANTITY
  1860. for (int index = 0; index < CCS_QUANTITY; index++)
  1861. {
  1862. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1863. {
  1864. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1865. {
  1866. currentStatus = 1; //OCPP Status: Preparing
  1867. }
  1868. else
  1869. {
  1870. currentStatus = 0; //OCPP Status: Available
  1871. }
  1872. }
  1873. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1874. {
  1875. currentStatus = 1; //OCPP Status: Preparing
  1876. }
  1877. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1878. {
  1879. currentStatus = 2; //OCPP Status: Charging
  1880. }
  1881. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1882. {
  1883. currentStatus = 5; //OCPP Status: Finishing
  1884. }
  1885. 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
  1886. {
  1887. currentStatus = 4; //OCPP Status: SuspendedEV
  1888. }
  1889. 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
  1890. {
  1891. currentStatus = 7; //OCPP Status : Unavailable
  1892. }
  1893. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1894. {
  1895. currentStatus = 8; //OCPP Status: Faulted
  1896. }
  1897. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1898. {
  1899. currentStatus = 6; //OCPP Status: Reserved
  1900. }
  1901. }
  1902. for (int index = 0; index < GB_QUANTITY; index++)
  1903. {
  1904. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1905. {
  1906. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1907. {
  1908. currentStatus = 1; //OCPP Status: Preparing
  1909. }
  1910. else
  1911. {
  1912. currentStatus = 0; //OCPP Status: Available
  1913. }
  1914. }
  1915. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1916. {
  1917. currentStatus = 1; //OCPP Status: Preparing
  1918. }
  1919. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1920. {
  1921. currentStatus = 2; //OCPP Status: Charging
  1922. }
  1923. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1924. {
  1925. currentStatus = 5; //OCPP Status: Finishing
  1926. }
  1927. 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
  1928. {
  1929. currentStatus = 4; //OCPP Status: SuspendedEV
  1930. }
  1931. 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
  1932. {
  1933. currentStatus = 7; //OCPP Status: Unavailable
  1934. }
  1935. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1936. {
  1937. currentStatus = 8; //OCPP Status: Faulted
  1938. }
  1939. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1940. {
  1941. currentStatus = 6; //OCPP Status: Reserved
  1942. }
  1943. }
  1944. }
  1945. else
  1946. {
  1947. for (int index = 0; index < AC_QUANTITY; index++)
  1948. {
  1949. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1950. {
  1951. 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))
  1952. {
  1953. currentStatus = 1; //OCPP Status: Preparing
  1954. }
  1955. else
  1956. {
  1957. currentStatus = 0; //OCPP Status: Available
  1958. }
  1959. }
  1960. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1961. {
  1962. currentStatus = 1; //OCPP Status: Preparing
  1963. }
  1964. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1965. {
  1966. currentStatus = 2; //OCPP Status: Charging
  1967. }
  1968. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1969. {
  1970. currentStatus = 5; //OCPP Status: Finishing
  1971. }
  1972. 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
  1973. {
  1974. currentStatus = 4; //OCPP Status: SuspendedEV
  1975. }
  1976. 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
  1977. {
  1978. currentStatus = 7; //OCPP Status: Unavailable
  1979. }
  1980. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1981. {
  1982. currentStatus = 8; //OCPP Status: Faulted
  1983. }
  1984. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1985. {
  1986. currentStatus = 6; //OCPP Status: Reserved
  1987. }
  1988. }//end of for AC_QUANTITY
  1989. }//END OF ELSE
  1990. //it's option
  1991. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1992. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1993. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1994. random_uuid(guid);
  1995. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1996. , MESSAGE_TYPE_CALL
  1997. , guid
  1998. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1999. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2000. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2001. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2002. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2003. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2004. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2005. LWS_Send(message);
  2006. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2007. 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*/)
  2008. {
  2009. //DEBUG_ERROR("statusNotification mapitem pass");
  2010. result = PASS;
  2011. }
  2012. return result;
  2013. }
  2014. int sendStopTransactionRequest(int gun_index)
  2015. {
  2016. mtrace();
  2017. int result = FAIL;
  2018. //char message[1500]={0};
  2019. char guid[37]={0};
  2020. char tempdata[65]={0};
  2021. //int idx_sample=0;
  2022. DEBUG_ERROR("sendStopTransactionRequest \n");
  2023. memset(queuedata, 0, sizeof(queuedata));
  2024. //ENERGY_ACTIVE_IMPORT_REGISTER
  2025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2026. {
  2027. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2028. {
  2029. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2030. {
  2031. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2032. }
  2033. }// END OF CHAdeMO_QUANTITY
  2034. for (int index = 0; index < CCS_QUANTITY; index++)
  2035. {
  2036. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2037. {
  2038. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2039. }
  2040. }// END OF CCS_QUANTITY
  2041. for (int index = 0; index < GB_QUANTITY; index++)
  2042. {
  2043. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2044. {
  2045. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2046. }
  2047. }// END OF GB_QUANTITY
  2048. }
  2049. else
  2050. {
  2051. for (int index = 0; index < AC_QUANTITY; index++)
  2052. {
  2053. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2054. {
  2055. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2056. }
  2057. }// END OF AC_QUANTITY
  2058. }//END OF ELSE
  2059. //Stop Transaction Time
  2060. struct timeval tmnow;
  2061. struct tm *tm;
  2062. char buf[28];//, usec_buf[6];
  2063. gettimeofday(&tmnow, NULL);
  2064. time_t t;
  2065. t = time(NULL);
  2066. /*UTC time and date*/
  2067. tm = gmtime(&t);
  2068. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2070. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2071. random_uuid(guid);
  2072. /***********************************transactionData******************************************************/
  2073. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2075. //=================================
  2076. // Transaction_Begin
  2077. //=================================
  2078. // Energy.Active.Export.Interval
  2079. //idx_sample=0;
  2080. 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
  2081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2083. 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*/]);
  2084. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2085. {
  2086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2087. }
  2088. else
  2089. {
  2090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2091. }
  2092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2094. //=================================
  2095. // Transaction_End
  2096. //=================================
  2097. //Current.Export
  2098. //idx_sample=1;
  2099. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2100. {
  2101. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2102. {
  2103. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2104. {
  2105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2106. }
  2107. }
  2108. for (int index = 0; index < CCS_QUANTITY; index++)
  2109. {
  2110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2111. {
  2112. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2113. }
  2114. }
  2115. for (int index = 0; index < GB_QUANTITY; index++)
  2116. {
  2117. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2118. {
  2119. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2120. }
  2121. }
  2122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2123. }
  2124. else
  2125. {
  2126. for (int index = 0; index < AC_QUANTITY; index++)
  2127. {
  2128. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2129. {
  2130. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2131. }
  2132. }
  2133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2134. }// END FOR AC ELSE
  2135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2138. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2141. //Energy.Active.Export.Interval
  2142. //idx_sample=2;
  2143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2144. {
  2145. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2146. {
  2147. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2148. {
  2149. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2150. }
  2151. }
  2152. for (int index = 0; index < CCS_QUANTITY; index++)
  2153. {
  2154. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2155. {
  2156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2157. }
  2158. }
  2159. for (int index = 0; index < GB_QUANTITY; index++)
  2160. {
  2161. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2162. {
  2163. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2164. }
  2165. }
  2166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2167. }
  2168. else
  2169. {
  2170. for (int index = 0; index < AC_QUANTITY; index++)
  2171. {
  2172. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2173. {
  2174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2175. }
  2176. }
  2177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2178. }// END FOR AC ELSE
  2179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2182. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2185. //Power.Active.Export
  2186. //idx_sample=3;
  2187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2188. {
  2189. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2190. {
  2191. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2192. {
  2193. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2194. }
  2195. }
  2196. for (int index = 0; index < CCS_QUANTITY; index++)
  2197. {
  2198. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2199. {
  2200. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2201. }
  2202. }
  2203. for (int index = 0; index < GB_QUANTITY; index++)
  2204. {
  2205. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2206. {
  2207. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2208. }
  2209. }
  2210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2211. }
  2212. else
  2213. {
  2214. for (int index = 0; index < AC_QUANTITY; index++)
  2215. {
  2216. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2217. {
  2218. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2219. }
  2220. }
  2221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2222. }// END FOR AC ELSE
  2223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2224. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2226. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2229. //Voltage
  2230. //idx_sample=4;
  2231. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2232. {
  2233. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2234. {
  2235. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2236. {
  2237. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2238. }
  2239. }
  2240. for (int index = 0; index < CCS_QUANTITY; index++)
  2241. {
  2242. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2243. {
  2244. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2245. }
  2246. }
  2247. for (int index = 0; index < GB_QUANTITY; index++)
  2248. {
  2249. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2250. {
  2251. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2252. }
  2253. }
  2254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2255. }
  2256. else
  2257. {
  2258. for (int index = 0; index < AC_QUANTITY; index++)
  2259. {
  2260. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2261. {
  2262. 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
  2263. }
  2264. }
  2265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2266. }// END FOR AC ELSE
  2267. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2268. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2270. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2273. //SoC
  2274. //idx_sample=5;
  2275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2276. {
  2277. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2278. {
  2279. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2280. {
  2281. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2282. }
  2283. }
  2284. for (int index = 0; index < CCS_QUANTITY; index++)
  2285. {
  2286. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2287. {
  2288. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2289. }
  2290. }
  2291. for (int index = 0; index < GB_QUANTITY; index++)
  2292. {
  2293. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2294. {
  2295. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2296. }
  2297. }
  2298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2304. } // END FOR DC CASE
  2305. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2306. {
  2307. 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\"}]}]}]"
  2308. ,MESSAGE_TYPE_CALL
  2309. ,guid
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2315. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2336. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2340. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2341. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2342. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2343. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2344. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2345. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2346. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2347. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2348. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2349. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2358. );
  2359. }
  2360. else
  2361. {
  2362. 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\"}]}]}]"
  2363. ,MESSAGE_TYPE_CALL
  2364. ,guid
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2366. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2367. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2368. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2369. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2370. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2385. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2386. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2387. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2388. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2390. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2391. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2392. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2393. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2394. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2395. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2396. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2397. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2398. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2399. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2400. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2401. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2402. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2403. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2404. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2405. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2406. );
  2407. }
  2408. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2409. if(hashmap_operation(0, guid, tempdata) == 1)
  2410. {
  2411. result = PASS;
  2412. DEBUG_INFO("StopTransaction mapitem pass\n");
  2413. }
  2414. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2415. if(GetTransactionQueueNum() == 1)
  2416. {
  2417. LWS_Send(queuedata);
  2418. }
  2419. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2420. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2421. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2422. {
  2423. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2424. }
  2425. #if 0
  2426. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2427. if(hashmap_operation(0, guid, tempdata) == 1)
  2428. {
  2429. result = PASS;
  2430. DEBUG_INFO("StopTransaction mapitem pass\n");
  2431. }
  2432. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2433. #endif
  2434. //for test
  2435. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2436. return result;
  2437. }
  2438. int sendMeterValuesRequest(int gun_index)
  2439. {
  2440. mtrace();
  2441. int result = FAIL;
  2442. // char message[1500]={0};
  2443. char guid[37]={0};
  2444. //int idx_sample=0;
  2445. //int length = 0;
  2446. char tempdata[65]={0};
  2447. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2448. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2449. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2450. {
  2451. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2452. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2453. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2454. return result;
  2455. }
  2456. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2457. {
  2458. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2459. }
  2460. memset(queuedata, 0, sizeof(queuedata));
  2461. //set value
  2462. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2463. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2464. random_uuid(guid);
  2465. //UTC Date time
  2466. struct timeval tmnow;
  2467. struct tm *tm;
  2468. char buf[28];//, usec_buf[6];
  2469. gettimeofday(&tmnow, NULL);
  2470. time_t t;
  2471. t = time(NULL);
  2472. /*UTC time and date*/
  2473. tm = gmtime(&t);
  2474. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2475. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2476. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2477. //idx_sample=0;
  2478. //********************************(1)Current.Export************************************************/
  2479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2480. {
  2481. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2482. {
  2483. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2484. {
  2485. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2486. }
  2487. }
  2488. for (int index = 0; index < CCS_QUANTITY; index++)
  2489. {
  2490. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2491. {
  2492. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2493. }
  2494. }
  2495. for (int index = 0; index < GB_QUANTITY; index++)
  2496. {
  2497. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2498. {
  2499. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2500. }
  2501. }
  2502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2503. }
  2504. else
  2505. {
  2506. for (int index = 0; index < AC_QUANTITY; index++)
  2507. {
  2508. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2509. {
  2510. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2511. }
  2512. }
  2513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2514. }// END FOR AC ELSE
  2515. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2518. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2521. //idx_sample=1;
  2522. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2523. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2524. {
  2525. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2526. {
  2527. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2528. {
  2529. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2530. }
  2531. }
  2532. for (int index = 0; index < CCS_QUANTITY; index++)
  2533. {
  2534. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2535. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2536. {
  2537. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2538. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2539. }
  2540. }
  2541. for (int index = 0; index < GB_QUANTITY; index++)
  2542. {
  2543. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2544. {
  2545. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2546. }
  2547. }
  2548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2549. }
  2550. else
  2551. {
  2552. for (int index = 0; index < AC_QUANTITY; index++)
  2553. {
  2554. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2555. {
  2556. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2557. }
  2558. }
  2559. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2560. }//END FOR AC ELSE
  2561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2564. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2567. //idx_sample=2;
  2568. //********************************(4)Power.Active.Export************************************************/
  2569. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2570. {
  2571. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2572. {
  2573. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2574. {
  2575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2576. }
  2577. }
  2578. for (int index = 0; index < CCS_QUANTITY; index++)
  2579. {
  2580. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2581. {
  2582. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2583. }
  2584. }
  2585. for (int index = 0; index < GB_QUANTITY; index++)
  2586. {
  2587. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2588. {
  2589. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2590. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2591. }
  2592. }
  2593. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2594. }
  2595. else
  2596. {
  2597. for (int index = 0; index < AC_QUANTITY; index++)
  2598. {
  2599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2600. {
  2601. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2602. }
  2603. }
  2604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2605. }// END FOR AC ELSE
  2606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2609. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2612. //idx_sample=3;
  2613. //***********************************************(5)VOLTAGE******************************************************/
  2614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2615. {
  2616. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2617. {
  2618. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2619. {
  2620. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2621. }
  2622. }
  2623. for (int index = 0; index < CCS_QUANTITY; index++)
  2624. {
  2625. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2626. {
  2627. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2628. }
  2629. }
  2630. for (int index = 0; index < GB_QUANTITY; index++)
  2631. {
  2632. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2633. {
  2634. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2635. }
  2636. }
  2637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2638. }
  2639. else
  2640. {
  2641. for (int index = 0; index < AC_QUANTITY; index++)
  2642. {
  2643. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2644. {
  2645. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2646. }
  2647. }
  2648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2649. }//END FOR AC ELSE
  2650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2651. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2653. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2656. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2657. {
  2658. //idx_sample=4;
  2659. //sampledValue = NULL;
  2660. //***********************************************(6)SOC******************************************************/
  2661. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2662. {
  2663. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2664. {
  2665. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2666. }
  2667. }
  2668. for (int index = 0; index < CCS_QUANTITY; index++)
  2669. {
  2670. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2671. {
  2672. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2673. }
  2674. }
  2675. for (int index = 0; index < GB_QUANTITY; index++)
  2676. {
  2677. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2678. {
  2679. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2680. }
  2681. }
  2682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2684. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2685. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2686. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2687. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2688. }
  2689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2690. {
  2691. 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\"}]}]}]"
  2692. ,MESSAGE_TYPE_CALL
  2693. ,guid
  2694. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2695. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2696. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2732. );
  2733. }
  2734. else
  2735. {
  2736. 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\"}]}]}]"
  2737. ,MESSAGE_TYPE_CALL
  2738. ,guid
  2739. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2740. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2741. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2758. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2770. );
  2771. }
  2772. // Put request guid to hash map
  2773. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2774. 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*/)
  2775. {
  2776. result = PASS;
  2777. DEBUG_INFO("MeterValues mapitem pass\n");
  2778. }
  2779. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2780. if(GetTransactionQueueNum() == 1)
  2781. {
  2782. LWS_Send(queuedata);
  2783. }
  2784. #if 0
  2785. // Put request guid to hash map
  2786. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2787. 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*/)
  2788. {
  2789. result = PASS;
  2790. DEBUG_INFO("MeterValues mapitem pass\n");
  2791. }
  2792. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2793. #endif
  2794. return result;
  2795. }
  2796. //==========================================
  2797. // send confirm routine
  2798. //==========================================
  2799. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2800. {
  2801. mtrace();
  2802. int result = FAIL;
  2803. char message[100]={0};
  2804. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2805. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2806. LWS_Send(message);
  2807. result = TRUE;
  2808. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2809. return result;
  2810. }
  2811. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2812. {
  2813. mtrace();
  2814. int result = FAIL;
  2815. char message[100]={0};
  2816. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2817. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2818. LWS_Send(message);
  2819. result = TRUE;
  2820. return result;
  2821. }
  2822. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2823. {
  2824. mtrace();
  2825. int result = FAIL;
  2826. char message[100]={0};
  2827. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2828. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2829. LWS_Send(message);
  2830. result = TRUE;
  2831. return result;
  2832. }
  2833. int sendClearCacheConfirmation(char *uuid,char *payload)
  2834. {
  2835. mtrace();
  2836. int result = FAIL;
  2837. char message[500]={0};
  2838. // int count = 0;
  2839. // int gun_index = 0;
  2840. // char guid[37];
  2841. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2842. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2843. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2844. LWS_Send(message);
  2845. return result;
  2846. }
  2847. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2848. {
  2849. mtrace();
  2850. int result = FAIL;
  2851. char message[500]={0};
  2852. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2853. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2854. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2855. LWS_Send(message);
  2856. return result;
  2857. }
  2858. int sendDataTransferConfirmation(char *uuid,char *payload)
  2859. {
  2860. mtrace();
  2861. char statusStr[20]={0};
  2862. char dataStr[10]={0};
  2863. char sstr[20]={0};
  2864. int c = 0;
  2865. char *loc;
  2866. int result = FAIL;
  2867. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2868. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2869. /**********************status**************************/
  2870. loc = strstr(payload, "status");
  2871. memset(sstr ,0, sizeof(sstr) );
  2872. c = 0;
  2873. while (loc[3+strlen("status")+c] != '\"')
  2874. {
  2875. sstr[c] = loc[3+strlen("status")+c];
  2876. c++;
  2877. }
  2878. sstr[c] = '\0';
  2879. strcpy(statusStr, sstr);
  2880. /**********************data**************************/
  2881. loc = strstr(payload, "data");
  2882. memset(sstr ,0, sizeof(sstr) );
  2883. c = 0;
  2884. while (loc[3+strlen("data")+c] != '\"')
  2885. {
  2886. sstr[c] = loc[3+strlen("data")+c];
  2887. c++;
  2888. }
  2889. sstr[c] = '\0';
  2890. strcpy(dataStr, sstr);
  2891. return result;
  2892. }
  2893. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2894. {
  2895. mtrace();
  2896. int result = FAIL;
  2897. char message[1000]={0};
  2898. double diff_f = 0.0;
  2899. int diff_i = 0;
  2900. int diffSeconds = 0;
  2901. struct tm tp;
  2902. int TimeZero = FALSE;
  2903. int CompositeScheduleIndex = 0;
  2904. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2905. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2906. {
  2907. TimeZero = TRUE;
  2908. }
  2909. else
  2910. {
  2911. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2912. }
  2913. if(TimeZero == FALSE)
  2914. {
  2915. tp.tm_isdst = -1;
  2916. time_t utc = mktime(&tp);
  2917. time_t t = time(NULL);
  2918. diff_f = difftime(t, utc);
  2919. diff_i = (int)diff_f;
  2920. diffSeconds = diff_i % 86400;//86400 seconds/day
  2921. }
  2922. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2923. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2924. #if 0 //remove temporally
  2925. 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}"
  2926. ,MESSAGE_TYPE_CALLRESULT
  2927. ,uuid
  2928. ,payload
  2929. ,connectorIdInt
  2930. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2931. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2932. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2933. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2934. #endif
  2935. if(nPeriod == 0)
  2936. {
  2937. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  2938. {
  2939. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  2940. ,MESSAGE_TYPE_CALLRESULT
  2941. ,uuid
  2942. ,payload
  2943. ,connectorIdInt);
  2944. }
  2945. else
  2946. {
  2947. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2948. ,MESSAGE_TYPE_CALLRESULT
  2949. ,uuid
  2950. ,payload
  2951. ,connectorIdInt
  2952. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2953. }
  2954. }
  2955. else
  2956. {
  2957. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2958. ,MESSAGE_TYPE_CALLRESULT
  2959. ,uuid
  2960. ,payload
  2961. ,connectorIdInt
  2962. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2963. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2964. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2965. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2966. int len = nPeriod;
  2967. //Last Period StartPriod is less than diffSeconds
  2968. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds)
  2969. {
  2970. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2971. , 0
  2972. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2973. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2974. }
  2975. else
  2976. {
  2977. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2978. {
  2979. 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)
  2980. {
  2981. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2982. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2983. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2984. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2985. }
  2986. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2987. {
  2988. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2989. , ((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*/))
  2990. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2991. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2992. }
  2993. }
  2994. }
  2995. sprintf(message + strlen(message), "]}}]");
  2996. }
  2997. LWS_Send(message);
  2998. result = TRUE;
  2999. return result;
  3000. }
  3001. int sendGetConfigurationConfirmation(char *uuid)
  3002. {
  3003. mtrace();
  3004. int result = FAIL;
  3005. int MaxKeySupported = 0;
  3006. int sentConfigurationNumber= 0;
  3007. int sentunConfigurationNumber= 0;
  3008. char message[4000]={0};
  3009. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3010. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3011. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3012. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3013. ,MESSAGE_TYPE_CALLRESULT
  3014. ,uuid );
  3015. //configuration key
  3016. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3017. {
  3018. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3019. {
  3020. if (sentConfigurationNumber == 0)
  3021. {
  3022. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3023. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3024. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3025. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3026. }
  3027. else
  3028. {
  3029. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3030. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3031. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3032. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3033. }
  3034. sentConfigurationNumber = sentConfigurationNumber + 1;
  3035. }
  3036. }
  3037. sprintf(message + strlen(message), "]");
  3038. if(UnknownKeynum != 0)
  3039. {
  3040. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3041. //unkown key
  3042. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3043. {
  3044. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3045. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3046. if(sentunConfigurationNumber == 0)
  3047. {
  3048. sprintf(message + strlen(message), "\"%s\""
  3049. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3050. }
  3051. else
  3052. {
  3053. sprintf(message + strlen(message), ",\"%s\""
  3054. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3055. }
  3056. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3057. }
  3058. sprintf(message + strlen(message), "]");
  3059. }
  3060. sprintf(message + strlen(message), "}]");
  3061. LWS_Send(message);
  3062. return result;
  3063. }
  3064. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3065. {
  3066. mtrace();
  3067. int result = FAIL;
  3068. char message[400]={0};
  3069. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3070. if(strcmp(payload,"")==0)
  3071. {
  3072. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3073. }
  3074. else
  3075. {
  3076. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3077. }
  3078. LWS_Send(message);
  3079. result = TRUE;
  3080. return result;
  3081. }
  3082. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3083. {
  3084. mtrace();
  3085. int result = FAIL;
  3086. char message[80]={0};
  3087. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3088. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3089. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3090. LWS_Send(message);
  3091. result = TRUE;
  3092. return result;
  3093. }
  3094. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3095. {
  3096. mtrace();
  3097. int result = FAIL;
  3098. char message[80]={0};
  3099. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3100. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3101. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3102. LWS_Send(message);
  3103. result = TRUE;
  3104. return result;
  3105. }
  3106. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3107. {
  3108. mtrace();
  3109. int result = FAIL;
  3110. char message[80]={0};
  3111. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3112. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3113. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3114. LWS_Send(message);
  3115. result = TRUE;
  3116. return result;
  3117. }
  3118. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3119. {
  3120. mtrace();
  3121. int result = FAIL;
  3122. char message[80]={0};
  3123. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3124. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3125. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3126. LWS_Send(message);
  3127. result = TRUE;
  3128. return result;
  3129. }
  3130. int sendResetConfirmation(char *uuid,char *payload)
  3131. {
  3132. mtrace();
  3133. int result = FAIL;
  3134. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3135. char message[80]={0};
  3136. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3137. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3138. LWS_Send(message);
  3139. result = TRUE;
  3140. return result;
  3141. }
  3142. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3143. {
  3144. mtrace();
  3145. int result = FAIL;
  3146. char message[500]={0};
  3147. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3148. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3149. LWS_Send(message);
  3150. result = TRUE;
  3151. return result;
  3152. }
  3153. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3154. {
  3155. mtrace();
  3156. int result = FAIL;
  3157. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3158. char message[80]={0};
  3159. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3160. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3161. LWS_Send(message);
  3162. result = TRUE;
  3163. return result;
  3164. }
  3165. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3166. {
  3167. mtrace();
  3168. int result = FAIL;
  3169. char message[80]={0};
  3170. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3171. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3172. LWS_Send(message);
  3173. result = TRUE;
  3174. return result;
  3175. }
  3176. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3177. {
  3178. mtrace();
  3179. int result = FAIL;
  3180. char message[80]={0};
  3181. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3182. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3183. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3184. LWS_Send(message);
  3185. result = TRUE;
  3186. return result;
  3187. }
  3188. int sendUpdateFirmwareConfirmation(char *uuid)
  3189. {
  3190. mtrace();
  3191. int result = FAIL;
  3192. char message[60]={0};
  3193. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3194. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3195. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3196. LWS_Send(message);
  3197. result = TRUE;
  3198. return result;
  3199. }
  3200. //==========================================
  3201. // send CallError routine
  3202. //==========================================
  3203. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3204. {
  3205. mtrace();
  3206. //int result = FAIL;
  3207. char message[220]={0};
  3208. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3209. #ifdef SystemLogMessage
  3210. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3211. uniqueId, action, errorCode, errorDescription);
  3212. #endif
  3213. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3214. LWS_Send(message);
  3215. //result = TRUE;
  3216. }
  3217. //==========================================
  3218. // Handle server request routine Start
  3219. //==========================================
  3220. #define GUN_NUM 1
  3221. int handleCancelReservationRequest(char *uuid, char *payload)
  3222. {
  3223. mtrace();
  3224. int result = FAIL;
  3225. int gunNO = 0;
  3226. int reservationIdInt =0;
  3227. char comfirmstr[20];
  3228. int c = 0;
  3229. char *loc;
  3230. char sstr[100]={0};
  3231. DEBUG_INFO("handle CancelReservationRequest\n");
  3232. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3233. c = 0;
  3234. loc = strstr(payload, "reservationId");
  3235. memset(sstr ,0, sizeof(sstr) );
  3236. while (loc[strlen("reservationId")+2+c] != '}')
  3237. {
  3238. sstr[c] = loc[strlen("reservationId")+2+c];
  3239. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3240. c++;
  3241. }
  3242. sstr[c] = '\0';
  3243. reservationIdInt = atoi(sstr);
  3244. memset(comfirmstr, 0, sizeof comfirmstr);
  3245. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3246. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3247. //check Transaction active
  3248. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3249. {
  3250. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3251. {
  3252. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3253. {
  3254. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3255. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3256. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3257. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3258. goto end;
  3259. }
  3260. }
  3261. for (int index = 0; index < CCS_QUANTITY; index++)
  3262. {
  3263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3264. {
  3265. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3266. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3267. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3268. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3269. goto end;
  3270. }
  3271. }
  3272. for (int index = 0; index < GB_QUANTITY; index++)
  3273. {
  3274. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3275. {
  3276. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3277. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3278. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3279. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3280. goto end;
  3281. }
  3282. }
  3283. }
  3284. else
  3285. {
  3286. for (int index = 0; index < AC_QUANTITY; index++)
  3287. {
  3288. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3289. {
  3290. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3291. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3292. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3293. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3294. goto end;
  3295. }
  3296. }
  3297. }// END FOR AC ELSE
  3298. //The reservationId does NOT match the reservationId
  3299. sendCancelReservationConfirmation(uuid, comfirmstr);
  3300. end:
  3301. // Fill in ocpp packet uuid
  3302. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3303. return result;
  3304. }
  3305. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3306. {
  3307. mtrace();
  3308. int result = FAIL;
  3309. int gunIndex = 0;
  3310. char sstr[90]={0};
  3311. char typeStr[16]={0};
  3312. char comfirmstr[20];
  3313. int specificId = FALSE;
  3314. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3315. char *loc;
  3316. //int intervalInt = 0;
  3317. int c = 0;
  3318. /*** connectorId ****/
  3319. c = 0;
  3320. loc = strstr(payload, "connectorId");
  3321. memset(sstr ,0, sizeof(sstr) );
  3322. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3323. {
  3324. sstr[c] = loc[strlen("connectorId")+2+c];
  3325. c++;
  3326. }
  3327. sstr[c] = '\0';
  3328. gunIndex = atoi(sstr);
  3329. /***type ****/
  3330. loc = strstr(payload, "type");
  3331. memset(sstr ,0, sizeof(sstr) );
  3332. c = 0;
  3333. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3334. {
  3335. sstr[c] = loc[3+strlen("type")+c];
  3336. c++;
  3337. }
  3338. sstr[c] = '\0';
  3339. strcpy(typeStr, sstr);
  3340. if(gunIndex != 0)
  3341. {
  3342. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3343. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3344. }
  3345. else
  3346. {
  3347. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3348. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3349. }
  3350. memset(comfirmstr, 0, sizeof comfirmstr);
  3351. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3352. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3353. {
  3354. specificId = TRUE;
  3355. }
  3356. if(specificId == FALSE)
  3357. goto end;
  3358. if(gunIndex != 0)
  3359. {
  3360. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3361. }
  3362. else
  3363. {
  3364. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3365. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3366. }
  3367. /*
  3368. enum SYSTEM_STATUS
  3369. {
  3370. SYS_MODE_BOOTING = 0,
  3371. SYS_MODE_IDLE = 1,
  3372. SYS_MODE_AUTHORIZING = 2,
  3373. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3374. SYS_MODE_REASSIGN = 4,
  3375. SYS_MODE_PREPARING = 5,
  3376. SYS_MODE_PREPARE_FOR_EV = 6,
  3377. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3378. SYS_MODE_CHARGING = 8,
  3379. SYS_MODE_TERMINATING = 9,
  3380. SYS_MODE_COMPLETE = 10,
  3381. SYS_MODE_ALARM = 11,
  3382. SYS_MODE_FAULT = 12,
  3383. SYS_MODE_RESERVATION = 13,
  3384. SYS_MODE_BOOKING = 14,
  3385. SYS_MODE_MAINTAIN = 15,
  3386. SYS_MODE_DEBUG = 16,
  3387. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3388. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3389. SYS_MODE_UPDATE = 19
  3390. };
  3391. */
  3392. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3393. {
  3394. //check Transaction active
  3395. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3396. {
  3397. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3398. {
  3399. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3400. {
  3401. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3402. {
  3403. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3404. }
  3405. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3406. {
  3407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3408. }
  3409. else
  3410. {
  3411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3412. }
  3413. goto end;
  3414. }
  3415. }//END FOR CHAdeMO_QUANTITY
  3416. for (int index = 0; index < CCS_QUANTITY; index++)
  3417. {
  3418. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3419. {
  3420. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3421. {
  3422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3423. }
  3424. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3425. {
  3426. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3427. }
  3428. else
  3429. {
  3430. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3431. }
  3432. goto end;
  3433. }
  3434. }//END FOR CCS_QUANTITY
  3435. for (int index = 0; index < GB_QUANTITY; index++)
  3436. {
  3437. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3438. {
  3439. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3440. {
  3441. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3442. }
  3443. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3444. {
  3445. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3446. }
  3447. else
  3448. {
  3449. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3450. }
  3451. goto end;
  3452. }
  3453. }// END FOR GB_QUANTITY
  3454. }
  3455. else
  3456. {
  3457. for (int index = 0; index < AC_QUANTITY; index++)
  3458. {
  3459. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3460. {
  3461. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3462. {
  3463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3464. }
  3465. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3466. {
  3467. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3468. }
  3469. else
  3470. {
  3471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3472. }
  3473. goto end;
  3474. }
  3475. }//END FOR AC_QUANTITY
  3476. }// END FOR AC ELSE
  3477. }//END FOR AvailabilityTypeStr[Inoperative]
  3478. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3479. {
  3480. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3481. //check Transaction active
  3482. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3483. {
  3484. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3485. {
  3486. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3487. {
  3488. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3489. goto end;
  3490. }
  3491. }//END FOR CHAdeMO_QUANTITY
  3492. for (int index = 0; index < CCS_QUANTITY; index++)
  3493. {
  3494. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3495. {
  3496. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3497. goto end;
  3498. }
  3499. }//END FOR CCS_QUANTITY
  3500. for (int index = 0; index < GB_QUANTITY; index++)
  3501. {
  3502. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3503. {
  3504. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3505. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3506. goto end;
  3507. }
  3508. }// END FOR GB_QUANTITY
  3509. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3510. }
  3511. else
  3512. {
  3513. for (int index = 0; index < AC_QUANTITY; index++)
  3514. {
  3515. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3516. {
  3517. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3518. goto end;
  3519. }
  3520. }//END FOR CHAdeMO_QUANTITY
  3521. }//END FOR AC ELSE
  3522. }//END FOR AvailabilityTypeStr[Operative]
  3523. end:
  3524. if(gunIndex != 0)
  3525. {
  3526. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3527. }
  3528. else
  3529. {
  3530. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3531. }
  3532. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3533. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3534. return result;
  3535. }
  3536. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3537. {
  3538. mtrace();
  3539. int result = FAIL;
  3540. char sstr[100]={0};
  3541. char keystr[40]={0};
  3542. char valuestr[100]={0};
  3543. char *loc;
  3544. int c = 0;
  3545. char comfirmstr[20]={0};
  3546. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3547. /***key ****/
  3548. loc = strstr(payload, "key");
  3549. memset(sstr ,0, sizeof(sstr) );
  3550. c = 0;
  3551. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3552. {
  3553. sstr[c] = loc[3+strlen("key")+c];
  3554. c++;
  3555. }
  3556. sstr[c] = '\0';
  3557. strcpy(keystr, sstr);
  3558. //DEBUG_INFO( "keystr=%s\n",keystr);
  3559. /***value ****/
  3560. loc = strstr(payload, "value");
  3561. memset(sstr ,0, sizeof(sstr) );
  3562. c = 0;
  3563. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3564. {
  3565. sstr[c] = loc[3+strlen("value")+c];
  3566. c++;
  3567. }
  3568. sstr[c] = '\0';
  3569. strcpy(valuestr, sstr);
  3570. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3571. if((uuid==NULL) || (payload ==NULL) )
  3572. {
  3573. #ifdef Debug
  3574. DEBUG_INFO("payload is null\n");
  3575. #endif
  3576. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3577. }
  3578. else
  3579. {
  3580. int status = setKeyValue(keystr, valuestr);
  3581. switch(status)
  3582. {
  3583. case ConfigurationStatus_Accepted:
  3584. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3585. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3586. StoreConfigurationTable();
  3587. break;
  3588. case ConfigurationStatus_Rejected:
  3589. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3590. break;
  3591. case RebootRequired:
  3592. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3593. StoreConfigurationTable();
  3594. break;
  3595. case NotSupported:
  3596. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3597. break;
  3598. default:
  3599. break;
  3600. }
  3601. }
  3602. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3603. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3604. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3605. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3606. {
  3607. ChageWebSocketPingInterval(atoi(valuestr));
  3608. }
  3609. return result;
  3610. }
  3611. int handleClearCacheRequest(char *uuid, char *payload)
  3612. {
  3613. mtrace();
  3614. int result = FAIL;
  3615. char comfirmstr[20];
  3616. int fd;
  3617. char rmFileCmd[100]={0};
  3618. struct stat stats;
  3619. DEBUG_INFO("handle ClearCacheRequest\n");
  3620. stat("/Storage/OCPP", &stats);
  3621. // Check for directory existence
  3622. if (S_ISDIR(stats.st_mode) == 1)
  3623. {
  3624. //DEBUG_ERROR("\n OCPP directory exist \n");
  3625. }
  3626. else
  3627. {
  3628. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3629. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3630. system(rmFileCmd);
  3631. }
  3632. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3633. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3634. {
  3635. DEBUG_INFO("AuthorizationCache file exist.\n");
  3636. }
  3637. else
  3638. {
  3639. DEBUG_INFO("AuthorizationCache file not exist\n");
  3640. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3641. if(log == NULL)
  3642. {
  3643. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3644. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3645. goto end;
  3646. }
  3647. else
  3648. {
  3649. fclose(log);
  3650. }
  3651. }
  3652. fd = open(AuthorizationCache_JSON,O_RDWR);
  3653. if(fd < 0)
  3654. {
  3655. DEBUG_INFO("open AuthorizationCache file failed\n");
  3656. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3657. }
  3658. else
  3659. {
  3660. DEBUG_INFO("open AuthorizationCache file successful\n");
  3661. //* 清空? 件 */
  3662. ftruncate(fd,0);
  3663. //* ? 新设置? 件? 移??*/
  3664. lseek(fd,0,SEEK_SET);
  3665. close(fd);
  3666. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3667. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3668. }
  3669. end:
  3670. sendClearCacheConfirmation(uuid, comfirmstr);
  3671. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3672. return result;
  3673. }
  3674. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3675. {
  3676. mtrace();
  3677. int result = FAIL;
  3678. int resultRename;
  3679. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3680. char chargingProfilePurposeStr[26]={0};
  3681. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3682. char tempchargingProfilePurposeStr[26]={0};
  3683. char sstr[160]={0};//sstr[200]={ 0 };
  3684. char str[100]={0};
  3685. int c = 0;
  3686. //int i = 0;
  3687. //char * pch;
  3688. char *loc;
  3689. char fname[200]={0};
  3690. char comfirmstr[20]={0};
  3691. char word[1600]={0};
  3692. int clearflag = FALSE;
  3693. int chargingProfileIdIsNULL = FALSE;
  3694. int connectorIsNULL = FALSE;
  3695. int chargingProfilePurposeIsNULL = FALSE;
  3696. int stackLevelIsNULL = FALSE;
  3697. //int GotoEnd = FALSE;
  3698. FILE *fptr1, *fptr2;
  3699. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3700. int n_chargingProfile=0;
  3701. int isEmptyFile = FALSE;
  3702. char sLineWord[1600]={0};
  3703. char chargingProfiles[10][100]={0};
  3704. int ChargeProfileCount = 0;
  3705. char ch;
  3706. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3707. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3708. //***id ****/
  3709. c = 0;
  3710. loc = strstr(payload, "id");
  3711. memset(sstr ,0, sizeof(sstr) );
  3712. if(loc == NULL)
  3713. {
  3714. chargingProfileIdIsNULL = TRUE;
  3715. }
  3716. else
  3717. {
  3718. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3719. {
  3720. sstr[c] = loc[strlen("id")+2+c];
  3721. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3722. c++;
  3723. }
  3724. sstr[c] = '\0';
  3725. chargingProfileIdInt = atoi(sstr);
  3726. }
  3727. //***connectorId ****/
  3728. c=0;
  3729. loc = strstr(payload, "connectorId");
  3730. memset(sstr ,0, sizeof(sstr) );
  3731. if(loc == NULL)
  3732. {
  3733. connectorIsNULL = TRUE;
  3734. }
  3735. else
  3736. {
  3737. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3738. {
  3739. sstr[c] = loc[strlen("connectorId")+2+c];
  3740. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3741. c++;
  3742. }
  3743. sstr[c] = '\0';
  3744. connectorIdInt = atoi(sstr);
  3745. }
  3746. //***chargingProfilePurpose ****/
  3747. loc = strstr(payload, "chargingProfilePurpose");
  3748. memset(sstr ,0, sizeof(sstr) );
  3749. c = 0;
  3750. if(loc == NULL)
  3751. {
  3752. chargingProfilePurposeIsNULL = TRUE;
  3753. }
  3754. else
  3755. {
  3756. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3757. {
  3758. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3759. c++;
  3760. }
  3761. sstr[c] = '\0';
  3762. strcpy(chargingProfilePurposeStr, sstr);
  3763. }
  3764. //***stackLevel ****/
  3765. c=0;
  3766. loc = strstr(payload, "stackLevel");
  3767. memset(sstr ,0, sizeof(sstr) );
  3768. if(loc == NULL)
  3769. {
  3770. stackLevelIsNULL = TRUE;
  3771. }
  3772. else
  3773. {
  3774. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3775. {
  3776. sstr[c] = loc[strlen("stackLevel")+2+c];
  3777. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3778. c++;
  3779. }
  3780. sstr[c] = '\0';
  3781. stackLevelInt = atoi(sstr);
  3782. }
  3783. if(connectorIsNULL == FALSE)
  3784. {
  3785. switch(connectorIdInt)
  3786. {
  3787. case 0:
  3788. if(chargingProfilePurposeIsNULL == TRUE)
  3789. {
  3790. int l = 0;
  3791. strcpy(fname, ChargePointMaxProfile_JSON);
  3792. if((access(fname,F_OK))!=-1)
  3793. {
  3794. strcpy(chargingProfiles[l], fname);
  3795. l = l + 1;
  3796. }
  3797. strcpy(fname, TxDefaultProfile_0_JSON);
  3798. if((access(fname,F_OK))!=-1)
  3799. {
  3800. strcpy(chargingProfiles[l], fname);
  3801. l = l + 1;
  3802. }
  3803. ChargeProfileCount = l;
  3804. }
  3805. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3806. {
  3807. strcpy(fname, ChargePointMaxProfile_JSON);
  3808. if((access(fname,F_OK))!=-1)
  3809. {
  3810. strcpy(chargingProfiles[0], fname);
  3811. ChargeProfileCount = 1;
  3812. }
  3813. }
  3814. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3815. {
  3816. strcpy(fname, TxDefaultProfile_0_JSON);
  3817. if((access(fname,F_OK))!=-1)
  3818. {
  3819. strcpy(chargingProfiles[0], fname);
  3820. ChargeProfileCount = 1;
  3821. }
  3822. }
  3823. break;
  3824. default:
  3825. if(chargingProfilePurposeIsNULL == TRUE)
  3826. {
  3827. int m = 0;
  3828. memset(fname, 0, sizeof fname);
  3829. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3830. if((access(fname,F_OK))!=-1)
  3831. {
  3832. strcpy(chargingProfiles[m], fname);
  3833. m = m + 1;
  3834. }
  3835. memset(fname, 0, sizeof fname);
  3836. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3837. if((access(fname,F_OK))!=-1)
  3838. {
  3839. strcpy(chargingProfiles[m], fname);
  3840. m = m + 1;
  3841. }
  3842. ChargeProfileCount = m;
  3843. }
  3844. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3845. {
  3846. //strcpy(fname, TxDefaultProfile_1_JSON);
  3847. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3848. if((access(fname,F_OK))!=-1)
  3849. {
  3850. strcpy(chargingProfiles[0], fname);
  3851. ChargeProfileCount = 1;
  3852. }
  3853. }
  3854. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3855. {
  3856. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3857. if((access(fname,F_OK))!=-1)
  3858. {
  3859. strcpy(chargingProfiles[0], fname);
  3860. ChargeProfileCount = 1;
  3861. }
  3862. //strcpy(fname, TxProfile_1_JSON);
  3863. }
  3864. //strcpy(fname, ChargePointMaxProfile_JSON );
  3865. break;
  3866. }
  3867. }
  3868. else // Check all Charging Profiles
  3869. {
  3870. int i = 0;
  3871. char fnametemp[200]={0};
  3872. ChargeProfileCount = 0;
  3873. //Check ChargePointMaxProfile.json exit
  3874. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3875. {
  3876. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3877. i = i + 1;
  3878. }
  3879. //Check TxDefaultProfile_0.json exit
  3880. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3881. {
  3882. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3883. i = i + 1;
  3884. }
  3885. //Check TxDefaultProfile_%d.json
  3886. for(int j=1; j <= gunTotalNumber; j++)
  3887. {
  3888. memset(fnametemp, 0, sizeof fnametemp);
  3889. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3890. if((access(fnametemp,F_OK))!=-1)
  3891. {
  3892. strcpy(chargingProfiles[i], fnametemp);
  3893. i = i + 1;
  3894. }
  3895. }
  3896. //Check TxProfile_%d.json
  3897. for(int j=1; j <= gunTotalNumber; j++)
  3898. {
  3899. memset(fnametemp, 0, sizeof fnametemp);
  3900. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3901. if((access(fnametemp,F_OK))!=-1)
  3902. {
  3903. strcpy(chargingProfiles[i], fnametemp);
  3904. i = i + 1;
  3905. }
  3906. }
  3907. ChargeProfileCount = i;
  3908. }// End connectorIsNULL is TRUE
  3909. if(ChargeProfileCount == 0)
  3910. {
  3911. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3912. goto end;
  3913. }
  3914. #if 0
  3915. fptr1 = fopen(fname, "r");
  3916. if (!fptr1)
  3917. {
  3918. //file not exist
  3919. DEBUG_INFO("Unable to open the input file!!\n");
  3920. fptr1 = fopen(fname, "w+");
  3921. }
  3922. fclose(fptr1);
  3923. #endif
  3924. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3925. {
  3926. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3927. goto end;
  3928. }
  3929. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3930. {
  3931. memset(str, 0, sizeof str);
  3932. // clear temp file
  3933. sprintf(str,"rm -f %s",temp);
  3934. system(str);
  3935. for(int k=0; k < ChargeProfileCount; k++)
  3936. {
  3937. memset(str, 0, sizeof str);
  3938. //clear file in C
  3939. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3940. system(str);
  3941. }
  3942. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3943. goto end;
  3944. }
  3945. else if(connectorIsNULL == TRUE)
  3946. {
  3947. for(int k=0; k < ChargeProfileCount; k++)
  3948. {
  3949. fptr1 = fopen(chargingProfiles[k], "r");
  3950. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  3951. //Check Charging Profile Count
  3952. while(fscanf(fptr1, "%s", word) != EOF)
  3953. {
  3954. //DEBUG_INFO("word=%s\n",word);
  3955. if(strstr(word, "chargingProfileId")!= NULL)
  3956. {
  3957. //DEBUG_INFO("test chargingProfileId \n");
  3958. n_chargingProfile = n_chargingProfile + 1;
  3959. //DEBUG_INFO("chargingProfileId Found\n");
  3960. }
  3961. }
  3962. rewind(fptr1);
  3963. //search Charging Profile Element
  3964. //int i= 0;
  3965. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3966. {
  3967. //------------------------tempconnectorIdInt------------------------//
  3968. loc = strstr(sLineWord, "connectorId");
  3969. c = 0;
  3970. memset(sstr ,0, sizeof(sstr) );
  3971. while (loc[strlen("connectorId")+2+c] != ',')
  3972. {
  3973. sstr[c] = loc[strlen("connectorId")+2+c];
  3974. c++;
  3975. }
  3976. sstr[c] = '\0';
  3977. tempconnectorIdInt = atoi(sstr);
  3978. printf("file's gun number is %d\n", tempconnectorIdInt);
  3979. //--------------------------chargingProfileId--------------------//
  3980. c = 0;
  3981. loc = strstr(sLineWord, "chargingProfileId");
  3982. memset(sstr ,0, sizeof(sstr) );
  3983. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3984. {
  3985. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3986. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3987. c++;
  3988. }
  3989. sstr[c] = '\0';
  3990. tempchargingProfileIdInt = atoi(sstr);
  3991. //stackLevel
  3992. c = 0;
  3993. loc = strstr(sLineWord, "stackLevel");
  3994. memset(sstr ,0, sizeof(sstr) );
  3995. while (loc[strlen("stackLevel")+2+c] != ',')
  3996. {
  3997. sstr[c] = loc[strlen("stackLevel")+2+c];
  3998. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3999. c++;
  4000. }
  4001. sstr[c] = '\0';
  4002. tempstackLevelInt = atoi(sstr);
  4003. c = 0;
  4004. loc = strstr(sLineWord, "chargingProfilePurpose");
  4005. memset(sstr ,0, sizeof(sstr) );
  4006. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4007. {
  4008. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4009. c++;
  4010. }
  4011. sstr[c] = '\0';
  4012. strcpy(tempchargingProfilePurposeStr, sstr);
  4013. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4014. {
  4015. //------- not write to fptr2-------//
  4016. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4017. //clearflag = TRUE;
  4018. }
  4019. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4020. {
  4021. //------- not write to fptr2-------//
  4022. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4023. }
  4024. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4025. {
  4026. //------- not write to fptr2-------//
  4027. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4028. }
  4029. else
  4030. {
  4031. fprintf(fptr2, sLineWord);//writing data into file
  4032. }
  4033. memset(sLineWord, 0, sizeof sLineWord);
  4034. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4035. if(clearflag == TRUE)
  4036. {
  4037. fclose(fptr1);
  4038. fclose(fptr2);
  4039. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4040. system(str);
  4041. // clear temp file
  4042. sprintf(str,"rm -f %s",temp);
  4043. system(str);
  4044. }
  4045. else
  4046. {
  4047. fclose(fptr1);
  4048. fclose(fptr2);
  4049. memset(str, 0, sizeof str);
  4050. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4051. system(str);
  4052. resultRename = rename(temp, chargingProfiles[k]);
  4053. if(resultRename == 0)
  4054. {
  4055. DEBUG_INFO("File ChargingProfile renamed successfully");
  4056. }
  4057. else
  4058. {
  4059. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4060. }
  4061. if(comfirmstr[0]== 0)
  4062. {
  4063. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4064. }
  4065. //Check chargingProfile is empty file
  4066. /*------ Read the file ----------------*/
  4067. fptr1=fopen(chargingProfiles[k],"r");
  4068. ch=fgetc(fptr1);
  4069. rewind(fptr1);
  4070. memset(sLineWord, 0, sizeof sLineWord);
  4071. if(ch!=EOF)
  4072. {
  4073. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4074. {
  4075. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4076. if(sLineWord[0]=='\0')
  4077. {
  4078. isEmptyFile = TRUE;
  4079. break;
  4080. }
  4081. else
  4082. {
  4083. isEmptyFile = FALSE;
  4084. break;
  4085. }
  4086. }
  4087. }
  4088. fclose(fptr1);
  4089. if(isEmptyFile == TRUE)
  4090. {
  4091. memset(str, 0, sizeof str);
  4092. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4093. system(str);
  4094. }
  4095. }
  4096. }// End of while(int k=0; k < ChargePointCount; k++)
  4097. }
  4098. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4099. {
  4100. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4101. for(int k=0; k < ChargeProfileCount; k++)
  4102. {
  4103. fptr1 = fopen(chargingProfiles[k], "r");
  4104. fptr2 = fopen(temp, "w+");
  4105. //Check Charging Profile Count
  4106. while(fscanf(fptr1, "%s", word) != EOF)
  4107. {
  4108. //DEBUG_INFO("word=%s\n",word);
  4109. if(strstr(word, "chargingProfileId")!= NULL)
  4110. {
  4111. //DEBUG_INFO("test chargingProfileId \n");
  4112. n_chargingProfile = n_chargingProfile + 1;
  4113. //DEBUG_INFO("chargingProfileId Found\n");
  4114. }
  4115. }
  4116. rewind(fptr1);
  4117. //search Charging Profile Element
  4118. //int i= 0;
  4119. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4120. {
  4121. //*************************tempconnectorIdInt*********************************/
  4122. loc = strstr(sLineWord, "connectorId");
  4123. c = 0;
  4124. memset(sstr ,0, sizeof(sstr) );
  4125. while (loc[strlen("connectorId")+2+c] != ',')
  4126. {
  4127. sstr[c] = loc[strlen("connectorId")+2+c];
  4128. c++;
  4129. }
  4130. sstr[c] = '\0';
  4131. tempconnectorIdInt = atoi(sstr);
  4132. //chargingProfileId
  4133. c = 0;
  4134. loc = strstr(sLineWord, "chargingProfileId");
  4135. memset(sstr ,0, sizeof(sstr) );
  4136. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4137. {
  4138. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4139. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4140. c++;
  4141. }
  4142. sstr[c] = '\0';
  4143. tempchargingProfileIdInt = atoi(sstr);
  4144. //stackLevel
  4145. c = 0;
  4146. loc = strstr(sLineWord, "stackLevel");
  4147. memset(sstr ,0, sizeof(sstr) );
  4148. while (loc[strlen("stackLevel")+2+c] != ',')
  4149. {
  4150. sstr[c] = loc[strlen("stackLevel")+2+c];
  4151. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4152. c++;
  4153. }
  4154. sstr[c] = '\0';
  4155. tempstackLevelInt = atoi(sstr);
  4156. c = 0;
  4157. loc = strstr(sLineWord, "chargingProfilePurpose");
  4158. memset(sstr ,0, sizeof(sstr) );
  4159. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4160. {
  4161. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4162. c++;
  4163. }
  4164. sstr[c] = '\0';
  4165. strcpy(tempchargingProfilePurposeStr, sstr);
  4166. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4167. {
  4168. //------- not write to fptr2-------//
  4169. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4170. //clearflag = TRUE;
  4171. }
  4172. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4173. {
  4174. //------- not write to fptr2-------//
  4175. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4176. }
  4177. else if(stackLevelIsNULL == TRUE)
  4178. {
  4179. //Clear Whole File
  4180. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4181. clearflag = TRUE;
  4182. break;
  4183. }
  4184. else
  4185. {
  4186. fprintf(fptr2, sLineWord);//writing data into file
  4187. }
  4188. memset(sLineWord, 0, sizeof sLineWord);
  4189. }
  4190. if(clearflag == TRUE)
  4191. {
  4192. fclose(fptr1);
  4193. fclose(fptr2);
  4194. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4195. system(str);
  4196. // clear temp file
  4197. sprintf(str,"rm -f %s",temp);
  4198. system(str);
  4199. }
  4200. else
  4201. {
  4202. fclose(fptr1);
  4203. fclose(fptr2);
  4204. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4205. system(str);
  4206. resultRename = rename(temp, chargingProfiles[k]);
  4207. if(resultRename == 0)
  4208. {
  4209. DEBUG_INFO("File ChargingProfile renamed successfully");
  4210. }
  4211. else
  4212. {
  4213. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4214. }
  4215. if(comfirmstr[0]== 0)
  4216. {
  4217. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4218. }
  4219. //Check chargingProfile is empty file
  4220. /*------ Read the file ----------------*/
  4221. fptr1=fopen(chargingProfiles[k],"r");
  4222. ch=fgetc(fptr1);
  4223. rewind(fptr1);
  4224. memset(sLineWord, 0, sizeof sLineWord);
  4225. if(ch!=EOF)
  4226. {
  4227. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4228. {
  4229. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4230. if(sLineWord[0]=='\0')
  4231. {
  4232. isEmptyFile = TRUE;
  4233. break;
  4234. }
  4235. else
  4236. {
  4237. isEmptyFile = FALSE;
  4238. break;
  4239. }
  4240. }
  4241. }
  4242. fclose(fptr1);
  4243. if(isEmptyFile == TRUE)
  4244. {
  4245. memset(str, 0, sizeof str);
  4246. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4247. system(str);
  4248. }
  4249. /*------- End of reading ---------------*/
  4250. }
  4251. } // while(int k=0; k < ChargeProfileCount; k++)
  4252. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4253. end:
  4254. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4255. return result;
  4256. }
  4257. int handleDataTransferRequest(char *uuid, char *payload)
  4258. {
  4259. mtrace();
  4260. int result = FAIL;
  4261. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4262. char tempvendorId[255]={0};
  4263. char tempmessageId[50]={0};
  4264. char tempdata[50]={0};
  4265. char sstr[160]={0};//sstr[200]={ 0 };
  4266. char message[80]={0};
  4267. int c = 0;
  4268. char *loc;
  4269. DEBUG_INFO("handle DataTransferRequest\n");
  4270. if((uuid != NULL) && (payload != NULL))
  4271. {
  4272. //===============================
  4273. // vendorId
  4274. //===============================
  4275. c = 0;
  4276. loc = strstr(payload, "vendorId");
  4277. while (loc[strlen("vendorId")+3+c] != '\"')
  4278. {
  4279. sstr[c] = loc[strlen("vendorId")+3+c];
  4280. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4281. c++;
  4282. }
  4283. sstr[c] = '\0';
  4284. strcpy(tempvendorId,sstr);
  4285. //===============================
  4286. // messageId
  4287. //===============================
  4288. memset(sstr ,0, sizeof(sstr) );
  4289. c = 0;
  4290. loc = strstr(payload, "messageId");
  4291. while (loc[strlen("messageId")+3+c] != '\"')
  4292. {
  4293. sstr[c] = loc[strlen("messageId")+3+c];
  4294. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4295. c++;
  4296. }
  4297. sstr[c] = '\0';
  4298. strcpy(tempmessageId,sstr);
  4299. //===============================
  4300. // data
  4301. //===============================
  4302. memset(sstr ,0, sizeof(sstr) );
  4303. c = 0;
  4304. loc = strstr(payload, "data");
  4305. printf("loc=%s\n",loc);
  4306. while (loc[strlen("data")+3+c] != '\"')
  4307. {
  4308. sstr[c] = loc[strlen("data")+3+c];
  4309. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4310. c++;
  4311. }
  4312. sstr[c] = '\0';
  4313. strcpy(tempdata,sstr);
  4314. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4315. }
  4316. else
  4317. {
  4318. char guid[37]={0};
  4319. random_uuid(guid);
  4320. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4321. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4322. }
  4323. LWS_Send(message);
  4324. return result;
  4325. }
  4326. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4327. {
  4328. mtrace();
  4329. int result = FAIL;
  4330. int connectorIdInt, durationInt;
  4331. char chargingRateUnitStr[4]={0};
  4332. //int tempconnectorIdInt,
  4333. int tempdurationInt;
  4334. float tempminChargingRateFloat = 0.0;
  4335. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4336. int tempStartPeriodInt=0;
  4337. float tempLimitInt=0.0;//0.1;
  4338. int tempNumberPhasesInt=0;
  4339. char fname[200];
  4340. char comfirmstr[20];
  4341. //float totallimit =0.0;
  4342. float MinChargingRate =0.0;
  4343. //double diff_t;
  4344. //struct tm tp;
  4345. FILE *fptr1;
  4346. int c = 0;
  4347. //int i = 0;
  4348. char * pch;
  4349. char *loc;
  4350. char sstr[200]={ 0 };
  4351. int n_chargingProfile = 0;
  4352. int n_SchedulePeriods = 0;
  4353. char SchedulePeriodList[10][200]={0};
  4354. char sLineWord[1600]={0};
  4355. //int n_periods = 0;
  4356. char word[1000]={0};
  4357. int confirmPeriods = 0;
  4358. struct StructProfile ChargePointMaxProfile;
  4359. struct StructProfile TxDefaultProfile;
  4360. struct StructProfile TxProfile;
  4361. struct StructProfile TxDefaultProfiletemp[2]={0};
  4362. int TxDefaultProfileFileIsNull=FALSE;
  4363. int ChargePointMaxProfileIsNull=FALSE;
  4364. int TxProfileIsNull=FALSE;
  4365. int CompositeSceduleIndex = 0;
  4366. char ChargePointMaxProfileScheduleStr[30]={0};
  4367. char TxDefaultProfileScheduleStr[30]={0};
  4368. char TxProfileScheduleStr[30]={0};
  4369. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4370. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4371. memset(&TxProfile,0,sizeof(struct StructProfile));
  4372. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4373. c=0;
  4374. loc = strstr(payload, "connectorId");
  4375. memset(sstr ,0, sizeof(sstr) );
  4376. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4377. {
  4378. sstr[c] = loc[strlen("connectorId")+2+c];
  4379. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4380. c++;
  4381. }
  4382. sstr[c] = '\0';
  4383. connectorIdInt = atoi(sstr);
  4384. c=0;
  4385. loc = strstr(payload, "duration");
  4386. memset(sstr ,0, sizeof(sstr) );
  4387. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4388. {
  4389. sstr[c] = loc[strlen("duration")+2+c];
  4390. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4391. c++;
  4392. }
  4393. sstr[c] = '\0';
  4394. durationInt = atoi(sstr);
  4395. c = 0;
  4396. loc = strstr(payload, "chargingRateUnit");
  4397. memset(sstr ,0, sizeof(sstr) );
  4398. if(loc == NULL)
  4399. {
  4400. }
  4401. else
  4402. {
  4403. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4404. {
  4405. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4406. c++;
  4407. }
  4408. sstr[c] = '\0';
  4409. strcpy(chargingRateUnitStr, sstr);
  4410. }
  4411. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4412. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4413. if(connectorIdInt==0) // connectorId is 0
  4414. {
  4415. //******************************ChargePointMaxProfile*****************************************************/
  4416. strcpy(fname, ChargePointMaxProfile_JSON );
  4417. char word[30]={0};
  4418. char sLineWord[1060]={0};
  4419. int n_chargingProfile=0;
  4420. ChargePointMaxProfileIsNull=TRUE;
  4421. if((access(fname,F_OK))!=-1)
  4422. {
  4423. fptr1 = fopen(fname, "r");
  4424. int c;
  4425. c = fgetc(fptr1);
  4426. //DEBUG_INFO("c:%d\n",c);
  4427. rewind(fptr1);
  4428. if(c == EOF)
  4429. {
  4430. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4431. ChargePointMaxProfileIsNull=TRUE;
  4432. fclose(fptr1);
  4433. }
  4434. else
  4435. {
  4436. ChargePointMaxProfileIsNull=FALSE;
  4437. while(fscanf(fptr1, "%s", word) != EOF)
  4438. {
  4439. if(strcmp(word, "chargingProfileId") == 0)
  4440. {
  4441. n_chargingProfile = n_chargingProfile + 1;
  4442. printf("Found\n");
  4443. }
  4444. }
  4445. rewind(fptr1);
  4446. //search Charging Profile Element
  4447. int i= 0;
  4448. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4449. #if 0
  4450. /***********connectorId****************/
  4451. c = 0;
  4452. loc = strstr(sLineWord, "connectorId");
  4453. // printf("loc=%s\n",loc);
  4454. memset(sstr ,0, sizeof(sstr) );
  4455. while (loc[strlen("connectorId")+2+c] != ',')
  4456. {
  4457. sstr[c] = loc[strlen("connectorId")+2+c];
  4458. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4459. c++;
  4460. }
  4461. sstr[c] = '\0';
  4462. tempconnectorIdInt = atoi(sstr);
  4463. #endif
  4464. //***********validFrom**************/
  4465. c = 0;
  4466. loc = strstr(sLineWord, "validFrom");
  4467. //DEBUG_INFO("loc=%s\n",loc);
  4468. memset(sstr ,0, sizeof(sstr) );
  4469. if(loc != NULL)
  4470. {
  4471. while (loc[3+strlen("validFrom")+c] != '\"')
  4472. {
  4473. sstr[c] = loc[3+strlen("validFrom")+c];
  4474. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4475. c++;
  4476. }
  4477. sstr[c] = '\0';
  4478. DEBUG_INFO("validFrom=%s\n",sstr);
  4479. strcpy(tempvalidFromStr,sstr);
  4480. }
  4481. else
  4482. {
  4483. strcpy(tempvalidFromStr,"");
  4484. }
  4485. //**********startSchedule**********/
  4486. c = 0;
  4487. loc = strstr(sLineWord, "startSchedule");
  4488. //DEBUG_INFO("loc=%s\n",loc);
  4489. memset(sstr ,0, sizeof(sstr) );
  4490. while (loc[3+strlen("startSchedule")+c] != '\"')
  4491. {
  4492. sstr[c] = loc[3+strlen("startSchedule")+c];
  4493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4494. c++;
  4495. }
  4496. sstr[c] = '\0';
  4497. strcpy(tempstartScheduleStr, sstr);
  4498. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4499. //**********chargingRateUnit**********/
  4500. c = 0;
  4501. loc = strstr(sLineWord, "chargingRateUnit");
  4502. memset(sstr ,0, sizeof(sstr) );
  4503. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4504. {
  4505. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4506. c++;
  4507. }
  4508. sstr[c] = '\0';
  4509. strcpy(tempchargingRateUnitStr, sstr);
  4510. //**********minChargingRate*******/
  4511. c = 0;
  4512. loc = strstr(sLineWord, "minChargingRate");
  4513. //printf("loc=%s\n",loc);
  4514. if(loc != NULL)
  4515. {
  4516. memset(sstr ,0, sizeof(sstr) );
  4517. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4518. {
  4519. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4521. c++;
  4522. }
  4523. sstr[c] = '\0';
  4524. tempminChargingRateFloat = atof(sstr);
  4525. }
  4526. else
  4527. {
  4528. tempminChargingRateFloat = 0.0;
  4529. }
  4530. //
  4531. #if 0
  4532. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4533. tp.tm_isdst = -1;
  4534. time_t utc = mktime(&tp);
  4535. // current time
  4536. time_t t = time(NULL);
  4537. #endif
  4538. //diff_t = difftime(t, utc);
  4539. //parsing strings to words
  4540. i = 0;
  4541. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4542. loc = loc+3+strlen("chargingSchedulePeriod");
  4543. pch = strtok(loc ,"{");
  4544. while (pch != NULL)
  4545. {
  4546. strcpy(SchedulePeriodList[i], pch);
  4547. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4548. //printf ("%s\n",pch);
  4549. pch = strtok (NULL, "{");
  4550. i = i + 1;
  4551. }
  4552. n_SchedulePeriods = i;
  4553. for(int i=0;i<n_SchedulePeriods;i++)
  4554. {
  4555. //*************startPeriod****************/
  4556. c = 0;
  4557. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4558. memset(sstr ,0, sizeof(sstr) );
  4559. while (loc[strlen("startPeriod")+2+c] != ',')
  4560. {
  4561. sstr[c] = loc[strlen("startPeriod")+2+c];
  4562. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4563. c++;
  4564. }
  4565. sstr[c] = '\0';
  4566. tempStartPeriodInt = atoi(sstr);
  4567. //*************limit****************/
  4568. c = 0;
  4569. loc = strstr(SchedulePeriodList[i], "limit");
  4570. memset(sstr ,0, sizeof(sstr) );
  4571. while (loc[strlen("limit")+2+c] != ',')
  4572. {
  4573. sstr[c] = loc[strlen("limit")+2+c];
  4574. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4575. c++;
  4576. }
  4577. sstr[c] = '\0';
  4578. tempLimitInt = atof(sstr);
  4579. //*************numberPhases****************/
  4580. c = 0;
  4581. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4582. memset(sstr ,0, sizeof(sstr) );
  4583. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4584. {
  4585. sstr[c] = loc[strlen("numberPhases")+2+c];
  4586. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4587. c++;
  4588. }
  4589. sstr[c] = '\0';
  4590. tempNumberPhasesInt = atoi(sstr);
  4591. ChargePointMaxProfile.Duration = durationInt;
  4592. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4593. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4594. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4595. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4596. }
  4597. if(MinChargingRate < tempminChargingRateFloat)
  4598. MinChargingRate = tempminChargingRateFloat;
  4599. }
  4600. }// End of file ChargingProfile
  4601. } //THE END OF ACCESS ChargePointMaxProfile
  4602. //******************************TxDefaultProfile***********************************************/
  4603. strcpy(fname, TxDefaultProfile_0_JSON);
  4604. memset(word, 0, 30);
  4605. memset(sLineWord, 0, 1060);
  4606. //char word[30]={0};
  4607. //char sLineWord[1060]={0};
  4608. n_chargingProfile=0;
  4609. TxDefaultProfileFileIsNull=TRUE;
  4610. if((access(fname,F_OK))!=-1)
  4611. {
  4612. fptr1 = fopen(fname, "r");
  4613. c = 0;
  4614. c = fgetc(fptr1);
  4615. //DEBUG_INFO("c:%d\n",c);
  4616. rewind(fptr1);
  4617. if(c == EOF)
  4618. {
  4619. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4620. TxDefaultProfileFileIsNull=TRUE;
  4621. fclose(fptr1);
  4622. }
  4623. else
  4624. {
  4625. TxDefaultProfileFileIsNull=FALSE;
  4626. while(fscanf(fptr1, "%s", word) != EOF)
  4627. {
  4628. if(strcmp(word, "chargingProfileId") == 0)
  4629. {
  4630. n_chargingProfile = n_chargingProfile + 1;
  4631. printf("Found\n");
  4632. }
  4633. }
  4634. rewind(fptr1);
  4635. //search Charging Profile Element
  4636. int i= 0;
  4637. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4638. #if 0
  4639. /***********connectorId****************/
  4640. c = 0;
  4641. loc = strstr(sLineWord, "connectorId");
  4642. // printf("loc=%s\n",loc);
  4643. memset(sstr ,0, sizeof(sstr) );
  4644. while (loc[strlen("connectorId")+2+c] != ',')
  4645. {
  4646. sstr[c] = loc[strlen("connectorId")+2+c];
  4647. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4648. c++;
  4649. }
  4650. sstr[c] = '\0';
  4651. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4652. tempconnectorIdInt = atoi(sstr);
  4653. #endif
  4654. //***********validFrom**************/
  4655. c = 0;
  4656. loc = strstr(sLineWord, "validFrom");
  4657. //DEBUG_INFO("loc=%s\n",loc);
  4658. memset(sstr ,0, sizeof(sstr) );
  4659. if(loc != NULL)
  4660. {
  4661. while (loc[3+strlen("validFrom")+c] != '\"')
  4662. {
  4663. sstr[c] = loc[3+strlen("validFrom")+c];
  4664. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4665. c++;
  4666. }
  4667. sstr[c] = '\0';
  4668. DEBUG_INFO("validFrom=%s\n",sstr);
  4669. strcpy(tempvalidFromStr,sstr);
  4670. }
  4671. else
  4672. {
  4673. strcpy(tempvalidFromStr,"");
  4674. }
  4675. //**********startSchedule**********/
  4676. c = 0;
  4677. loc = strstr(sLineWord, "startSchedule");
  4678. //DEBUG_INFO("loc=%s\n",loc);
  4679. memset(sstr ,0, sizeof(sstr) );
  4680. while (loc[3+strlen("startSchedule")+c] != '\"')
  4681. {
  4682. sstr[c] = loc[3+strlen("startSchedule")+c];
  4683. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4684. c++;
  4685. }
  4686. sstr[c] = '\0';
  4687. strcpy(tempstartScheduleStr, sstr);
  4688. strcpy(TxDefaultProfileScheduleStr, sstr);
  4689. //**********chargingRateUnit**********/
  4690. c = 0;
  4691. loc = strstr(sLineWord, "chargingRateUnit");
  4692. memset(sstr ,0, sizeof(sstr) );
  4693. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4694. {
  4695. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4696. c++;
  4697. }
  4698. sstr[c] = '\0';
  4699. strcpy(tempchargingRateUnitStr, sstr);
  4700. //**********minChargingRate*******/
  4701. c = 0;
  4702. loc = strstr(sLineWord, "minChargingRate");
  4703. //printf("loc=%s\n",loc);
  4704. if(loc != NULL)
  4705. {
  4706. memset(sstr ,0, sizeof(sstr) );
  4707. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4708. {
  4709. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4710. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4711. c++;
  4712. }
  4713. sstr[c] = '\0';
  4714. tempminChargingRateFloat = atof(sstr);
  4715. }
  4716. else
  4717. {
  4718. tempminChargingRateFloat = 0.0;
  4719. }
  4720. #if 0
  4721. //
  4722. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4723. tp.tm_isdst = -1;
  4724. time_t utc = mktime(&tp);
  4725. // current time
  4726. time_t t = time(NULL);
  4727. //diff_t = difftime(t, utc);
  4728. #endif
  4729. //parsing strings to words
  4730. i = 0;
  4731. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4732. loc = loc+3+strlen("chargingSchedulePeriod");
  4733. pch = strtok(loc ,"{");
  4734. while (pch != NULL)
  4735. {
  4736. strcpy(SchedulePeriodList[i], pch);
  4737. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4738. //printf ("%s\n",pch);
  4739. pch = strtok (NULL, "{");
  4740. i = i + 1;
  4741. }
  4742. n_SchedulePeriods = i;
  4743. for(int i=0;i<n_SchedulePeriods;i++)
  4744. {
  4745. //*************startPeriod****************/
  4746. c = 0;
  4747. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4748. memset(sstr ,0, sizeof(sstr) );
  4749. while (loc[strlen("startPeriod")+2+c] != ',')
  4750. {
  4751. sstr[c] = loc[strlen("startPeriod")+2+c];
  4752. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4753. c++;
  4754. }
  4755. sstr[c] = '\0';
  4756. tempStartPeriodInt = atoi(sstr);
  4757. //*************limit****************/
  4758. c = 0;
  4759. loc = strstr(SchedulePeriodList[i], "limit");
  4760. memset(sstr ,0, sizeof(sstr) );
  4761. while (loc[strlen("limit")+2+c] != ',')
  4762. {
  4763. sstr[c] = loc[strlen("limit")+2+c];
  4764. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4765. c++;
  4766. }
  4767. sstr[c] = '\0';
  4768. tempLimitInt = atof(sstr);
  4769. //*************numberPhases****************/
  4770. c = 0;
  4771. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4772. memset(sstr ,0, sizeof(sstr) );
  4773. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4774. {
  4775. sstr[c] = loc[strlen("numberPhases")+2+c];
  4776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4777. c++;
  4778. }
  4779. sstr[c] = '\0';
  4780. tempNumberPhasesInt = atoi(sstr);
  4781. TxDefaultProfile.Duration = durationInt;
  4782. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4783. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4784. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4785. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4786. }
  4787. if(MinChargingRate < tempminChargingRateFloat)
  4788. MinChargingRate = tempminChargingRateFloat;
  4789. }
  4790. }
  4791. }// the end of ACCESS TxDefaultProfile
  4792. //--------------------- Composite Schedule-----------------------------//
  4793. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4794. {
  4795. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4796. struct tm tp;
  4797. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4798. tp.tm_isdst = -1;
  4799. time_t utc = mktime(&tp);
  4800. time_t t = time(NULL);
  4801. double diff_f = difftime(t, utc);
  4802. int diff_i; //= (int)diff_f;
  4803. int quotient; //= diff_i / 86400;//86400 seconds/day
  4804. int period = 0;
  4805. if(diff_f >= 0)
  4806. {
  4807. diff_i = (int)diff_f;
  4808. quotient = diff_i / 86400;
  4809. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4810. {
  4811. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4812. {
  4813. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4814. {
  4815. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4816. }
  4817. else
  4818. {
  4819. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  4820. }
  4821. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4822. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4823. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4824. period = period + 1;
  4825. }
  4826. }
  4827. }
  4828. confirmPeriods = period;
  4829. }
  4830. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  4831. {
  4832. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4833. struct tm tp;
  4834. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4835. tp.tm_isdst = -1;
  4836. time_t utc = mktime(&tp);
  4837. time_t t = time(NULL);
  4838. double diff_f = difftime(t, utc);
  4839. int diff_i; // = (int)diff_f;
  4840. int quotient; // = diff_i / 86400;//86400 seconds/day
  4841. int period = 0;
  4842. if(diff_f >= 0)
  4843. {
  4844. diff_i = (int)diff_f;
  4845. quotient = diff_i / 86400;//86400 seconds/day
  4846. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4847. {
  4848. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4849. {
  4850. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4851. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4852. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4853. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4854. period = period + 1;
  4855. }
  4856. }
  4857. }
  4858. confirmPeriods = period;
  4859. }
  4860. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  4861. {
  4862. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  4863. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  4864. {
  4865. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  4866. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  4867. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  4868. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4869. }
  4870. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  4871. }
  4872. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  4873. {
  4874. confirmPeriods = 0;
  4875. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  4876. goto end;
  4877. }
  4878. //* Define temporary variables */
  4879. struct tm *gtime;
  4880. time_t now;
  4881. char buf[28];
  4882. /* Read the current system time */
  4883. time(&now);
  4884. /* Convert the system time to GMT (now UTC) */
  4885. gtime = gmtime(&now);
  4886. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4887. // make .conf
  4888. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4889. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  4890. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  4891. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4892. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4893. }
  4894. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4895. {
  4896. //*****************************ChargePointMaxProfile******************************************/
  4897. strcpy(fname, ChargePointMaxProfile_JSON);
  4898. ChargePointMaxProfileIsNull=TRUE;
  4899. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4900. {
  4901. fptr1 = fopen(fname, "r");
  4902. int c;
  4903. c = fgetc(fptr1);
  4904. //DEBUG_INFO("c:%d\n",c);
  4905. rewind(fptr1);
  4906. if(c == EOF)
  4907. {
  4908. DEBUG_INFO("\n End of file reached.");
  4909. ChargePointMaxProfileIsNull=TRUE;
  4910. fclose(fptr1);
  4911. }
  4912. else
  4913. {
  4914. ChargePointMaxProfileIsNull=FALSE;
  4915. while(fscanf(fptr1, "%s", word) != EOF)
  4916. {
  4917. if(strcmp(word, "chargingProfileId") == 0)
  4918. {
  4919. n_chargingProfile = n_chargingProfile + 1;
  4920. }
  4921. }
  4922. rewind(fptr1);
  4923. //search Charging Profile Element
  4924. int i = 0;
  4925. int j = 0;
  4926. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4927. #if 0
  4928. /***********connectorId****************/
  4929. c = 0;
  4930. loc = strstr(sLineWord, "connectorId");
  4931. memset(sstr ,0, sizeof(sstr) );
  4932. while (loc[strlen("connectorId")+2+c] != ',')
  4933. {
  4934. sstr[c] = loc[strlen("connectorId")+2+c];
  4935. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4936. c++;
  4937. }
  4938. sstr[c] = '\0';
  4939. tempconnectorIdInt = atoi(sstr);
  4940. #endif
  4941. //***********validFrom**************/
  4942. c = 0;
  4943. loc = strstr(sLineWord, "validFrom");
  4944. if(loc != NULL)
  4945. {
  4946. memset(sstr ,0, sizeof(sstr) );
  4947. while (loc[3+strlen("validFrom")+c] != '\"')
  4948. {
  4949. sstr[c] = loc[3+strlen("validFrom")+c];
  4950. c++;
  4951. }
  4952. sstr[c] = '\0';
  4953. strcpy(tempvalidFromStr,sstr);
  4954. }
  4955. else
  4956. {
  4957. strcpy(tempvalidFromStr,"");
  4958. }
  4959. //***********validFrom**************/
  4960. c = 0;
  4961. loc = strstr(sLineWord, "duration");
  4962. if(loc != NULL)
  4963. {
  4964. memset(sstr ,0, sizeof(sstr) );
  4965. while (loc[2+strlen("duration")+c] != ',')
  4966. {
  4967. sstr[c] = loc[2+strlen("duration")+c];
  4968. c++;
  4969. }
  4970. sstr[c] = '\0';
  4971. tempdurationInt = atoi(sstr);
  4972. }
  4973. else
  4974. {
  4975. tempdurationInt = 0;
  4976. }
  4977. //**********startSchedule**********/
  4978. c = 0;
  4979. loc = strstr(sLineWord, "startSchedule");
  4980. memset(sstr ,0, sizeof(sstr) );
  4981. while (loc[3+strlen("startSchedule")+c] != '\"')
  4982. {
  4983. sstr[c] = loc[3+strlen("startSchedule")+c];
  4984. c++;
  4985. }
  4986. sstr[c] = '\0';
  4987. strcpy(tempstartScheduleStr, sstr);
  4988. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4989. //**********chargingRateUnit**********/
  4990. c = 0;
  4991. loc = strstr(sLineWord, "chargingRateUnit");
  4992. memset(sstr ,0, sizeof(sstr) );
  4993. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4994. {
  4995. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4996. c++;
  4997. }
  4998. sstr[c] = '\0';
  4999. strcpy(tempchargingRateUnitStr, sstr);
  5000. //**********minChargingRate*******/
  5001. c = 0;
  5002. loc = strstr(sLineWord, "minChargingRate");
  5003. if(loc != NULL)
  5004. {
  5005. memset(sstr ,0, sizeof(sstr) );
  5006. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5007. {
  5008. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5009. c++;
  5010. }
  5011. sstr[c] = '\0';
  5012. tempminChargingRateFloat = atof(sstr);
  5013. }
  5014. else
  5015. {
  5016. tempminChargingRateFloat = 0.0;
  5017. }
  5018. #if 0
  5019. //
  5020. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5021. tp.tm_isdst = -1;
  5022. time_t utc = mktime(&tp);
  5023. time_t t = time(NULL);
  5024. //diff_t = difftime(t, utc);
  5025. #endif
  5026. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5027. //DEBUG_INFO(" debug 5 -1\n");
  5028. //parsing strings to words
  5029. i = 0;
  5030. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5031. loc = loc+3+strlen("chargingSchedulePeriod");
  5032. pch = strtok(loc ,"{");
  5033. while (pch != NULL)
  5034. {
  5035. strcpy(SchedulePeriodList[i], pch);
  5036. pch = strtok (NULL, "{");
  5037. i = i + 1;
  5038. }
  5039. n_SchedulePeriods = i;
  5040. for(int i=0;i<n_SchedulePeriods;i++)
  5041. {
  5042. //*************startPeriod****************/
  5043. c = 0;
  5044. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5045. memset(sstr ,0, sizeof(sstr) );
  5046. while (loc[strlen("startPeriod")+2+c] != ',')
  5047. {
  5048. sstr[c] = loc[strlen("startPeriod")+2+c];
  5049. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5050. c++;
  5051. }
  5052. sstr[c] = '\0';
  5053. tempStartPeriodInt = atoi(sstr);
  5054. //*************limit****************/
  5055. c = 0;
  5056. loc = strstr(SchedulePeriodList[i], "limit");
  5057. memset(sstr ,0, sizeof(sstr) );
  5058. while (loc[strlen("limit")+2+c] != ',')
  5059. {
  5060. sstr[c] = loc[strlen("limit")+2+c];
  5061. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5062. c++;
  5063. }
  5064. sstr[c] = '\0';
  5065. tempLimitInt = atof(sstr);
  5066. //*************numberPhases****************/
  5067. c = 0;
  5068. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5069. memset(sstr ,0, sizeof(sstr) );
  5070. while (loc[strlen("numberPhases")+2+c] != '}')
  5071. {
  5072. sstr[c] = loc[strlen("numberPhases")+2+c];
  5073. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5074. c++;
  5075. }
  5076. sstr[c] = '\0';
  5077. tempNumberPhasesInt = atoi(sstr);
  5078. if(j == 0)
  5079. {
  5080. ChargePointMaxProfile.Duration = tempdurationInt;
  5081. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5082. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5083. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5084. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5085. }
  5086. }
  5087. if(MinChargingRate < tempminChargingRateFloat)
  5088. {
  5089. MinChargingRate = tempminChargingRateFloat;
  5090. }
  5091. if(confirmPeriods < n_SchedulePeriods)
  5092. {
  5093. confirmPeriods = n_SchedulePeriods;
  5094. }
  5095. j = j + 1;
  5096. }
  5097. fclose(fptr1);
  5098. }
  5099. }// the end of access file ChargePointMaxProfile
  5100. //****************************TxDefaultProfile************************************************/
  5101. #if 0
  5102. switch(connectorIdInt)
  5103. {
  5104. case 0:
  5105. break;
  5106. case 1:
  5107. strcpy(fname, TxDefaultProfile_1_JSON );
  5108. break;
  5109. case 2:
  5110. strcpy(fname, TxDefaultProfile_2_JSON );
  5111. break;
  5112. default:
  5113. strcpy(fname, TxDefaultProfile_1_JSON );
  5114. break;
  5115. }
  5116. #endif
  5117. memset(fname, 0, sizeof fname);
  5118. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5119. TxDefaultProfileFileIsNull=TRUE;
  5120. if((access(fname,F_OK))!=-1)
  5121. {
  5122. fptr1 = fopen(fname, "r");
  5123. c = 0;
  5124. c = fgetc(fptr1);
  5125. //DEBUG_INFO("c:%d\n",c);
  5126. rewind(fptr1);
  5127. if(c == EOF)
  5128. {
  5129. DEBUG_INFO("\n End of file reached.");
  5130. TxDefaultProfileFileIsNull=TRUE;
  5131. fclose(fptr1);
  5132. }
  5133. else
  5134. {
  5135. TxDefaultProfileFileIsNull=FALSE;
  5136. while(fscanf(fptr1, "%s", word) != EOF)
  5137. {
  5138. if(strcmp(word, "chargingProfileId") == 0)
  5139. {
  5140. n_chargingProfile = n_chargingProfile + 1;
  5141. }
  5142. }
  5143. rewind(fptr1);
  5144. //search Charging Profile Element
  5145. int i = 0;
  5146. int j = 0;
  5147. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5148. //DEBUG_INFO(" 1-1\n");
  5149. #if 0
  5150. /***********connectorId****************/
  5151. c = 0;
  5152. loc = strstr(sLineWord, "connectorId");
  5153. memset(sstr ,0, sizeof(sstr) );
  5154. while (loc[strlen("connectorId")+2+c] != ',')
  5155. {
  5156. sstr[c] = loc[strlen("connectorId")+2+c];
  5157. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5158. c++;
  5159. }
  5160. sstr[c] = '\0';
  5161. tempconnectorIdInt = atoi(sstr);
  5162. #endif
  5163. //***********validFrom**************/
  5164. c = 0;
  5165. loc = strstr(sLineWord, "validFrom");
  5166. if(loc != NULL)
  5167. {
  5168. memset(sstr ,0, sizeof(sstr) );
  5169. while (loc[3+strlen("validFrom")+c] != '\"')
  5170. {
  5171. sstr[c] = loc[3+strlen("validFrom")+c];
  5172. c++;
  5173. }
  5174. sstr[c] = '\0';
  5175. strcpy(tempvalidFromStr,sstr);
  5176. }
  5177. else
  5178. {
  5179. strcpy(tempvalidFromStr,"");
  5180. }
  5181. //***********validFrom**************/
  5182. c = 0;
  5183. loc = strstr(sLineWord, "duration");
  5184. if(loc != NULL)
  5185. {
  5186. memset(sstr ,0, sizeof(sstr) );
  5187. while (loc[2+strlen("duration")+c] != ',')
  5188. {
  5189. sstr[c] = loc[2+strlen("duration")+c];
  5190. c++;
  5191. }
  5192. sstr[c] = '\0';
  5193. tempdurationInt = atoi(sstr);
  5194. }
  5195. else
  5196. {
  5197. tempdurationInt = 0;
  5198. }
  5199. //**********startSchedule**********/
  5200. c = 0;
  5201. loc = strstr(sLineWord, "startSchedule");
  5202. memset(sstr ,0, sizeof(sstr) );
  5203. while (loc[3+strlen("startSchedule")+c] != '\"')
  5204. {
  5205. sstr[c] = loc[3+strlen("startSchedule")+c];
  5206. c++;
  5207. }
  5208. sstr[c] = '\0';
  5209. strcpy(tempstartScheduleStr, sstr);
  5210. strcpy(TxDefaultProfileScheduleStr, sstr);
  5211. //**********chargingRateUnit**********/
  5212. c = 0;
  5213. loc = strstr(sLineWord, "chargingRateUnit");
  5214. memset(sstr ,0, sizeof(sstr) );
  5215. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5216. {
  5217. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5218. c++;
  5219. }
  5220. sstr[c] = '\0';
  5221. strcpy(tempchargingRateUnitStr, sstr);
  5222. //**********minChargingRate*******/
  5223. c = 0;
  5224. loc = strstr(sLineWord, "minChargingRate");
  5225. if(loc != NULL)
  5226. {
  5227. memset(sstr ,0, sizeof(sstr) );
  5228. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5229. {
  5230. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5231. c++;
  5232. }
  5233. sstr[c] = '\0';
  5234. tempminChargingRateFloat = atof(sstr);
  5235. }
  5236. else
  5237. {
  5238. tempminChargingRateFloat = 0.0;
  5239. }
  5240. #if 0
  5241. //
  5242. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5243. tp.tm_isdst = -1;
  5244. time_t utc = mktime(&tp);
  5245. time_t t = time(NULL);
  5246. //diff_t = difftime(t, utc);
  5247. #endif
  5248. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5249. //parsing strings to words
  5250. i = 0;
  5251. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5252. loc = loc+3+strlen("chargingSchedulePeriod");
  5253. pch = strtok(loc ,"{");
  5254. while (pch != NULL)
  5255. {
  5256. strcpy(SchedulePeriodList[i], pch);
  5257. pch = strtok (NULL, "{");
  5258. i = i + 1;
  5259. }
  5260. n_SchedulePeriods = i;
  5261. for(int i=0;i<n_SchedulePeriods;i++)
  5262. {
  5263. //*************startPeriod****************/
  5264. c = 0;
  5265. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5266. memset(sstr ,0, sizeof(sstr) );
  5267. while (loc[strlen("startPeriod")+2+c] != ',')
  5268. {
  5269. sstr[c] = loc[strlen("startPeriod")+2+c];
  5270. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5271. c++;
  5272. }
  5273. sstr[c] = '\0';
  5274. tempStartPeriodInt = atoi(sstr);
  5275. //*************limit****************/
  5276. c = 0;
  5277. loc = strstr(SchedulePeriodList[i], "limit");
  5278. memset(sstr ,0, sizeof(sstr) );
  5279. while (loc[strlen("limit")+2+c] != ',')
  5280. {
  5281. sstr[c] = loc[strlen("limit")+2+c];
  5282. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5283. c++;
  5284. }
  5285. sstr[c] = '\0';
  5286. tempLimitInt = atof(sstr);
  5287. //*************numberPhases****************/
  5288. c = 0;
  5289. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5290. memset(sstr ,0, sizeof(sstr) );
  5291. while (loc[strlen("numberPhases")+2+c] != '}')
  5292. {
  5293. sstr[c] = loc[strlen("numberPhases")+2+c];
  5294. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5295. c++;
  5296. }
  5297. sstr[c] = '\0';
  5298. tempNumberPhasesInt = atoi(sstr);
  5299. if(j == 0)
  5300. {
  5301. TxDefaultProfile.Duration = tempdurationInt;
  5302. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5303. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5304. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5305. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5306. }
  5307. else
  5308. {
  5309. //other stack level charging Profile
  5310. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5311. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5312. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5313. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5314. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5315. }
  5316. }
  5317. if(MinChargingRate < tempminChargingRateFloat)
  5318. MinChargingRate = tempminChargingRateFloat;
  5319. if(confirmPeriods < n_SchedulePeriods)
  5320. confirmPeriods = n_SchedulePeriods;
  5321. j = j + 1;
  5322. //DEBUG_INFO(" 1-2\n");
  5323. }
  5324. fclose(fptr1);
  5325. //Stacking Charging Profiles
  5326. for(int l=0; l <(j-1) ;l++)
  5327. {
  5328. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5329. {
  5330. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5331. {
  5332. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5333. {
  5334. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5335. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5336. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5337. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5338. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5339. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5340. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5341. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5342. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5343. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5344. }
  5345. else
  5346. {
  5347. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5348. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5349. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5350. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5351. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5352. }
  5353. }
  5354. }
  5355. }
  5356. //end of Stacking Charging Profiles
  5357. }
  5358. }// the end of ACCESS TxDefaultProfile
  5359. //****************************TxProfile************************************************/
  5360. #if 0
  5361. switch(connectorIdInt)
  5362. {
  5363. case 0:
  5364. break;
  5365. case 1:
  5366. strcpy(fname, TxProfile_1_JSON );
  5367. break;
  5368. case 2:
  5369. strcpy(fname, TxProfile_2_JSON );
  5370. break;
  5371. default:
  5372. strcpy(fname, TxProfile_1_JSON );
  5373. break;
  5374. }
  5375. #endif
  5376. memset(fname, 0, sizeof fname);
  5377. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5378. TxProfileIsNull=TRUE;
  5379. if((access(fname,F_OK))!=-1)
  5380. {
  5381. fptr1 = fopen(fname, "r");
  5382. c = 0;
  5383. c = fgetc(fptr1);
  5384. //DEBUG_INFO("c:%d\n",c);
  5385. rewind(fptr1);
  5386. if(c == EOF)
  5387. {
  5388. DEBUG_INFO("\n End of file reached.");
  5389. TxProfileIsNull=TRUE;
  5390. fclose(fptr1);
  5391. }
  5392. else
  5393. {
  5394. TxProfileIsNull=FALSE;
  5395. while(fscanf(fptr1, "%s", word) != EOF)
  5396. {
  5397. if(strcmp(word, "chargingProfileId") == 0)
  5398. {
  5399. n_chargingProfile = n_chargingProfile + 1;
  5400. }
  5401. }
  5402. rewind(fptr1);
  5403. //search Charging Profile Element
  5404. int i= 0;
  5405. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5406. #if 0
  5407. /***********connectorId****************/
  5408. c = 0;
  5409. loc = strstr(sLineWord, "connectorId");
  5410. memset(sstr ,0, sizeof(sstr) );
  5411. while (loc[strlen("connectorId")+2+c] != ',')
  5412. {
  5413. sstr[c] = loc[strlen("connectorId")+2+c];
  5414. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5415. c++;
  5416. }
  5417. sstr[c] = '\0';
  5418. tempconnectorIdInt = atoi(sstr);
  5419. #endif
  5420. //***********validFrom**************/
  5421. c = 0;
  5422. loc = strstr(sLineWord, "validFrom");
  5423. if(loc != NULL)
  5424. {
  5425. memset(sstr ,0, sizeof(sstr) );
  5426. while (loc[3+strlen("validFrom")+c] != '\"')
  5427. {
  5428. sstr[c] = loc[3+strlen("validFrom")+c];
  5429. c++;
  5430. }
  5431. sstr[c] = '\0';
  5432. strcpy(tempvalidFromStr,sstr);
  5433. }
  5434. else
  5435. {
  5436. strcpy(tempvalidFromStr,"");
  5437. }
  5438. //**********startSchedule**********/
  5439. c = 0;
  5440. loc = strstr(sLineWord, "startSchedule");
  5441. memset(sstr ,0, sizeof(sstr) );
  5442. while (loc[3+strlen("startSchedule")+c] != '\"')
  5443. {
  5444. sstr[c] = loc[3+strlen("startSchedule")+c];
  5445. c++;
  5446. }
  5447. sstr[c] = '\0';
  5448. strcpy(tempstartScheduleStr, sstr);
  5449. strcpy(TxProfileScheduleStr, sstr);
  5450. //**********chargingRateUnit**********/
  5451. c = 0;
  5452. loc = strstr(sLineWord, "chargingRateUnit");
  5453. memset(sstr ,0, sizeof(sstr) );
  5454. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5455. {
  5456. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5457. c++;
  5458. }
  5459. sstr[c] = '\0';
  5460. strcpy(tempchargingRateUnitStr, sstr);
  5461. //**********minChargingRate*******/
  5462. c = 0;
  5463. loc = strstr(sLineWord, "minChargingRate");
  5464. if(loc != NULL)
  5465. {
  5466. memset(sstr ,0, sizeof(sstr) );
  5467. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5468. {
  5469. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5470. c++;
  5471. }
  5472. sstr[c] = '\0';
  5473. tempminChargingRateFloat = atof(sstr);
  5474. }
  5475. else
  5476. {
  5477. tempminChargingRateFloat = 0.0;
  5478. }
  5479. #if 0
  5480. //
  5481. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5482. tp.tm_isdst = -1;
  5483. time_t utc = mktime(&tp);
  5484. time_t t = time(NULL);
  5485. //diff_t = difftime(t, utc);
  5486. #endif
  5487. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5488. //parsing strings to words
  5489. i = 0;
  5490. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5491. loc = loc+3+strlen("chargingSchedulePeriod");
  5492. pch = strtok(loc ,"{");
  5493. while (pch != NULL)
  5494. {
  5495. strcpy(SchedulePeriodList[i], pch);
  5496. pch = strtok (NULL, "{");
  5497. i = i + 1;
  5498. }
  5499. n_SchedulePeriods = i;
  5500. for(int i=0;i<n_SchedulePeriods;i++)
  5501. {
  5502. //*************startPeriod****************/
  5503. c = 0;
  5504. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5505. memset(sstr ,0, sizeof(sstr) );
  5506. while (loc[strlen("startPeriod")+2+c] != ',')
  5507. {
  5508. sstr[c] = loc[strlen("startPeriod")+2+c];
  5509. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5510. c++;
  5511. }
  5512. sstr[c] = '\0';
  5513. tempStartPeriodInt = atoi(sstr);
  5514. //*************limit****************/
  5515. c = 0;
  5516. loc = strstr(SchedulePeriodList[i], "limit");
  5517. memset(sstr ,0, sizeof(sstr) );
  5518. while (loc[strlen("limit")+2+c] != ',')
  5519. {
  5520. sstr[c] = loc[strlen("limit")+2+c];
  5521. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5522. c++;
  5523. }
  5524. sstr[c] = '\0';
  5525. tempLimitInt = atof(sstr);
  5526. //*************numberPhases****************/
  5527. c = 0;
  5528. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5529. memset(sstr ,0, sizeof(sstr) );
  5530. while (loc[strlen("numberPhases")+2+c] != '}')
  5531. {
  5532. sstr[c] = loc[strlen("numberPhases")+2+c];
  5533. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5534. c++;
  5535. }
  5536. sstr[c] = '\0';
  5537. tempNumberPhasesInt = atoi(sstr);
  5538. TxProfile.Duration = durationInt;
  5539. TxProfile.TotalPeriod = n_SchedulePeriods;
  5540. TxProfile.Period[i].Limit = tempLimitInt;
  5541. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5542. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5543. }
  5544. if(MinChargingRate < tempminChargingRateFloat)
  5545. MinChargingRate = tempminChargingRateFloat;
  5546. if(confirmPeriods < n_SchedulePeriods)
  5547. confirmPeriods = n_SchedulePeriods;
  5548. }
  5549. fclose(fptr1);
  5550. }
  5551. }// the end of ACCESS TxProfile
  5552. //CompositeSchedule
  5553. int period=0;
  5554. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5555. {
  5556. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5557. struct tm tp;
  5558. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5559. tp.tm_isdst = -1;
  5560. time_t utc = mktime(&tp);
  5561. time_t t = time(NULL);
  5562. double diff_f = difftime(t, utc);
  5563. int diff_i; // = (int)diff_f;
  5564. int quotient; // = diff_i / 86400;//86400 seconds/day
  5565. //int remainder = diff_i % 86400;
  5566. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5567. {
  5568. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5569. {
  5570. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5571. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5572. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5573. period = period + 1;
  5574. }
  5575. else
  5576. {
  5577. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5578. {
  5579. }
  5580. else
  5581. {
  5582. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5583. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5584. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5585. period = period + 1;
  5586. }
  5587. }
  5588. }
  5589. if( diff_f >= 0)
  5590. {
  5591. diff_i = (int)diff_f;
  5592. quotient = diff_i / 86400;//86400 seconds/day
  5593. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5594. {
  5595. 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))
  5596. {
  5597. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5598. {
  5599. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5600. }
  5601. else
  5602. {
  5603. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5604. }
  5605. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5606. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  5607. period = period + 1;
  5608. }
  5609. }
  5610. // Check Last Period
  5611. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5612. {
  5613. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5614. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5615. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5616. period = period + 1;
  5617. }
  5618. } // diff_f >= 0
  5619. }
  5620. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5621. {
  5622. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5623. struct tm tp;
  5624. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5625. tp.tm_isdst = -1;
  5626. time_t utc = mktime(&tp);
  5627. time_t t = time(NULL);
  5628. double diff_f = difftime(t, utc);
  5629. int diff_i;// = (int)diff_f;
  5630. int quotient; // = diff_i / 86400;//86400 seconds/day
  5631. //int remainder = diff_i % 86400;
  5632. if(diff_f >= 0)
  5633. {
  5634. diff_i = (int)diff_f;
  5635. quotient = diff_i / 86400;//86400 seconds/day
  5636. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5637. {
  5638. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5639. {
  5640. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5641. {
  5642. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5643. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5644. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5645. period = period + 1;
  5646. }
  5647. else
  5648. {
  5649. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5650. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5651. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5652. period = period + 1;
  5653. }
  5654. }
  5655. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5656. {
  5657. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5658. {
  5659. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5660. {
  5661. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5662. {
  5663. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5664. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5665. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5666. period = period + 1;
  5667. }
  5668. else
  5669. {
  5670. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5671. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5672. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5673. period = period + 1;
  5674. }
  5675. }
  5676. }
  5677. }
  5678. }
  5679. } // end diff_f >= 0
  5680. }
  5681. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5682. {
  5683. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5684. struct tm tp;
  5685. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5686. tp.tm_isdst = -1;
  5687. time_t utc = mktime(&tp);
  5688. time_t t = time(NULL);
  5689. double diff_f = difftime(t, utc);
  5690. int diff_i; // = (int)diff_f;
  5691. int quotient; // = diff_i / 86400;//86400 seconds/day
  5692. //int remainder = diff_i % 86400;
  5693. if(diff_f >= 0)
  5694. {
  5695. diff_i = (int)diff_f;
  5696. quotient = diff_i / 86400;//86400 seconds/day
  5697. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5698. {
  5699. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5700. {
  5701. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5702. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5703. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5704. period = period + 1;
  5705. }
  5706. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5707. {
  5708. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5709. {
  5710. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5711. {
  5712. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5713. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5714. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5715. period = period + 1;
  5716. }
  5717. }
  5718. }
  5719. }
  5720. } // diff_f >= 0
  5721. }
  5722. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  5723. {
  5724. confirmPeriods = 0;
  5725. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5726. goto end;
  5727. }
  5728. confirmPeriods = period;
  5729. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5730. //---- Define StartSchedule----/
  5731. struct tm *gtime;
  5732. time_t now;
  5733. char buf[28];
  5734. //---Read the current system time---/
  5735. time(&now);
  5736. //---Convert the system time to GMT (now UTC)---/
  5737. gtime = gmtime(&now);
  5738. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5739. // make .conf
  5740. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5741. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5742. //DEBUG_INFO(" debug 11\n");
  5743. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5744. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5745. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5746. }
  5747. else
  5748. {
  5749. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5750. }
  5751. end:
  5752. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5753. return result;
  5754. }
  5755. int handleGetConfigurationRequest(char *uuid, char *payload)
  5756. {
  5757. mtrace();
  5758. int result = FAIL;
  5759. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5760. //struct json_object *jsonitem;
  5761. int MaxKeySupported = 0;
  5762. int n_keys = 0;
  5763. char requestKey[43][50]={0};
  5764. char search[]="[";
  5765. char sstr[500]={ 0 };
  5766. //int pos;
  5767. int l, c = 0;
  5768. int i = 0;
  5769. char *delim = "\",\"";
  5770. char * pch;
  5771. char *loc = strstr(payload, search);
  5772. //********************* Parsing String ***********************************/
  5773. if(loc == NULL) {
  5774. DEBUG_INFO("no key match in Configuration \n");
  5775. }
  5776. else {
  5777. //pos = loc - payload;
  5778. l = strlen(loc)-4;
  5779. while (c < l)
  5780. {
  5781. sstr[c] = loc[c+2];
  5782. c++;
  5783. }
  5784. sstr[c] = '\0';
  5785. //parsing strings to words
  5786. pch = strtok(sstr,delim);
  5787. if(pch == NULL)
  5788. {
  5789. strcpy(requestKey[0], sstr);
  5790. }
  5791. else
  5792. {
  5793. while (pch != NULL)
  5794. {
  5795. strcpy(requestKey[i], pch);
  5796. pch = strtok (NULL, delim);
  5797. i = i + 1;
  5798. }
  5799. n_keys = i;
  5800. }
  5801. }
  5802. UnknownKeynum = 0;
  5803. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5804. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5805. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5806. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5807. if(n_keys != 0)
  5808. {
  5809. for(int i=0;i<n_keys;i++)
  5810. {
  5811. getKeyValue(requestKey[i]);
  5812. //json_object_put(jsonitem);
  5813. }
  5814. }
  5815. else
  5816. {
  5817. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5818. getKeyValue("");
  5819. }
  5820. processUnkownKey();
  5821. sendGetConfigurationConfirmation(uuid);
  5822. return result;
  5823. }
  5824. static char fnamePlusPath[100]={0};
  5825. static char fnamePWithNoPath[60]={0};
  5826. void checkUploadLog(void)
  5827. {
  5828. FILE *fp;
  5829. /* Open the command for reading. */
  5830. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5831. if (fp == NULL) {
  5832. printf("Failed to run command\n" );
  5833. exit(1);
  5834. }
  5835. int ftppathlen = 0;
  5836. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5837. int i = 0;
  5838. /* Read the output a line at a time - output it. */
  5839. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5840. if(i==0)
  5841. {
  5842. ftppathlen = strlen(fnamePlusPath);
  5843. printf("%s\n", fnamePlusPath);
  5844. fnamePlusPath[ftppathlen]='\0';
  5845. break;
  5846. }
  5847. i= i+1;
  5848. }
  5849. /* close */
  5850. pclose(fp);
  5851. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5852. {
  5853. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5854. {
  5855. fnamePlusPath[k]='\0';
  5856. }
  5857. }
  5858. i=1;
  5859. //char fname[60]={0};
  5860. while(i < ftppathlen)
  5861. {
  5862. int len=ftppathlen-i;
  5863. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5864. {
  5865. printf("compare '/' all right\n");
  5866. break;
  5867. }
  5868. i=i+1;
  5869. }
  5870. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5871. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5872. fnamePWithNoPath[i+1] = '\0';
  5873. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5874. {
  5875. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5876. {
  5877. fnamePWithNoPath[j]='\0';
  5878. }
  5879. }
  5880. FILE* fp1 = fopen(fnamePlusPath, "r");
  5881. if (fp1)
  5882. {
  5883. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5884. // file exists
  5885. fclose(fp1);
  5886. }
  5887. else
  5888. {
  5889. // file doesn't exist
  5890. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5891. }
  5892. }
  5893. static char GetDiagnosticspayloadData[300]={0};
  5894. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5895. {
  5896. mtrace();
  5897. int result = FAIL;
  5898. pthread_t t; // pthread 變數
  5899. system("exec /root/logPackTools 'log' 6");
  5900. #if 0
  5901. //char buffer [128];
  5902. time (&rawtime);
  5903. //printf("%ld\n", rawtime);
  5904. timeinfo = localtime (&rawtime);
  5905. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5906. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5907. if((access(fnamePlusPath,F_OK))!=-1)
  5908. {
  5909. DEBUG_INFO("fnamePlusPath exist.\n");
  5910. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5911. }
  5912. else
  5913. {
  5914. DEBUG_INFO("fnamePlusPath not exist!\n");
  5915. }
  5916. #endif
  5917. checkUploadLog();
  5918. memset(GetDiagnosticspayloadData, 0, 300);
  5919. strcpy(GetDiagnosticspayloadData, payload);
  5920. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5921. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5922. return result;
  5923. }
  5924. void* GetDiagnosticsProcess(void* data)
  5925. {
  5926. pthread_detach(pthread_self());
  5927. mtrace();
  5928. int retriesInt=0, retryIntervalInt=0;
  5929. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5930. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5931. 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};
  5932. int port=0;
  5933. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5934. int c = 0;
  5935. char *loc;
  5936. int isSuccess = FALSE;
  5937. char ftpbuf[200]={0};
  5938. //char temp[100]={0};
  5939. char * pch;
  5940. // [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"}]
  5941. char str[300]={ 0 };
  5942. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5943. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5944. DEBUG_INFO("GetDiagnosticsProcess\n");
  5945. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5946. //****************location*******************/
  5947. c = 0;
  5948. memset(sstr ,0, sizeof(sstr) );
  5949. loc = strstr(str, "location");
  5950. while (loc[3+strlen("location")+c] != '\"')
  5951. {
  5952. sstr[c] = loc[3+strlen("location")+c];
  5953. c++;
  5954. }
  5955. sstr[c] = '\0';
  5956. strcpy(locationstr,sstr);
  5957. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5958. if(strcmp(locationstr,"")==0)
  5959. {
  5960. DEBUG_INFO("location is <Empty>!\n");
  5961. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5962. goto end;
  5963. }
  5964. //****************retries*******************/
  5965. c = 0;
  5966. loc = strstr(str, "retries");
  5967. if(loc == NULL)
  5968. {
  5969. retriesIsNULL = TRUE;
  5970. }
  5971. else
  5972. {
  5973. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5974. {
  5975. sstr[c] = loc[strlen("retries")+2+c];
  5976. c++;
  5977. }
  5978. sstr[c] = '\0';
  5979. retriesInt = atoi(sstr);
  5980. }
  5981. if(retriesIsNULL == TRUE)
  5982. {
  5983. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5984. }
  5985. //****************retryInterval*******************/
  5986. c = 0;
  5987. loc = strstr(str, "retryInterval");
  5988. if(loc == NULL)
  5989. {
  5990. retryIntervalIsNULL = TRUE;
  5991. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5992. }
  5993. else
  5994. {
  5995. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5996. {
  5997. sstr[c] = loc[strlen("retryInterval")+2+c];
  5998. c++;
  5999. }
  6000. sstr[c] = '\0';
  6001. retryIntervalInt = atoi(sstr);
  6002. }
  6003. //****************startTime*******************/
  6004. c = 0;
  6005. memset(sstr ,0, sizeof(sstr) );
  6006. loc = strstr(str, "startTime");
  6007. if(loc == NULL)
  6008. {
  6009. startTimeIsNULL = TRUE;
  6010. }
  6011. else
  6012. {
  6013. while (loc[3+strlen("startTime")+c] != '\"')
  6014. {
  6015. sstr[c] = loc[3+strlen("startTime")+c];
  6016. c++;
  6017. }
  6018. sstr[c] = '\0';
  6019. strcpy(startTimestr,sstr);
  6020. }
  6021. //****************stopTime*******************/
  6022. c = 0;
  6023. memset(sstr ,0, sizeof(sstr) );
  6024. loc = strstr(str, "stopTime");
  6025. if(loc == NULL)
  6026. {
  6027. stopTimeIsNULL = TRUE;
  6028. }
  6029. else
  6030. {
  6031. while (loc[3+strlen("stopTime")+c] != '\"')
  6032. {
  6033. sstr[c] = loc[3+strlen("stopTime")+c];
  6034. c++;
  6035. }
  6036. sstr[c] = '\0';
  6037. strcpy(stopTimestr,sstr);
  6038. }
  6039. memset(protocol, 0, sizeof(protocol));
  6040. memset(user, 0, sizeof(user) );
  6041. memset(password, 0, sizeof(password));
  6042. memset(host, 0, sizeof(host));
  6043. memset(path, 0, sizeof(path));
  6044. memset(ftppath, 0, sizeof(ftppath));
  6045. memset(host1, 0, sizeof(host1));
  6046. memset(path1, 0, sizeof(path1));
  6047. /*location: ftp://user:password@host:port/path*/
  6048. #if 0
  6049. time_t rawtime;
  6050. struct tm * timeinfo;
  6051. //char buffer [128];
  6052. time (&rawtime);
  6053. //printf("%ld\n", rawtime);
  6054. timeinfo = localtime (&rawtime);
  6055. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6056. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6057. #endif
  6058. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6059. if((access(fnamePlusPath,F_OK))!=-1)
  6060. {
  6061. DEBUG_INFO("fnamePlusPath exist.\n");
  6062. }
  6063. else
  6064. {
  6065. DEBUG_INFO("fnamePlusPath not exist!\n");
  6066. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6067. goto end;
  6068. }
  6069. pch=strchr(locationstr,'@');
  6070. if(pch==NULL)
  6071. {
  6072. sscanf(locationstr,
  6073. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6074. protocol, host, &port, path);
  6075. strcpy(user,"anonymous");
  6076. strcpy(password,"");
  6077. }
  6078. else
  6079. {
  6080. //DEBUG_INFO("pch=%s\n", pch);
  6081. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6082. protocol, user, password, host, &port, path);
  6083. }
  6084. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6085. {
  6086. DEBUG_INFO("protocol is not ftp/http ! \n");
  6087. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6088. goto end;
  6089. }
  6090. if(strncmp(locationstr,"http", 4) == 0)
  6091. {
  6092. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6093. sprintf(ftppath,"/%s", path);
  6094. do{
  6095. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6096. sleep(retryIntervalInt);
  6097. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6098. if(!isSuccess)
  6099. {
  6100. DEBUG_INFO("Diagnostics fail.\n");
  6101. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6102. }
  6103. else
  6104. {
  6105. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6106. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6107. }
  6108. }
  6109. else
  6110. {
  6111. sscanf(host,"%[^/]%s",host1, path1);
  6112. sprintf(ftppath,"%s", path1);
  6113. int ftppathlen=strlen(ftppath);
  6114. int i=1;
  6115. char filenametemp[50];
  6116. while(i < ftppathlen)
  6117. {
  6118. int len=ftppathlen-i;
  6119. if(ftppath[len]== 47) // '/' ascll code: 47
  6120. {
  6121. DEBUG_INFO("find '/' all right\n");
  6122. break;
  6123. }
  6124. i=i+1;
  6125. }
  6126. memset(filenametemp, 0, sizeof(filenametemp));
  6127. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6128. filenametemp[i+1] = 0;
  6129. memset(ftpbuf, 0, sizeof(ftpbuf));
  6130. if(port == 0)
  6131. port = 21;
  6132. do{
  6133. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6134. sleep(retryIntervalInt);
  6135. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6136. if(!isSuccess)
  6137. {
  6138. DEBUG_INFO("Diagnostics fail.\n");
  6139. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6140. }
  6141. else
  6142. {
  6143. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6144. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6145. }
  6146. }
  6147. end:
  6148. DiagnosticsStatusNotificationStatus = 0; //Idle
  6149. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6150. }
  6151. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6152. {
  6153. mtrace();
  6154. int result = FAIL;
  6155. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6156. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6157. {
  6158. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6159. localversion = -1;
  6160. }
  6161. else
  6162. {
  6163. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6164. OCPP_getListVerion();
  6165. }
  6166. //from db.OCPP_getListVerion
  6167. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6168. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6169. sendGetLocalListVersionConfirmation(uuid,"");
  6170. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6171. return result;
  6172. }
  6173. int handleRemoteStartRequest(char *uuid, char *payload)
  6174. {
  6175. mtrace();
  6176. int result = FAIL;
  6177. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6178. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6179. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6180. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6181. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6182. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6183. int chargingSchedulePeriodCount = 0;
  6184. char sstr[30]={ 0 };//sstr[200]={ 0 };
  6185. int c = 0;
  6186. char *loc;
  6187. char comfirmstr[20]={0};
  6188. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6189. if(server_pending == TRUE)
  6190. {
  6191. return 0;
  6192. }
  6193. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6194. //**********connectorId****************/
  6195. c = 0;
  6196. memset(sstr ,0, sizeof(sstr) );
  6197. loc = strstr(payload, "connectorId");
  6198. if(loc == NULL)
  6199. {
  6200. connectorIdIsNULL = TRUE;
  6201. }
  6202. else
  6203. {
  6204. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6205. {
  6206. sstr[c] = loc[strlen("connectorId")+2+c];
  6207. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6208. c++;
  6209. }
  6210. sstr[c] = '\0';
  6211. connectorIdInt = atoi(sstr);
  6212. }
  6213. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6214. {
  6215. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6216. goto end;
  6217. }
  6218. //****************idTag*******************/
  6219. c = 0;
  6220. memset(sstr ,0, sizeof(sstr) );
  6221. loc = strstr(payload, "idTag");
  6222. while (loc[3+strlen("idTag")+c] != '\"')
  6223. {
  6224. sstr[c] = loc[3+strlen("idTag")+c];
  6225. c++;
  6226. }
  6227. sstr[c] = '\0';
  6228. strcpy(idTagstr,sstr);
  6229. //****************chargingProfile*******************/
  6230. c = 0;
  6231. memset(sstr ,0, sizeof(sstr) );
  6232. loc = strstr(payload, "chargingProfile");
  6233. if(loc == NULL)
  6234. {
  6235. chargingProfileIsNULL = TRUE;
  6236. }
  6237. else
  6238. {
  6239. //****************chargingProfileId*******************/
  6240. c=0;
  6241. loc = strstr(payload, "chargingProfileId");
  6242. memset(sstr ,0, sizeof(sstr) );
  6243. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6244. {
  6245. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6246. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6247. c++;
  6248. }
  6249. sstr[c] = '\0';
  6250. chargingProfileIdInt = atoi(sstr);
  6251. //****************transactionId*******************/
  6252. loc = strstr(payload, "transactionId");
  6253. if(loc == NULL)
  6254. {
  6255. transactionIdIsNULL = TRUE;
  6256. }
  6257. else
  6258. {
  6259. c=0;
  6260. memset(sstr ,0, sizeof(sstr) );
  6261. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6262. {
  6263. sstr[c] = loc[strlen("transactionId")+2+c];
  6264. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6265. c++;
  6266. }
  6267. sstr[c] = '\0';
  6268. transactionIdInt = atoi(sstr);
  6269. }
  6270. //****************stackLevel*******************/
  6271. c=0;
  6272. loc = strstr(payload, "stackLevel");
  6273. memset(sstr ,0, sizeof(sstr) );
  6274. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6275. {
  6276. sstr[c] = loc[strlen("stackLevel")+2+c];
  6277. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6278. c++;
  6279. }
  6280. sstr[c] = '\0';
  6281. stackLevelInt = atoi(sstr);
  6282. //****************chargingProfilePurpose*******************/
  6283. c = 0;
  6284. memset(sstr ,0, sizeof(sstr) );
  6285. loc = strstr(payload, "chargingProfilePurpose");
  6286. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6287. {
  6288. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6289. c++;
  6290. }
  6291. sstr[c] = '\0';
  6292. strcpy(chargingProfilePurposestr,sstr);
  6293. //****************chargingProfileKind*******************/
  6294. c = 0;
  6295. memset(sstr ,0, sizeof(sstr) );
  6296. loc = strstr(payload, "chargingProfileKind");
  6297. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6298. {
  6299. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6300. c++;
  6301. }
  6302. sstr[c] = '\0';
  6303. strcpy(chargingProfileKindstr,sstr);
  6304. //****************recurrencyKind*******************/
  6305. loc = strstr(payload, "recurrencyKind");
  6306. if(loc == NULL)
  6307. {
  6308. recurrencyKindIsNULL = TRUE;
  6309. }
  6310. else
  6311. {
  6312. c = 0;
  6313. memset(sstr ,0, sizeof(sstr) );
  6314. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6315. {
  6316. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6317. c++;
  6318. }
  6319. sstr[c] = '\0';
  6320. strcpy(recurrencyKindstr,sstr);
  6321. }
  6322. //****************validFrom*******************/
  6323. loc = strstr(payload, "validFrom");
  6324. if(loc == NULL)
  6325. {
  6326. validFromIsNULL = TRUE;
  6327. }
  6328. else
  6329. {
  6330. c = 0;
  6331. memset(sstr ,0, sizeof(sstr) );
  6332. while (loc[3+strlen("validFrom")+c] != '\"')
  6333. {
  6334. sstr[c] = loc[3+strlen("validFrom")+c];
  6335. c++;
  6336. }
  6337. sstr[c] = '\0';
  6338. strcpy(validFromstr,sstr);
  6339. }
  6340. //****************validTo*******************/
  6341. loc = strstr(payload, "validTo");
  6342. if(loc == NULL)
  6343. {
  6344. validToIsNULL = TRUE;
  6345. }
  6346. else
  6347. {
  6348. c = 0;
  6349. memset(sstr ,0, sizeof(sstr) );
  6350. while (loc[3+strlen("validTo")+c] != '\"')
  6351. {
  6352. sstr[c] = loc[3+strlen("validTo")+c];
  6353. c++;
  6354. }
  6355. sstr[c] = '\0';
  6356. strcpy(validTostr,sstr);
  6357. }
  6358. //****************chargingSchedule*******************/
  6359. loc = strstr(payload, "chargingSchedule");
  6360. if(loc != NULL)
  6361. {
  6362. //****************duration*******************/
  6363. loc = strstr(payload, "duration");
  6364. if(loc == NULL)
  6365. {
  6366. durationIsNULL = TRUE;
  6367. }
  6368. else
  6369. {
  6370. c=0;
  6371. memset(sstr ,0, sizeof(sstr) );
  6372. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6373. {
  6374. sstr[c] = loc[strlen("duration")+2+c];
  6375. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6376. c++;
  6377. }
  6378. sstr[c] = '\0';
  6379. durationInt = atoi(sstr);
  6380. }
  6381. //****************startSchedule******************/
  6382. loc = strstr(payload, "startSchedule");
  6383. if(loc == NULL)
  6384. {
  6385. startScheduleIsNULL = TRUE;
  6386. }
  6387. else
  6388. {
  6389. c = 0;
  6390. memset(sstr ,0, sizeof(sstr) );
  6391. while (loc[3+strlen("startSchedule")+c] != '\"')
  6392. {
  6393. sstr[c] = loc[3+strlen("startSchedule")+c];
  6394. c++;
  6395. }
  6396. sstr[c] = '\0';
  6397. strcpy(startSchedulestr,sstr);
  6398. }
  6399. //****************chargingRateUnit*******************/
  6400. c = 0;
  6401. memset(sstr ,0, sizeof(sstr) );
  6402. loc = strstr(payload, "chargingRateUnit");
  6403. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6404. {
  6405. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6406. c++;
  6407. }
  6408. sstr[c] = '\0';
  6409. strcpy(chargingRateUnitstr,sstr);
  6410. //****************minChargingRate*******************/
  6411. loc = strstr(payload, "minChargingRate");
  6412. if(loc == NULL)
  6413. {
  6414. minChargingRateIsNULL = TRUE;
  6415. }
  6416. else
  6417. {
  6418. c=0;
  6419. memset(sstr ,0, sizeof(sstr) );
  6420. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6421. {
  6422. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6423. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6424. c++;
  6425. }
  6426. sstr[c] = '\0';
  6427. minChargingRateflaot = atof(sstr);
  6428. }
  6429. //****************chargingSchedulePeriod count*******************/
  6430. int what_len = strlen("startPeriod");
  6431. char *where = payload;
  6432. while ((where = strstr(where, "startPeriod"))) {
  6433. where += what_len;
  6434. chargingSchedulePeriodCount++;
  6435. }
  6436. where = payload;
  6437. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6438. {
  6439. //****************startPeriod*******************/
  6440. c=0;
  6441. loc = strstr(where, "startPeriod");
  6442. memset(sstr ,0, sizeof(sstr) );
  6443. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6444. {
  6445. sstr[c] = loc[strlen("startPeriod")+2+c];
  6446. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6447. c++;
  6448. }
  6449. sstr[c] = '\0';
  6450. startPeriodInt[periodNums] = atoi(sstr);
  6451. //****************limit*******************/
  6452. c=0;
  6453. loc = strstr(where, "limit");
  6454. memset(sstr ,0, sizeof(sstr) );
  6455. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6456. {
  6457. sstr[c] = loc[strlen("limit")+2+c];
  6458. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6459. c++;
  6460. }
  6461. sstr[c] = '\0';
  6462. limitflaot[periodNums] = atof(sstr);
  6463. //****************numberPhases*******************/
  6464. loc = strstr(where, "numberPhases");
  6465. if(loc == NULL)
  6466. {
  6467. numberPhasesIsNULL = TRUE;
  6468. }
  6469. else
  6470. {
  6471. c=0;
  6472. memset(sstr ,0, sizeof(sstr) );
  6473. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6474. {
  6475. sstr[c] = loc[strlen("numberPhases")+2+c];
  6476. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6477. c++;
  6478. }
  6479. sstr[c] = '\0';
  6480. numberPhasesInt[periodNums] = atoi(sstr);
  6481. }
  6482. where = loc;
  6483. }
  6484. }
  6485. }
  6486. /*
  6487. enum _SYSTEM_STATUS
  6488. {
  6489. S_BOOTING = 0,
  6490. S_IDLE, = 1
  6491. S_AUTHORIZING, =2
  6492. S_REASSIGN_CHECK, =3
  6493. S_REASSIGN, =4
  6494. S_PRECHARGE, =5
  6495. S_PREPARING_FOR_EV, =6
  6496. S_PREPARING_FOR_EVSE, =7
  6497. S_CHARGING, =8
  6498. S_TERMINATING, =9
  6499. S_COMPLETE, =10
  6500. S_ALARM, =11
  6501. S_FAULT =12
  6502. }
  6503. */
  6504. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6505. {
  6506. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6507. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6508. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6509. //check Transaction active
  6510. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6511. {
  6512. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6513. {
  6514. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6515. {
  6516. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6517. {
  6518. //Reserved
  6519. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6520. }
  6521. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6522. {
  6523. //Reserved
  6524. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6525. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6526. goto end;
  6527. }
  6528. else
  6529. {
  6530. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6531. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6532. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6533. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6534. {
  6535. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6536. goto end;
  6537. }
  6538. }//END FOR ELSE
  6539. }
  6540. }// END FOR CHAdeMO_QUANTITY
  6541. for (int index = 0; index < CCS_QUANTITY; index++)
  6542. {
  6543. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6544. {
  6545. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6546. {
  6547. //Reserved
  6548. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6549. }
  6550. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6551. {
  6552. //Reserved
  6553. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6554. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6555. goto end;
  6556. }
  6557. else
  6558. {
  6559. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6560. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6561. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6562. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6563. {
  6564. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6565. goto end;
  6566. }
  6567. }// END FOR ELSE
  6568. }
  6569. }// END FOR CCS_QUANTITY
  6570. for (int index = 0; index < GB_QUANTITY; index++)
  6571. {
  6572. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6573. {
  6574. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6575. {
  6576. //Reserved
  6577. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6578. }
  6579. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6580. {
  6581. //Reserved
  6582. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6583. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6584. goto end;
  6585. }
  6586. else
  6587. {
  6588. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6589. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6590. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6591. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6592. {
  6593. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6594. goto end;
  6595. }
  6596. }// END FOR ELSE
  6597. }
  6598. } // END FOR GB_QUANTITY
  6599. }
  6600. else
  6601. {
  6602. for (int index = 0; index < AC_QUANTITY; index++)
  6603. {
  6604. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6605. {
  6606. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6607. {
  6608. //Reserved
  6609. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6610. }
  6611. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6612. {
  6613. //Reserved
  6614. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6615. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6616. goto end;
  6617. }
  6618. else
  6619. {
  6620. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6621. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6622. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6623. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6624. {
  6625. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6626. goto end;
  6627. }
  6628. }//END FOR ELSE
  6629. }
  6630. }// END FOR AC_QUANTITY
  6631. }
  6632. if(chargingProfileIsNULL == FALSE)
  6633. {
  6634. //ChargingProfile
  6635. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6636. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6637. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6638. if(recurrencyKindIsNULL == FALSE) //OPTION
  6639. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6640. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6641. if(transactionIdIsNULL == FALSE) // OPTION
  6642. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6643. if(validFromIsNULL == FALSE) // OPTION
  6644. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6645. if(validToIsNULL == FALSE) //OPTION
  6646. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6647. //ChargingSchedule
  6648. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6649. if(durationIsNULL == FALSE) //OPTION
  6650. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6651. if(minChargingRateIsNULL == FALSE) //OPTION
  6652. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6653. if(startScheduleIsNULL == FALSE) //OPTION
  6654. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6655. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6656. {
  6657. //ChargingSchedulePeriod
  6658. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6659. if(numberPhasesIsNULL == FALSE)
  6660. {
  6661. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6662. }
  6663. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6664. }
  6665. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6666. {
  6667. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6668. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6669. //memset idTag
  6670. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6671. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6672. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6673. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6674. }
  6675. else
  6676. {
  6677. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6678. }
  6679. }
  6680. else
  6681. {
  6682. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6683. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6684. //memset idTag
  6685. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6686. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6687. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6688. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6689. }
  6690. }
  6691. else
  6692. {
  6693. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6694. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6695. }
  6696. end:
  6697. if(connectorIdIsNULL == FALSE)
  6698. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6699. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6700. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6701. //OCPP send RemoteStartConfirmation by first.
  6702. sendRemoteStartConfirmation(uuid, comfirmstr);
  6703. return result;
  6704. }
  6705. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6706. {
  6707. mtrace();
  6708. int result = FAIL;
  6709. int match = FALSE;
  6710. int GunNO = 0;
  6711. int transactionIdInt=0;
  6712. int transactionIdIsNULL= FALSE;
  6713. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6714. int c = 0;
  6715. char *loc;
  6716. char comfirmstr[20];
  6717. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6718. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6719. if(server_pending == TRUE)
  6720. {
  6721. return 0;
  6722. }
  6723. c=0;
  6724. loc = strstr(payload, "transactionId");
  6725. if(loc == NULL)
  6726. {
  6727. transactionIdIsNULL= TRUE;
  6728. }
  6729. else
  6730. {
  6731. memset(sstr ,0, sizeof(sstr) );
  6732. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6733. {
  6734. sstr[c] = loc[strlen("transactionId")+2+c];
  6735. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6736. c++;
  6737. }
  6738. sstr[c] = '\0';
  6739. transactionIdInt = atoi(sstr);
  6740. }
  6741. if(transactionIdIsNULL == FALSE)
  6742. {
  6743. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6744. {
  6745. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6746. {
  6747. //check Transaction active
  6748. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6749. {
  6750. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6751. {
  6752. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6753. {
  6754. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6755. {
  6756. match = TRUE;
  6757. GunNO = gun_index;
  6758. }
  6759. }
  6760. }// END FOR CHAdeMO_QUANTITY
  6761. for (int index = 0; index < CCS_QUANTITY; index++)
  6762. {
  6763. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6764. {
  6765. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6766. {
  6767. match = TRUE;
  6768. GunNO = gun_index;
  6769. }
  6770. }
  6771. }// END FOR CCS_QUANTITY
  6772. for (int index = 0; index < GB_QUANTITY; index++)
  6773. {
  6774. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6775. {
  6776. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6777. {
  6778. match = TRUE;
  6779. GunNO = gun_index;
  6780. }
  6781. }
  6782. }// END FOR GB_QUANTITY
  6783. }
  6784. else
  6785. {
  6786. for (int index = 0; index < AC_QUANTITY; index++)
  6787. {
  6788. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6789. {
  6790. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6791. {
  6792. match = TRUE;
  6793. GunNO = gun_index;
  6794. }
  6795. }
  6796. }// END FOR CHAdeMO_QUANTITY
  6797. }// END FOR AC ELSE
  6798. }// CHECK IF ResponseTransactionId == transactionIdInt
  6799. }//END FOR
  6800. if( match == TRUE)
  6801. {
  6802. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6803. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6804. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6805. }
  6806. else
  6807. {
  6808. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6809. }
  6810. }
  6811. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6812. return result;
  6813. }
  6814. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6815. {
  6816. mtrace();
  6817. int result = FAIL;
  6818. int connectorIdInt=0, reservationIdInt=0;
  6819. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6820. char comfirmstr[20]={0};
  6821. char sstr[180]={ 0 };
  6822. int c = 0;
  6823. char *loc;
  6824. //char *ptr;
  6825. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6826. //***(1)connectorId ****/
  6827. c=0;
  6828. loc = strstr(payload, "connectorId");
  6829. memset(sstr ,0, sizeof(sstr) );
  6830. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6831. {
  6832. sstr[c] = loc[strlen("connectorId")+2+c];
  6833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6834. c++;
  6835. }
  6836. sstr[c] = '\0';
  6837. connectorIdInt = atoi(sstr);
  6838. //***(2)expiryDate ****/
  6839. loc = strstr(payload, "expiryDate");
  6840. memset(sstr ,0, sizeof(sstr) );
  6841. c = 0;
  6842. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6843. {
  6844. sstr[c] = loc[3+strlen("expiryDate")+c];
  6845. c++;
  6846. }
  6847. sstr[c] = '\0';
  6848. strcpy(expiryDatestr, sstr);
  6849. //***(3)idTag ****/
  6850. loc = strstr(payload, "idTag");
  6851. memset(sstr ,0, sizeof(sstr) );
  6852. c = 0;
  6853. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6854. {
  6855. sstr[c] = loc[3+strlen("idTag")+c];
  6856. c++;
  6857. }
  6858. sstr[c] = '\0';
  6859. strcpy(idTagstr, sstr);
  6860. //***(4)parentIdTag ****/
  6861. loc = strstr(payload, "parentIdTag");
  6862. memset(sstr ,0, sizeof(sstr) );
  6863. c = 0;
  6864. if(loc == NULL)
  6865. {
  6866. strcpy(parentIdTagstr, "");
  6867. }
  6868. else
  6869. {
  6870. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6871. {
  6872. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6873. c++;
  6874. }
  6875. sstr[c] = '\0';
  6876. strcpy(parentIdTagstr, sstr);
  6877. }
  6878. //***(5)reservationId ****/
  6879. c=0;
  6880. loc = strstr(payload, "reservationId");
  6881. memset(sstr ,0, sizeof(sstr) );
  6882. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6883. {
  6884. sstr[c] = loc[strlen("reservationId")+2+c];
  6885. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6886. c++;
  6887. }
  6888. sstr[c] = '\0';
  6889. reservationIdInt = atoi(sstr);
  6890. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6891. /*
  6892. enum SYSTEM_STATUS
  6893. {
  6894. SYS_MODE_BOOTING = 0,
  6895. SYS_MODE_IDLE = 1,
  6896. SYS_MODE_AUTHORIZING = 2,
  6897. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6898. SYS_MODE_REASSIGN = 4,
  6899. SYS_MODE_PREPARING = 5,
  6900. SYS_MODE_PREPARE_FOR_EV = 6,
  6901. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6902. SYS_MODE_CHARGING = 8,
  6903. SYS_MODE_TERMINATING = 9,
  6904. SYS_MODE_COMPLETE = 10,
  6905. SYS_MODE_ALARM = 11,
  6906. SYS_MODE_FAULT = 12,
  6907. SYS_MODE_RESERVATION = 13,
  6908. SYS_MODE_BOOKING = 14,
  6909. SYS_MODE_MAINTAIN = 15,
  6910. SYS_MODE_DEBUG = 16,
  6911. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6912. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6913. SYS_MODE_UPDATE = 19
  6914. };
  6915. */
  6916. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6917. {
  6918. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6919. goto end;
  6920. }
  6921. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6922. {
  6923. //check Transaction active
  6924. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6925. {
  6926. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6927. {
  6928. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6929. {
  6930. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6931. {
  6932. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6933. {
  6934. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6935. {
  6936. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6937. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6938. }
  6939. 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'))
  6940. {
  6941. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6942. }
  6943. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6944. {
  6945. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6946. }
  6947. else
  6948. {
  6949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6950. }
  6951. }
  6952. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6953. {
  6954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6955. }
  6956. }
  6957. else
  6958. {
  6959. //replace reservation
  6960. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6961. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6962. }
  6963. }
  6964. } // END FOR CHAdeMO_QUANTITY
  6965. for (int index = 0; index < CCS_QUANTITY; index++)
  6966. {
  6967. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6968. {
  6969. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6970. {
  6971. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6972. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6973. {
  6974. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6975. {
  6976. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6977. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6978. }
  6979. 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'))
  6980. {
  6981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6982. }
  6983. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6984. {
  6985. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6986. }
  6987. else
  6988. {
  6989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6990. }
  6991. }
  6992. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6993. {
  6994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6995. }
  6996. }
  6997. else
  6998. {
  6999. //replace reservation
  7000. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7001. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7002. }
  7003. }
  7004. } // END FOR CCS_QUANTITY
  7005. for (int index = 0; index < GB_QUANTITY; index++)
  7006. {
  7007. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  7008. {
  7009. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7010. {
  7011. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7012. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7013. {
  7014. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7015. {
  7016. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7018. }
  7019. 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'))
  7020. {
  7021. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7022. }
  7023. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7024. {
  7025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7026. }
  7027. else
  7028. {
  7029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7030. }
  7031. }
  7032. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7033. {
  7034. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7035. }
  7036. }
  7037. else
  7038. {
  7039. //replace reservation
  7040. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7041. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7042. }
  7043. }
  7044. }// END FOR GB_QUANTITY
  7045. }
  7046. else
  7047. {
  7048. for (int index = 0; index < AC_QUANTITY; index++)
  7049. {
  7050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  7051. {
  7052. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7053. {
  7054. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7055. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7056. {
  7057. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7058. {
  7059. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7061. }
  7062. 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'))
  7063. {
  7064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7065. }
  7066. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7067. {
  7068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7069. }
  7070. else
  7071. {
  7072. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7073. }
  7074. }
  7075. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7076. {
  7077. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7078. }
  7079. }
  7080. else
  7081. {
  7082. //replace reservation
  7083. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7084. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7085. }
  7086. }
  7087. } // END FOR AC_QUANTITY
  7088. }//END FOR AC ELSE
  7089. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7090. }
  7091. else if(connectorIdInt == 0)
  7092. {
  7093. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7094. {
  7095. //check Transaction active
  7096. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7097. {
  7098. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7099. {
  7100. 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'))
  7101. {
  7102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7103. goto end;
  7104. }
  7105. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7106. {
  7107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7108. goto end;
  7109. }
  7110. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7111. {
  7112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7113. goto end;
  7114. }
  7115. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7116. {
  7117. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7118. goto end;
  7119. }
  7120. }
  7121. }// END FOR CHAdeMO_QUANTITY
  7122. for (int index = 0; index < CCS_QUANTITY; index++)
  7123. {
  7124. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7125. {
  7126. 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'))
  7127. {
  7128. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7129. }
  7130. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7131. {
  7132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7133. }
  7134. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7135. {
  7136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7137. }
  7138. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7139. {
  7140. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7141. }
  7142. }
  7143. } // END FOR CCS_QUANTITY
  7144. for (int index = 0; index < GB_QUANTITY; index++)
  7145. {
  7146. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7147. {
  7148. 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'))
  7149. {
  7150. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7151. }
  7152. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7153. {
  7154. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7155. }
  7156. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7157. {
  7158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7159. }
  7160. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7161. {
  7162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7163. }
  7164. }
  7165. } // END FOR GB_QUANTITY
  7166. }
  7167. else
  7168. {
  7169. for (int index = 0; index < AC_QUANTITY; index++)
  7170. {
  7171. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7172. {
  7173. 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'))
  7174. {
  7175. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7176. goto end;
  7177. }
  7178. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7179. {
  7180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7181. goto end;
  7182. }
  7183. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7184. {
  7185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7186. goto end;
  7187. }
  7188. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7189. {
  7190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7191. goto end;
  7192. }
  7193. }
  7194. }// END FOR AC_QUANTITY
  7195. }
  7196. //The connectorId is 0
  7197. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7198. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7199. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7200. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7201. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7202. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7203. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7204. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7205. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7206. result = TRUE;
  7207. return result;
  7208. }
  7209. else
  7210. {
  7211. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7212. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7213. }
  7214. if(strcmp(comfirmstr,"Accepted") == 0)
  7215. {
  7216. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7217. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7218. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7219. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7220. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7221. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7222. result = TRUE;
  7223. return result;
  7224. }
  7225. end:
  7226. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7227. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7228. return result;
  7229. }
  7230. int handleResetRequest(char *uuid, char *payload)
  7231. {
  7232. mtrace();
  7233. int result = FAIL;
  7234. char sstr[10]={0};
  7235. char typestr[10]={0};
  7236. char comfirmstr[20]={0};
  7237. int c = 0;
  7238. char *loc;
  7239. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7240. DEBUG_INFO("handleResetRequest ...\n");
  7241. loc = strstr(payload, "type");
  7242. memset(sstr ,0, sizeof(sstr) );
  7243. c = 0;
  7244. while (loc[3+strlen("type")+c] != '\"')
  7245. {
  7246. sstr[c] = loc[3+strlen("type")+c];
  7247. c++;
  7248. }
  7249. sstr[c] = '\0';
  7250. strcpy(typestr,sstr);
  7251. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7252. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7253. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7254. {
  7255. //check Transaction active
  7256. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7257. {
  7258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7259. {
  7260. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7261. {
  7262. //0: unplug, 1: Plug-in
  7263. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7264. }
  7265. }
  7266. for (int index = 0; index < CCS_QUANTITY; index++)
  7267. {
  7268. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7269. {
  7270. //0: unplug, 1: Plug-in
  7271. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7272. }
  7273. }
  7274. for (int index = 0; index < GB_QUANTITY; index++)
  7275. {
  7276. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7277. {
  7278. //0: unplug, 1: Plug-in
  7279. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7280. }
  7281. }
  7282. }
  7283. else
  7284. {
  7285. for (int index = 0; index < AC_QUANTITY; index++)
  7286. {
  7287. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7288. {
  7289. //0: unplug, 1: Plug-in
  7290. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7291. }
  7292. }
  7293. }// END FOR AC ELSE
  7294. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7295. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7296. result = TRUE;
  7297. return result;
  7298. }
  7299. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7300. {
  7301. //check Transaction active
  7302. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7303. {
  7304. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7305. {
  7306. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7307. {
  7308. //0: unplug, 1: Plug-in
  7309. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7310. }
  7311. }
  7312. for (int index = 0; index < CCS_QUANTITY; index++)
  7313. {
  7314. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7315. {
  7316. //0: unplug, 1: Plug-in
  7317. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7318. }
  7319. }
  7320. for (int index = 0; index < GB_QUANTITY; index++)
  7321. {
  7322. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7323. {
  7324. //0: unplug, 1: Plug-in
  7325. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7326. }
  7327. }
  7328. }
  7329. else
  7330. {
  7331. for (int index = 0; index < AC_QUANTITY; index++)
  7332. {
  7333. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7334. {
  7335. //0: unplug, 1: Plug-in
  7336. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7337. }
  7338. }
  7339. }// END FOR AC ELSE
  7340. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7341. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7342. result = TRUE;
  7343. return result;
  7344. }
  7345. else
  7346. {
  7347. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7348. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7349. goto errorend;
  7350. }
  7351. errorend:
  7352. sendResetConfirmation(uuid, comfirmstr);
  7353. return result;
  7354. }
  7355. int handleSendLocalListRequest(char *uuid, char *payload)
  7356. {
  7357. mtrace();
  7358. int result = FAIL;
  7359. int listVersionInt;
  7360. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7361. char listsearch[]="listVersion";
  7362. char updateTypesearch[]="updateType";
  7363. char localAuthorizationListsearch[]="localAuthorizationList";
  7364. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7365. char CardList[500][160]={0};
  7366. char updateTypestr[15]={0};
  7367. char idTagstr[20]={0};
  7368. char parentIdTag[20]={0};
  7369. char expiryDate[30]={0};
  7370. char idTagstatus[16]={0};
  7371. int c = 0;
  7372. int i = 0;
  7373. char *delim1 = "}";
  7374. char * pch;
  7375. char *loc;
  7376. //char *ptr;
  7377. char comfirmstr[20];
  7378. //int n_localAuthorizations = 0;
  7379. int checkState_Faulted = FALSE;
  7380. DEBUG_INFO("handleSendLocalListRequest\n");
  7381. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7382. {
  7383. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7384. goto end;
  7385. }
  7386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7387. {
  7388. //check Charge Point state
  7389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7390. {
  7391. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7392. {
  7393. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7394. }
  7395. }
  7396. for (int index = 0; index < CCS_QUANTITY; index++)
  7397. {
  7398. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7399. {
  7400. checkState_Faulted = TRUE; //OCPP Status
  7401. }
  7402. }
  7403. for (int index = 0; index < GB_QUANTITY; index++)
  7404. {
  7405. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7406. {
  7407. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7408. }
  7409. }
  7410. }
  7411. else
  7412. {
  7413. //check Charge Point state
  7414. for (int index = 0; index < AC_QUANTITY; index++)
  7415. {
  7416. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7417. {
  7418. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7419. }
  7420. }
  7421. }// END FOR AC ELSE
  7422. if(checkState_Faulted == TRUE)
  7423. {
  7424. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7425. goto end;
  7426. }
  7427. //listVersion
  7428. c = 0;
  7429. loc = strstr(payload, listsearch);
  7430. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7431. {
  7432. sstr[c] = loc[strlen("listVersion")+2+c];
  7433. c++;
  7434. }
  7435. sstr[c] = '\0';
  7436. listVersionInt = atoi(sstr);
  7437. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7438. //updateType
  7439. loc = strstr(payload, updateTypesearch);
  7440. c = 0;
  7441. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7442. {
  7443. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7444. c++;
  7445. }
  7446. sstr[c] = '\0';
  7447. strcpy(updateTypestr, sstr);
  7448. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7449. //localAuthorizationList
  7450. memset(sstr ,0, sizeof(sstr) );
  7451. loc = strstr(payload, localAuthorizationListsearch);
  7452. if(loc != NULL) // localAuthorizationList is not NULL
  7453. {
  7454. //Check UpdateType
  7455. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7456. {
  7457. //Local list full update
  7458. printf("Local list full update.\n");
  7459. OCPP_cleanLocalList();
  7460. }
  7461. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7462. {
  7463. //Local list different update
  7464. printf("Local list different update.\n");
  7465. OCPP_getListVerion();
  7466. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7467. {
  7468. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7469. goto end;
  7470. }
  7471. }
  7472. else
  7473. {
  7474. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7475. goto end;
  7476. }
  7477. c = 0;
  7478. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7479. {
  7480. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7481. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7482. c++;
  7483. }
  7484. sstr[c] = '\0';
  7485. //DEBUG_INFO("sstr=%s\n", sstr);
  7486. //parsing strings to words
  7487. i = 0;
  7488. pch = strtok(sstr,delim1);
  7489. while (pch != NULL)
  7490. {
  7491. strcpy(CardList[i], pch);
  7492. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7493. pch = strtok (NULL, delim1);
  7494. i = i + 1;
  7495. }
  7496. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7497. //local Authorizations List Numbers
  7498. //n_localAuthorizations = i;
  7499. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7500. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7501. c= 0;
  7502. while(c < i) // i is CardList Number
  7503. {
  7504. //Search "IdToken"
  7505. memset(sstr ,0, sizeof(sstr) );
  7506. loc = strstr(CardList[c], "idTag");
  7507. int j = 0;
  7508. while (loc[3+strlen("idTag")+j] != '\"')
  7509. {
  7510. sstr[j] = loc[3+strlen("idTag")+j];
  7511. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7512. j++;
  7513. }
  7514. sstr[j] = '\0';
  7515. strcpy(idTagstr, sstr);
  7516. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7517. //Search "expiryDate"
  7518. memset(sstr ,0, sizeof(sstr) );
  7519. loc = strstr(CardList[c], "expiryDate");
  7520. j = 0;
  7521. if(loc != NULL)
  7522. {
  7523. while (loc[3+strlen("expiryDate")+j] != '\"')
  7524. {
  7525. sstr[j] = loc[3+strlen("expiryDate")+j];
  7526. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7527. j++;
  7528. }
  7529. sstr[j] = '\0';
  7530. strcpy(expiryDate, sstr);
  7531. }
  7532. else
  7533. {
  7534. strcpy(expiryDate, "");
  7535. }
  7536. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7537. //Search "parentIdTag"
  7538. memset(sstr ,0, sizeof(sstr) );
  7539. loc = strstr(CardList[c], "parentIdTag");
  7540. j = 0;
  7541. if(loc != NULL)
  7542. {
  7543. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7544. {
  7545. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7546. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7547. j++;
  7548. }
  7549. sstr[j] = '\0';
  7550. strcpy(parentIdTag, sstr);
  7551. }
  7552. else
  7553. {
  7554. strcpy(parentIdTag, "");
  7555. }
  7556. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7557. //Search "status"
  7558. memset(sstr ,0, sizeof(sstr) );
  7559. loc = strstr(CardList[c], "status");
  7560. j = 0;
  7561. while (loc[3+strlen("status")+j] != '\"')
  7562. {
  7563. sstr[j] = loc[3+strlen("status")+j];
  7564. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7565. j++;
  7566. }
  7567. sstr[j] = '\0';
  7568. strcpy(idTagstatus, sstr);
  7569. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7570. OCPP_getIdTag(idTagstr);
  7571. //OCPP_getIdTag("test"); For Test
  7572. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7573. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7574. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7575. {
  7576. //Local list full update
  7577. DEBUG_INFO("Local list full update.\n");
  7578. // update list
  7579. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7580. //DEBUG_INFO("Local list full update. 1\n");
  7581. //OCPP_get_TableAuthlocalAllData();
  7582. //DEBUG_INFO("Local list full update. 2\n");
  7583. }
  7584. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7585. {
  7586. #if 0
  7587. if(strcmp(idTagstr, idTagAuthorization) == 0)
  7588. {
  7589. //OCPP_deleteIdTag(idTagstr);
  7590. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7591. }
  7592. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  7593. {
  7594. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7595. }
  7596. #endif
  7597. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7598. }
  7599. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7600. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7601. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7602. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7603. c++;
  7604. }
  7605. }
  7606. else
  7607. {
  7608. //Check UpdateType
  7609. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7610. {
  7611. //Local list full update
  7612. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7613. OCPP_cleanLocalList();
  7614. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7615. goto end;
  7616. }
  7617. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7618. {
  7619. //Local list different update
  7620. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7621. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7622. goto end;
  7623. }
  7624. }
  7625. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7626. end:
  7627. sendSendLocalListConfirmation(uuid, comfirmstr);
  7628. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7629. return result;
  7630. }
  7631. #define MAX 200
  7632. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7633. {
  7634. mtrace();
  7635. int result = FAIL;
  7636. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7637. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7638. char chargingProfilePurposeStr[30]={0};
  7639. char chargingProfileKindStr[16]={0};
  7640. char recurrencyKindStr[10]={0};
  7641. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7642. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7643. int chargingSchedulePeriodCount = 0;
  7644. //int updateflag = FALSE;
  7645. char comfirmstr[20]={0};
  7646. int meet= FALSE;
  7647. char sstr[10]={0};
  7648. int c = 0;
  7649. char *loc;
  7650. FILE *fptr1;//, *fptr2;
  7651. //int lno=0;//, linectr = 0;
  7652. //int modifyflag = FALSE;
  7653. char filename[MAX]={0};
  7654. char tempfile[] = "/Storage/OCPP/temp.json";
  7655. //int resultRename=0;
  7656. char rmFileCmd[50]={0};
  7657. char tempchargingProfilePurposeStr[30]={0};
  7658. char word[1600]={0};
  7659. int n_chargingProfile = 0;
  7660. //[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}}}]
  7661. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7662. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7663. //*********************connectorId***************************/
  7664. loc = strstr(payload, "connectorId");
  7665. c = 0;
  7666. memset(sstr ,0, sizeof(sstr) );
  7667. while (loc[strlen("connectorId")+2+c] != ',')
  7668. {
  7669. sstr[c] = loc[strlen("connectorId")+2+c];
  7670. c++;
  7671. }
  7672. sstr[c] = '\0';
  7673. connectorIdInt = atoi(sstr);
  7674. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7675. {
  7676. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7677. }
  7678. else
  7679. {
  7680. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7681. }
  7682. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7683. //*********************chargingProfileId***************************/
  7684. loc = strstr(payload, "chargingProfileId");
  7685. c = 0;
  7686. memset(sstr ,0, sizeof(sstr) );
  7687. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7688. {
  7689. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7690. c++;
  7691. }
  7692. sstr[c] = '\0';
  7693. chargingProfileIdInt = atoi(sstr);
  7694. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7695. {
  7696. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7697. }
  7698. else
  7699. {
  7700. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7701. }
  7702. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7703. //*********************transactionId***************************/
  7704. loc = strstr(payload, "transactionId");
  7705. if(loc != NULL)
  7706. {
  7707. c = 0;
  7708. memset(sstr ,0, sizeof(sstr) );
  7709. while (loc[strlen("transactionId")+2+c] != ',')
  7710. {
  7711. sstr[c] = loc[strlen("transactionId")+2+c];
  7712. c++;
  7713. }
  7714. sstr[c] = '\0';
  7715. transactionIdInt = atoi(sstr);
  7716. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7717. {
  7718. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7719. }
  7720. else
  7721. {
  7722. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7723. }
  7724. }
  7725. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7726. //*********************stackLevel***************************/
  7727. loc = strstr(payload, "stackLevel");
  7728. c = 0;
  7729. memset(sstr ,0, sizeof(sstr) );
  7730. while (loc[strlen("stackLevel")+2+c] != ',')
  7731. {
  7732. sstr[c] = loc[strlen("stackLevel")+2+c];
  7733. c++;
  7734. }
  7735. sstr[c] = '\0';
  7736. stackLevelInt = atoi(sstr);
  7737. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7738. {
  7739. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7740. }
  7741. else
  7742. {
  7743. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7744. }
  7745. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7746. //*********************chargingProfilePurpose***************************/
  7747. loc = strstr(payload, "chargingProfilePurpose");
  7748. c = 0;
  7749. memset(sstr ,0, sizeof(sstr) );
  7750. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7751. {
  7752. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7753. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7754. c++;
  7755. }
  7756. sstr[c] = '\0';
  7757. strcpy(chargingProfilePurposeStr,sstr);
  7758. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7759. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7760. {
  7761. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7762. }
  7763. else
  7764. {
  7765. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7766. }
  7767. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7768. //*********************chargingProfileKind***************************/
  7769. loc = strstr(payload, "chargingProfileKind");
  7770. c = 0;
  7771. memset(sstr ,0, sizeof(sstr) );
  7772. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7773. {
  7774. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7775. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7776. c++;
  7777. }
  7778. sstr[c] = '\0';
  7779. strcpy(chargingProfileKindStr,sstr);
  7780. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7781. {
  7782. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7783. }
  7784. else
  7785. {
  7786. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7787. }
  7788. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7789. //*********************recurrencyKind***************************/
  7790. loc = strstr(payload, "recurrencyKind");
  7791. if(loc != NULL)
  7792. {
  7793. c = 0;
  7794. memset(sstr ,0, sizeof(sstr) );
  7795. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7796. {
  7797. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7798. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7799. c++;
  7800. }
  7801. sstr[c] = '\0';
  7802. strcpy(recurrencyKindStr,sstr);
  7803. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7804. {
  7805. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7806. }
  7807. else
  7808. {
  7809. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7810. }
  7811. }
  7812. else
  7813. {
  7814. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7815. {
  7816. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7817. }
  7818. else
  7819. {
  7820. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7821. }
  7822. }
  7823. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7824. //*********************validFrom***************************/
  7825. loc = strstr(payload, "validFrom");
  7826. if(loc != NULL)
  7827. {
  7828. c = 0;
  7829. memset(sstr ,0, sizeof(sstr) );
  7830. while (loc[3+strlen("validFrom")+c] != '\"')
  7831. {
  7832. sstr[c] = loc[3+strlen("validFrom")+c];
  7833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7834. c++;
  7835. }
  7836. sstr[c] = '\0';
  7837. strcpy(validFromStr,sstr);
  7838. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7839. {
  7840. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7841. }
  7842. else
  7843. {
  7844. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7845. }
  7846. }
  7847. else
  7848. {
  7849. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7850. {
  7851. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7852. }
  7853. else
  7854. {
  7855. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7856. }
  7857. }
  7858. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7859. //*********************validTo***************************/
  7860. loc = strstr(payload, "validTo");
  7861. if(loc != NULL)
  7862. {
  7863. c = 0;
  7864. memset(sstr ,0, sizeof(sstr) );
  7865. while (loc[3+strlen("validTo")+c] != '\"')
  7866. {
  7867. sstr[c] = loc[3+strlen("validTo")+c];
  7868. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7869. c++;
  7870. }
  7871. sstr[c] = '\0';
  7872. strcpy(validToStr,sstr);
  7873. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7874. {
  7875. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7876. }
  7877. else
  7878. {
  7879. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7880. }
  7881. }
  7882. else
  7883. {
  7884. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7885. {
  7886. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7887. }
  7888. else
  7889. {
  7890. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7891. }
  7892. }
  7893. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7894. //*********************duration***************************/
  7895. loc = strstr(payload, "duration");
  7896. if(loc != NULL)
  7897. {
  7898. c = 0;
  7899. memset(sstr ,0, sizeof(sstr) );
  7900. while (loc[strlen("duration")+2+c] != ',')
  7901. {
  7902. sstr[c] = loc[strlen("duration")+2+c];
  7903. c++;
  7904. }
  7905. sstr[c] = '\0';
  7906. durationInt = atoi(sstr);
  7907. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7908. {
  7909. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7910. }
  7911. else
  7912. {
  7913. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7914. }
  7915. }
  7916. else
  7917. {
  7918. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7919. {
  7920. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7921. }
  7922. else
  7923. {
  7924. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7925. }
  7926. }
  7927. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7928. //*********************startSchedule***************************/
  7929. loc = strstr(payload, "startSchedule");
  7930. if(loc != NULL)
  7931. {
  7932. c = 0;
  7933. memset(sstr ,0, sizeof(sstr) );
  7934. while (loc[3+strlen("startSchedule")+c] != '\"')
  7935. {
  7936. sstr[c] = loc[3+strlen("startSchedule")+c];
  7937. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7938. c++;
  7939. }
  7940. sstr[c] = '\0';
  7941. strcpy(startScheduleStr,sstr);
  7942. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7943. {
  7944. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7945. }
  7946. else
  7947. {
  7948. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7949. }
  7950. }
  7951. else
  7952. {
  7953. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7954. {
  7955. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7956. }
  7957. else
  7958. {
  7959. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7960. }
  7961. }
  7962. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7963. //*********************chargingRateUnit***************************/
  7964. loc = strstr(payload, "chargingRateUnit");
  7965. if(loc != NULL)
  7966. {
  7967. c = 0;
  7968. memset(sstr ,0, sizeof(sstr) );
  7969. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7970. {
  7971. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7972. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7973. c++;
  7974. }
  7975. sstr[c] = '\0';
  7976. strcpy(chargingRateUnitStr,sstr);
  7977. #if 0
  7978. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  7979. {
  7980. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7981. goto end;
  7982. }
  7983. #endif
  7984. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7985. {
  7986. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7987. }
  7988. else
  7989. {
  7990. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7991. }
  7992. }
  7993. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7994. //****************chargingSchedulePeriod count start*******************/
  7995. int what_len = strlen("startPeriod");
  7996. char tempChargingProfile[1000]={0};
  7997. strcpy(tempChargingProfile,(const char*)payload);
  7998. char *where = tempChargingProfile;
  7999. if (what_len)
  8000. {
  8001. while ((where = strstr(where, "startPeriod"))) {
  8002. where += what_len;
  8003. chargingSchedulePeriodCount++;
  8004. }
  8005. }
  8006. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8007. {
  8008. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8009. goto end;
  8010. }
  8011. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8012. //where = payload;
  8013. int templength = 0;
  8014. //int searchstart = 0;
  8015. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8016. {
  8017. //****************startPeriod*******************/
  8018. c=0;
  8019. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8020. memset(sstr ,0, sizeof(sstr) );
  8021. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8022. {
  8023. sstr[c] = loc[strlen("startPeriod")+2+c];
  8024. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8025. c++;
  8026. }
  8027. sstr[c] = '\0';
  8028. startPeriodInt[periodNums] = atoi(sstr);
  8029. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8030. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8031. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8032. {
  8033. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8034. }
  8035. else
  8036. {
  8037. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8038. }
  8039. templength = strlen("startPeriod")+2+c;
  8040. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8041. //****************limit*******************/
  8042. c=0;
  8043. loc = strstr(tempChargingProfile + templength, "limit");
  8044. memset(sstr ,0, sizeof(sstr) );
  8045. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8046. {
  8047. sstr[c] = loc[strlen("limit")+2+c];
  8048. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8049. c++;
  8050. }
  8051. sstr[c] = '\0';
  8052. limitflaot[periodNums] = atof(sstr);
  8053. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8054. {
  8055. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8056. }
  8057. else
  8058. {
  8059. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8060. }
  8061. templength = templength + strlen("limit")+2+c;
  8062. //****************numberPhases*******************/
  8063. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8064. if(loc != NULL)
  8065. {
  8066. c=0;
  8067. memset(sstr ,0, sizeof(sstr) );
  8068. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8069. {
  8070. sstr[c] = loc[strlen("numberPhases")+2+c];
  8071. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8072. c++;
  8073. }
  8074. sstr[c] = '\0';
  8075. numberPhasesInt[periodNums] = atoi(sstr);
  8076. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8077. {
  8078. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8079. }
  8080. else
  8081. {
  8082. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8083. }
  8084. templength = templength + strlen("numberPhases")+2+c;
  8085. }
  8086. //where = loc;
  8087. }
  8088. //****************chargingSchedulePeriod count end*******************/
  8089. //*********************minChargingRate***************************/
  8090. loc = strstr(payload, "minChargingRate");
  8091. if(loc != NULL)
  8092. {
  8093. c = 0;
  8094. memset(sstr ,0, sizeof(sstr) );
  8095. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8096. {
  8097. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8098. c++;
  8099. }
  8100. sstr[c] = '\0';
  8101. minChargingRateFloat = atof(sstr);
  8102. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8103. {
  8104. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8105. }
  8106. else
  8107. {
  8108. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8109. }
  8110. }
  8111. else
  8112. {
  8113. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8114. {
  8115. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8116. }
  8117. else
  8118. {
  8119. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8120. }
  8121. }
  8122. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8123. {
  8124. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8125. if(connectorIdInt != 0)
  8126. {
  8127. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8128. goto end;
  8129. }
  8130. strcpy(filename, ChargePointMaxProfile_JSON );
  8131. fptr1 = fopen(filename, "r");
  8132. if (!fptr1)
  8133. {
  8134. //file not exist
  8135. DEBUG_INFO("Unable to open the input file!!\n");
  8136. fptr1 = fopen(filename, "w+");
  8137. }
  8138. else
  8139. {
  8140. //Check Charging Profile Count
  8141. while(fscanf(fptr1, "%s", word) != EOF)
  8142. {
  8143. //DEBUG_INFO("word=%s\n",word);
  8144. if(strstr(word, "chargingProfileId")!= NULL)
  8145. {
  8146. //DEBUG_INFO("test chargingProfileId \n");
  8147. n_chargingProfile = n_chargingProfile + 1;
  8148. //DEBUG_INFO("chargingProfileId Found\n");
  8149. }
  8150. }
  8151. }
  8152. fclose(fptr1);
  8153. }
  8154. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8155. {
  8156. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8157. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8158. {
  8159. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8160. goto end;
  8161. }
  8162. #if 0
  8163. switch(connectorIdInt)
  8164. {
  8165. case 0:
  8166. strcpy(filename, TxDefaultProfile_0_JSON );
  8167. break;
  8168. case 1:
  8169. strcpy(filename, TxDefaultProfile_1_JSON );
  8170. break;
  8171. case 2:
  8172. strcpy(filename, TxDefaultProfile_2_JSON );
  8173. break;
  8174. default:
  8175. strcpy(filename, TxDefaultProfile_0_JSON );
  8176. break;
  8177. }
  8178. #endif
  8179. memset(filename, 0, sizeof filename);
  8180. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8181. fptr1 = fopen(filename, "r");
  8182. if (!fptr1)
  8183. {
  8184. //file not exist
  8185. //DEBUG_INFO("Unable to open the input file!!\n");
  8186. fptr1 = fopen(filename, "w+");
  8187. }
  8188. else
  8189. {
  8190. //Check Charging Profile Count
  8191. while(fscanf(fptr1, "%s", word) != EOF)
  8192. {
  8193. //DEBUG_INFO("word=%s\n",word);
  8194. if(strstr(word, "chargingProfileId")!= NULL)
  8195. {
  8196. //DEBUG_INFO("test chargingProfileId \n");
  8197. n_chargingProfile = n_chargingProfile + 1;
  8198. //DEBUG_INFO("chargingProfileId Found\n");
  8199. }
  8200. }
  8201. }
  8202. fclose(fptr1);
  8203. }
  8204. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8205. {
  8206. //printf("set chargingProfile 1-4\n");
  8207. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8208. //check Transaction active
  8209. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8210. {
  8211. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8212. {
  8213. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8214. {
  8215. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8216. {
  8217. meet = TRUE;
  8218. break;
  8219. }
  8220. }
  8221. }
  8222. }
  8223. for (int index = 0; index < CCS_QUANTITY; index++)
  8224. {
  8225. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8226. {
  8227. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8228. {
  8229. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8230. {
  8231. meet = TRUE;
  8232. break;
  8233. }
  8234. }
  8235. }
  8236. }
  8237. for (int index = 0; index < GB_QUANTITY; index++)
  8238. {
  8239. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8240. {
  8241. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8242. {
  8243. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8244. {
  8245. meet = TRUE;
  8246. break;
  8247. }
  8248. }
  8249. }
  8250. }
  8251. if(meet == FALSE)
  8252. {
  8253. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8254. goto end;
  8255. }
  8256. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8257. {
  8258. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8259. goto end;
  8260. }
  8261. #if 0
  8262. switch(connectorIdInt)
  8263. {
  8264. case 0:
  8265. break;
  8266. case 1:
  8267. strcpy(filename, TxProfile_1_JSON);
  8268. break;
  8269. case 2:
  8270. strcpy(filename, TxProfile_2_JSON);
  8271. break;
  8272. default:
  8273. strcpy(filename, TxProfile_1_JSON);
  8274. break;
  8275. }
  8276. #endif
  8277. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8278. fptr1 = fopen(filename, "r");
  8279. if (!fptr1)
  8280. {
  8281. //file not exist
  8282. DEBUG_INFO("Unable to open the input file!!\n");
  8283. fptr1 = fopen(filename, "w+");
  8284. }
  8285. else
  8286. {
  8287. //Check Charging Profile Count
  8288. while(fscanf(fptr1, "%s", word) != EOF)
  8289. {
  8290. //DEBUG_INFO("word=%s\n",word);
  8291. if(strstr(word, "chargingProfileId")!= NULL)
  8292. {
  8293. //DEBUG_INFO("test chargingProfileId \n");
  8294. n_chargingProfile = n_chargingProfile + 1;
  8295. //DEBUG_INFO("chargingProfileId Found\n");
  8296. }
  8297. }
  8298. }
  8299. fclose(fptr1);
  8300. DEBUG_INFO("n_chargingProfile_3=%d\n",n_chargingProfile);
  8301. }
  8302. // Check ChargeProfileMaxStackLevel
  8303. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8304. {
  8305. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8306. goto end;
  8307. }
  8308. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8309. {
  8310. int i = 0;
  8311. char fnametemp[200]={0};
  8312. n_chargingProfile = 0;
  8313. //Check ChargePointMaxProfile.json exit
  8314. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8315. {
  8316. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8317. //Check Charging Profile Count
  8318. while(fscanf(fptr1, "%s", word) != EOF)
  8319. {
  8320. //DEBUG_INFO("word=%s\n",word);
  8321. if(strstr(word, "chargingProfileId")!= NULL)
  8322. {
  8323. //DEBUG_INFO("test chargingProfileId \n");
  8324. n_chargingProfile = n_chargingProfile + 1;
  8325. i = i + 1;
  8326. //DEBUG_INFO("chargingProfileId Found\n");
  8327. }
  8328. memset(word, 0, sizeof word);
  8329. }
  8330. fclose(fptr1);
  8331. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8332. }
  8333. //Check TxDefaultProfile_0.json exit
  8334. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8335. {
  8336. i = 0;
  8337. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8338. //Check Charging Profile Count
  8339. while(fscanf(fptr1, "%s", word) != EOF)
  8340. {
  8341. //DEBUG_INFO("word=%s\n",word);
  8342. if(strstr(word, "chargingProfileId")!= NULL)
  8343. {
  8344. //DEBUG_INFO("test chargingProfileId \n");
  8345. n_chargingProfile = n_chargingProfile + 1;
  8346. i = i + 1;
  8347. //DEBUG_INFO("chargingProfileId Found\n");
  8348. }
  8349. memset(word, 0, sizeof word);
  8350. }
  8351. fclose(fptr1);
  8352. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8353. }
  8354. //Check TxDefaultProfile_%d.json
  8355. for(int j=1; j <= gunTotalNumber; j++)
  8356. {
  8357. memset(fnametemp, 0, sizeof fnametemp);
  8358. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8359. if((access(fnametemp,F_OK))!=-1)
  8360. {
  8361. i = 0;
  8362. fptr1 = fopen(fnametemp, "r");
  8363. //Check Charging Profile Count
  8364. while(fscanf(fptr1, "%s", word) != EOF)
  8365. {
  8366. //DEBUG_INFO("word=%s\n",word);
  8367. if(strstr(word, "chargingProfileId")!= NULL)
  8368. {
  8369. //DEBUG_INFO("test chargingProfileId \n");
  8370. n_chargingProfile = n_chargingProfile + 1;
  8371. i = i + 1;
  8372. //DEBUG_INFO("chargingProfileId Found\n");
  8373. }
  8374. memset(word, 0, sizeof word);
  8375. }
  8376. fclose(fptr1);
  8377. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8378. }
  8379. }
  8380. //Check TxProfile_%d.json
  8381. for(int j=1; j <= gunTotalNumber; j++)
  8382. {
  8383. memset(fnametemp, 0, sizeof fnametemp);
  8384. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8385. if((access(fnametemp,F_OK))!=-1)
  8386. {
  8387. i = 0;
  8388. fptr1 = fopen(fnametemp, "r");
  8389. //Check Charging Profile Count
  8390. while(fscanf(fptr1, "%s", word) != EOF)
  8391. {
  8392. //DEBUG_INFO("word=%s\n",word);
  8393. if(strstr(word, "chargingProfileId")!= NULL)
  8394. {
  8395. //DEBUG_INFO("test chargingProfileId \n");
  8396. n_chargingProfile = n_chargingProfile + 1;
  8397. i = i + 1;
  8398. //DEBUG_INFO("chargingProfileId Found\n");
  8399. }
  8400. memset(word, 0, sizeof word);
  8401. }
  8402. fclose(fptr1);
  8403. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8404. }
  8405. }
  8406. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8407. {
  8408. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8409. goto end;
  8410. }
  8411. }
  8412. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8413. //**********************************Write to File********************************************************/
  8414. FILE *infile;
  8415. FILE *outfile;
  8416. // open file for writing
  8417. infile = fopen (filename, "r");
  8418. outfile = fopen (tempfile, "w");
  8419. int d =0;
  8420. d = fgetc(infile);
  8421. //DEBUG_INFO("d:%d\n",d);
  8422. rewind(infile);
  8423. //*检测到文件结束标识返回1,否则返回0。*/
  8424. if(d == EOF)
  8425. {
  8426. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8427. fprintf(outfile,"%s\n",payload);
  8428. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8429. fclose(infile);
  8430. fclose(outfile);
  8431. sprintf(rmFileCmd,"rm -f %s",filename);
  8432. system(rmFileCmd);
  8433. rename(tempfile, filename);
  8434. #if 0
  8435. resultRename = rename(tempfile, filename);
  8436. if(resultRename == 0)
  8437. {
  8438. DEBUG_INFO("File chargingProfile renamed successfully");
  8439. }
  8440. else
  8441. {
  8442. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8443. }
  8444. #endif
  8445. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8446. //system(rmFileCmd);
  8447. }
  8448. else
  8449. {
  8450. char buf[1000]={0};
  8451. int ChargingProfileAdded = FALSE;
  8452. while (fgets(buf, sizeof(buf), infile) != NULL)
  8453. {
  8454. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8455. //*************************tempconnectorIdInt*********************************/
  8456. loc = strstr(buf, "connectorId");
  8457. c = 0;
  8458. memset(sstr ,0, sizeof(sstr) );
  8459. while (loc[strlen("connectorId")+2+c] != ',')
  8460. {
  8461. sstr[c] = loc[strlen("connectorId")+2+c];
  8462. c++;
  8463. }
  8464. sstr[c] = '\0';
  8465. tempconnectorIdInt = atoi(sstr);
  8466. //*************************tempchargingProfileIdInt*********************************/
  8467. loc = strstr(buf, "chargingProfileId");
  8468. c = 0;
  8469. memset(sstr ,0, sizeof(sstr) );
  8470. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8471. {
  8472. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8473. c++;
  8474. }
  8475. sstr[c] = '\0';
  8476. tempchargingProfileIdInt = atoi(sstr);
  8477. //*************************tempstackLevelInt*********************************/
  8478. loc = strstr(buf, "stackLevel");
  8479. c = 0;
  8480. memset(sstr ,0, sizeof(sstr) );
  8481. while (loc[strlen("stackLevel")+2+c] != ',')
  8482. {
  8483. sstr[c] = loc[strlen("stackLevel")+2+c];
  8484. c++;
  8485. }
  8486. sstr[c] = '\0';
  8487. tempstackLevelInt = atoi(sstr);
  8488. //*************************tempchargingProfilePurposeStr*********************************/
  8489. loc = strstr(payload, "chargingProfilePurpose");
  8490. c = 0;
  8491. memset(sstr ,0, sizeof(sstr) );
  8492. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8493. {
  8494. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8495. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8496. c++;
  8497. }
  8498. sstr[c] = '\0';
  8499. strcpy(tempchargingProfilePurposeStr,sstr);
  8500. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8501. {
  8502. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8503. {
  8504. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8505. if(ChargingProfileAdded == FALSE)
  8506. {
  8507. fprintf(outfile,"%s\n",payload);
  8508. ChargingProfileAdded = TRUE;
  8509. }
  8510. }
  8511. else
  8512. {
  8513. if(tempstackLevelInt < stackLevelInt)
  8514. {
  8515. if(ChargingProfileAdded == FALSE)
  8516. {
  8517. fprintf(outfile,"%s\n",payload);
  8518. ChargingProfileAdded = TRUE;
  8519. fprintf(outfile,"%s\n",buf);
  8520. }
  8521. else
  8522. {
  8523. fprintf(outfile,"%s\n",buf);
  8524. }
  8525. }
  8526. else
  8527. {
  8528. if(ChargingProfileAdded == FALSE)
  8529. {
  8530. fprintf(outfile,"%s\n",buf);
  8531. fprintf(outfile,"%s\n",payload);
  8532. ChargingProfileAdded = TRUE;
  8533. }
  8534. else
  8535. {
  8536. fprintf(outfile,"%s\n",buf);
  8537. }
  8538. }
  8539. }
  8540. }
  8541. else
  8542. {
  8543. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8544. {
  8545. if(ChargingProfileAdded == FALSE)
  8546. {
  8547. fprintf(outfile,"%s\n",payload);
  8548. ChargingProfileAdded = TRUE;
  8549. fprintf(outfile,"%s\n",buf);
  8550. }
  8551. else
  8552. {
  8553. fprintf(outfile,"%s\n",buf);
  8554. }
  8555. }
  8556. else if(tempstackLevelInt < stackLevelInt)
  8557. {
  8558. if(ChargingProfileAdded == FALSE)
  8559. {
  8560. fprintf(outfile,"%s\n",payload);
  8561. ChargingProfileAdded = TRUE;
  8562. fprintf(outfile,"%s\n",buf);
  8563. }
  8564. else
  8565. {
  8566. fprintf(outfile,"%s\n",buf);
  8567. }
  8568. }
  8569. else
  8570. {
  8571. if(ChargingProfileAdded == FALSE)
  8572. {
  8573. fprintf(outfile,"%s\n",buf);
  8574. fprintf(outfile,"%s\n",payload);
  8575. ChargingProfileAdded = TRUE;
  8576. }
  8577. else
  8578. {
  8579. fprintf(outfile,"%s\n",buf);
  8580. }
  8581. }
  8582. }
  8583. } // end of while loop
  8584. fclose(infile);
  8585. fclose(outfile);
  8586. sprintf(rmFileCmd,"rm -f %s",filename);
  8587. system(rmFileCmd);
  8588. rename(tempfile, filename);
  8589. #if 0
  8590. resultRename = rename(tempfile, filename);
  8591. if(resultRename == 0)
  8592. {
  8593. DEBUG_INFO("File chargingProfile renamed successfully");
  8594. }
  8595. else
  8596. {
  8597. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8598. }
  8599. #endif
  8600. result = TRUE;
  8601. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8602. }
  8603. end:
  8604. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8605. return result;
  8606. return result;
  8607. }
  8608. int handleTriggerMessageRequest(char *uuid, char *payload)
  8609. {
  8610. mtrace();
  8611. int result = FAIL;
  8612. int connectorIdIsNULL = FALSE;
  8613. int connectorIdInt =0;
  8614. char sstr[40]={0};
  8615. char requestedMessagestr[40]={0};
  8616. char comfirmstr[20]={0};
  8617. int c = 0;
  8618. char *loc;
  8619. DEBUG_INFO("handleTriggerMessageRequest\n");
  8620. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8621. c = 0;
  8622. loc = strstr(payload, "requestedMessage");
  8623. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8624. {
  8625. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8626. c++;
  8627. }
  8628. sstr[c] = '\0';
  8629. strcpy(requestedMessagestr, sstr);
  8630. c = 0;
  8631. loc = strstr(payload, "connectorId");
  8632. if(loc == NULL)
  8633. {
  8634. connectorIdIsNULL = TRUE;
  8635. }
  8636. else
  8637. {
  8638. memset(sstr ,0, sizeof(sstr) );
  8639. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8640. {
  8641. sstr[c] = loc[strlen("connectorId")+2+c];
  8642. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8643. c++;
  8644. }
  8645. sstr[c] = '\0';
  8646. connectorIdInt = atoi(sstr);
  8647. }
  8648. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8649. {
  8650. //connectorIdInt = json_object_get_int(connectorId);
  8651. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8652. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8653. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8654. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8655. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8656. }
  8657. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8658. {
  8659. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8660. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8661. return TRUE;
  8662. }
  8663. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8664. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8665. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8666. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8667. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8668. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8669. {
  8670. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8671. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8672. return TRUE;
  8673. }
  8674. else
  8675. {
  8676. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8677. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8678. }
  8679. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8680. {
  8681. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8682. {
  8683. FirmwareStatusNotificationStatus = 3;
  8684. }
  8685. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8686. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8687. }
  8688. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8689. {
  8690. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8691. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8692. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8693. }
  8694. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8695. {
  8696. sendBootNotificationRequest();
  8697. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8698. }
  8699. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8700. {
  8701. sendHeartbeatRequest(connectorIdInt);
  8702. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8703. }
  8704. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8705. {
  8706. if(connectorIdIsNULL == FALSE)
  8707. {
  8708. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8709. {
  8710. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8711. sendMeterValuesRequest(connectorIdInt -1);
  8712. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8713. }
  8714. }
  8715. else
  8716. {
  8717. for(int idx=0;idx< gunTotalNumber;idx++)
  8718. {
  8719. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8720. sendMeterValuesRequest(idx);
  8721. }
  8722. }
  8723. }
  8724. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8725. {
  8726. if(connectorIdIsNULL == FALSE)
  8727. {
  8728. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8729. {
  8730. sendStatusNotificationRequest(connectorIdInt -1);
  8731. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8732. }
  8733. }
  8734. else
  8735. {
  8736. for(int idx=0;idx< gunTotalNumber;idx++)
  8737. sendStatusNotificationRequest(idx);
  8738. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8739. }
  8740. }
  8741. return result;
  8742. }
  8743. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8744. {
  8745. mtrace();
  8746. int result = FAIL;
  8747. char sstr[6]={0};
  8748. int connectorIdInt =0;
  8749. char comfirmstr[20]={0};
  8750. int c = 0;
  8751. char *loc;
  8752. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8753. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8754. c = 0;
  8755. loc = strstr(payload, "connectorId");
  8756. memset(sstr ,0, sizeof(sstr) );
  8757. while (loc[strlen("connectorId")+2+c] != '}')
  8758. {
  8759. sstr[c] = loc[strlen("connectorId")+2+c];
  8760. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8761. c++;
  8762. }
  8763. sstr[c] = '\0';
  8764. connectorIdInt = atoi(sstr);
  8765. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8766. if(gunTotalNumber == 0)
  8767. {
  8768. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8769. goto end;
  8770. }
  8771. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8772. {
  8773. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8774. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8775. goto end;
  8776. }
  8777. else
  8778. {
  8779. //check Transaction active
  8780. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8781. {
  8782. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8783. {
  8784. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8785. {
  8786. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8787. }
  8788. }
  8789. for (int index = 0; index < CCS_QUANTITY; index++)
  8790. {
  8791. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8792. {
  8793. //stop Transaction
  8794. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8795. }
  8796. }
  8797. for (int index = 0; index < GB_QUANTITY; index++)
  8798. {
  8799. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8800. {
  8801. //stop Transaction
  8802. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8803. }
  8804. }
  8805. }
  8806. else
  8807. {
  8808. for (int index = 0; index < AC_QUANTITY; index++)
  8809. {
  8810. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8811. {
  8812. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8813. }
  8814. }
  8815. }// END FOR AC ELSE
  8816. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8817. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8818. result = TRUE;
  8819. return result;
  8820. }
  8821. end:
  8822. //json_object_put(obj); --- remove temporally
  8823. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8824. return result;
  8825. }
  8826. static char UpdateFirmwarepayloadData[300]={0};
  8827. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8828. {
  8829. mtrace();
  8830. int result = FAIL;
  8831. pthread_t t;
  8832. sendUpdateFirmwareConfirmation(uuid);
  8833. memset(UpdateFirmwarepayloadData, 0, 300);
  8834. strcpy(UpdateFirmwarepayloadData, payload);
  8835. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8836. ////pthread_join(t, NULL); //
  8837. //pthread_detach(t);
  8838. //sendUpdateFirmwareConfirmation(uuid);
  8839. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8840. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8841. return result;
  8842. }
  8843. void *UpdateFirmwareProcess(void *data)
  8844. {
  8845. pthread_detach(pthread_self());
  8846. mtrace();
  8847. int retriesInt =0, retryIntervalInt=0;
  8848. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8849. int port=0;
  8850. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8851. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8852. //char comfirmstr[20];
  8853. int isSuccess = 0;
  8854. char ftpbuf[200];
  8855. char temp[100];
  8856. char * pch;
  8857. int retriesISNULL=FALSE;
  8858. int retryInterval=FALSE;
  8859. int c = 0;
  8860. //int i = 0;
  8861. char *loc;
  8862. char sstr[300]={ 0 };
  8863. char str[300]={ 0 };
  8864. //char *str = (char*) data; // ? ?輸入資 ?
  8865. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8866. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8867. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8868. //***************location **************/
  8869. loc = strstr(str, "location");
  8870. memset(sstr ,0, sizeof(sstr) );
  8871. c = 0;
  8872. while (loc[3+strlen("location")+c] != '\"')
  8873. {
  8874. sstr[c] = loc[3+strlen("location")+c];
  8875. c++;
  8876. }
  8877. sstr[c] = '\0';
  8878. strcpy(locationstr, sstr);
  8879. //***************retries**************/
  8880. c = 0;
  8881. loc = strstr(str, "retries");
  8882. if(loc == NULL)
  8883. {
  8884. retriesISNULL=TRUE;
  8885. }
  8886. else
  8887. {
  8888. memset(sstr ,0, sizeof(sstr) );
  8889. while (loc[strlen("retries")+2+c] != ',')
  8890. {
  8891. sstr[c] = loc[strlen("retries")+2+c];
  8892. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8893. c++;
  8894. }
  8895. sstr[c] = '\0';
  8896. }
  8897. if(retriesISNULL == FALSE)
  8898. {
  8899. retriesInt = atoi(sstr);
  8900. }
  8901. //***************retrieveDate **************/
  8902. loc = strstr(str, "retrieveDate");
  8903. memset(sstr ,0, sizeof(sstr) );
  8904. c = 0;
  8905. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8906. {
  8907. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8908. c++;
  8909. }
  8910. sstr[c] = '\0';
  8911. strcpy(retrieveDatestr, sstr);
  8912. //***************retryInterval **************/
  8913. c = 0;
  8914. loc = strstr(str, "retryInterval");
  8915. memset(sstr ,0, sizeof(sstr) );
  8916. if(loc == NULL)
  8917. {
  8918. retryInterval=TRUE;
  8919. }
  8920. else
  8921. {
  8922. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8923. {
  8924. sstr[c] = loc[strlen("retryInterval")+2+c];
  8925. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8926. c++;
  8927. }
  8928. sstr[c] = '\0';
  8929. }
  8930. if(retryInterval==FALSE)
  8931. {
  8932. retryIntervalInt = atoi(sstr);
  8933. }
  8934. memset(ftppath, 0, sizeof(ftppath));
  8935. memset(path, 0, sizeof(path));
  8936. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8937. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8938. if(strncmp(locationstr,"http", 4) == 0)
  8939. {
  8940. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8941. protocol, host, path);
  8942. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8943. // protocol, user, password, host, path);
  8944. sprintf(ftppath,"/%s", path);
  8945. //DEBUG_INFO("protocol =%s\n",protocol);
  8946. //DEBUG_INFO("host =%s\n",host);
  8947. //DEBUG_INFO("path =%s\n",path);
  8948. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8949. int ftppathlen=strlen(ftppath);
  8950. int i=1;
  8951. char filenametemp[50];
  8952. while(i < ftppathlen)
  8953. {
  8954. int len=ftppathlen-i;
  8955. if(ftppath[len]== 47) // '/' ascll code: 47
  8956. {
  8957. DEBUG_INFO("compare '/' all right\n");
  8958. break;
  8959. }
  8960. i=i+1;
  8961. }
  8962. memset(filenametemp, 0, sizeof(filenametemp));
  8963. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8964. filenametemp[i+1] = 0;
  8965. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8966. do{
  8967. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8968. sleep(retryIntervalInt);
  8969. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8970. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8971. if(!isSuccess)
  8972. {
  8973. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8974. }
  8975. else
  8976. {
  8977. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8978. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8979. isUpdateRequest = TRUE;
  8980. }
  8981. }
  8982. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8983. {
  8984. memset(ftpbuf, 0, sizeof(ftpbuf));
  8985. memset(temp, 0, sizeof(temp));
  8986. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8987. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8988. int ftppathlen=strlen(ftpbuf);
  8989. int i=1;
  8990. char filenametemp[50];
  8991. while(i < ftppathlen)
  8992. {
  8993. int len=ftppathlen-i;
  8994. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8995. {
  8996. DEBUG_INFO(" compare '/' all right\n");
  8997. break;
  8998. }
  8999. i=i+1;
  9000. }
  9001. memset(filenametemp, 0, sizeof(filenametemp));
  9002. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9003. filenametemp[i+1] = 0;
  9004. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9005. pch=strchr(temp,'@');
  9006. if(pch==NULL)
  9007. {
  9008. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9009. protocol, host, &port, path);
  9010. strcpy(user,"anonymous");
  9011. strcpy(password,"");
  9012. }
  9013. else
  9014. {
  9015. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9016. protocol, user, password, host, &port, path);
  9017. }
  9018. sscanf(host,"%[^/]%s",host1, path1);
  9019. sprintf(ftppath,"%s", path1);
  9020. //DEBUG_INFO("protocol =%s\n",protocol);
  9021. //DEBUG_INFO("user =%s\n",user);
  9022. //DEBUG_INFO("password =%s\n",password);
  9023. //DEBUG_INFO("host1 =%s\n",host1);
  9024. //DEBUG_INFO("port =%d\n",port);
  9025. //DEBUG_INFO("path1 =%s\n",path1);
  9026. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9027. //ftpFile(host, user, password, port, ftppath, fname);
  9028. //download firmware pthred
  9029. if(port == 0)
  9030. {
  9031. port = 21;
  9032. }
  9033. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9034. do{
  9035. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9036. sleep(retryIntervalInt);
  9037. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9038. if(!isSuccess)
  9039. {
  9040. //BulldogUtil.sleepMs(interval*1000);
  9041. DEBUG_INFO("Update firmware request and download file fail.\n");
  9042. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9043. }
  9044. else
  9045. {
  9046. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9047. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9048. isUpdateRequest = TRUE;
  9049. }
  9050. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9051. }
  9052. else
  9053. {
  9054. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9055. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9056. }
  9057. pthread_exit(NULL);
  9058. }
  9059. //==========================================
  9060. // Handle server response routine
  9061. //==========================================
  9062. void handleAuthorizeResponse(char *payload, int gun_index)
  9063. {
  9064. mtrace();
  9065. char expiryDatestr[30]={0};
  9066. char parentIdTagstr[20]={0};
  9067. char statusstr[20]={0};
  9068. char expiryDatestrtemp[30]={0};
  9069. char parentIdTagstrtemp[20]={0};
  9070. char IdTagstrtemp[20]={0};
  9071. char statusstrtemp[20]={0};
  9072. int expiryDateISNULL=FALSE;
  9073. int parentIdTagISNULL=FALSE;
  9074. char sstr[160]={ 0 };
  9075. char* filename = AuthorizationCache_JSON;
  9076. char tempfile[] = "/Storage/OCPP/temp.json";
  9077. int c = 0;
  9078. char *loc;
  9079. int resultRename=0;
  9080. int responseIdTagInfoAsZero= 0;
  9081. char rmFileCmd[50]={0};
  9082. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9083. //***********expiryDate*************/
  9084. loc = strstr(payload, "expiryDate");
  9085. memset(sstr ,0, sizeof(sstr) );
  9086. c = 0;
  9087. if(loc == NULL)
  9088. {
  9089. expiryDateISNULL = TRUE;
  9090. }
  9091. else
  9092. {
  9093. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9094. {
  9095. sstr[c] = loc[3+strlen("expiryDate")+c];
  9096. c++;
  9097. }
  9098. sstr[c] = '\0';
  9099. strcpy(expiryDatestr, sstr);
  9100. }
  9101. //***********parentIdTag*************/
  9102. loc = strstr(payload, "parentIdTag");
  9103. memset(sstr ,0, sizeof(sstr) );
  9104. c = 0;
  9105. if(loc == NULL)
  9106. {
  9107. parentIdTagISNULL = TRUE;
  9108. }
  9109. else
  9110. {
  9111. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9112. {
  9113. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9114. c++;
  9115. }
  9116. sstr[c] = '\0';
  9117. strcpy(parentIdTagstr, sstr);
  9118. }
  9119. //***********status*************/
  9120. loc = strstr(payload, "status");
  9121. memset(sstr ,0, sizeof(sstr) );
  9122. c = 0;
  9123. while (loc[3+strlen("status")+c] != '\"')
  9124. {
  9125. sstr[c] = loc[3+strlen("status")+c];
  9126. c++;
  9127. }
  9128. sstr[c] = '\0';
  9129. strcpy(statusstr, sstr);
  9130. if(expiryDateISNULL == FALSE)
  9131. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9132. if(parentIdTagISNULL == FALSE)
  9133. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9134. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9135. //Update idTag information to authorization cache if supproted
  9136. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9137. {
  9138. if((access(filename,F_OK))!=-1)
  9139. {
  9140. printf("AuthorizationCache exist.\n");
  9141. }
  9142. else
  9143. {
  9144. printf("AuthorizationCache not exist\n");
  9145. FILE *log = fopen(filename, "w+");
  9146. if(log == NULL)
  9147. {
  9148. printf("log is NULL\n");
  9149. goto out;
  9150. }
  9151. else
  9152. {
  9153. fclose(log);
  9154. }
  9155. }
  9156. FILE *infile;
  9157. FILE *outfile;
  9158. // open file for writing
  9159. infile = fopen (filename, "r");
  9160. outfile = fopen (tempfile, "w");
  9161. //*检测到文件结束标识返回1,否则返回0。*/
  9162. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9163. int c;
  9164. c = fgetc(infile);
  9165. //DEBUG_INFO("c:%d\n",c);
  9166. rewind(infile);
  9167. if(c == EOF)
  9168. {
  9169. DEBUG_INFO("Orignal File is NULL\n");
  9170. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9171. {
  9172. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9173. }
  9174. else
  9175. {
  9176. strcpy(expiryDatestrtemp, "");
  9177. }
  9178. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9179. {
  9180. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9181. }
  9182. else
  9183. {
  9184. //write Authorize IdTag
  9185. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9186. }
  9187. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9188. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9189. fclose(infile);
  9190. fclose(outfile);
  9191. sprintf(rmFileCmd,"rm -f %s",filename);
  9192. system(rmFileCmd);
  9193. resultRename = rename(tempfile, filename);
  9194. if(resultRename == 0)
  9195. {
  9196. printf("File renamed successfully");
  9197. }
  9198. else
  9199. {
  9200. printf("Error: unable to rename the file");
  9201. }
  9202. }
  9203. else
  9204. {
  9205. char buf[160]={0};
  9206. while (fgets(buf, sizeof(buf), infile) != NULL)
  9207. {
  9208. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9209. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9210. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9211. memset(statusstr, 0, sizeof(statusstrtemp));
  9212. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9213. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9214. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9215. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9216. //------------------IdTag-----------------------
  9217. loc = strstr(buf, "idTag");
  9218. memset(sstr ,0, sizeof(sstr) );
  9219. c = 0;
  9220. while (loc[3+strlen("idTag")+c] != '\"')
  9221. {
  9222. sstr[c] = loc[3+strlen("idTag")+c];
  9223. c++;
  9224. }
  9225. sstr[c] = '\0';
  9226. strcpy(IdTagstrtemp,sstr);
  9227. //*********************expiryDate***************/
  9228. loc = strstr(buf, "expiryDate");
  9229. memset(sstr ,0, sizeof(sstr) );
  9230. c = 0;
  9231. while (loc[3+strlen("expiryDate")+c] != '\"')
  9232. {
  9233. sstr[c] = loc[3+strlen("expiryDate")+c];
  9234. c++;
  9235. }
  9236. sstr[c] = '\0';
  9237. strcpy(expiryDatestr,sstr);
  9238. //*********************parentIdTag***************/
  9239. loc = strstr(buf, "parentIdTag");
  9240. memset(sstr ,0, sizeof(sstr) );
  9241. c = 0;
  9242. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9243. {
  9244. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9245. c++;
  9246. }
  9247. sstr[c] = '\0';
  9248. strcpy(parentIdTagstr,sstr);
  9249. //*********************status***************/
  9250. loc = strstr(buf, "status");
  9251. memset(sstr ,0, sizeof(sstr) );
  9252. c = 0;
  9253. while (loc[3+strlen("status")+c] != '\"')
  9254. {
  9255. sstr[c] = loc[3+strlen("status")+c];
  9256. c++;
  9257. }
  9258. sstr[c] = '\0';
  9259. strcpy(statusstr,sstr);
  9260. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9261. {
  9262. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9263. responseIdTagInfoAsZero = 1;
  9264. }
  9265. else
  9266. {
  9267. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9268. }
  9269. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9270. {
  9271. //modify item
  9272. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9273. {
  9274. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9275. }
  9276. else
  9277. {
  9278. strcpy(expiryDatestrtemp, "");
  9279. }
  9280. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9281. {
  9282. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9283. }
  9284. else
  9285. {
  9286. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9287. }
  9288. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9289. }
  9290. else
  9291. {
  9292. //wrie original item
  9293. strcpy(expiryDatestrtemp, expiryDatestr);
  9294. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9295. strcpy(statusstrtemp, statusstr);
  9296. }
  9297. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9298. }
  9299. fclose(infile);
  9300. fclose(outfile);
  9301. sprintf(rmFileCmd,"rm -f %s",filename);
  9302. system(rmFileCmd);
  9303. resultRename = rename(tempfile, filename);
  9304. if(resultRename == 0)
  9305. {
  9306. DEBUG_INFO("File renamed successfully");
  9307. }
  9308. else
  9309. {
  9310. DEBUG_INFO("Error: unable to rename the file");
  9311. }
  9312. }
  9313. }
  9314. out:
  9315. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9316. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9317. authorizeRetryTimes = 0;
  9318. }
  9319. void handleBootNotificationResponse(char *payload, int gun_index)
  9320. {
  9321. mtrace();
  9322. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9323. char statusStr[12]={0};
  9324. char currentTimeStr[30]={0};
  9325. char *loc;
  9326. int intervalInt = 0;
  9327. int c = 0;
  9328. //double diff_t;
  9329. struct tm tp;
  9330. char buf[28]={0};
  9331. char timebuf[50]={0};
  9332. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9333. //*** interval ****/
  9334. c = 0;
  9335. loc = strstr(payload, "interval");
  9336. //printf("loc=%s\n",loc);
  9337. memset(sstr ,0, sizeof(sstr) );
  9338. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9339. {
  9340. sstr[c] = loc[strlen("interval")+2+c];
  9341. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9342. c++;
  9343. }
  9344. sstr[c] = '\0';
  9345. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9346. intervalInt = atoi(sstr);
  9347. //***status ****/
  9348. loc = strstr(payload, "status");
  9349. memset(sstr ,0, sizeof(sstr) );
  9350. c = 0;
  9351. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9352. {
  9353. sstr[c] = loc[3+strlen("status")+c];
  9354. c++;
  9355. }
  9356. sstr[c] = '\0';
  9357. strcpy(statusStr, sstr);
  9358. //***currentTime ****/
  9359. loc = strstr(payload, "currentTime");
  9360. //printf("loc=%s\n",loc);
  9361. memset(sstr ,0, sizeof(sstr) );
  9362. c = 0;
  9363. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9364. {
  9365. sstr[c] = loc[3+strlen("currentTime")+c];
  9366. c++;
  9367. }
  9368. sstr[c] = '\0';
  9369. strcpy(currentTimeStr, sstr);
  9370. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9371. HeartBeatWaitTime = BootNotificationInterval;
  9372. clientTime.Heartbeat=time((time_t*)NULL);
  9373. //write back to ShmOCPP16Data->BootNotification
  9374. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9375. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9376. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9377. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9378. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9379. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9380. {
  9381. server_sign = TRUE;
  9382. server_pending =FALSE;
  9383. }
  9384. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9385. {
  9386. server_pending = TRUE;
  9387. }
  9388. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9389. tp.tm_isdst = -1;
  9390. //time_t utc = mktime(&tp);
  9391. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9392. memset(timebuf, 0, sizeof timebuf);
  9393. sprintf(timebuf,"date -s '%s'",buf);
  9394. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9395. system(timebuf);
  9396. //==============================================
  9397. // RTC sync
  9398. //==============================================
  9399. system("/sbin/hwclock -w --systohc");
  9400. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9401. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9402. }
  9403. void handleDataTransferResponse(char *payload, int gun_index)
  9404. {
  9405. char sstr[160]={0};//sstr[200]={ 0 };
  9406. int c = 0;
  9407. char *loc;
  9408. DEBUG_INFO("handleDataTransferResponse ...\n");
  9409. loc = strstr(payload, "status");
  9410. printf("loc=%s\n",loc);
  9411. c = 0;
  9412. while (loc[3+strlen("status")+c] != '\"')
  9413. {
  9414. sstr[c] = loc[3+strlen("status")+c];
  9415. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9416. c++;
  9417. }
  9418. sstr[c] = '\0';
  9419. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9420. }
  9421. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9422. {
  9423. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9424. //struct json_object *obj;
  9425. // obj = json_tokener_parse(payload);
  9426. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9427. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9428. //No fields are defined.
  9429. }
  9430. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9431. {
  9432. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9433. //struct json_object *obj;
  9434. // obj = json_tokener_parse(payload);
  9435. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9436. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9437. //No fields are defined.
  9438. }
  9439. void handleHeartbeatResponse(char *payload, int gun_index)
  9440. {
  9441. mtrace();
  9442. //double diff_t;
  9443. struct tm tp;
  9444. char buf[28]={0};
  9445. char timebuf[50]={0};
  9446. char sstr[30]={ 0 };
  9447. int c = 0;
  9448. char *loc;
  9449. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9450. c = 0;
  9451. loc = strstr(payload, "currentTime");
  9452. memset(sstr ,0, sizeof(sstr) );
  9453. while (loc[3+strlen("currentTime")+c] != '\"')
  9454. {
  9455. sstr[c] = loc[3+strlen("currentTime")+c];
  9456. c++;
  9457. }
  9458. sstr[c] = '\0';
  9459. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9460. // #ifdef SystemLogMessage
  9461. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9462. // #endif
  9463. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9464. tp.tm_isdst = -1;
  9465. //time_t utc = mktime(&tp);
  9466. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9467. memset(timebuf, 0, sizeof timebuf);
  9468. sprintf(timebuf,"date -s '%s'",buf);
  9469. system(timebuf);
  9470. //==============================================
  9471. // RTC sync
  9472. //==============================================
  9473. system("/sbin/hwclock -w --systohc");
  9474. if(FirstHeartBeat == 0)
  9475. {
  9476. FirstHeartBeat = 1;
  9477. }
  9478. HeartBeatWithNOResponse = 0;
  9479. //--------Print Out HeartBeat log
  9480. {
  9481. double diff_t;
  9482. struct tm tp,tp1;
  9483. // BootNotification Receive Time
  9484. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9485. tp.tm_isdst = -1;
  9486. time_t BootNotificationReceiveTime = mktime(&tp);
  9487. //HeartBeat Receive Time
  9488. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9489. tp1.tm_isdst = -1;
  9490. time_t HeartBeatReceiveTime = mktime(&tp1);
  9491. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9492. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9493. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9494. {
  9495. HeartBeatCountPerHour = (int)diff_t / 3600;
  9496. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9497. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9498. }
  9499. }
  9500. }
  9501. void handleMeterValuesResponse(char *payload, int gun_index)
  9502. {
  9503. mtrace();
  9504. //struct json_object *obj;
  9505. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9506. //No fields are defined.
  9507. }
  9508. void handleStartTransactionResponse(char *payload, int gun_index)
  9509. {
  9510. mtrace();
  9511. char sstr[28]={ 0 };
  9512. int c = 0;
  9513. char *loc;
  9514. int transactionIdInt = 0;
  9515. FILE *outfile;
  9516. char data[100]={0};
  9517. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9518. DEBUG_INFO("handleStartTransactionResponse\n");
  9519. //****************expiryDate********************/
  9520. loc = strstr(payload, "expiryDate");
  9521. if(loc == NULL)
  9522. {
  9523. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9524. }
  9525. else
  9526. {
  9527. c = 0;
  9528. memset(sstr ,0, sizeof(sstr) );
  9529. while (loc[3+strlen("expiryDate")+c] != '\"')
  9530. {
  9531. sstr[c] = loc[3+strlen("expiryDate")+c];
  9532. c++;
  9533. }
  9534. sstr[c] = '\0';
  9535. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9536. }
  9537. //****************parentIdTag********************/
  9538. loc = strstr(payload, "parentIdTag");
  9539. if(loc == NULL)
  9540. {
  9541. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9542. }
  9543. else
  9544. {
  9545. c = 0;
  9546. memset(sstr ,0, sizeof(sstr) );
  9547. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9548. {
  9549. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9550. c++;
  9551. }
  9552. sstr[c] = '\0';
  9553. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9554. }
  9555. //****************status********************/
  9556. loc = strstr(payload, "status");
  9557. if(loc == NULL)
  9558. {
  9559. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9560. }
  9561. else
  9562. {
  9563. c = 0;
  9564. memset(sstr ,0, sizeof(sstr) );
  9565. while (loc[3+strlen("status")+c] != '\"')
  9566. {
  9567. sstr[c] = loc[3+strlen("status")+c];
  9568. c++;
  9569. }
  9570. sstr[c] = '\0';
  9571. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9572. }
  9573. //****************transactionId********************/
  9574. c=0;
  9575. loc = strstr(payload, "transactionId");
  9576. memset(sstr ,0, sizeof(sstr) );
  9577. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9578. {
  9579. sstr[c] = loc[strlen("transactionId")+2+c];
  9580. c++;
  9581. }
  9582. sstr[c] = '\0';
  9583. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9584. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9585. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9586. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9587. //-----------Start : write to the Queue TransactionId file -----------------//
  9588. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9589. {
  9590. //DEBUG_INFO("QueueTransactionId exist.\n");
  9591. }
  9592. else
  9593. {
  9594. //DEBUG_INFO("QueueTransactionId not exist\n");
  9595. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9596. if(log == NULL)
  9597. {
  9598. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9599. return ;
  9600. }
  9601. else
  9602. {
  9603. fclose(log);
  9604. }
  9605. }
  9606. // open file for writing
  9607. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9608. //DEBUG_INFO("data=%s\n",data);
  9609. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9610. fputs(data, outfile);
  9611. //fputs("\n", outfile);
  9612. fclose (outfile);
  9613. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9614. TransactionId[gun_index] = transactionIdInt;
  9615. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9616. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9617. #ifdef SystemLogMessage
  9618. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9619. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9620. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9621. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9622. #endif
  9623. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  9624. {
  9625. //add Charging Record
  9626. SettingChargingRecord(gun_index, transactionIdInt);
  9627. }
  9628. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  9629. }
  9630. void handleStatusNotificationResponse(char *payload, int gun_index)
  9631. {
  9632. mtrace();
  9633. printf("handleStatusNotificationResponse\n");
  9634. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9635. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9636. }
  9637. void handleStopTransactionnResponse(char *payload, int gun_index)
  9638. {
  9639. mtrace();
  9640. char sstr[30]={ 0 };
  9641. int c = 0;
  9642. char *loc;
  9643. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9644. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9645. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9646. loc = strstr(payload, "idTagInfo");
  9647. //***********************idTagInfo************************/
  9648. if(loc != NULL)
  9649. {
  9650. //***********************expiryDate************************/
  9651. loc = strstr(payload, "expiryDate");
  9652. if(loc != NULL)
  9653. {
  9654. memset(sstr ,0, sizeof(sstr) );
  9655. c = 0;
  9656. while (loc[3+strlen("expiryDate")+c] != '\"')
  9657. {
  9658. sstr[c] = loc[3+strlen("expiryDate")+c];
  9659. c++;
  9660. }
  9661. sstr[c] = '\0';
  9662. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9663. }
  9664. //***********************parentIdTag************************/
  9665. loc = strstr(payload, "parentIdTag");
  9666. if(loc != NULL)
  9667. {
  9668. memset(sstr ,0, sizeof(sstr) );
  9669. c = 0;
  9670. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9671. {
  9672. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9673. c++;
  9674. }
  9675. sstr[c] = '\0';
  9676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9677. }
  9678. //***********************status************************/
  9679. loc = strstr(payload, "status");
  9680. memset(sstr ,0, sizeof(sstr) );
  9681. c = 0;
  9682. while (loc[3+strlen("status")+c] != '\"')
  9683. {
  9684. sstr[c] = loc[3+strlen("status")+c];
  9685. c++;
  9686. }
  9687. sstr[c] = '\0';
  9688. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9689. }
  9690. #ifdef SystemLogMessage
  9691. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9692. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9693. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9694. #endif
  9695. }
  9696. //==========================================
  9697. // Handle Error routine
  9698. //==========================================
  9699. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9700. {
  9701. mtrace();
  9702. #ifdef SystemLogMessage
  9703. DEBUG_INFO("errorCode: %s\n", errorCode);
  9704. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9705. DEBUG_INFO("errorDetails: %s\n", payload);
  9706. #endif
  9707. }
  9708. //===============================================
  9709. // Common routine
  9710. //===============================================
  9711. int initialConfigurationTable(void)
  9712. {
  9713. FILE *fp;
  9714. FILE *outfile;
  9715. char str[200]={0};
  9716. char sstr[100]={0};
  9717. int c = 0;
  9718. char *loc;
  9719. printf("initialConfigurationTable \n");
  9720. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9721. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9722. {
  9723. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9724. if(outfile == NULL) {
  9725. DEBUG_INFO("Error opening file");
  9726. return FALSE;
  9727. }
  9728. /*Core Profile*/
  9729. //AllowOfflineTxForUnknownId
  9730. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9731. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  9735. //AuthorizationCacheEnabled
  9736. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9740. //AuthorizeRemoteTxRequests
  9741. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9745. //BlinkRepeat
  9746. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9750. //ClockAlignedDataInterval
  9751. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9755. //ConnectionTimeOut
  9756. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9760. //GetConfigurationMaxKeys
  9761. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9765. // HeartbeatInterval
  9766. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9770. // LightIntensity
  9771. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9775. // LocalAuthorizeOffline
  9776. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9780. // LocalPreAuthorize
  9781. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9785. // MaxEnergyOnInvalidId
  9786. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9789. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9791. // MeterValuesAlignedData
  9792. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9796. // MeterValuesAlignedDataMaxLength
  9797. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9801. // MeterValuesSampledData
  9802. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9806. // MeterValuesSampledDataMaxLength
  9807. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9811. // MeterValueSampleInterval
  9812. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9816. // MinimumStatusDuration
  9817. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9821. // NumberOfConnectors
  9822. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9824. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9825. {
  9826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9827. }
  9828. else
  9829. {
  9830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9831. }
  9832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9833. // ResetRetries
  9834. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9838. // ConnectorPhaseRotation
  9839. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9843. // ConnectorPhaseRotationMaxLength
  9844. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9848. // StopTransactionOnEVSideDisconnect
  9849. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9853. // StopTransactionOnInvalidId
  9854. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  9855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE" );
  9857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "TRUE");
  9858. // StopTxnAlignedData
  9859. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9863. // StopTxnAlignedDataMaxLength
  9864. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9868. // StopTxnSampledData
  9869. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9873. // StopTxnSampledDataMaxLength
  9874. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9877. {
  9878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9879. }
  9880. else
  9881. {
  9882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9883. }
  9884. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9886. // SupportedFeatureProfiles
  9887. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9891. // SupportedFeatureProfilesMaxLength
  9892. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9896. // TransactionMessageAttempts
  9897. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9900. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9902. // TransactionMessageRetryInterval
  9903. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9906. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9908. // UnlockConnectorOnEVSideDisconnect
  9909. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9913. // WebSocketPingInterval
  9914. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9918. //* Local Auth List Management Profile*/
  9919. #if 0
  9920. //For OCTT Test Case
  9921. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9924. #endif
  9925. #if 1
  9926. //LocalAuthListEnabled
  9927. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9931. #endif
  9932. //LocalAuthListMaxLength
  9933. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9937. //SendLocalListMaxLength
  9938. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9942. //ReserveConnectorZeroSupported
  9943. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9947. //* Smart Charging Profile */
  9948. //ChargeProfileMaxStackLevel
  9949. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9953. // ChargingScheduleAllowedChargingRateUnit
  9954. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9958. // ChargingScheduleMaxPeriods
  9959. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9963. // ConnectorSwitch3to1PhaseSupported
  9964. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9968. // MaxChargingProfilesInstalled
  9969. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9973. fclose(outfile);
  9974. }
  9975. else
  9976. {
  9977. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9978. char keystr[60]={0};
  9979. char readonlystr[10]={0};
  9980. char valuestr[100]={0};
  9981. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9982. if(fp == NULL) {
  9983. DEBUG_INFO("Error opening file");
  9984. return FALSE;
  9985. }
  9986. while( fgets (str, sizeof(str), fp)!=NULL )
  9987. {
  9988. //DEBUG_INFO("Get Configuration \n");
  9989. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9990. //*************************key*********************************/
  9991. loc = strstr(str, "key");
  9992. c = 0;
  9993. memset(sstr ,0, sizeof(sstr) );
  9994. while (loc[strlen("key")+3+c] != '\"')
  9995. {
  9996. sstr[c] = loc[strlen("key")+3+c];
  9997. c++;
  9998. }
  9999. sstr[c] = '\0';
  10000. strcpy(keystr,sstr);
  10001. //*************************readonly*********************************/
  10002. loc = strstr(str, "readonly");
  10003. c = 0;
  10004. memset(sstr ,0, sizeof(sstr) );
  10005. while (loc[strlen("readonly")+2+c] != ',')
  10006. {
  10007. sstr[c] = loc[strlen("readonly")+2+c];
  10008. c++;
  10009. }
  10010. sstr[c] = '\0';
  10011. strcpy(readonlystr,sstr);
  10012. //*************************value*********************************/
  10013. loc = strstr(str, "value");
  10014. c = 0;
  10015. memset(sstr ,0, sizeof(sstr) );
  10016. while (loc[strlen("value")+3+c] != '\"')
  10017. {
  10018. sstr[c] = loc[strlen("value")+3+c];
  10019. c++;
  10020. }
  10021. sstr[c] = '\0';
  10022. strcpy(valuestr,sstr);
  10023. // DEBUG_INFO("keystr=%s\n",keystr);
  10024. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10025. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10026. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10027. {
  10028. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10029. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10031. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10032. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10033. }
  10034. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10035. {
  10036. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10037. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10039. }
  10040. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10041. {
  10042. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10044. }
  10045. if(strcmp(keystr, "BlinkRepeat") == 0)
  10046. {
  10047. //Charger.BlinkRepeat = Integer.parseInt(value);
  10048. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10050. }
  10051. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10052. {
  10053. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10055. }
  10056. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10057. {
  10058. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10060. }
  10061. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10062. {
  10063. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10065. }
  10066. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10067. {
  10068. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10070. HeartBeatWaitTime = atoi(valuestr);
  10071. }
  10072. if(strcmp(keystr, "LightIntensity") == 0)
  10073. {
  10074. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10076. }
  10077. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10078. {
  10079. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10081. }
  10082. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10083. {
  10084. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10086. }
  10087. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10088. {
  10089. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10091. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10092. }
  10093. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10094. {
  10095. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10097. }
  10098. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10099. {
  10100. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10101. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10102. }
  10103. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10104. {
  10105. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10107. }
  10108. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10109. {
  10110. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10112. }
  10113. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10114. {
  10115. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10117. }
  10118. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10119. {
  10120. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10122. }
  10123. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10124. {
  10125. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10127. }
  10128. if(strcmp(keystr, "ResetRetries") == 0)
  10129. {
  10130. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10132. }
  10133. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10134. {
  10135. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10137. }
  10138. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10139. {
  10140. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10142. }
  10143. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10144. {
  10145. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10147. }
  10148. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10149. {
  10150. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10152. }
  10153. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10154. {
  10155. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10157. }
  10158. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10159. {
  10160. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10162. }
  10163. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10164. {
  10165. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10167. }
  10168. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10169. {
  10170. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10172. }
  10173. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10174. {
  10175. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10177. }
  10178. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10179. {
  10180. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10182. }
  10183. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10184. {
  10185. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10187. TransactionMessageAttemptsValue = atoi(valuestr);
  10188. }
  10189. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10190. {
  10191. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10193. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10194. }
  10195. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10196. {
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10199. }
  10200. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10201. {
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10204. }
  10205. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10206. {
  10207. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10209. }
  10210. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10211. {
  10212. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10214. }
  10215. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10216. {
  10217. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10219. }
  10220. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10221. {
  10222. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10224. }
  10225. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10226. {
  10227. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10229. }
  10230. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10231. {
  10232. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10234. }
  10235. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10236. {
  10237. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10239. }
  10240. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10241. {
  10242. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10244. }
  10245. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10246. {
  10247. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10249. }
  10250. }
  10251. fclose(fp);
  10252. }
  10253. return 0;
  10254. }
  10255. void StoreConfigurationTable(void)
  10256. {
  10257. FILE *outfile;
  10258. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10259. if(outfile == NULL)
  10260. {
  10261. DEBUG_INFO("Error opening file");
  10262. return ;
  10263. }
  10264. /*Core Profile*/
  10265. //AllowOfflineTxForUnknownId
  10266. /*
  10267. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10268. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10271. */
  10272. //DEBUG_INFO("data=%s\n",data);
  10273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10274. //AuthorizationCacheEnabled
  10275. /*
  10276. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10279. */
  10280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10281. //AuthorizeRemoteTxRequests
  10282. /*
  10283. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10286. */
  10287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10288. //BlinkRepeat
  10289. /*
  10290. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10293. */
  10294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10295. //ClockAlignedDataInterval
  10296. /*
  10297. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10300. */
  10301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10302. //ConnectionTimeOut
  10303. /*
  10304. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10307. */
  10308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10309. //GetConfigurationMaxKeys
  10310. /*
  10311. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10314. */
  10315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10316. // HeartbeatInterval
  10317. /*
  10318. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10321. */
  10322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10323. // LightIntensity
  10324. /*
  10325. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10328. */
  10329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10330. // LocalAuthorizeOffline
  10331. /*
  10332. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10335. */
  10336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10337. // LocalPreAuthorize
  10338. /*
  10339. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10342. */
  10343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10344. // MaxEnergyOnInvalidId
  10345. /*
  10346. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10349. */
  10350. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10352. // MeterValuesAlignedData
  10353. /*
  10354. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10357. */
  10358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10359. // MeterValuesAlignedDataMaxLength
  10360. /*
  10361. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10364. */
  10365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10366. // MeterValuesSampledData
  10367. /*
  10368. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10371. */
  10372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10373. // MeterValuesSampledDataMaxLength
  10374. /*
  10375. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10378. */
  10379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10380. // MeterValueSampleInterval
  10381. /*
  10382. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10385. */
  10386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10387. // MinimumStatusDuration
  10388. /*
  10389. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10392. */
  10393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10394. // NumberOfConnectors
  10395. /*
  10396. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10399. {
  10400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10401. }
  10402. else
  10403. {
  10404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10405. }
  10406. */
  10407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10408. // ResetRetries
  10409. /*
  10410. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10413. */
  10414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10415. // ConnectorPhaseRotation
  10416. /*
  10417. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10420. */
  10421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10422. // ConnectorPhaseRotationMaxLength
  10423. /*
  10424. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10427. */
  10428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10429. // StopTransactionOnEVSideDisconnect
  10430. /*
  10431. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10434. */
  10435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10436. // StopTransactionOnInvalidId
  10437. /*
  10438. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  10439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10441. */
  10442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10443. // StopTxnAlignedData
  10444. /*
  10445. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10448. */
  10449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10450. // StopTxnAlignedDataMaxLength
  10451. /*
  10452. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10455. */
  10456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10457. // StopTxnSampledData
  10458. /*
  10459. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10462. */
  10463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10464. // StopTxnSampledDataMaxLength
  10465. /*
  10466. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10469. */
  10470. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10471. // SupportedFeatureProfiles
  10472. /*
  10473. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10476. */
  10477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10478. // SupportedFeatureProfilesMaxLength
  10479. /*
  10480. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10483. */
  10484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10485. // TransactionMessageAttempts
  10486. /*
  10487. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10490. */
  10491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10492. // TransactionMessageRetryInterval
  10493. /*
  10494. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10497. */
  10498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10499. // UnlockConnectorOnEVSideDisconnect
  10500. /*
  10501. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10504. */
  10505. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10506. // WebSocketPingInterval
  10507. /*
  10508. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10511. */
  10512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10513. //* Local Auth List Management Profile*/
  10514. //LocalAuthListEnabled
  10515. /*
  10516. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10519. */
  10520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10521. //LocalAuthListMaxLength
  10522. /*
  10523. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10526. */
  10527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10528. //SendLocalListMaxLength
  10529. /*
  10530. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10533. */
  10534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10535. //ReserveConnectorZeroSupported
  10536. /*
  10537. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10540. */
  10541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10542. //* Smart Charging Profile */
  10543. //ChargeProfileMaxStackLevel
  10544. /*
  10545. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10548. */
  10549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10550. // ChargingScheduleAllowedChargingRateUnit
  10551. /*
  10552. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10555. */
  10556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10557. // ChargingScheduleMaxPeriods
  10558. /*
  10559. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10562. */
  10563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10564. // ConnectorSwitch3to1PhaseSupported
  10565. /*
  10566. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10569. */
  10570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10571. // MaxChargingProfilesInstalled
  10572. /*
  10573. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10576. */
  10577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10578. fclose(outfile);
  10579. }
  10580. void getKeyValue(char *keyReq)
  10581. {
  10582. int isEmpty = FALSE;
  10583. int isKnowKey = FALSE;
  10584. //int unKnowIndex = 0;
  10585. DEBUG_INFO("getKeyValue \n");
  10586. DEBUG_INFO("keyReq=%s \n",keyReq);
  10587. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10588. isEmpty = TRUE;
  10589. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10590. {
  10591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10594. {
  10595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10596. }
  10597. else
  10598. {
  10599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10600. }
  10601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10602. isKnowKey = TRUE;
  10603. }
  10604. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10605. {
  10606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10609. {
  10610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10611. }
  10612. else
  10613. {
  10614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10615. }
  10616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10617. isKnowKey = TRUE;
  10618. }
  10619. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10620. {
  10621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10624. {
  10625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10626. }
  10627. else
  10628. {
  10629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10630. }
  10631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10632. isKnowKey = TRUE;
  10633. }
  10634. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10635. {
  10636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10639. {
  10640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10641. }
  10642. else
  10643. {
  10644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10645. }
  10646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10647. isKnowKey = TRUE;
  10648. }
  10649. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10650. {
  10651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10653. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10654. {
  10655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10656. }
  10657. else
  10658. {
  10659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10660. }
  10661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10662. isKnowKey = TRUE;
  10663. }
  10664. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10665. {
  10666. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10669. {
  10670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10671. }
  10672. else
  10673. {
  10674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10675. }
  10676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10677. isKnowKey = TRUE;
  10678. }
  10679. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10680. {
  10681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10684. {
  10685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10686. }
  10687. else
  10688. {
  10689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10690. }
  10691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10692. isKnowKey = TRUE;
  10693. }
  10694. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10695. {
  10696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10699. {
  10700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10701. }
  10702. else
  10703. {
  10704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10705. }
  10706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10707. isKnowKey = TRUE;
  10708. }
  10709. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10710. {
  10711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10714. {
  10715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10716. }
  10717. else
  10718. {
  10719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10720. }
  10721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10722. isKnowKey = TRUE;
  10723. }
  10724. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10725. {
  10726. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10729. {
  10730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10731. }
  10732. else
  10733. {
  10734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10735. }
  10736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10737. isKnowKey = TRUE;
  10738. }
  10739. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10740. {
  10741. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10744. {
  10745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10746. }
  10747. else
  10748. {
  10749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10750. }
  10751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10752. isKnowKey = TRUE;
  10753. }
  10754. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10755. {
  10756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10759. {
  10760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10761. }
  10762. else
  10763. {
  10764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10765. }
  10766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10767. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10768. isKnowKey = TRUE;
  10769. }
  10770. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10771. {
  10772. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10775. {
  10776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10777. }
  10778. else
  10779. {
  10780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10781. }
  10782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10783. isKnowKey = TRUE;
  10784. }
  10785. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10786. {
  10787. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10789. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10790. {
  10791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10792. }
  10793. else
  10794. {
  10795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10796. }
  10797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10798. isKnowKey = TRUE;
  10799. }
  10800. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10801. {
  10802. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10804. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10805. {
  10806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10807. }
  10808. else
  10809. {
  10810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10811. }
  10812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10813. isKnowKey = TRUE;
  10814. }
  10815. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10816. {
  10817. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10819. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10820. {
  10821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10822. }
  10823. else
  10824. {
  10825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10826. }
  10827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10828. isKnowKey = TRUE;
  10829. }
  10830. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10831. {
  10832. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10835. {
  10836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10837. }
  10838. else
  10839. {
  10840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10841. }
  10842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10843. isKnowKey = TRUE;
  10844. }
  10845. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10846. {
  10847. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10850. {
  10851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10852. }
  10853. else
  10854. {
  10855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10856. }
  10857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10858. isKnowKey = TRUE;
  10859. }
  10860. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10861. {
  10862. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10865. {
  10866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10867. }
  10868. else
  10869. {
  10870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10871. }
  10872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10873. isKnowKey = TRUE;
  10874. }
  10875. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10876. {
  10877. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10880. {
  10881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10882. }
  10883. else
  10884. {
  10885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10886. }
  10887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10888. isKnowKey = TRUE;
  10889. }
  10890. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10891. {
  10892. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10895. {
  10896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10897. }
  10898. else
  10899. {
  10900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10901. }
  10902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10903. isKnowKey = TRUE;
  10904. }
  10905. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10906. {
  10907. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10910. {
  10911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10912. }
  10913. else
  10914. {
  10915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10916. }
  10917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10918. isKnowKey = TRUE;
  10919. }
  10920. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10921. {
  10922. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10925. {
  10926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10927. }
  10928. else
  10929. {
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10931. }
  10932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10933. isKnowKey = TRUE;
  10934. }
  10935. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10936. {
  10937. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10940. {
  10941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10942. }
  10943. else
  10944. {
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10946. }
  10947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10948. isKnowKey = TRUE;
  10949. }
  10950. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10951. {
  10952. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10955. {
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10957. }
  10958. else
  10959. {
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10961. }
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10963. isKnowKey = TRUE;
  10964. }
  10965. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10966. {
  10967. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10970. {
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10972. }
  10973. else
  10974. {
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10976. }
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10978. isKnowKey = TRUE;
  10979. }
  10980. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10981. {
  10982. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10985. {
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10987. }
  10988. else
  10989. {
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10991. }
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10993. isKnowKey = TRUE;
  10994. }
  10995. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10996. {
  10997. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11000. {
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11002. }
  11003. else
  11004. {
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11006. }
  11007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11008. isKnowKey = TRUE;
  11009. }
  11010. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11011. {
  11012. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11015. {
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11017. }
  11018. else
  11019. {
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11021. }
  11022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11023. isKnowKey = TRUE;
  11024. }
  11025. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11026. {
  11027. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11030. {
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11032. }
  11033. else
  11034. {
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11036. }
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11038. isKnowKey = TRUE;
  11039. }
  11040. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11041. {
  11042. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11045. {
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11047. }
  11048. else
  11049. {
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11051. }
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11053. isKnowKey = TRUE;
  11054. }
  11055. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11056. {
  11057. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11059. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11060. {
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11062. }
  11063. else
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11066. }
  11067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11068. isKnowKey = TRUE;
  11069. }
  11070. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11071. {
  11072. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11074. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11075. {
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11077. }
  11078. else
  11079. {
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11081. }
  11082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11083. isKnowKey = TRUE;
  11084. }
  11085. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11086. {
  11087. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11090. {
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11092. }
  11093. else
  11094. {
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11096. }
  11097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11098. isKnowKey = TRUE;
  11099. }
  11100. #if 0
  11101. //For OCTT Test Case
  11102. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11103. {
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11106. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11107. {
  11108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11109. }
  11110. else
  11111. {
  11112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11113. }
  11114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11115. isKnowKey = TRUE;
  11116. }
  11117. #endif
  11118. #if 1
  11119. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11120. {
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11123. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11124. {
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11126. }
  11127. else
  11128. {
  11129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11130. }
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11132. isKnowKey = TRUE;
  11133. }
  11134. #endif
  11135. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11136. {
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11139. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11140. {
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11142. }
  11143. else
  11144. {
  11145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11146. }
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11148. isKnowKey = TRUE;
  11149. }
  11150. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11151. {
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11154. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11155. {
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11157. }
  11158. else
  11159. {
  11160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11161. }
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11163. isKnowKey = TRUE;
  11164. }
  11165. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11166. {
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11169. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11170. {
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11172. }
  11173. else
  11174. {
  11175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11176. }
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11178. isKnowKey = TRUE;
  11179. }
  11180. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11181. {
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11184. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11185. {
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11187. }
  11188. else
  11189. {
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11191. }
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11193. isKnowKey = TRUE;
  11194. }
  11195. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11196. {
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11199. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11200. {
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11202. }
  11203. else
  11204. {
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11206. }
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11208. isKnowKey = TRUE;
  11209. }
  11210. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11211. {
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11214. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11217. }
  11218. else
  11219. {
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11221. }
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11223. isKnowKey = TRUE;
  11224. }
  11225. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11226. {
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11229. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11232. }
  11233. else
  11234. {
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11236. }
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11238. isKnowKey = TRUE;
  11239. }
  11240. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11241. {
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11244. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11247. }
  11248. else
  11249. {
  11250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11251. }
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11253. isKnowKey = TRUE;
  11254. }
  11255. //=========================================================
  11256. if(!isEmpty && !isKnowKey)
  11257. {
  11258. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11259. strcpy(unknownkey[UnknownKeynum], keyReq);
  11260. UnknownKeynum = UnknownKeynum + 1;
  11261. }
  11262. }
  11263. void processUnkownKey(void)
  11264. {
  11265. DEBUG_INFO("processUnkownKey\n");
  11266. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11267. for(int index=0; index < UnknownKeynum; index++)
  11268. {
  11269. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11270. {
  11271. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11272. }
  11273. }
  11274. }
  11275. int setKeyValue(char *key, char *value)
  11276. {
  11277. int isSuccess = NotSupported;
  11278. int check_ascii=0;
  11279. char str[10]={0};
  11280. #ifdef Debug
  11281. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11282. #endif
  11283. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11284. {
  11285. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11287. {
  11288. strcpy(str, (const char*)value);
  11289. for(int i = 0; str[i]; i++){
  11290. str[i] = tolower(str[i]);
  11291. }
  11292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11293. isSuccess = ConfigurationStatus_Accepted;
  11294. }
  11295. else
  11296. {
  11297. isSuccess = ConfigurationStatus_Rejected;
  11298. }
  11299. }
  11300. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11301. {
  11302. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11304. {
  11305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  11306. isSuccess = ConfigurationStatus_Accepted;
  11307. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11308. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11309. }
  11310. else
  11311. {
  11312. isSuccess = ConfigurationStatus_Rejected;
  11313. }
  11314. }
  11315. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11316. {
  11317. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11318. {
  11319. strcpy(str, (const char*)value);
  11320. for(int i = 0; str[i]; i++)
  11321. {
  11322. str[i] = tolower(str[i]);
  11323. }
  11324. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11326. isSuccess = ConfigurationStatus_Accepted;
  11327. }
  11328. else
  11329. {
  11330. isSuccess = ConfigurationStatus_Rejected;
  11331. }
  11332. }
  11333. if(strcmp(key, "BlinkRepeat") == 0)
  11334. {
  11335. //Charger.BlinkRepeat = Integer.parseInt(value);
  11336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11337. {
  11338. check_ascii = value[0];
  11339. if( (check_ascii < 48) || (check_ascii > 57) )
  11340. {
  11341. isSuccess = ConfigurationStatus_Rejected;
  11342. }
  11343. else
  11344. {
  11345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11346. isSuccess = ConfigurationStatus_Accepted;
  11347. }
  11348. }
  11349. else
  11350. {
  11351. isSuccess = ConfigurationStatus_Rejected;
  11352. }
  11353. }
  11354. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11355. {
  11356. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11357. {
  11358. check_ascii = value[0];
  11359. if( (check_ascii < 48) || (check_ascii > 57) )
  11360. {
  11361. isSuccess = ConfigurationStatus_Rejected;
  11362. }
  11363. else
  11364. {
  11365. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11367. isSuccess = ConfigurationStatus_Accepted;
  11368. }
  11369. }
  11370. else
  11371. {
  11372. isSuccess = ConfigurationStatus_Rejected;
  11373. }
  11374. }
  11375. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11376. {
  11377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11378. {
  11379. check_ascii = value[0];
  11380. if( (check_ascii < 48) || (check_ascii > 57) )
  11381. {
  11382. isSuccess = ConfigurationStatus_Rejected;
  11383. }
  11384. else
  11385. {
  11386. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11388. isSuccess = ConfigurationStatus_Accepted;
  11389. }
  11390. }
  11391. else
  11392. {
  11393. isSuccess = ConfigurationStatus_Rejected;
  11394. }
  11395. }
  11396. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11397. {
  11398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11399. {
  11400. check_ascii = value[0];
  11401. if( (check_ascii < 48) || (check_ascii > 57) )
  11402. {
  11403. isSuccess = ConfigurationStatus_Rejected;
  11404. }
  11405. else
  11406. {
  11407. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11409. isSuccess = ConfigurationStatus_Accepted;
  11410. }
  11411. }
  11412. else
  11413. {
  11414. isSuccess = ConfigurationStatus_Rejected;
  11415. }
  11416. }
  11417. if(strcmp(key, "HeartbeatInterval") == 0)
  11418. {
  11419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11420. {
  11421. check_ascii = value[0];
  11422. if( (check_ascii < 48) || (check_ascii > 57) )
  11423. {
  11424. isSuccess = ConfigurationStatus_Rejected;
  11425. }
  11426. else
  11427. {
  11428. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11430. HeartBeatWaitTime = atoi(value);
  11431. isSuccess = ConfigurationStatus_Accepted;
  11432. }
  11433. }
  11434. else
  11435. {
  11436. isSuccess = ConfigurationStatus_Rejected;
  11437. }
  11438. }
  11439. if(strcmp(key, "LightIntensity") == 0)
  11440. {
  11441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11442. {
  11443. check_ascii = value[0];
  11444. if( (check_ascii < 48) || (check_ascii > 57) )
  11445. {
  11446. isSuccess = ConfigurationStatus_Rejected;
  11447. }
  11448. else
  11449. {
  11450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11451. isSuccess = ConfigurationStatus_Accepted;
  11452. }
  11453. }
  11454. else
  11455. {
  11456. isSuccess = ConfigurationStatus_Rejected;
  11457. }
  11458. }
  11459. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11460. {
  11461. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11462. {
  11463. strcpy(str, (const char*)value);
  11464. for(int i = 0; str[i]; i++)
  11465. {
  11466. str[i] = tolower(str[i]);
  11467. }
  11468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11469. isSuccess = ConfigurationStatus_Accepted;
  11470. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11471. }
  11472. else
  11473. {
  11474. isSuccess = ConfigurationStatus_Rejected;
  11475. }
  11476. }
  11477. if(strcmp(key, "LocalPreAuthorize") == 0)
  11478. {
  11479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11480. {
  11481. strcpy(str, (const char*)value);
  11482. for(int i = 0; str[i]; i++)
  11483. {
  11484. str[i] = tolower(str[i]);
  11485. }
  11486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11487. isSuccess = ConfigurationStatus_Accepted;
  11488. }
  11489. else
  11490. {
  11491. isSuccess = ConfigurationStatus_Rejected;
  11492. }
  11493. }
  11494. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11495. {
  11496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11497. {
  11498. check_ascii = value[0];
  11499. if( (check_ascii < 48) || (check_ascii > 57) )
  11500. {
  11501. isSuccess = ConfigurationStatus_Rejected;
  11502. }
  11503. else
  11504. {
  11505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11506. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11507. isSuccess = ConfigurationStatus_Accepted;
  11508. }
  11509. }
  11510. else
  11511. {
  11512. isSuccess = ConfigurationStatus_Rejected;
  11513. }
  11514. }
  11515. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11516. {
  11517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11518. {
  11519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11520. isSuccess = ConfigurationStatus_Accepted;
  11521. }
  11522. else
  11523. {
  11524. isSuccess = ConfigurationStatus_Rejected;
  11525. }
  11526. }
  11527. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11528. {
  11529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11530. {
  11531. check_ascii = value[0];
  11532. if( (check_ascii < 48) || (check_ascii > 57) )
  11533. {
  11534. isSuccess = ConfigurationStatus_Rejected;
  11535. }
  11536. else
  11537. {
  11538. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11540. isSuccess = ConfigurationStatus_Accepted;
  11541. }
  11542. }
  11543. else
  11544. {
  11545. isSuccess = ConfigurationStatus_Rejected;
  11546. }
  11547. }
  11548. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11549. {
  11550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11551. {
  11552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11553. isSuccess = ConfigurationStatus_Accepted;
  11554. }
  11555. else
  11556. {
  11557. isSuccess = ConfigurationStatus_Rejected;
  11558. }
  11559. }
  11560. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11561. {
  11562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11563. {
  11564. check_ascii = value[0];
  11565. if( (check_ascii < 48) || (check_ascii > 57) )
  11566. {
  11567. isSuccess = ConfigurationStatus_Rejected;
  11568. }
  11569. else
  11570. {
  11571. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11573. isSuccess = ConfigurationStatus_Accepted;
  11574. }
  11575. }
  11576. else
  11577. {
  11578. isSuccess = ConfigurationStatus_Rejected;
  11579. }
  11580. }
  11581. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11582. {
  11583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11584. {
  11585. check_ascii = value[0];
  11586. if( (check_ascii < 48) || (check_ascii > 57) )
  11587. {
  11588. isSuccess = ConfigurationStatus_Rejected;
  11589. }
  11590. else
  11591. {
  11592. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11594. isSuccess = ConfigurationStatus_Accepted;
  11595. }
  11596. }
  11597. else
  11598. {
  11599. isSuccess = ConfigurationStatus_Rejected;
  11600. }
  11601. }
  11602. if(strcmp(key, "MinimumStatusDuration") == 0)
  11603. {
  11604. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11605. {
  11606. check_ascii = value[0];
  11607. if( (check_ascii < 48) || (check_ascii > 57) )
  11608. {
  11609. isSuccess = ConfigurationStatus_Rejected;
  11610. }
  11611. else
  11612. {
  11613. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11615. isSuccess = ConfigurationStatus_Accepted;
  11616. }
  11617. }
  11618. else
  11619. {
  11620. isSuccess = ConfigurationStatus_Rejected;
  11621. }
  11622. }
  11623. if(strcmp(key, "NumberOfConnectors") == 0)
  11624. {
  11625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11626. {
  11627. check_ascii = value[0];
  11628. if( (check_ascii < 48) || (check_ascii > 57) )
  11629. {
  11630. isSuccess = ConfigurationStatus_Rejected;
  11631. }
  11632. else
  11633. {
  11634. //Charger.ResetRetries = Integer.parseInt(value);
  11635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11636. isSuccess = ConfigurationStatus_Accepted;
  11637. }
  11638. }
  11639. else
  11640. {
  11641. isSuccess = ConfigurationStatus_Rejected;
  11642. }
  11643. }
  11644. if(strcmp(key, "ResetRetries") == 0)
  11645. {
  11646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11647. {
  11648. check_ascii = value[0];
  11649. if( (check_ascii < 48) || (check_ascii > 57) )
  11650. {
  11651. isSuccess = ConfigurationStatus_Rejected;
  11652. }
  11653. else
  11654. {
  11655. //Charger.ResetRetries = Integer.parseInt(value);
  11656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11657. isSuccess = ConfigurationStatus_Accepted;
  11658. }
  11659. }
  11660. else
  11661. {
  11662. isSuccess = ConfigurationStatus_Rejected;
  11663. }
  11664. }
  11665. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11666. {
  11667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11668. {
  11669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  11670. isSuccess = ConfigurationStatus_Accepted;
  11671. }
  11672. else
  11673. {
  11674. isSuccess = ConfigurationStatus_Rejected;
  11675. }
  11676. }
  11677. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11678. {
  11679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11680. {
  11681. check_ascii = value[0];
  11682. if( (check_ascii < 48) || (check_ascii > 57) )
  11683. {
  11684. isSuccess = ConfigurationStatus_Rejected;
  11685. }
  11686. else
  11687. {
  11688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11689. isSuccess = ConfigurationStatus_Accepted;
  11690. }
  11691. }
  11692. else
  11693. {
  11694. isSuccess = ConfigurationStatus_Rejected;
  11695. }
  11696. }
  11697. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11698. {
  11699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11700. {
  11701. strcpy(str, (const char*)value);
  11702. for(int i = 0; str[i]; i++)
  11703. {
  11704. str[i] = tolower(str[i]);
  11705. }
  11706. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11708. isSuccess = ConfigurationStatus_Accepted;
  11709. }
  11710. else
  11711. {
  11712. isSuccess = ConfigurationStatus_Rejected;
  11713. }
  11714. }
  11715. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11716. {
  11717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11718. {
  11719. strcpy(str, (const char*)value);
  11720. for(int i = 0; str[i]; i++)
  11721. {
  11722. str[i] = tolower(str[i]);
  11723. }
  11724. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11726. isSuccess = ConfigurationStatus_Accepted;
  11727. }
  11728. else
  11729. {
  11730. isSuccess = ConfigurationStatus_Rejected;
  11731. }
  11732. }
  11733. if(strcmp(key, "StopTxnAlignedData") == 0)
  11734. {
  11735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11736. {
  11737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11738. isSuccess = ConfigurationStatus_Accepted;
  11739. }
  11740. else
  11741. {
  11742. isSuccess = ConfigurationStatus_Rejected;
  11743. }
  11744. }
  11745. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11746. {
  11747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11748. {
  11749. check_ascii = value[0];
  11750. if( (check_ascii < 48) || (check_ascii > 57) )
  11751. {
  11752. isSuccess = ConfigurationStatus_Rejected;
  11753. }
  11754. else
  11755. {
  11756. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11757. isSuccess = ConfigurationStatus_Accepted;
  11758. }
  11759. }
  11760. else
  11761. {
  11762. isSuccess = ConfigurationStatus_Rejected;
  11763. }
  11764. }
  11765. if(strcmp(key, "StopTxnSampledData") == 0)
  11766. {
  11767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11768. {
  11769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11770. isSuccess = ConfigurationStatus_Accepted;
  11771. }
  11772. else
  11773. {
  11774. isSuccess = ConfigurationStatus_Rejected;
  11775. }
  11776. }
  11777. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11778. {
  11779. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11780. {
  11781. check_ascii = value[0];
  11782. if( (check_ascii < 48) || (check_ascii > 57) )
  11783. {
  11784. isSuccess = ConfigurationStatus_Rejected;
  11785. }
  11786. else
  11787. {
  11788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11789. isSuccess = ConfigurationStatus_Accepted;
  11790. }
  11791. }
  11792. else
  11793. {
  11794. isSuccess = ConfigurationStatus_Rejected;
  11795. }
  11796. }
  11797. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11798. {
  11799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11800. {
  11801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11802. isSuccess = ConfigurationStatus_Accepted;
  11803. }
  11804. else
  11805. {
  11806. isSuccess = ConfigurationStatus_Rejected;
  11807. }
  11808. }
  11809. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11810. {
  11811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11812. {
  11813. check_ascii = value[0];
  11814. if( (check_ascii < 48) || (check_ascii > 57) )
  11815. {
  11816. isSuccess = ConfigurationStatus_Rejected;
  11817. }
  11818. else
  11819. {
  11820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11821. isSuccess = ConfigurationStatus_Accepted;
  11822. }
  11823. }
  11824. else
  11825. {
  11826. isSuccess = ConfigurationStatus_Rejected;
  11827. }
  11828. }
  11829. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11830. {
  11831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11832. {
  11833. check_ascii = value[0];
  11834. if( (check_ascii < 48) || (check_ascii > 57) )
  11835. {
  11836. isSuccess = ConfigurationStatus_Rejected;
  11837. }
  11838. else
  11839. {
  11840. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11842. TransactionMessageAttemptsValue = atoi(value);
  11843. isSuccess = ConfigurationStatus_Accepted;
  11844. }
  11845. }
  11846. else
  11847. {
  11848. isSuccess = ConfigurationStatus_Rejected;
  11849. }
  11850. }
  11851. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11852. {
  11853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11854. {
  11855. check_ascii = value[0];
  11856. if( (check_ascii < 48) || (check_ascii > 57) )
  11857. {
  11858. isSuccess = ConfigurationStatus_Rejected;
  11859. }
  11860. else
  11861. {
  11862. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11864. TransactionMessageRetryIntervalValue = atoi(value);
  11865. isSuccess = ConfigurationStatus_Accepted;
  11866. }
  11867. }
  11868. else
  11869. {
  11870. isSuccess = ConfigurationStatus_Rejected;
  11871. }
  11872. }
  11873. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11874. {
  11875. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11876. {
  11877. strcpy(str, (const char*)value);
  11878. for(int i = 0; str[i]; i++)
  11879. {
  11880. str[i] = tolower(str[i]);
  11881. }
  11882. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11884. isSuccess = ConfigurationStatus_Accepted;
  11885. }
  11886. else
  11887. {
  11888. isSuccess = ConfigurationStatus_Rejected;
  11889. }
  11890. }
  11891. if(strcmp(key, "WebSocketPingInterval") == 0)
  11892. {
  11893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11894. {
  11895. check_ascii = value[0];
  11896. if( (check_ascii < 48) || (check_ascii > 57) )
  11897. {
  11898. isSuccess = ConfigurationStatus_Rejected;
  11899. }
  11900. else
  11901. {
  11902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11903. isSuccess = ConfigurationStatus_Accepted;
  11904. }
  11905. }
  11906. else
  11907. {
  11908. isSuccess = ConfigurationStatus_Rejected;
  11909. }
  11910. }
  11911. #if 0
  11912. //For OCPP Test Case
  11913. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11914. {
  11915. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11916. {
  11917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11918. isSuccess = ConfigurationStatus_Accepted;
  11919. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11920. }
  11921. else
  11922. {
  11923. isSuccess = ConfigurationStatus_Rejected;
  11924. }
  11925. }
  11926. #endif
  11927. #if 1
  11928. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11929. {
  11930. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11931. {
  11932. strcpy(str, (const char*)value);
  11933. for(int i = 0; str[i]; i++)
  11934. {
  11935. str[i] = tolower(str[i]);
  11936. }
  11937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11938. isSuccess = ConfigurationStatus_Accepted;
  11939. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11940. }
  11941. else
  11942. {
  11943. isSuccess = ConfigurationStatus_Rejected;
  11944. }
  11945. }
  11946. #endif
  11947. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11948. {
  11949. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11950. {
  11951. check_ascii = value[0];
  11952. if( (check_ascii < 48) || (check_ascii > 57) )
  11953. {
  11954. isSuccess = ConfigurationStatus_Rejected;
  11955. }
  11956. else
  11957. {
  11958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11959. isSuccess = ConfigurationStatus_Accepted;
  11960. }
  11961. }
  11962. else
  11963. {
  11964. isSuccess = ConfigurationStatus_Rejected;
  11965. }
  11966. }
  11967. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11968. {
  11969. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11970. {
  11971. check_ascii = value[0];
  11972. if( (check_ascii < 48) || (check_ascii > 57) )
  11973. {
  11974. isSuccess = ConfigurationStatus_Rejected;
  11975. }
  11976. else
  11977. {
  11978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11979. isSuccess = ConfigurationStatus_Accepted;
  11980. }
  11981. }
  11982. else
  11983. {
  11984. isSuccess = ConfigurationStatus_Rejected;
  11985. }
  11986. }
  11987. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11988. {
  11989. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11990. {
  11991. strcpy(str, (const char*)value);
  11992. for(int i = 0; str[i]; i++)
  11993. {
  11994. str[i] = tolower(str[i]);
  11995. }
  11996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11997. isSuccess = ConfigurationStatus_Accepted;
  11998. }
  11999. else
  12000. {
  12001. isSuccess = ConfigurationStatus_Rejected;
  12002. }
  12003. }
  12004. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12005. {
  12006. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12007. {
  12008. check_ascii = value[0];
  12009. if( (check_ascii < 48) || (check_ascii > 57) )
  12010. {
  12011. isSuccess = ConfigurationStatus_Rejected;
  12012. }
  12013. else
  12014. {
  12015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12016. isSuccess = ConfigurationStatus_Accepted;
  12017. }
  12018. }
  12019. else
  12020. {
  12021. isSuccess = ConfigurationStatus_Rejected;
  12022. }
  12023. }
  12024. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12025. {
  12026. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12027. {
  12028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12029. isSuccess = ConfigurationStatus_Accepted;
  12030. }
  12031. else
  12032. {
  12033. isSuccess = ConfigurationStatus_Rejected;
  12034. }
  12035. }
  12036. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12037. {
  12038. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12039. {
  12040. check_ascii = value[0];
  12041. if( (check_ascii < 48) || (check_ascii > 57) )
  12042. {
  12043. isSuccess = ConfigurationStatus_Rejected;
  12044. }
  12045. else
  12046. {
  12047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12048. isSuccess = ConfigurationStatus_Accepted;
  12049. }
  12050. }
  12051. else
  12052. {
  12053. isSuccess = ConfigurationStatus_Rejected;
  12054. }
  12055. }
  12056. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12057. {
  12058. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12059. {
  12060. strcpy(str, (const char*)value);
  12061. for(int i = 0; str[i]; i++)
  12062. {
  12063. str[i] = tolower(str[i]);
  12064. }
  12065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12066. isSuccess = ConfigurationStatus_Accepted;
  12067. }
  12068. else
  12069. {
  12070. isSuccess = ConfigurationStatus_Rejected;
  12071. }
  12072. }
  12073. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12074. {
  12075. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12076. {
  12077. check_ascii = value[0];
  12078. if( (check_ascii < 48) || (check_ascii > 57) )
  12079. {
  12080. isSuccess = ConfigurationStatus_Rejected;
  12081. }
  12082. else
  12083. {
  12084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12085. isSuccess = ConfigurationStatus_Accepted;
  12086. }
  12087. }
  12088. else
  12089. {
  12090. isSuccess = ConfigurationStatus_Rejected;
  12091. }
  12092. }
  12093. return isSuccess;
  12094. }
  12095. int updateSetting(char *key, char *value)
  12096. {
  12097. mtrace();
  12098. int isSuccess = FALSE;
  12099. char string[1000]={0}, buffer[1000]={0};
  12100. char strtemp[50]={0};
  12101. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12102. int pos, c = 0;
  12103. char *loc;
  12104. int pos1=0;
  12105. FILE *f = fopen("/var/www/settings1", "r");
  12106. if(f == NULL)
  12107. {
  12108. #ifdef Debug
  12109. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12110. #endif
  12111. return isSuccess;
  12112. }
  12113. fseek(f, 0, SEEK_END);
  12114. long fsize = ftell(f);
  12115. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12116. fread(string, 1, fsize, f);
  12117. fclose(f);
  12118. string[fsize] = 0;
  12119. loc = strstr(string, key);
  12120. if(loc != NULL)
  12121. {
  12122. DEBUG_INFO("key exist!\n");
  12123. pos = loc - string-1;
  12124. f = fopen("/var/www/settings1", "w");
  12125. strncpy(buffer, string, pos);
  12126. fprintf(f, "%s", buffer);
  12127. memset(sstr ,0, sizeof(sstr) );
  12128. c = 0;
  12129. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12130. {
  12131. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12132. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12133. c++;
  12134. }
  12135. sstr[c] = '\0';
  12136. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12137. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12138. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12139. memset(buffer ,0, sizeof(buffer) );
  12140. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12141. //printf("buffer=%s",buffer);
  12142. fprintf(f, "%s", buffer);
  12143. fclose(f);
  12144. }
  12145. else
  12146. {
  12147. printf("key not exist!\n");
  12148. f = fopen("/var/www/settings1", "w+");
  12149. fputs(string, f);
  12150. fseek(f, -1, SEEK_CUR);
  12151. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12152. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12153. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12154. fclose(f);
  12155. }
  12156. isSuccess = TRUE;
  12157. return isSuccess;
  12158. }
  12159. int TransactionMessageAttemptsGet(void)
  12160. {
  12161. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12162. }
  12163. int FirstHeartBeatResponse(void)
  12164. {
  12165. return FirstHeartBeat;
  12166. }
  12167. int TransactionMessageRetryIntervalGet(void)
  12168. {
  12169. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12170. }
  12171. #define SA struct sockaddr
  12172. #define MAXBUF 1024
  12173. //static int m_socket_data;
  12174. //static int sockfd;
  12175. int ReadHttpStatus(int sock){
  12176. //char c;
  12177. char buff[1024]="",*ptr=buff+1;
  12178. int bytes_received, status;
  12179. DEBUG_INFO("Begin Response ..\n");
  12180. while((bytes_received = recv(sock, ptr, 1, 0))){
  12181. if(bytes_received==-1){
  12182. perror("ReadHttpStatus");
  12183. exit(1);
  12184. }
  12185. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12186. ptr++;
  12187. }
  12188. *ptr=0;
  12189. ptr=buff+1;
  12190. sscanf(ptr,"%*s %d ", &status);
  12191. DEBUG_INFO("%s\n",ptr);
  12192. DEBUG_INFO("status=%d\n",status);
  12193. DEBUG_INFO("End Response ..\n");
  12194. return (bytes_received>0)?status:0;
  12195. }
  12196. //the only filed that it parsed is 'Content-Length'
  12197. int ParseHeader(int sock){
  12198. //char c;
  12199. char buff[1024]="",*ptr=buff+4;
  12200. int bytes_received;
  12201. DEBUG_INFO("Begin HEADER ..\n");
  12202. while((bytes_received = recv(sock, ptr, 1, 0))){
  12203. if(bytes_received==-1){
  12204. perror("Parse Header");
  12205. exit(1);
  12206. }
  12207. if(
  12208. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12209. (ptr[-1]=='\r') && (*ptr=='\n' )
  12210. ) break;
  12211. ptr++;
  12212. }
  12213. *ptr=0;
  12214. ptr=buff+4;
  12215. //printf("%s",ptr);
  12216. if(bytes_received){
  12217. ptr=strstr(ptr,"Content-Length:");
  12218. if(ptr){
  12219. sscanf(ptr,"%*s %d",&bytes_received);
  12220. }else
  12221. bytes_received=-1; //unknown size
  12222. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12223. }
  12224. DEBUG_INFO("End HEADER ..\n");
  12225. return bytes_received ;
  12226. }
  12227. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12228. {
  12229. char rmFileCmd[100]={0};
  12230. char FilePath[100]={0};
  12231. char ftpbuf[200];
  12232. int systemresult;
  12233. //DEBUG_INFO("filename=%s\n",filename);
  12234. //DEBUG_INFO("url=%s\n",url);
  12235. sprintf(FilePath,"/mnt/%s",filename);
  12236. if((access(FilePath,F_OK))!=-1)
  12237. {
  12238. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12239. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12240. system(rmFileCmd);
  12241. }
  12242. memset(ftpbuf, 0, sizeof(ftpbuf));
  12243. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12244. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12245. systemresult = system(ftpbuf);
  12246. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12247. if(systemresult != 0)
  12248. {
  12249. DEBUG_INFO("http DownLoad error!\n");
  12250. return FALSE;
  12251. }
  12252. return TRUE;
  12253. }
  12254. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12255. {
  12256. char rmFileCmd[100]={0};
  12257. char FilePath[100]={0};
  12258. char ftpbuf[200];
  12259. int systemresult;
  12260. //char temp[100];
  12261. #if 0
  12262. struct hostent* server;
  12263. char *IPbuffer;
  12264. server = gethostbyname(location);
  12265. // To convert an Internet network
  12266. // address into ASCII string
  12267. IPbuffer = inet_ntoa(*((struct in_addr*)
  12268. server->h_addr_list[0]));
  12269. #endif
  12270. sprintf(FilePath,"/mnt/%s",filename);
  12271. if((access(FilePath,F_OK))!=-1)
  12272. {
  12273. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12274. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12275. system(rmFileCmd);
  12276. }
  12277. memset(ftpbuf, 0, sizeof(ftpbuf));
  12278. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12279. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12280. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12281. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12282. systemresult = system(ftpbuf);
  12283. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12284. if(systemresult != 0)
  12285. {
  12286. printf("wget error!\n");
  12287. return FALSE;
  12288. }
  12289. return TRUE;
  12290. }
  12291. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12292. {
  12293. char rmFileCmd[100]={0};
  12294. char FilePath[100]={0};
  12295. char ftpbuf[200];
  12296. char filenametemp[60]={0};
  12297. int systemresult;
  12298. //DEBUG_INFO("filename=%s\n",filename);
  12299. //DEBUG_INFO("url=%s\n",url);
  12300. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12301. if((access(FilePath,F_OK))!=-1)
  12302. {
  12303. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12304. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12305. system(rmFileCmd);
  12306. }
  12307. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12308. if(fp == NULL)
  12309. {
  12310. DEBUG_INFO("log is NULL\n");
  12311. return FALSE;
  12312. }
  12313. else
  12314. {
  12315. fprintf(fp, "%s\n", url);
  12316. sscanf(filename, "%*2[.]%s", filenametemp);
  12317. fprintf(fp, "%s\n", filenametemp);
  12318. fclose(fp);
  12319. }
  12320. memset(ftpbuf, 0, sizeof(ftpbuf));
  12321. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12322. systemresult = system(ftpbuf);
  12323. DEBUG_INFO("systemresult=%d\n",systemresult);
  12324. if(systemresult != 0)
  12325. {
  12326. DEBUG_INFO("http upload error!\n");
  12327. return FALSE;
  12328. }
  12329. return TRUE;
  12330. }
  12331. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12332. {
  12333. struct hostent* server;
  12334. char *IPbuffer;
  12335. char ftpbuf[200];
  12336. int systemresult;
  12337. // To retrieve host information
  12338. server = gethostbyname(location);
  12339. // To convert an Internet network
  12340. // address into ASCII string
  12341. IPbuffer = inet_ntoa(*((struct in_addr*)
  12342. server->h_addr_list[0]));
  12343. memset(ftpbuf, 0, sizeof(ftpbuf));
  12344. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12345. /* format : ftpput -u username -p passwd IP target source*/
  12346. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12347. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12348. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12349. systemresult = system(ftpbuf);
  12350. DEBUG_INFO("systemresult=%d\n",systemresult);
  12351. if(systemresult != 0)
  12352. {
  12353. DEBUG_INFO("ftpput error!\n");
  12354. return FALSE;
  12355. }
  12356. return TRUE;
  12357. }
  12358. int SettingChargingRecord(int target, int transactionId)
  12359. {
  12360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12361. {
  12362. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12363. {
  12364. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12365. {
  12366. addBuff(target, transactionId, 0);
  12367. return TRUE;
  12368. }
  12369. }
  12370. for (int index = 0; index < CCS_QUANTITY; index++)
  12371. {
  12372. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12373. {
  12374. addBuff(target, transactionId, 0);
  12375. return TRUE;
  12376. }
  12377. }
  12378. for (int index = 0; index < GB_QUANTITY; index++)
  12379. {
  12380. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12381. {
  12382. addBuff(target, transactionId, 0);
  12383. return TRUE;
  12384. }
  12385. }
  12386. }
  12387. else
  12388. {
  12389. for (int index = 0; index < AC_QUANTITY; index++)
  12390. {
  12391. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12392. {
  12393. addBuff(target, transactionId, 0);
  12394. return TRUE;
  12395. }
  12396. }
  12397. }
  12398. return FALSE;
  12399. }
  12400. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12401. {
  12402. int isSuccess = FALSE;
  12403. //char *query = NULL;
  12404. sqlite3_stmt *stmt;
  12405. int rc; // return code
  12406. char str[20];
  12407. sprintf(str,"%d",user_id);
  12408. 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 */
  12409. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12410. rc = sqlite3_step(stmt); /* 3 */
  12411. if (rc != SQLITE_DONE) {
  12412. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12413. goto out;
  12414. }
  12415. sqlite3_finalize(stmt);
  12416. // free(query);
  12417. out:
  12418. //----------------------
  12419. // close SQLite database
  12420. //----------------------
  12421. sqlite3_close(db);
  12422. printf("database closed.\n");
  12423. return isSuccess;
  12424. }
  12425. /**
  12426. * Place the contents of the specified file into a memory buffer
  12427. *
  12428. * @param[in] filename The path and name of the file to read
  12429. * @param[out] filebuffer A pointer to the contents in memory
  12430. * @return status 0 success, 1 on failure
  12431. */
  12432. int get_file_contents(const char* filename, char** outbuffer) {
  12433. FILE* file = NULL;
  12434. long filesize;
  12435. const int blocksize = 1;
  12436. size_t readsize;
  12437. char* filebuffer;
  12438. // Open the file
  12439. file = fopen(filename, "r");
  12440. if (NULL == file)
  12441. {
  12442. printf("'%s' not opened\n", filename);
  12443. exit(EXIT_FAILURE);
  12444. }
  12445. // Determine the file size
  12446. fseek(file, 0, SEEK_END);
  12447. filesize = ftell(file);
  12448. rewind (file);
  12449. // Allocate memory for the file contents
  12450. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12451. *outbuffer = filebuffer;
  12452. if (filebuffer == NULL)
  12453. {
  12454. fputs ("malloc out-of-memory", stderr);
  12455. exit(EXIT_FAILURE);
  12456. }
  12457. // Read in the file
  12458. readsize = fread(filebuffer, blocksize, filesize, file);
  12459. if (readsize != filesize)
  12460. {
  12461. fputs ("didn't read file completely",stderr);
  12462. exit(EXIT_FAILURE);
  12463. }
  12464. // Clean exit
  12465. fclose(file);
  12466. return EXIT_SUCCESS;
  12467. }
  12468. static int selectSqlCount = 0;
  12469. static int callback(void *data, int argc, char **argv, char **azColName){
  12470. int i;
  12471. //printf("%s: ", (const char*)data);
  12472. selectSqlCount = argc;
  12473. for(i = 0; i<argc; i++){
  12474. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12475. }
  12476. //printf("\n");
  12477. return 0;
  12478. }
  12479. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12480. //int i;
  12481. //printf("%s:\n", (const char*)data);
  12482. localversion = argv[5] ? atoi(argv[5]) : 0;
  12483. //printf("localversion=%d\n", localversion);
  12484. return 0;
  12485. }
  12486. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12487. //int i;
  12488. //printf("%s:\n", (const char*)data);
  12489. //idTag
  12490. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12491. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12492. //parentIdTag
  12493. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12494. //expir_date
  12495. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12496. //status
  12497. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12498. //version
  12499. idTagQuery.listVersionInt = atoi(argv[5]);
  12500. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12501. return 0;
  12502. }
  12503. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12504. #if 0
  12505. int i;
  12506. //printf("%s:\n", (const char*)data);
  12507. for(i=0; i<argc; i++){
  12508. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12509. }
  12510. //printf("");
  12511. #endif
  12512. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12513. // printf("localversion=%d\n", localversion);
  12514. return 0;
  12515. }
  12516. /** sqlite3_exec的回调。
  12517. *
  12518. * 向控制台打印查询的结果。
  12519. *
  12520. * @param in data 传递给回调函数的数据。
  12521. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12522. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12523. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12524. * @return 状态码。
  12525. */
  12526. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12527. {
  12528. for (int i = 0; i < n_columns; i++)
  12529. {
  12530. DEBUG_INFO("%s/t", col_values[i]);
  12531. }
  12532. DEBUG_INFO("/n");
  12533. return 0;
  12534. }
  12535. void OCPP_getListVerion()
  12536. {
  12537. int rc = 0;
  12538. // const char* data = "Callback function called";
  12539. char sql[100];
  12540. char zErrMsg[100];
  12541. memset(sql, 0, 100);
  12542. memset(zErrMsg, 0, 100);
  12543. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12544. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12545. /* Execute SQL statement */
  12546. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12547. DEBUG_INFO("rc=%d\n",rc);
  12548. if( rc != SQLITE_OK ){
  12549. DEBUG_INFO("SQL error: %s", zErrMsg);
  12550. //sqlite3_free(zErrMsg);
  12551. }
  12552. }
  12553. void OCPP_getIdTag(char idTag[])
  12554. {
  12555. int rc = 0;
  12556. // const char* data = "Callback function called";
  12557. char sql[100];
  12558. char zErrMsg[100];
  12559. memset(sql, 0, 100);
  12560. memset(zErrMsg, 0, 100);
  12561. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12562. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12563. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12564. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12565. /* Execute SQL statement */
  12566. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12567. if( rc != SQLITE_OK ){
  12568. DEBUG_INFO("SQL error: %s", zErrMsg);
  12569. //sqlite3_free(zErrMsg);
  12570. }
  12571. //return ver;
  12572. }
  12573. void OCPP_get_TableAuthlocalAllData(void)
  12574. {
  12575. int rc = 0;
  12576. // const char* data = "Callback function called";
  12577. char sql[100];
  12578. char zErrMsg[100];
  12579. memset(sql, 0, 100);
  12580. memset(zErrMsg, 0, 100);
  12581. sprintf(sql,"select * from ocpp_auth_local ");
  12582. /* Execute SQL statement */
  12583. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12584. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12585. if( rc != SQLITE_OK ){
  12586. DEBUG_INFO("SQL error: %s", zErrMsg);
  12587. //sqlite3_free(zErrMsg);
  12588. }
  12589. //return ver;
  12590. }
  12591. int OCPP_cleanLocalList()
  12592. {
  12593. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12594. char *errMsg = 0;
  12595. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12596. if (SQLITE_OK != rc)
  12597. {
  12598. DEBUG_INFO("%s\n",errMsg);
  12599. return FALSE;
  12600. }
  12601. else
  12602. {
  12603. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12604. }
  12605. return TRUE;
  12606. }
  12607. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12608. {
  12609. int isSuccess = FALSE;
  12610. int ret = 0;
  12611. //const char* data = "Callback function called";
  12612. char sql[300];
  12613. char zErrMsg[200];
  12614. memset(sql, 0, 300);
  12615. memset(zErrMsg, 0, 200);
  12616. 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);
  12617. //* Execute SQL statement */
  12618. //zErrMsg = 0;
  12619. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12620. if( ret != SQLITE_OK ){
  12621. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12622. // free(zErrMsg);
  12623. // free(sql);
  12624. return isSuccess;
  12625. }
  12626. memset(sql, 0, 300);
  12627. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12628. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12629. if( ret != SQLITE_OK ){
  12630. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12631. // free(zErrMsg);
  12632. // free(sql);
  12633. return isSuccess;
  12634. }
  12635. // DEBUG_INFO("successfully Insert records created\n");
  12636. isSuccess = TRUE;
  12637. return isSuccess;
  12638. }
  12639. void OCPP_deleteIdTag(char idTag[])
  12640. {
  12641. //int ver = 0;
  12642. //int isSuccess = FALSE;
  12643. int rc = 0;
  12644. char sql[100];
  12645. char zErrMsg[100];
  12646. memset(sql, 0, 100);
  12647. memset(zErrMsg, 0, 100);
  12648. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12649. //* Execute SQL statement */
  12650. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12651. if( rc != SQLITE_OK ){
  12652. DEBUG_INFO("SQL error: %s", zErrMsg);
  12653. //sqlite3_free(zErrMsg);
  12654. }
  12655. }
  12656. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12657. {
  12658. int isSuccess = FALSE;
  12659. int ret = 0;
  12660. const char* data = "Callback function called";
  12661. char sql[200];
  12662. char zErrMsg[100];
  12663. memset(sql, 0, 200);
  12664. memset(zErrMsg, 0, 100);
  12665. //* selectFromTable */
  12666. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12667. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12668. //* Execute SQL statement */
  12669. selectSqlCount = 0;
  12670. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12671. if( ret != SQLITE_OK ){
  12672. printf("Error SQL: %s\n", zErrMsg);
  12673. }
  12674. printf("successfully select operation done\n");
  12675. memset(sql, 0, 200);
  12676. memset(zErrMsg, 0, 100);
  12677. if(selectSqlCount == 0)
  12678. {
  12679. //Insert
  12680. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12681. 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);
  12682. DEBUG_INFO("sql:%s\n", sql);
  12683. //* Execute SQL statement */
  12684. //zErrMsg = 0;
  12685. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12686. if( ret != SQLITE_OK ){
  12687. printf("SQL error: %s\n", zErrMsg);
  12688. return isSuccess;
  12689. }
  12690. DEBUG_INFO("successfully Insert records created\n");
  12691. isSuccess = TRUE;
  12692. }
  12693. else
  12694. {
  12695. //Update
  12696. //* Create merged SQL statement */
  12697. 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);
  12698. /* Execute SQL statement */
  12699. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12700. if( ret != SQLITE_OK ){
  12701. printf("SQL error: %s\n", zErrMsg);
  12702. //sqlite3_free(zErrMsg);
  12703. //sqlite3_free(sql);
  12704. return isSuccess;
  12705. }
  12706. DEBUG_INFO("Successfully operation done \n");
  12707. isSuccess = TRUE;
  12708. }
  12709. return isSuccess;
  12710. }
  12711. int GetOcppServerURL()
  12712. {
  12713. int result = FALSE;
  12714. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12715. memset(OcppHost, 0, sizeof(OcppHost));
  12716. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12717. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12718. {
  12719. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12720. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12721. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12722. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12723. result = TRUE;
  12724. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12725. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12726. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12727. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12728. goto End;
  12729. }
  12730. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12731. {
  12732. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12733. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12734. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12735. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12736. result = TRUE;
  12737. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12738. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12739. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12740. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12741. goto End;
  12742. }
  12743. else
  12744. {
  12745. strcpy(OcppHost,"");
  12746. }
  12747. End:
  12748. return result;
  12749. }
  12750. int GetOcppPath()
  12751. {
  12752. int result = FALSE;
  12753. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12754. {
  12755. if(OcppTempPath == NULL)
  12756. {
  12757. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12758. }
  12759. else
  12760. {
  12761. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12762. }
  12763. result = TRUE;
  12764. goto End;
  12765. }
  12766. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12767. {
  12768. if(OcppTempPath == NULL)
  12769. {
  12770. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12771. }
  12772. else
  12773. {
  12774. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12775. }
  12776. result = TRUE;
  12777. goto End;
  12778. }
  12779. else
  12780. {
  12781. strcpy(OcppPath,"");
  12782. }
  12783. End:
  12784. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12785. return result;
  12786. }
  12787. int GetOcppPort()
  12788. {
  12789. return OcppPort;
  12790. }
  12791. int GetOcppConnStatus(void)
  12792. {
  12793. return ShmOCPP16Data->OcppConnStatus;
  12794. }
  12795. void SetOcppConnStatus(uint8_t status)
  12796. {
  12797. ShmOCPP16Data->OcppConnStatus = status;
  12798. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12799. if(status == FALSE)
  12800. {
  12801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12802. {
  12803. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12804. }
  12805. else
  12806. {
  12807. SystemInitial = AC_QUANTITY;
  12808. }
  12809. }
  12810. }
  12811. int GetHeartBeatWithNOResponse(void)
  12812. {
  12813. return HeartBeatWithNOResponse;
  12814. }
  12815. void SetHeartBeatWithNOResponse(void)
  12816. {
  12817. HeartBeatWithNOResponse = 0;
  12818. }
  12819. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12820. /*
  12821. src 源字串的首地址(buf的地址)
  12822. separator 指定的分割字元
  12823. dest 接收子字串的陣列
  12824. num 分割後子字串的個數
  12825. */
  12826. char *pNext;
  12827. int count = 0;
  12828. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12829. return;
  12830. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12831. return;
  12832. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12833. while(pNext != NULL) {
  12834. *dest++ = pNext;
  12835. ++count;
  12836. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12837. }
  12838. *num = count;
  12839. }
  12840. int GetTransactionId(int gunindex, unsigned char idTag[])
  12841. {
  12842. char ch;
  12843. FILE *fptr1;
  12844. int temptransactionId;
  12845. char str[100]={0};
  12846. temptransactionId = 0;
  12847. /*------ Read the file ----------------*/
  12848. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12849. ch=fgetc(fptr1);
  12850. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12851. rewind(fptr1);
  12852. if(ch!=EOF)
  12853. {
  12854. // printf("%c",ch);
  12855. while (fgets(str, 100, fptr1) != NULL)
  12856. {
  12857. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12858. if(str[0]=='\0')
  12859. {
  12860. break;
  12861. }
  12862. char *revbuf[8] = {0}; //存放分割後的子字串
  12863. int num = 0;//分割後子字串的個數
  12864. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12865. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12866. {
  12867. temptransactionId = atoi(revbuf[2]);
  12868. break;
  12869. }
  12870. }
  12871. }
  12872. fclose(fptr1);
  12873. /*------- End of reading ---------------*/
  12874. return temptransactionId;
  12875. }
  12876. void SetTransactionIdZero(int transactionId)
  12877. {
  12878. //TransactionId[gunindex] = 0;
  12879. char ch;
  12880. FILE *fptr1, *fptr2;
  12881. int temptransactionId;
  12882. char str[100]={0}, temp[] = "/Storage/OCPP/temp.txt";
  12883. printf("\n\n Delete a specific line from a file :\n");
  12884. printf("-----------------------------------------\n");
  12885. //scanf("%s",fname);
  12886. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12887. if (!fptr1)
  12888. {
  12889. printf(" File not found or unable to open the input file!!\n");
  12890. return ;
  12891. }
  12892. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12893. if (!fptr2)
  12894. {
  12895. printf("Unable to open a temporary file to write!!\n");
  12896. fclose(fptr1);
  12897. return ;
  12898. }
  12899. ch=fgetc(fptr1);
  12900. //printf(" Now the content of the file %s is : \n",fname);
  12901. rewind(fptr1);
  12902. if(ch!=EOF)
  12903. {
  12904. // copy all contents to the temporary file except the specific line
  12905. while (fgets(str, 100, fptr1) != NULL)
  12906. {
  12907. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12908. if(str[0]=='\0')
  12909. {
  12910. break;
  12911. }
  12912. char *revbuf[8] = {0}; //存放分割後的子字串
  12913. int num = 0;//分割後子字串的個數
  12914. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12915. temptransactionId = atoi(revbuf[2]);
  12916. if(transactionId != temptransactionId)
  12917. {
  12918. fprintf(fptr2, "%s", str);
  12919. }
  12920. }
  12921. }
  12922. fclose(fptr1);
  12923. fclose(fptr2);
  12924. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12925. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12926. /*------ Read the file ----------------*/
  12927. }
  12928. int InternetDisconnect(void)
  12929. {
  12930. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12931. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12932. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12933. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12934. }
  12935. void GetChargingProfileRequest(int gunindex)
  12936. {
  12937. mtrace();
  12938. //int connectorIdInt, durationInt;
  12939. //char chargingRateUnitStr[4]={0};
  12940. int tempdurationInt = 0;
  12941. int tempchargingProfileId = 0;
  12942. int tempstackLevel = 0;
  12943. int temptransactionId = 0;
  12944. float tempminChargingRateFloat = 0.0;
  12945. char tempchargingProfilePurposeStr[24]={0};
  12946. char tempchargingProfileKindStr[12]={0};
  12947. char temprecurrencyKindStr[8]={0};
  12948. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12949. char tempvalidToStr[28]={0};
  12950. int tempStartPeriodInt = 0;
  12951. float tempLimitInt = 0.0;//0.1;
  12952. int tempNumberPhasesInt=0;
  12953. char fname[200];
  12954. //char comfirmstr[20];
  12955. float MinChargingRate =0.0;
  12956. double diff_t;
  12957. struct tm tp;
  12958. FILE *fptr1;//, *fptr2;
  12959. int c = 0;
  12960. char * pch;
  12961. char *loc;
  12962. char sstr[200]={ 0 };
  12963. int n_chargingProfile = 0;
  12964. int n_SchedulePeriods = 0;
  12965. char SchedulePeriodList[10][200]={0};
  12966. char sLineWord[1600]={0};
  12967. char word[1000]={0};
  12968. int confirmPeriods = 0;
  12969. struct StructProfile ChargePointMaxProfile;
  12970. struct StructProfile TxDefaultProfile;
  12971. struct StructProfile TxProfile;
  12972. struct StructProfile TxDefaultProfiletemp[2]={0};
  12973. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12974. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12975. struct StructChargingProfile TxProfile_TEMP={0};
  12976. int TxDefaultProfileFileIsNull=FALSE;
  12977. int ChargePointMaxProfileIsNull=FALSE;
  12978. int TxProfileIsNull=FALSE;
  12979. // int CompositeSceduleIndex = 0;
  12980. char ChargePointMaxProfileScheduleStr[30]={0};
  12981. char TxDefaultProfileScheduleStr[30]={0};
  12982. char TxProfileScheduleStr[30]={0};
  12983. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12984. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12985. memset(&TxProfile,0,sizeof(struct StructProfile));
  12986. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  12987. DEBUG_INFO("GetChargingProfileRequest\n");
  12988. //*****************************ChargePointMaxProfile******************************************/
  12989. strcpy(fname, ChargePointMaxProfile_JSON);
  12990. ChargePointMaxProfileIsNull=TRUE;
  12991. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12992. {
  12993. fptr1 = fopen(fname, "r");
  12994. int c;
  12995. c = fgetc(fptr1);
  12996. //DEBUG_INFO("c:%d\n",c);
  12997. rewind(fptr1);
  12998. if(c == EOF)
  12999. {
  13000. DEBUG_INFO("\n End of file reached.");
  13001. ChargePointMaxProfileIsNull=TRUE;
  13002. fclose(fptr1);
  13003. }
  13004. else
  13005. {
  13006. ChargePointMaxProfileIsNull=FALSE;
  13007. while(fscanf(fptr1, "%s", word) != EOF)
  13008. {
  13009. if(strcmp(word, "chargingProfileId") == 0)
  13010. {
  13011. n_chargingProfile = n_chargingProfile + 1;
  13012. }
  13013. }
  13014. rewind(fptr1);
  13015. //search Charging Profile Element
  13016. int i = 0;
  13017. int j = 0;
  13018. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13019. //***********chargingProfileId**************/
  13020. c = 0;
  13021. loc = strstr(sLineWord, "chargingProfileId");
  13022. //DEBUG_INFO("loc=%s\n",loc);
  13023. memset(sstr ,0, sizeof(sstr) );
  13024. if(loc != NULL)
  13025. {
  13026. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13027. {
  13028. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13029. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13030. c++;
  13031. }
  13032. sstr[c] = '\0';
  13033. tempchargingProfileId = atoi(sstr);
  13034. }
  13035. else
  13036. {
  13037. tempchargingProfileId = 0;
  13038. }
  13039. //***********stackLevel**************/
  13040. c = 0;
  13041. loc = strstr(sLineWord, "stackLevel");
  13042. //DEBUG_INFO("loc=%s\n",loc);
  13043. memset(sstr ,0, sizeof(sstr) );
  13044. if(loc != NULL)
  13045. {
  13046. while (loc[2+strlen("stackLevel")+c] != '\"')
  13047. {
  13048. sstr[c] = loc[2+strlen("stackLevel")+c];
  13049. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13050. c++;
  13051. }
  13052. sstr[c] = '\0';
  13053. tempstackLevel = atoi(sstr);
  13054. }
  13055. else
  13056. {
  13057. tempstackLevel = 0;
  13058. }
  13059. //***********chargingProfilePurpose **************/
  13060. c = 0;
  13061. loc = strstr(sLineWord, "chargingProfilePurpose");
  13062. //DEBUG_INFO("loc=%s\n",loc);
  13063. memset(sstr ,0, sizeof(sstr) );
  13064. if(loc != NULL)
  13065. {
  13066. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13067. {
  13068. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13069. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13070. c++;
  13071. }
  13072. sstr[c] = '\0';
  13073. strcpy(tempchargingProfilePurposeStr,sstr);
  13074. }
  13075. else
  13076. {
  13077. strcpy(tempchargingProfilePurposeStr,"");
  13078. }
  13079. //***********chargingProfileKind **************/
  13080. c = 0;
  13081. loc = strstr(sLineWord, "chargingProfileKind");
  13082. //DEBUG_INFO("loc=%s\n",loc);
  13083. memset(sstr ,0, sizeof(sstr) );
  13084. if(loc != NULL)
  13085. {
  13086. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13087. {
  13088. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13089. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13090. c++;
  13091. }
  13092. sstr[c] = '\0';
  13093. strcpy(tempchargingProfileKindStr,sstr);
  13094. }
  13095. else
  13096. {
  13097. strcpy(tempchargingProfileKindStr,"");
  13098. }
  13099. //***********recurrencyKind **************/
  13100. c = 0;
  13101. loc = strstr(sLineWord, "recurrencyKind");
  13102. //DEBUG_INFO("loc=%s\n",loc);
  13103. memset(sstr ,0, sizeof(sstr) );
  13104. if(loc != NULL)
  13105. {
  13106. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13107. {
  13108. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13109. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13110. c++;
  13111. }
  13112. sstr[c] = '\0';
  13113. strcpy(temprecurrencyKindStr,sstr);
  13114. }
  13115. else
  13116. {
  13117. strcpy(temprecurrencyKindStr,"");
  13118. }
  13119. //***********validFrom**************/
  13120. c = 0;
  13121. loc = strstr(sLineWord, "validFrom");
  13122. //DEBUG_INFO("loc=%s\n",loc);
  13123. memset(sstr ,0, sizeof(sstr) );
  13124. if(loc != NULL)
  13125. {
  13126. while (loc[3+strlen("validFrom")+c] != '\"')
  13127. {
  13128. sstr[c] = loc[3+strlen("validFrom")+c];
  13129. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13130. c++;
  13131. }
  13132. sstr[c] = '\0';
  13133. strcpy(tempvalidFromStr,sstr);
  13134. }
  13135. else
  13136. {
  13137. strcpy(tempvalidFromStr,"");
  13138. }
  13139. //***********validTo **************/
  13140. c = 0;
  13141. loc = strstr(sLineWord, "validTo");
  13142. //DEBUG_INFO("loc=%s\n",loc);
  13143. memset(sstr ,0, sizeof(sstr) );
  13144. if(loc != NULL)
  13145. {
  13146. while (loc[3+strlen("validTo")+c] != '\"')
  13147. {
  13148. sstr[c] = loc[3+strlen("validTo")+c];
  13149. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13150. c++;
  13151. }
  13152. sstr[c] = '\0';
  13153. strcpy(tempvalidToStr,sstr);
  13154. }
  13155. else
  13156. {
  13157. strcpy(tempvalidToStr,"");
  13158. }
  13159. //***********validFrom**************/
  13160. c = 0;
  13161. loc = strstr(sLineWord, "validFrom");
  13162. if(loc != NULL)
  13163. {
  13164. memset(sstr ,0, sizeof(sstr) );
  13165. while (loc[3+strlen("validFrom")+c] != '\"')
  13166. {
  13167. sstr[c] = loc[3+strlen("validFrom")+c];
  13168. c++;
  13169. }
  13170. sstr[c] = '\0';
  13171. strcpy(tempvalidFromStr,sstr);
  13172. }
  13173. else
  13174. {
  13175. strcpy(tempvalidFromStr,"");
  13176. }
  13177. //***********validTo **************/
  13178. c = 0;
  13179. loc = strstr(sLineWord, "validTo");
  13180. if(loc != NULL)
  13181. {
  13182. memset(sstr ,0, sizeof(sstr) );
  13183. while (loc[3+strlen("validTo")+c] != '\"')
  13184. {
  13185. sstr[c] = loc[3+strlen("validTo")+c];
  13186. c++;
  13187. }
  13188. sstr[c] = '\0';
  13189. strcpy(tempvalidToStr,sstr);
  13190. }
  13191. else
  13192. {
  13193. strcpy(tempvalidToStr,"");
  13194. }
  13195. //***********duration**************/
  13196. c = 0;
  13197. loc = strstr(sLineWord, "duration");
  13198. if(loc != NULL)
  13199. {
  13200. memset(sstr ,0, sizeof(sstr) );
  13201. while (loc[2+strlen("duration")+c] != ',')
  13202. {
  13203. sstr[c] = loc[2+strlen("duration")+c];
  13204. c++;
  13205. }
  13206. sstr[c] = '\0';
  13207. tempdurationInt = atoi(sstr);
  13208. }
  13209. else
  13210. {
  13211. tempdurationInt = 0;
  13212. }
  13213. //**********startSchedule**********/
  13214. c = 0;
  13215. loc = strstr(sLineWord, "startSchedule");
  13216. memset(sstr ,0, sizeof(sstr) );
  13217. while (loc[3+strlen("startSchedule")+c] != '\"')
  13218. {
  13219. sstr[c] = loc[3+strlen("startSchedule")+c];
  13220. c++;
  13221. }
  13222. sstr[c] = '\0';
  13223. strcpy(tempstartScheduleStr, sstr);
  13224. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  13225. //**********chargingRateUnit**********/
  13226. c = 0;
  13227. loc = strstr(sLineWord, "chargingRateUnit");
  13228. memset(sstr ,0, sizeof(sstr) );
  13229. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13230. {
  13231. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13232. c++;
  13233. }
  13234. sstr[c] = '\0';
  13235. strcpy(tempchargingRateUnitStr, sstr);
  13236. //**********minChargingRate*******/
  13237. c = 0;
  13238. loc = strstr(sLineWord, "minChargingRate");
  13239. if(loc != NULL)
  13240. {
  13241. memset(sstr ,0, sizeof(sstr) );
  13242. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13243. {
  13244. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13245. c++;
  13246. }
  13247. sstr[c] = '\0';
  13248. tempminChargingRateFloat = atof(sstr);
  13249. }
  13250. else
  13251. {
  13252. tempminChargingRateFloat = 0.0;
  13253. }
  13254. //
  13255. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13256. tp.tm_isdst = -1;
  13257. time_t utc = mktime(&tp);
  13258. time_t t = time(NULL);
  13259. diff_t = difftime(t, utc);
  13260. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13261. //parsing strings to words
  13262. i = 0;
  13263. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13264. loc = loc+3+strlen("chargingSchedulePeriod");
  13265. pch = strtok(loc ,"{");
  13266. while (pch != NULL)
  13267. {
  13268. strcpy(SchedulePeriodList[i], pch);
  13269. pch = strtok (NULL, "{");
  13270. i = i + 1;
  13271. }
  13272. n_SchedulePeriods = i;
  13273. for(int i=0;i<n_SchedulePeriods;i++)
  13274. {
  13275. //*************startPeriod****************/
  13276. c = 0;
  13277. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13278. memset(sstr ,0, sizeof(sstr) );
  13279. while (loc[strlen("startPeriod")+2+c] != ',')
  13280. {
  13281. sstr[c] = loc[strlen("startPeriod")+2+c];
  13282. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13283. c++;
  13284. }
  13285. sstr[c] = '\0';
  13286. tempStartPeriodInt = atoi(sstr);
  13287. //*************limit****************/
  13288. c = 0;
  13289. loc = strstr(SchedulePeriodList[i], "limit");
  13290. memset(sstr ,0, sizeof(sstr) );
  13291. while (loc[strlen("limit")+2+c] != ',')
  13292. {
  13293. sstr[c] = loc[strlen("limit")+2+c];
  13294. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13295. c++;
  13296. }
  13297. sstr[c] = '\0';
  13298. tempLimitInt = atof(sstr);
  13299. //*************numberPhases****************/
  13300. c = 0;
  13301. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13302. memset(sstr ,0, sizeof(sstr) );
  13303. while (loc[strlen("numberPhases")+2+c] != '}')
  13304. {
  13305. sstr[c] = loc[strlen("numberPhases")+2+c];
  13306. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13307. c++;
  13308. }
  13309. sstr[c] = '\0';
  13310. tempNumberPhasesInt = atoi(sstr);
  13311. if(j == 0)
  13312. {
  13313. ChargePointMaxProfile.Duration = tempdurationInt;
  13314. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13315. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13316. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13317. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13318. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13319. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13320. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13321. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13322. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13323. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13324. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13325. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13326. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13327. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13328. }
  13329. }
  13330. if(MinChargingRate < tempminChargingRateFloat)
  13331. {
  13332. MinChargingRate = tempminChargingRateFloat;
  13333. }
  13334. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13335. if(confirmPeriods < n_SchedulePeriods)
  13336. {
  13337. confirmPeriods = n_SchedulePeriods;
  13338. }
  13339. j = j + 1;
  13340. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13341. fclose(fptr1);
  13342. }// end else
  13343. }// the end of access file ChargePointMaxProfile
  13344. //****************************TxDefaultProfile************************************************/
  13345. #if 0
  13346. switch(gunindex + 1)
  13347. {
  13348. case 0:
  13349. strcpy(fname, TxDefaultProfile_0_JSON );
  13350. break;
  13351. case 1:
  13352. strcpy(fname, TxDefaultProfile_1_JSON );
  13353. break;
  13354. case 2:
  13355. strcpy(fname, TxDefaultProfile_2_JSON );
  13356. break;
  13357. default:
  13358. strcpy(fname, TxDefaultProfile_1_JSON );
  13359. break;
  13360. }
  13361. #endif
  13362. memset(fname, 0, sizeof fname);
  13363. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13364. TxDefaultProfileFileIsNull=TRUE;
  13365. if((access(fname,F_OK))!=-1)
  13366. {
  13367. fptr1 = fopen(fname, "r");
  13368. c = 0;
  13369. c = fgetc(fptr1);
  13370. //DEBUG_INFO("c:%d\n",c);
  13371. rewind(fptr1);
  13372. if(c == EOF)
  13373. {
  13374. DEBUG_INFO("\n End of file reached.");
  13375. TxDefaultProfileFileIsNull=TRUE;
  13376. fclose(fptr1);
  13377. }
  13378. else
  13379. {
  13380. TxDefaultProfileFileIsNull=FALSE;
  13381. while(fscanf(fptr1, "%s", word) != EOF)
  13382. {
  13383. if(strcmp(word, "chargingProfileId") == 0)
  13384. {
  13385. n_chargingProfile = n_chargingProfile + 1;
  13386. }
  13387. }
  13388. rewind(fptr1);
  13389. //search Charging Profile Element
  13390. int i = 0;
  13391. int j = 0;
  13392. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  13393. {
  13394. #if 0
  13395. //***********connectorId****************/
  13396. c = 0;
  13397. loc = strstr(sLineWord, "connectorId");
  13398. memset(sstr ,0, sizeof(sstr) );
  13399. while (loc[strlen("connectorId")+2+c] != ',')
  13400. {
  13401. sstr[c] = loc[strlen("connectorId")+2+c];
  13402. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13403. c++;
  13404. }
  13405. sstr[c] = '\0';
  13406. tempconnectorIdInt = atoi(sstr);
  13407. #endif
  13408. //***********chargingProfileId**************/
  13409. c = 0;
  13410. loc = strstr(sLineWord, "chargingProfileId");
  13411. //DEBUG_INFO("loc=%s\n",loc);
  13412. memset(sstr ,0, sizeof(sstr) );
  13413. if(loc != NULL)
  13414. {
  13415. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13416. {
  13417. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13418. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13419. c++;
  13420. }
  13421. sstr[c] = '\0';
  13422. tempchargingProfileId = atoi(sstr);
  13423. }
  13424. else
  13425. {
  13426. tempchargingProfileId = 0;
  13427. }
  13428. //***********stackLevel**************/
  13429. c = 0;
  13430. loc = strstr(sLineWord, "stackLevel");
  13431. //DEBUG_INFO("loc=%s\n",loc);
  13432. memset(sstr ,0, sizeof(sstr) );
  13433. if(loc != NULL)
  13434. {
  13435. while (loc[2+strlen("stackLevel")+c] != '\"')
  13436. {
  13437. sstr[c] = loc[2+strlen("stackLevel")+c];
  13438. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13439. c++;
  13440. }
  13441. sstr[c] = '\0';
  13442. tempstackLevel = atoi(sstr);
  13443. }
  13444. else
  13445. {
  13446. tempstackLevel = 0;
  13447. }
  13448. //***********chargingProfilePurpose **************/
  13449. c = 0;
  13450. loc = strstr(sLineWord, "chargingProfilePurpose");
  13451. //DEBUG_INFO("loc=%s\n",loc);
  13452. memset(sstr ,0, sizeof(sstr) );
  13453. if(loc != NULL)
  13454. {
  13455. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13456. {
  13457. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13458. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13459. c++;
  13460. }
  13461. sstr[c] = '\0';
  13462. strcpy(tempchargingProfilePurposeStr,sstr);
  13463. }
  13464. else
  13465. {
  13466. strcpy(tempchargingProfilePurposeStr,"");
  13467. }
  13468. //***********chargingProfileKind **************/
  13469. c = 0;
  13470. loc = strstr(sLineWord, "chargingProfileKind");
  13471. //DEBUG_INFO("loc=%s\n",loc);
  13472. memset(sstr ,0, sizeof(sstr) );
  13473. if(loc != NULL)
  13474. {
  13475. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13476. {
  13477. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13478. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13479. c++;
  13480. }
  13481. sstr[c] = '\0';
  13482. strcpy(tempchargingProfileKindStr,sstr);
  13483. }
  13484. else
  13485. {
  13486. strcpy(tempchargingProfileKindStr,"");
  13487. }
  13488. //***********recurrencyKind **************/
  13489. c = 0;
  13490. loc = strstr(sLineWord, "recurrencyKind");
  13491. //DEBUG_INFO("loc=%s\n",loc);
  13492. memset(sstr ,0, sizeof(sstr) );
  13493. if(loc != NULL)
  13494. {
  13495. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13496. {
  13497. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13498. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13499. c++;
  13500. }
  13501. sstr[c] = '\0';
  13502. strcpy(temprecurrencyKindStr,sstr);
  13503. }
  13504. else
  13505. {
  13506. strcpy(temprecurrencyKindStr,"");
  13507. }
  13508. //***********validFrom**************/
  13509. c = 0;
  13510. loc = strstr(sLineWord, "validFrom");
  13511. if(loc != NULL)
  13512. {
  13513. memset(sstr ,0, sizeof(sstr) );
  13514. while (loc[3+strlen("validFrom")+c] != '\"')
  13515. {
  13516. sstr[c] = loc[3+strlen("validFrom")+c];
  13517. c++;
  13518. }
  13519. sstr[c] = '\0';
  13520. strcpy(tempvalidFromStr,sstr);
  13521. }
  13522. else
  13523. {
  13524. strcpy(tempvalidFromStr,"");
  13525. }
  13526. //***********validTo **************/
  13527. c = 0;
  13528. loc = strstr(sLineWord, "validTo");
  13529. if(loc != NULL)
  13530. {
  13531. memset(sstr ,0, sizeof(sstr) );
  13532. while (loc[3+strlen("validTo")+c] != '\"')
  13533. {
  13534. sstr[c] = loc[3+strlen("validTo")+c];
  13535. c++;
  13536. }
  13537. sstr[c] = '\0';
  13538. strcpy(tempvalidToStr,sstr);
  13539. }
  13540. else
  13541. {
  13542. strcpy(tempvalidToStr,"");
  13543. }
  13544. //***********duration**************/
  13545. c = 0;
  13546. loc = strstr(sLineWord, "duration");
  13547. if(loc != NULL)
  13548. {
  13549. memset(sstr ,0, sizeof(sstr) );
  13550. while (loc[2+strlen("duration")+c] != ',')
  13551. {
  13552. sstr[c] = loc[2+strlen("duration")+c];
  13553. c++;
  13554. }
  13555. sstr[c] = '\0';
  13556. tempdurationInt = atoi(sstr);
  13557. }
  13558. else
  13559. {
  13560. tempdurationInt = 0;
  13561. }
  13562. //**********startSchedule**********/
  13563. c = 0;
  13564. loc = strstr(sLineWord, "startSchedule");
  13565. memset(sstr ,0, sizeof(sstr) );
  13566. while (loc[3+strlen("startSchedule")+c] != '\"')
  13567. {
  13568. sstr[c] = loc[3+strlen("startSchedule")+c];
  13569. c++;
  13570. }
  13571. sstr[c] = '\0';
  13572. strcpy(tempstartScheduleStr, sstr);
  13573. strcpy(TxDefaultProfileScheduleStr, sstr);
  13574. //**********chargingRateUnit**********/
  13575. c = 0;
  13576. loc = strstr(sLineWord, "chargingRateUnit");
  13577. memset(sstr ,0, sizeof(sstr) );
  13578. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13579. {
  13580. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13581. c++;
  13582. }
  13583. sstr[c] = '\0';
  13584. strcpy(tempchargingRateUnitStr, sstr);
  13585. //**********minChargingRate*******/
  13586. c = 0;
  13587. loc = strstr(sLineWord, "minChargingRate");
  13588. if(loc != NULL)
  13589. {
  13590. memset(sstr ,0, sizeof(sstr) );
  13591. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13592. {
  13593. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13594. c++;
  13595. }
  13596. sstr[c] = '\0';
  13597. tempminChargingRateFloat = atof(sstr);
  13598. }
  13599. else
  13600. {
  13601. tempminChargingRateFloat = 0.0;
  13602. }
  13603. //
  13604. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13605. tp.tm_isdst = -1;
  13606. time_t utc = mktime(&tp);
  13607. time_t t = time(NULL);
  13608. diff_t = difftime(t, utc);
  13609. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13610. //parsing strings to words
  13611. i = 0;
  13612. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13613. loc = loc+3+strlen("chargingSchedulePeriod");
  13614. pch = strtok(loc ,"{");
  13615. while (pch != NULL)
  13616. {
  13617. strcpy(SchedulePeriodList[i], pch);
  13618. pch = strtok (NULL, "{");
  13619. i = i + 1;
  13620. }
  13621. n_SchedulePeriods = i;
  13622. for(int i=0;i<n_SchedulePeriods;i++)
  13623. {
  13624. //*************startPeriod****************/
  13625. c = 0;
  13626. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13627. memset(sstr ,0, sizeof(sstr) );
  13628. while (loc[strlen("startPeriod")+2+c] != ',')
  13629. {
  13630. sstr[c] = loc[strlen("startPeriod")+2+c];
  13631. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13632. c++;
  13633. }
  13634. sstr[c] = '\0';
  13635. tempStartPeriodInt = atoi(sstr);
  13636. //*************limit****************/
  13637. c = 0;
  13638. loc = strstr(SchedulePeriodList[i], "limit");
  13639. memset(sstr ,0, sizeof(sstr) );
  13640. while (loc[strlen("limit")+2+c] != ',')
  13641. {
  13642. sstr[c] = loc[strlen("limit")+2+c];
  13643. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13644. c++;
  13645. }
  13646. sstr[c] = '\0';
  13647. tempLimitInt = atof(sstr);
  13648. //*************numberPhases****************/
  13649. c = 0;
  13650. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13651. memset(sstr ,0, sizeof(sstr) );
  13652. while (loc[strlen("numberPhases")+2+c] != '}')
  13653. {
  13654. sstr[c] = loc[strlen("numberPhases")+2+c];
  13655. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13656. c++;
  13657. }
  13658. sstr[c] = '\0';
  13659. tempNumberPhasesInt = atoi(sstr);
  13660. if(j == 0)
  13661. {
  13662. TxDefaultProfile.Duration = tempdurationInt;
  13663. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13664. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13665. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13666. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13667. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13668. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13669. TxDefaultProfile_TEMP.TransactionId = 0;
  13670. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13671. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13672. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13673. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13674. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13675. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13676. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13677. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13678. }
  13679. else
  13680. {
  13681. //other stack level charging Profile
  13682. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13683. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13684. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13685. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13686. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13687. }
  13688. }
  13689. if(MinChargingRate < tempminChargingRateFloat)
  13690. {
  13691. MinChargingRate = tempminChargingRateFloat;
  13692. }
  13693. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13694. if(confirmPeriods < n_SchedulePeriods)
  13695. confirmPeriods = n_SchedulePeriods;
  13696. j = j + 1;
  13697. }
  13698. fclose(fptr1);
  13699. //Stacking Charging Profiles
  13700. for(int l=0; l <(j-1) ;l++)
  13701. {
  13702. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13703. {
  13704. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13705. {
  13706. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13707. {
  13708. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13709. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13710. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13711. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13712. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13713. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13714. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13715. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13716. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13717. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13718. }
  13719. else
  13720. {
  13721. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13722. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13723. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13724. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13725. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13726. }
  13727. }
  13728. }
  13729. }//end of Stacking Charging Profiles
  13730. }// end else
  13731. }// the end of ACCESS TxDefaultProfile
  13732. //****************************TxProfile************************************************/
  13733. #if 0
  13734. switch(gunindex + 1)
  13735. {
  13736. case 0:
  13737. break;
  13738. case 1:
  13739. strcpy(fname, TxProfile_1_JSON );
  13740. break;
  13741. case 2:
  13742. strcpy(fname, TxProfile_2_JSON );
  13743. break;
  13744. default:
  13745. strcpy(fname, TxProfile_1_JSON );
  13746. break;
  13747. }
  13748. #endif
  13749. memset(fname, 0, sizeof fname);
  13750. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  13751. TxProfileIsNull=TRUE;
  13752. if((access(fname,F_OK))!=-1)
  13753. {
  13754. fptr1 = fopen(fname, "r");
  13755. c = 0;
  13756. c = fgetc(fptr1);
  13757. //DEBUG_INFO("c:%d\n",c);
  13758. rewind(fptr1);
  13759. if(c == EOF)
  13760. {
  13761. DEBUG_INFO("\n End of file reached.");
  13762. TxProfileIsNull=TRUE;
  13763. fclose(fptr1);
  13764. }
  13765. else
  13766. {
  13767. TxProfileIsNull=FALSE;
  13768. while(fscanf(fptr1, "%s", word) != EOF)
  13769. {
  13770. if(strcmp(word, "chargingProfileId") == 0)
  13771. {
  13772. n_chargingProfile = n_chargingProfile + 1;
  13773. }
  13774. }
  13775. rewind(fptr1);
  13776. //search Charging Profile Element
  13777. int i= 0;
  13778. int j= 0;
  13779. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13780. #if 0
  13781. /***********connectorId****************/
  13782. c = 0;
  13783. loc = strstr(sLineWord, "connectorId");
  13784. memset(sstr ,0, sizeof(sstr) );
  13785. while (loc[strlen("connectorId")+2+c] != ',')
  13786. {
  13787. sstr[c] = loc[strlen("connectorId")+2+c];
  13788. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13789. c++;
  13790. }
  13791. sstr[c] = '\0';
  13792. tempconnectorIdInt = atoi(sstr);
  13793. #endif
  13794. //***********chargingProfileId**************/
  13795. c = 0;
  13796. loc = strstr(sLineWord, "chargingProfileId");
  13797. memset(sstr ,0, sizeof(sstr) );
  13798. if(loc != NULL)
  13799. {
  13800. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13801. {
  13802. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13803. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13804. c++;
  13805. }
  13806. sstr[c] = '\0';
  13807. tempchargingProfileId = atoi(sstr);
  13808. }
  13809. else
  13810. {
  13811. tempchargingProfileId = 0;
  13812. }
  13813. //***********transactionId **************/
  13814. c = 0;
  13815. loc = strstr(sLineWord, "transactionId");
  13816. //DEBUG_INFO("loc=%s\n",loc);
  13817. memset(sstr ,0, sizeof(sstr) );
  13818. if(loc != NULL)
  13819. {
  13820. while (loc[2+strlen("transactionId")+c] != '\"')
  13821. {
  13822. sstr[c] = loc[2+strlen("transactionId")+c];
  13823. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13824. c++;
  13825. }
  13826. sstr[c] = '\0';
  13827. temptransactionId = atoi(sstr);
  13828. }
  13829. else
  13830. {
  13831. temptransactionId = 0;
  13832. }
  13833. //***********stackLevel**************/
  13834. c = 0;
  13835. loc = strstr(sLineWord, "stackLevel");
  13836. //DEBUG_INFO("loc=%s\n",loc);
  13837. memset(sstr ,0, sizeof(sstr) );
  13838. if(loc != NULL)
  13839. {
  13840. while (loc[2+strlen("stackLevel")+c] != '\"')
  13841. {
  13842. sstr[c] = loc[2+strlen("stackLevel")+c];
  13843. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13844. c++;
  13845. }
  13846. sstr[c] = '\0';
  13847. tempstackLevel = atoi(sstr);
  13848. }
  13849. else
  13850. {
  13851. tempstackLevel = 0;
  13852. }
  13853. //***********chargingProfilePurpose **************/
  13854. c = 0;
  13855. loc = strstr(sLineWord, "chargingProfilePurpose");
  13856. //DEBUG_INFO("loc=%s\n",loc);
  13857. memset(sstr ,0, sizeof(sstr) );
  13858. if(loc != NULL)
  13859. {
  13860. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13861. {
  13862. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13863. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13864. c++;
  13865. }
  13866. sstr[c] = '\0';
  13867. strcpy(tempchargingProfilePurposeStr,sstr);
  13868. }
  13869. else
  13870. {
  13871. strcpy(tempchargingProfilePurposeStr,"");
  13872. }
  13873. //***********chargingProfileKind **************/
  13874. c = 0;
  13875. loc = strstr(sLineWord, "chargingProfileKind");
  13876. //DEBUG_INFO("loc=%s\n",loc);
  13877. memset(sstr ,0, sizeof(sstr) );
  13878. if(loc != NULL)
  13879. {
  13880. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13881. {
  13882. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13883. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13884. c++;
  13885. }
  13886. sstr[c] = '\0';
  13887. strcpy(tempchargingProfileKindStr,sstr);
  13888. }
  13889. else
  13890. {
  13891. strcpy(tempchargingProfileKindStr,"");
  13892. }
  13893. //***********recurrencyKind **************/
  13894. c = 0;
  13895. loc = strstr(sLineWord, "recurrencyKind");
  13896. //DEBUG_INFO("loc=%s\n",loc);
  13897. memset(sstr ,0, sizeof(sstr) );
  13898. if(loc != NULL)
  13899. {
  13900. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13901. {
  13902. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13903. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13904. c++;
  13905. }
  13906. sstr[c] = '\0';
  13907. strcpy(temprecurrencyKindStr,sstr);
  13908. }
  13909. else
  13910. {
  13911. strcpy(temprecurrencyKindStr,"");
  13912. }
  13913. //***********validFrom**************/
  13914. c = 0;
  13915. loc = strstr(sLineWord, "validFrom");
  13916. if(loc != NULL)
  13917. {
  13918. memset(sstr ,0, sizeof(sstr) );
  13919. while (loc[3+strlen("validFrom")+c] != '\"')
  13920. {
  13921. sstr[c] = loc[3+strlen("validFrom")+c];
  13922. c++;
  13923. }
  13924. sstr[c] = '\0';
  13925. strcpy(tempvalidFromStr,sstr);
  13926. }
  13927. else
  13928. {
  13929. strcpy(tempvalidFromStr,"");
  13930. }
  13931. //***********validTo**************/
  13932. c = 0;
  13933. loc = strstr(sLineWord, "validTo");
  13934. if(loc != NULL)
  13935. {
  13936. memset(sstr ,0, sizeof(sstr) );
  13937. while (loc[3+strlen("validTo")+c] != '\"')
  13938. {
  13939. sstr[c] = loc[3+strlen("validTo")+c];
  13940. c++;
  13941. }
  13942. sstr[c] = '\0';
  13943. strcpy(tempvalidToStr,sstr);
  13944. }
  13945. else
  13946. {
  13947. strcpy(tempvalidToStr,"");
  13948. }
  13949. //***********duration**************/
  13950. c = 0;
  13951. loc = strstr(sLineWord, "duration");
  13952. //DEBUG_INFO("loc=%s\n",loc);
  13953. memset(sstr ,0, sizeof(sstr) );
  13954. if(loc != NULL)
  13955. {
  13956. while (loc[2+strlen("duration")+c] != '\"')
  13957. {
  13958. sstr[c] = loc[2+strlen("duration")+c];
  13959. c++;
  13960. }
  13961. sstr[c] = '\0';
  13962. tempdurationInt = atoi(sstr);
  13963. }
  13964. else
  13965. {
  13966. tempdurationInt = 0;
  13967. }
  13968. //**********startSchedule**********/
  13969. c = 0;
  13970. loc = strstr(sLineWord, "startSchedule");
  13971. memset(sstr ,0, sizeof(sstr) );
  13972. while (loc[3+strlen("startSchedule")+c] != '\"')
  13973. {
  13974. sstr[c] = loc[3+strlen("startSchedule")+c];
  13975. c++;
  13976. }
  13977. sstr[c] = '\0';
  13978. strcpy(tempstartScheduleStr, sstr);
  13979. strcpy(TxProfileScheduleStr, sstr);
  13980. //**********chargingRateUnit**********/
  13981. c = 0;
  13982. loc = strstr(sLineWord, "chargingRateUnit");
  13983. memset(sstr ,0, sizeof(sstr) );
  13984. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13985. {
  13986. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13987. c++;
  13988. }
  13989. sstr[c] = '\0';
  13990. strcpy(tempchargingRateUnitStr, sstr);
  13991. //**********minChargingRate*******/
  13992. c = 0;
  13993. loc = strstr(sLineWord, "minChargingRate");
  13994. if(loc != NULL)
  13995. {
  13996. memset(sstr ,0, sizeof(sstr) );
  13997. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13998. {
  13999. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14000. c++;
  14001. }
  14002. sstr[c] = '\0';
  14003. tempminChargingRateFloat = atof(sstr);
  14004. }
  14005. else
  14006. {
  14007. tempminChargingRateFloat = 0.0;
  14008. }
  14009. //
  14010. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14011. tp.tm_isdst = -1;
  14012. time_t utc = mktime(&tp);
  14013. time_t t = time(NULL);
  14014. diff_t = difftime(t, utc);
  14015. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14016. //parsing strings to words
  14017. i = 0;
  14018. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14019. loc = loc+3+strlen("chargingSchedulePeriod");
  14020. pch = strtok(loc ,"{");
  14021. while (pch != NULL)
  14022. {
  14023. strcpy(SchedulePeriodList[i], pch);
  14024. pch = strtok (NULL, "{");
  14025. i = i + 1;
  14026. }
  14027. n_SchedulePeriods = i;
  14028. for(int i=0;i<n_SchedulePeriods;i++)
  14029. {
  14030. //*************startPeriod****************/
  14031. c = 0;
  14032. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14033. memset(sstr ,0, sizeof(sstr) );
  14034. while (loc[strlen("startPeriod")+2+c] != ',')
  14035. {
  14036. sstr[c] = loc[strlen("startPeriod")+2+c];
  14037. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14038. c++;
  14039. }
  14040. sstr[c] = '\0';
  14041. tempStartPeriodInt = atoi(sstr);
  14042. //*************limit****************/
  14043. c = 0;
  14044. loc = strstr(SchedulePeriodList[i], "limit");
  14045. memset(sstr ,0, sizeof(sstr) );
  14046. while (loc[strlen("limit")+2+c] != ',')
  14047. {
  14048. sstr[c] = loc[strlen("limit")+2+c];
  14049. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14050. c++;
  14051. }
  14052. sstr[c] = '\0';
  14053. tempLimitInt = atof(sstr);
  14054. //*************numberPhases****************/
  14055. c = 0;
  14056. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14057. memset(sstr ,0, sizeof(sstr) );
  14058. while (loc[strlen("numberPhases")+2+c] != '}')
  14059. {
  14060. sstr[c] = loc[strlen("numberPhases")+2+c];
  14061. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14062. c++;
  14063. }
  14064. sstr[c] = '\0';
  14065. tempNumberPhasesInt = atoi(sstr);
  14066. //TxProfile.Duration = durationInt;
  14067. TxProfile.TotalPeriod = n_SchedulePeriods;
  14068. TxProfile.Period[i].Limit = tempLimitInt;
  14069. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14070. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14071. }
  14072. if(MinChargingRate < tempminChargingRateFloat)
  14073. {
  14074. MinChargingRate = tempminChargingRateFloat;
  14075. }
  14076. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14077. if(confirmPeriods < n_SchedulePeriods)
  14078. confirmPeriods = n_SchedulePeriods;
  14079. if(j == 0)
  14080. {
  14081. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14082. TxProfile_TEMP.StackLevel = tempstackLevel;
  14083. TxProfile_TEMP.TransactionId = 0;
  14084. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14085. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14086. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14087. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14088. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14089. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14090. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14091. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14092. }
  14093. }
  14094. fclose(fptr1);
  14095. }
  14096. }// the end of ACCESS TxProfile
  14097. //-----------------------------------------------CompositeSchedule--------------------------//
  14098. int period=0;
  14099. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14100. {
  14101. //TxProfile
  14102. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14103. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14104. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14105. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14106. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14107. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14108. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14109. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14110. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14111. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14112. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14113. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14114. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14115. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14116. {
  14117. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14118. {
  14119. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14120. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14121. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14122. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14123. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14124. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14125. period = period + 1;
  14126. }
  14127. else
  14128. {
  14129. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14130. {
  14131. }
  14132. else
  14133. {
  14134. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14135. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14136. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14137. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14138. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14139. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14140. period = period + 1;
  14141. }
  14142. }
  14143. }
  14144. struct tm tp;
  14145. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14146. tp.tm_isdst = -1;
  14147. time_t utc = mktime(&tp);
  14148. time_t t = time(NULL);
  14149. double diff_f = difftime(t, utc);
  14150. int diff_i;// = (int)diff_f;
  14151. int quotient; // = diff_i / 86400;//86400 seconds/day
  14152. if(diff_f >= 0)
  14153. {
  14154. diff_i = (int)diff_f;
  14155. quotient = diff_i / 86400;//86400 seconds/day
  14156. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14157. {
  14158. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  14159. {
  14160. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14161. {
  14162. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14163. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14164. }
  14165. else
  14166. {
  14167. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14168. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14169. }
  14170. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14171. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14172. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14173. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14174. period = period + 1;
  14175. }
  14176. }
  14177. }// end of if(diff_f >= 0)
  14178. }
  14179. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14180. {
  14181. //TxDefaultProfile
  14182. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14183. struct tm tp;
  14184. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14185. tp.tm_isdst = -1;
  14186. time_t utc = mktime(&tp);
  14187. time_t t = time(NULL);
  14188. double diff_f = difftime(t, utc);
  14189. int diff_i;// = (int)diff_f;
  14190. int quotient; // = diff_i / 86400;//86400 seconds/day
  14191. int remainder;
  14192. //---- Define StartSchedule----/
  14193. struct tm *gtime;
  14194. time_t now;
  14195. char buf[28];
  14196. //---Read the current system time---/
  14197. time(&now);
  14198. //---Convert the system time to GMT (now UTC)---/
  14199. gtime = gmtime(&now);
  14200. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14201. if(diff_f >= 0)
  14202. {
  14203. diff_i = (int)diff_f;
  14204. quotient = diff_i / 86400;//86400 seconds/day
  14205. remainder = diff_i % 86400;
  14206. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14207. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14208. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14209. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  14210. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14211. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14212. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14213. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14214. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14215. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14216. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14217. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14218. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14219. {
  14220. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14221. {
  14222. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14223. {
  14224. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14225. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14226. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14227. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14228. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14229. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14230. period = period + 1;
  14231. }
  14232. else
  14233. {
  14234. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14235. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14236. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14237. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14238. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14239. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14240. period = period + 1;
  14241. }
  14242. }
  14243. }
  14244. } // end of diff_f >= 0
  14245. }
  14246. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14247. {
  14248. //TxDefaultProfile
  14249. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14250. struct tm tp;
  14251. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14252. tp.tm_isdst = -1;
  14253. time_t utc = mktime(&tp);
  14254. time_t t = time(NULL);
  14255. double diff_f = difftime(t, utc);
  14256. int diff_i;// = (int)diff_f;
  14257. int quotient; // = diff_i / 86400;//86400 seconds/day
  14258. int remainder;
  14259. //---- Define StartSchedule----/
  14260. struct tm *gtime;
  14261. time_t now;
  14262. char buf[28];
  14263. //---Read the current system time---/
  14264. time(&now);
  14265. //---Convert the system time to GMT (now UTC)---/
  14266. gtime = gmtime(&now);
  14267. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  14268. if(diff_f >= 0)
  14269. {
  14270. diff_i = (int)diff_f;
  14271. quotient = diff_i / 86400;//86400 seconds/day
  14272. remainder = diff_i % 86400;
  14273. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14274. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14275. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14276. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14277. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14278. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14279. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14280. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14281. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14282. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  14283. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14284. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14285. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14286. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  14287. {
  14288. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  14289. {
  14290. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14291. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14292. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  14293. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14294. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14295. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14296. period = period + 1;
  14297. }
  14298. }
  14299. } //end of diff_f >= 0
  14300. }
  14301. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14302. {
  14303. //ChargePointMaxProfile
  14304. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14305. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14306. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14307. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14308. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14309. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14310. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14311. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14312. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14313. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14314. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14315. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14316. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14317. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  14318. {
  14319. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14320. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14321. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14322. period = period + 1;
  14323. }
  14324. }
  14325. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14326. {
  14327. //TxProfile Daily
  14328. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14329. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14330. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14331. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14332. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14333. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14334. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14335. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14336. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14337. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14338. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14339. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14340. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14341. for(int l=0; l< TxProfile.TotalPeriod; l++)
  14342. {
  14343. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  14344. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  14345. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  14346. }
  14347. }
  14348. confirmPeriods = period;
  14349. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14350. 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,"
  14351. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14352. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14353. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14354. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14355. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14356. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14357. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14358. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14359. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14360. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14361. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14362. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14363. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14364. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14365. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14366. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14367. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14368. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14369. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14370. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14371. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14372. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14373. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14374. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14375. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14376. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14377. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14378. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14379. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14380. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14381. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14383. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14384. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14385. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14386. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14387. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14388. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14389. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14390. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14391. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14394. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14395. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14396. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14397. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14398. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14399. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14400. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14401. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14402. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14403. }
  14404. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14405. {
  14406. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14407. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14408. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14409. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14410. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14411. }
  14412. int GetWebSocketPingInterval(void)
  14413. {
  14414. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14415. }
  14416. void LWS_Send(char * str)
  14417. {
  14418. //=====================================================
  14419. // Check InternetConn 0: disconnected, 1: connected
  14420. //====================================================
  14421. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14422. {
  14423. DEBUG_INFO("\n offline now !!!\n");
  14424. return;
  14425. }
  14426. pthread_mutex_lock(&lock);
  14427. memset(SendBuffer,0,SendBufLen);
  14428. sprintf((char *)SendBuffer, "%s", str);
  14429. pthread_mutex_unlock(&lock);
  14430. lws_callback_on_writable(wsi_client);
  14431. lws_service(context, 10000);//timeout_ms
  14432. }