MessageHandler.c 607 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785
  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[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1384. {
  1385. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1386. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1387. {
  1388. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1389. {
  1390. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1391. }
  1392. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1393. {
  1394. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1395. }
  1396. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1397. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1398. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1399. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1400. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1401. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1402. authorizeRetryTimes = 0;
  1403. return result;
  1404. }
  1405. else
  1406. {
  1407. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1408. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1409. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1410. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1411. result = PASS;
  1412. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1413. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1414. authorizeRetryTimes = 0;
  1415. return result;
  1416. }
  1417. }
  1418. //initailize struct Authorize
  1419. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1420. //get data from shared memory
  1421. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1422. random_uuid(guid);
  1423. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1424. LWS_Send(message);
  1425. sprintf(tempdata, "Authorize,%d", gun_index);
  1426. if(hashmap_operation(0, guid, tempdata) == 1)
  1427. {
  1428. result = PASS;
  1429. DEBUG_ERROR("Authorize mapItem pass\n");
  1430. }
  1431. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1432. return result;
  1433. }
  1434. int sendBootNotificationRequest(void)
  1435. {
  1436. mtrace();
  1437. int result = FAIL;
  1438. char message[500]={0}, payload[700]={0};
  1439. char guid[37]={0};
  1440. char tempdata[65]={0};
  1441. int IsGunCharging = FALSE;
  1442. //check Transaction active
  1443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1444. {
  1445. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1446. {
  1447. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1448. {
  1449. IsGunCharging = TRUE;
  1450. }
  1451. }
  1452. for (int index = 0; index < CCS_QUANTITY; index++)
  1453. {
  1454. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1455. {
  1456. IsGunCharging = TRUE;
  1457. }
  1458. }
  1459. for (int index = 0; index < GB_QUANTITY; index++)
  1460. {
  1461. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1462. {
  1463. IsGunCharging = TRUE;
  1464. }
  1465. }
  1466. }
  1467. else
  1468. {
  1469. for (int index = 0; index < AC_QUANTITY; index++)
  1470. {
  1471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1472. {
  1473. IsGunCharging = TRUE;
  1474. }
  1475. }
  1476. }
  1477. if(IsGunCharging == TRUE)
  1478. {
  1479. server_sign = TRUE;
  1480. return result;
  1481. }
  1482. // Fill BootNotification fields
  1483. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1484. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1485. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1486. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1487. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1488. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1489. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1490. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1491. ShmOCPP16Data->ChargeBoxId
  1492. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1493. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1494. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1495. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1496. ,ShmOCPP16Data->BootNotification.CpIccid
  1497. ,ShmOCPP16Data->BootNotification.CpImsi
  1498. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1499. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1500. random_uuid(guid);
  1501. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1502. LWS_Send(message);
  1503. sprintf(tempdata, "BootNotification,0");
  1504. 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*/)
  1505. {
  1506. result = PASS;
  1507. }
  1508. memset(queuedata, 0, sizeof(queuedata));
  1509. strcpy(queuedata,message);
  1510. return result;
  1511. }
  1512. int sendDataTransferRequest(int gun_index)
  1513. {
  1514. mtrace();
  1515. char message[1000]={0};
  1516. char guid[37]={0};
  1517. char tempdata[65]={0};
  1518. int result = FAIL;
  1519. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1520. random_uuid(guid);
  1521. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1522. MESSAGE_TYPE_CALL,
  1523. guid,
  1524. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1525. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1526. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1527. LWS_Send(message);
  1528. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1529. 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*/)
  1530. {
  1531. result = PASS;
  1532. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1533. }
  1534. return result;
  1535. }
  1536. int sendDiagnosticsStatusNotificationRequest(char *status)
  1537. {
  1538. mtrace();
  1539. int result = FAIL;
  1540. char message[110]={0};
  1541. char guid[37]={0};
  1542. char tempdata[65]={0};
  1543. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1544. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1545. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1546. random_uuid(guid);
  1547. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1548. LWS_Send(message);
  1549. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1550. if(hashmap_operation(0, guid, tempdata) == 1)
  1551. {
  1552. result = PASS;
  1553. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1554. }
  1555. //#ifdef SystemLogMessage
  1556. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1557. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1558. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1559. //#endif
  1560. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1561. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1562. //record status
  1563. if(strcmp(status,"Idle")==0)
  1564. {
  1565. DiagnosticsStatusNotificationStatus = 0;
  1566. }
  1567. else if(strcmp(status,"Uploaded")==0)
  1568. {
  1569. DiagnosticsStatusNotificationStatus = 1;
  1570. }
  1571. else if(strcmp(status,"UploadFailed")==0)
  1572. {
  1573. DiagnosticsStatusNotificationStatus = 2;
  1574. }
  1575. else if(strcmp(status,"Uploading")==0)
  1576. {
  1577. DiagnosticsStatusNotificationStatus = 3;
  1578. }
  1579. return result;
  1580. }
  1581. int sendFirmwareStatusNotificationRequest(char *status)
  1582. {
  1583. mtrace();
  1584. int result = FAIL;
  1585. char message[110]={0};
  1586. char guid[37]={0};
  1587. char tempdata[65]={0};
  1588. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1589. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1590. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1591. random_uuid(guid);
  1592. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1593. LWS_Send(message);
  1594. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1595. 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*/)
  1596. {
  1597. result = PASS;
  1598. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1599. }
  1600. //#ifdef SystemLogMessage
  1601. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1602. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1603. //#endif
  1604. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1605. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1606. //record status
  1607. if(strcmp(status,"Downloaded")==0)
  1608. {
  1609. FirmwareStatusNotificationStatus = 0;
  1610. }
  1611. else if(strcmp(status,"DownloadFailed")==0)
  1612. {
  1613. FirmwareStatusNotificationStatus = 1;
  1614. }
  1615. else if(strcmp(status,"Downloading")==0)
  1616. {
  1617. FirmwareStatusNotificationStatus = 2;
  1618. }
  1619. else if(strcmp(status,"Idle")==0)
  1620. {
  1621. FirmwareStatusNotificationStatus = 3;
  1622. }
  1623. else if(strcmp(status,"InstallationFailed")==0)
  1624. {
  1625. FirmwareStatusNotificationStatus = 4;
  1626. }
  1627. else if(strcmp(status,"Installing")==0)
  1628. {
  1629. FirmwareStatusNotificationStatus = 5;
  1630. }
  1631. else if(strcmp(status,"Installed")==0)
  1632. {
  1633. FirmwareStatusNotificationStatus = 6;
  1634. }
  1635. return result;
  1636. }
  1637. int sendHeartbeatRequest(int gun_index)
  1638. {
  1639. mtrace();
  1640. int result = FAIL;
  1641. char message[80]={0};
  1642. char guid[37]={0};
  1643. char tempdata[65]={0};
  1644. random_uuid(guid);
  1645. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1646. , MESSAGE_TYPE_CALL
  1647. , guid );
  1648. LWS_Send(message);
  1649. sprintf(tempdata, "Heartbeat,%d", 0);
  1650. 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*/)
  1651. {
  1652. result = PASS;
  1653. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1654. }
  1655. return result;
  1656. }
  1657. int sendStartTransactionRequest(int gun_index)
  1658. {
  1659. mtrace();
  1660. int result = FAIL;
  1661. char message[250]={0};
  1662. char guid[37]={0};
  1663. struct timeval tmnow;
  1664. struct tm *tm;
  1665. char buf[28];//, usec_buf[6];
  1666. char tempdata[65]={0};
  1667. DEBUG_INFO("sendStartTransactionRequest...");
  1668. gettimeofday(&tmnow, NULL);
  1669. time_t t;
  1670. t = time(NULL);
  1671. /*UTC time and date*/
  1672. tm = gmtime(&t);
  1673. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1674. #if 0 // remove temporally
  1675. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1676. strcat(buf,".");
  1677. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1678. strcat(buf,usec_buf);
  1679. #endif
  1680. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1681. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1682. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1683. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1684. {
  1685. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1686. {
  1687. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1688. {
  1689. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1690. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1691. }
  1692. }
  1693. for (int index = 0; index < CCS_QUANTITY; index++)
  1694. {
  1695. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1696. {
  1697. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1698. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1699. }
  1700. }
  1701. for (int index = 0; index < GB_QUANTITY; index++)
  1702. {
  1703. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1704. {
  1705. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1706. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1707. }
  1708. }
  1709. }
  1710. else
  1711. {
  1712. for (int index = 0; index < AC_QUANTITY; index++)
  1713. {
  1714. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1715. {
  1716. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1717. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1718. }
  1719. }
  1720. }//END OF ELSE
  1721. random_uuid(guid);
  1722. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1723. , MESSAGE_TYPE_CALL
  1724. , guid
  1725. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1726. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1727. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1728. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1729. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1730. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1731. 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*/)
  1732. {
  1733. result = PASS;
  1734. }
  1735. strcpy(queuedata, message);
  1736. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1737. if(GetTransactionQueueNum() == 1)
  1738. {
  1739. LWS_Send(message);
  1740. }
  1741. #if 0
  1742. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1743. 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*/)
  1744. {
  1745. result = PASS;
  1746. }
  1747. strcpy(queuedata, message);
  1748. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1749. #endif
  1750. //#ifdef SystemLogMessage
  1751. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1752. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1753. //#endif
  1754. return result;
  1755. }
  1756. int sendStatusNotificationRequest(int gun_index)
  1757. {
  1758. mtrace();
  1759. int result = FAIL;
  1760. char message[600]={0};
  1761. char guid[37];
  1762. int currentStatus = 0;
  1763. struct timeval tmnow;
  1764. struct tm *tm;
  1765. char buf[28];//, usec_buf[6];
  1766. char tempdata[65]={0};
  1767. gettimeofday(&tmnow, NULL);
  1768. time_t t;
  1769. t = time(NULL);
  1770. /*UTC time and date*/
  1771. tm = gmtime(&t);
  1772. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1773. #if 0 // remove temporally
  1774. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1775. strcat(buf,".");
  1776. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1777. strcat(buf,usec_buf);
  1778. #endif
  1779. printf("%s",buf);
  1780. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1781. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1782. // it's option
  1783. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1784. /*
  1785. enum _SYSTEM_STATUS
  1786. {
  1787. S_BOOTING = 0,
  1788. S_IDLE, = 1
  1789. S_AUTHORIZING, =2
  1790. S_REASSIGN_CHECK, =3
  1791. S_REASSIGN, =4
  1792. S_PRECHARGE, =5
  1793. S_PREPARING_FOR_EV, =6
  1794. S_PREPARING_FOR_EVSE, =7
  1795. S_CHARGING, =8
  1796. S_TERMINATING, =9
  1797. S_COMPLETE, =10
  1798. S_ALARM, =11
  1799. S_FAULT =12
  1800. }
  1801. */
  1802. //check Transaction active
  1803. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1804. {
  1805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1806. {
  1807. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1808. {
  1809. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1810. {
  1811. currentStatus = 1; //OCPP Status: Preparing
  1812. }
  1813. else
  1814. {
  1815. currentStatus = 0; //OCPP Status: Available
  1816. }
  1817. }
  1818. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1819. {
  1820. currentStatus = 1; //OCPP Status: Preparing
  1821. }
  1822. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1823. {
  1824. currentStatus = 2; //OCPP Status: Charging
  1825. }
  1826. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1827. {
  1828. currentStatus = 5; //OCPP Status: Finishing
  1829. }
  1830. 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
  1831. {
  1832. currentStatus = 4; //OCPP Status: SuspendedEV
  1833. }
  1834. 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
  1835. {
  1836. currentStatus = 7; //OCPP Status: Unavailable
  1837. }
  1838. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1839. {
  1840. currentStatus = 8; //OCPP Status: Faulted
  1841. }
  1842. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1843. {
  1844. currentStatus = 6; //OCPP Status: Reserved
  1845. }
  1846. }//end of for CHAdeMO_QUANTITY
  1847. for (int index = 0; index < CCS_QUANTITY; index++)
  1848. {
  1849. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1850. {
  1851. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1852. {
  1853. currentStatus = 1; //OCPP Status: Preparing
  1854. }
  1855. else
  1856. {
  1857. currentStatus = 0; //OCPP Status: Available
  1858. }
  1859. }
  1860. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1861. {
  1862. currentStatus = 1; //OCPP Status: Preparing
  1863. }
  1864. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1865. {
  1866. currentStatus = 2; //OCPP Status: Charging
  1867. }
  1868. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1869. {
  1870. currentStatus = 5; //OCPP Status: Finishing
  1871. }
  1872. 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
  1873. {
  1874. currentStatus = 4; //OCPP Status: SuspendedEV
  1875. }
  1876. 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
  1877. {
  1878. currentStatus = 7; //OCPP Status : Unavailable
  1879. }
  1880. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1881. {
  1882. currentStatus = 8; //OCPP Status: Faulted
  1883. }
  1884. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1885. {
  1886. currentStatus = 6; //OCPP Status: Reserved
  1887. }
  1888. }
  1889. for (int index = 0; index < GB_QUANTITY; index++)
  1890. {
  1891. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1892. {
  1893. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1894. {
  1895. currentStatus = 1; //OCPP Status: Preparing
  1896. }
  1897. else
  1898. {
  1899. currentStatus = 0; //OCPP Status: Available
  1900. }
  1901. }
  1902. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1903. {
  1904. currentStatus = 1; //OCPP Status: Preparing
  1905. }
  1906. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1907. {
  1908. currentStatus = 2; //OCPP Status: Charging
  1909. }
  1910. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1911. {
  1912. currentStatus = 5; //OCPP Status: Finishing
  1913. }
  1914. 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
  1915. {
  1916. currentStatus = 4; //OCPP Status: SuspendedEV
  1917. }
  1918. 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
  1919. {
  1920. currentStatus = 7; //OCPP Status: Unavailable
  1921. }
  1922. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1923. {
  1924. currentStatus = 8; //OCPP Status: Faulted
  1925. }
  1926. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1927. {
  1928. currentStatus = 6; //OCPP Status: Reserved
  1929. }
  1930. }
  1931. }
  1932. else
  1933. {
  1934. for (int index = 0; index < AC_QUANTITY; index++)
  1935. {
  1936. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1937. {
  1938. 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))
  1939. {
  1940. currentStatus = 1; //OCPP Status: Preparing
  1941. }
  1942. else
  1943. {
  1944. currentStatus = 0; //OCPP Status: Available
  1945. }
  1946. }
  1947. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1948. {
  1949. currentStatus = 1; //OCPP Status: Preparing
  1950. }
  1951. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1952. {
  1953. currentStatus = 2; //OCPP Status: Charging
  1954. }
  1955. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1956. {
  1957. currentStatus = 5; //OCPP Status: Finishing
  1958. }
  1959. 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
  1960. {
  1961. currentStatus = 4; //OCPP Status: SuspendedEV
  1962. }
  1963. 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
  1964. {
  1965. currentStatus = 7; //OCPP Status: Unavailable
  1966. }
  1967. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1968. {
  1969. currentStatus = 8; //OCPP Status: Faulted
  1970. }
  1971. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1972. {
  1973. currentStatus = 6; //OCPP Status: Reserved
  1974. }
  1975. }//end of for AC_QUANTITY
  1976. }//END OF ELSE
  1977. //it's option
  1978. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1979. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1980. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1981. random_uuid(guid);
  1982. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1983. , MESSAGE_TYPE_CALL
  1984. , guid
  1985. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1986. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1987. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1988. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1989. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1990. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1991. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1992. LWS_Send(message);
  1993. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1994. 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*/)
  1995. {
  1996. //DEBUG_ERROR("statusNotification mapitem pass");
  1997. result = PASS;
  1998. }
  1999. return result;
  2000. }
  2001. int sendStopTransactionRequest(int gun_index)
  2002. {
  2003. mtrace();
  2004. int result = FAIL;
  2005. //char message[1500]={0};
  2006. char guid[37]={0};
  2007. char tempdata[65]={0};
  2008. //int idx_sample=0;
  2009. DEBUG_ERROR("sendStopTransactionRequest \n");
  2010. memset(queuedata, 0, sizeof(queuedata));
  2011. //ENERGY_ACTIVE_IMPORT_REGISTER
  2012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2013. {
  2014. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2015. {
  2016. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2017. {
  2018. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2019. }
  2020. }// END OF CHAdeMO_QUANTITY
  2021. for (int index = 0; index < CCS_QUANTITY; index++)
  2022. {
  2023. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2024. {
  2025. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2026. }
  2027. }// END OF CCS_QUANTITY
  2028. for (int index = 0; index < GB_QUANTITY; index++)
  2029. {
  2030. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2031. {
  2032. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2033. }
  2034. }// END OF GB_QUANTITY
  2035. }
  2036. else
  2037. {
  2038. for (int index = 0; index < AC_QUANTITY; index++)
  2039. {
  2040. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2041. {
  2042. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2043. }
  2044. }// END OF AC_QUANTITY
  2045. }//END OF ELSE
  2046. //Stop Transaction Time
  2047. struct timeval tmnow;
  2048. struct tm *tm;
  2049. char buf[28];//, usec_buf[6];
  2050. gettimeofday(&tmnow, NULL);
  2051. time_t t;
  2052. t = time(NULL);
  2053. /*UTC time and date*/
  2054. tm = gmtime(&t);
  2055. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2057. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2058. random_uuid(guid);
  2059. /***********************************transactionData******************************************************/
  2060. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2062. //=================================
  2063. // Transaction_Begin
  2064. //=================================
  2065. // Energy.Active.Export.Interval
  2066. //idx_sample=0;
  2067. 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
  2068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2070. 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*/]);
  2071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2072. {
  2073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2074. }
  2075. else
  2076. {
  2077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2078. }
  2079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2081. //=================================
  2082. // Transaction_End
  2083. //=================================
  2084. //Current.Export
  2085. //idx_sample=1;
  2086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2087. {
  2088. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2089. {
  2090. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2091. {
  2092. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2093. }
  2094. }
  2095. for (int index = 0; index < CCS_QUANTITY; index++)
  2096. {
  2097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2098. {
  2099. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2100. }
  2101. }
  2102. for (int index = 0; index < GB_QUANTITY; index++)
  2103. {
  2104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2105. {
  2106. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2107. }
  2108. }
  2109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2110. }
  2111. else
  2112. {
  2113. for (int index = 0; index < AC_QUANTITY; index++)
  2114. {
  2115. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2116. {
  2117. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2118. }
  2119. }
  2120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2121. }// END FOR AC ELSE
  2122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2125. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2128. //Energy.Active.Export.Interval
  2129. //idx_sample=2;
  2130. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2131. {
  2132. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2133. {
  2134. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2135. {
  2136. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2137. }
  2138. }
  2139. for (int index = 0; index < CCS_QUANTITY; index++)
  2140. {
  2141. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2142. {
  2143. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2144. }
  2145. }
  2146. for (int index = 0; index < GB_QUANTITY; index++)
  2147. {
  2148. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2149. {
  2150. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2151. }
  2152. }
  2153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2154. }
  2155. else
  2156. {
  2157. for (int index = 0; index < AC_QUANTITY; index++)
  2158. {
  2159. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2160. {
  2161. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2162. }
  2163. }
  2164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2165. }// END FOR AC ELSE
  2166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2169. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2172. //Power.Active.Export
  2173. //idx_sample=3;
  2174. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2175. {
  2176. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2177. {
  2178. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2179. {
  2180. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2181. }
  2182. }
  2183. for (int index = 0; index < CCS_QUANTITY; index++)
  2184. {
  2185. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2186. {
  2187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2188. }
  2189. }
  2190. for (int index = 0; index < GB_QUANTITY; index++)
  2191. {
  2192. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2193. {
  2194. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2195. }
  2196. }
  2197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2198. }
  2199. else
  2200. {
  2201. for (int index = 0; index < AC_QUANTITY; index++)
  2202. {
  2203. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2204. {
  2205. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2206. }
  2207. }
  2208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2209. }// END FOR AC ELSE
  2210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2213. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2216. //Voltage
  2217. //idx_sample=4;
  2218. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2219. {
  2220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2221. {
  2222. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2223. {
  2224. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2225. }
  2226. }
  2227. for (int index = 0; index < CCS_QUANTITY; index++)
  2228. {
  2229. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2230. {
  2231. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2232. }
  2233. }
  2234. for (int index = 0; index < GB_QUANTITY; index++)
  2235. {
  2236. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2237. {
  2238. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2239. }
  2240. }
  2241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2242. }
  2243. else
  2244. {
  2245. for (int index = 0; index < AC_QUANTITY; index++)
  2246. {
  2247. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2248. {
  2249. 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
  2250. }
  2251. }
  2252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2253. }// END FOR AC ELSE
  2254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2257. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2260. //SoC
  2261. //idx_sample=5;
  2262. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2263. {
  2264. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2265. {
  2266. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2267. {
  2268. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2269. }
  2270. }
  2271. for (int index = 0; index < CCS_QUANTITY; index++)
  2272. {
  2273. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2274. {
  2275. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2276. }
  2277. }
  2278. for (int index = 0; index < GB_QUANTITY; index++)
  2279. {
  2280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2281. {
  2282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2283. }
  2284. }
  2285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2291. } // END FOR DC CASE
  2292. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2293. {
  2294. 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\"}]}]}]"
  2295. ,MESSAGE_TYPE_CALL
  2296. ,guid
  2297. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2298. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2299. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2302. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2304. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2336. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2340. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2341. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2342. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2343. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2344. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2345. );
  2346. }
  2347. else
  2348. {
  2349. 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\"}]}]}]"
  2350. ,MESSAGE_TYPE_CALL
  2351. ,guid
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2357. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2364. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2366. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2367. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2368. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2369. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2370. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2385. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2386. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2387. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2388. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2390. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2391. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2392. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2393. );
  2394. }
  2395. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2396. if(hashmap_operation(0, guid, tempdata) == 1)
  2397. {
  2398. result = PASS;
  2399. DEBUG_INFO("StopTransaction mapitem pass\n");
  2400. }
  2401. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2402. if(GetTransactionQueueNum() == 1)
  2403. {
  2404. LWS_Send(queuedata);
  2405. }
  2406. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2407. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2408. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2409. {
  2410. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2411. }
  2412. #if 0
  2413. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2414. if(hashmap_operation(0, guid, tempdata) == 1)
  2415. {
  2416. result = PASS;
  2417. DEBUG_INFO("StopTransaction mapitem pass\n");
  2418. }
  2419. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2420. #endif
  2421. //for test
  2422. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2423. return result;
  2424. }
  2425. int sendMeterValuesRequest(int gun_index)
  2426. {
  2427. mtrace();
  2428. int result = FAIL;
  2429. // char message[1500]={0};
  2430. char guid[37]={0};
  2431. //int idx_sample=0;
  2432. //int length = 0;
  2433. char tempdata[65]={0};
  2434. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2435. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2436. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2437. {
  2438. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2439. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2440. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2441. return result;
  2442. }
  2443. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2444. {
  2445. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2446. }
  2447. memset(queuedata, 0, sizeof(queuedata));
  2448. //set value
  2449. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2450. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2451. random_uuid(guid);
  2452. //UTC Date time
  2453. struct timeval tmnow;
  2454. struct tm *tm;
  2455. char buf[28];//, usec_buf[6];
  2456. gettimeofday(&tmnow, NULL);
  2457. time_t t;
  2458. t = time(NULL);
  2459. /*UTC time and date*/
  2460. tm = gmtime(&t);
  2461. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2462. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2463. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2464. //idx_sample=0;
  2465. //********************************(1)Current.Export************************************************/
  2466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2467. {
  2468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2469. {
  2470. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2471. {
  2472. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2473. }
  2474. }
  2475. for (int index = 0; index < CCS_QUANTITY; index++)
  2476. {
  2477. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2478. {
  2479. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2480. }
  2481. }
  2482. for (int index = 0; index < GB_QUANTITY; index++)
  2483. {
  2484. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2485. {
  2486. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2487. }
  2488. }
  2489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2490. }
  2491. else
  2492. {
  2493. for (int index = 0; index < AC_QUANTITY; index++)
  2494. {
  2495. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2496. {
  2497. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2498. }
  2499. }
  2500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2501. }// END FOR AC ELSE
  2502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2505. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2508. //idx_sample=1;
  2509. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2510. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2511. {
  2512. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2513. {
  2514. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2515. {
  2516. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2517. }
  2518. }
  2519. for (int index = 0; index < CCS_QUANTITY; index++)
  2520. {
  2521. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2522. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2523. {
  2524. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2525. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2526. }
  2527. }
  2528. for (int index = 0; index < GB_QUANTITY; index++)
  2529. {
  2530. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2531. {
  2532. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2533. }
  2534. }
  2535. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2536. }
  2537. else
  2538. {
  2539. for (int index = 0; index < AC_QUANTITY; index++)
  2540. {
  2541. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2542. {
  2543. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2544. }
  2545. }
  2546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2547. }//END FOR AC ELSE
  2548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2551. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2554. //idx_sample=2;
  2555. //********************************(4)Power.Active.Export************************************************/
  2556. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2557. {
  2558. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2559. {
  2560. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2561. {
  2562. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2563. }
  2564. }
  2565. for (int index = 0; index < CCS_QUANTITY; index++)
  2566. {
  2567. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2568. {
  2569. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2570. }
  2571. }
  2572. for (int index = 0; index < GB_QUANTITY; index++)
  2573. {
  2574. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2575. {
  2576. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2577. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2578. }
  2579. }
  2580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2581. }
  2582. else
  2583. {
  2584. for (int index = 0; index < AC_QUANTITY; index++)
  2585. {
  2586. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2587. {
  2588. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2589. }
  2590. }
  2591. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2592. }// END FOR AC ELSE
  2593. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2594. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2595. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2596. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2598. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2599. //idx_sample=3;
  2600. //***********************************************(5)VOLTAGE******************************************************/
  2601. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2602. {
  2603. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2604. {
  2605. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2606. {
  2607. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2608. }
  2609. }
  2610. for (int index = 0; index < CCS_QUANTITY; index++)
  2611. {
  2612. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2613. {
  2614. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2615. }
  2616. }
  2617. for (int index = 0; index < GB_QUANTITY; index++)
  2618. {
  2619. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2620. {
  2621. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2622. }
  2623. }
  2624. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2625. }
  2626. else
  2627. {
  2628. for (int index = 0; index < AC_QUANTITY; index++)
  2629. {
  2630. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2631. {
  2632. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2633. }
  2634. }
  2635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2636. }//END FOR AC ELSE
  2637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2640. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2641. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2643. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2644. {
  2645. //idx_sample=4;
  2646. //sampledValue = NULL;
  2647. //***********************************************(6)SOC******************************************************/
  2648. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2649. {
  2650. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2651. {
  2652. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2653. }
  2654. }
  2655. for (int index = 0; index < CCS_QUANTITY; index++)
  2656. {
  2657. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2658. {
  2659. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2660. }
  2661. }
  2662. for (int index = 0; index < GB_QUANTITY; index++)
  2663. {
  2664. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2665. {
  2666. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2667. }
  2668. }
  2669. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2670. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2671. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2672. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2673. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2674. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2675. }
  2676. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2677. {
  2678. 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\"}]}]}]"
  2679. ,MESSAGE_TYPE_CALL
  2680. ,guid
  2681. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2682. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2683. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2719. );
  2720. }
  2721. else
  2722. {
  2723. 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\"}]}]}]"
  2724. ,MESSAGE_TYPE_CALL
  2725. ,guid
  2726. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2727. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2728. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2757. );
  2758. }
  2759. // Put request guid to hash map
  2760. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2761. 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*/)
  2762. {
  2763. result = PASS;
  2764. DEBUG_INFO("MeterValues mapitem pass\n");
  2765. }
  2766. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2767. if(GetTransactionQueueNum() == 1)
  2768. {
  2769. LWS_Send(queuedata);
  2770. }
  2771. #if 0
  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. #endif
  2781. return result;
  2782. }
  2783. //==========================================
  2784. // send confirm routine
  2785. //==========================================
  2786. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2787. {
  2788. mtrace();
  2789. int result = FAIL;
  2790. char message[100]={0};
  2791. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2792. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2793. LWS_Send(message);
  2794. result = TRUE;
  2795. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2796. return result;
  2797. }
  2798. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2799. {
  2800. mtrace();
  2801. int result = FAIL;
  2802. char message[100]={0};
  2803. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2804. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2805. LWS_Send(message);
  2806. result = TRUE;
  2807. return result;
  2808. }
  2809. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2810. {
  2811. mtrace();
  2812. int result = FAIL;
  2813. char message[100]={0};
  2814. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2815. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2816. LWS_Send(message);
  2817. result = TRUE;
  2818. return result;
  2819. }
  2820. int sendClearCacheConfirmation(char *uuid,char *payload)
  2821. {
  2822. mtrace();
  2823. int result = FAIL;
  2824. char message[500]={0};
  2825. // int count = 0;
  2826. // int gun_index = 0;
  2827. // char guid[37];
  2828. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2829. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2830. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2831. LWS_Send(message);
  2832. return result;
  2833. }
  2834. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2835. {
  2836. mtrace();
  2837. int result = FAIL;
  2838. char message[500]={0};
  2839. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2840. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2841. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2842. LWS_Send(message);
  2843. return result;
  2844. }
  2845. int sendDataTransferConfirmation(char *uuid,char *payload)
  2846. {
  2847. mtrace();
  2848. char statusStr[20]={0};
  2849. char dataStr[10]={0};
  2850. char sstr[20]={0};
  2851. int c = 0;
  2852. char *loc;
  2853. int result = FAIL;
  2854. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2855. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2856. /**********************status**************************/
  2857. loc = strstr(payload, "status");
  2858. memset(sstr ,0, sizeof(sstr) );
  2859. c = 0;
  2860. while (loc[3+strlen("status")+c] != '\"')
  2861. {
  2862. sstr[c] = loc[3+strlen("status")+c];
  2863. c++;
  2864. }
  2865. sstr[c] = '\0';
  2866. strcpy(statusStr, sstr);
  2867. /**********************data**************************/
  2868. loc = strstr(payload, "data");
  2869. memset(sstr ,0, sizeof(sstr) );
  2870. c = 0;
  2871. while (loc[3+strlen("data")+c] != '\"')
  2872. {
  2873. sstr[c] = loc[3+strlen("data")+c];
  2874. c++;
  2875. }
  2876. sstr[c] = '\0';
  2877. strcpy(dataStr, sstr);
  2878. return result;
  2879. }
  2880. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2881. {
  2882. mtrace();
  2883. int result = FAIL;
  2884. char message[1000]={0};
  2885. double diff_f = 0.0;
  2886. int diff_i = 0;
  2887. int diffSeconds = 0;
  2888. struct tm tp;
  2889. int TimeZero = FALSE;
  2890. int CompositeScheduleIndex = 0;
  2891. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2892. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2893. {
  2894. TimeZero = TRUE;
  2895. }
  2896. else
  2897. {
  2898. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2899. }
  2900. if(TimeZero == FALSE)
  2901. {
  2902. tp.tm_isdst = -1;
  2903. time_t utc = mktime(&tp);
  2904. time_t t = time(NULL);
  2905. diff_f = difftime(t, utc);
  2906. diff_i = (int)diff_f;
  2907. diffSeconds = diff_i % 86400;//86400 seconds/day
  2908. }
  2909. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2910. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2911. #if 0 //remove temporally
  2912. 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}"
  2913. ,MESSAGE_TYPE_CALLRESULT
  2914. ,uuid
  2915. ,payload
  2916. ,connectorIdInt
  2917. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2918. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2919. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2920. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2921. #endif
  2922. if(nPeriod == 0)
  2923. {
  2924. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  2925. {
  2926. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  2927. ,MESSAGE_TYPE_CALLRESULT
  2928. ,uuid
  2929. ,payload
  2930. ,connectorIdInt);
  2931. }
  2932. else
  2933. {
  2934. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2935. ,MESSAGE_TYPE_CALLRESULT
  2936. ,uuid
  2937. ,payload
  2938. ,connectorIdInt
  2939. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2940. }
  2941. }
  2942. else
  2943. {
  2944. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2945. ,MESSAGE_TYPE_CALLRESULT
  2946. ,uuid
  2947. ,payload
  2948. ,connectorIdInt
  2949. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2950. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2951. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2952. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2953. int len = nPeriod;
  2954. //Last Period StartPriod is less than diffSeconds
  2955. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds)
  2956. {
  2957. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2958. , 0
  2959. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2960. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2961. }
  2962. else
  2963. {
  2964. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2965. {
  2966. 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)
  2967. {
  2968. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2969. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2970. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2971. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2972. }
  2973. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2974. {
  2975. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2976. , ((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*/))
  2977. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2978. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2979. }
  2980. }
  2981. }
  2982. sprintf(message + strlen(message), "]}}]");
  2983. }
  2984. LWS_Send(message);
  2985. result = TRUE;
  2986. return result;
  2987. }
  2988. int sendGetConfigurationConfirmation(char *uuid)
  2989. {
  2990. mtrace();
  2991. int result = FAIL;
  2992. int MaxKeySupported = 0;
  2993. int sentConfigurationNumber= 0;
  2994. int sentunConfigurationNumber= 0;
  2995. char message[4000]={0};
  2996. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2997. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2998. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2999. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3000. ,MESSAGE_TYPE_CALLRESULT
  3001. ,uuid );
  3002. //configuration key
  3003. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3004. {
  3005. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3006. {
  3007. if (sentConfigurationNumber == 0)
  3008. {
  3009. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3010. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3011. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3012. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3013. }
  3014. else
  3015. {
  3016. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3017. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3018. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3019. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3020. }
  3021. sentConfigurationNumber = sentConfigurationNumber + 1;
  3022. }
  3023. }
  3024. sprintf(message + strlen(message), "]");
  3025. if(UnknownKeynum != 0)
  3026. {
  3027. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3028. //unkown key
  3029. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3030. {
  3031. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3032. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3033. if(sentunConfigurationNumber == 0)
  3034. {
  3035. sprintf(message + strlen(message), "\"%s\""
  3036. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3037. }
  3038. else
  3039. {
  3040. sprintf(message + strlen(message), ",\"%s\""
  3041. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3042. }
  3043. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3044. }
  3045. sprintf(message + strlen(message), "]");
  3046. }
  3047. sprintf(message + strlen(message), "}]");
  3048. LWS_Send(message);
  3049. return result;
  3050. }
  3051. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3052. {
  3053. mtrace();
  3054. int result = FAIL;
  3055. char message[400]={0};
  3056. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3057. if(strcmp(payload,"")==0)
  3058. {
  3059. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3060. }
  3061. else
  3062. {
  3063. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3064. }
  3065. LWS_Send(message);
  3066. result = TRUE;
  3067. return result;
  3068. }
  3069. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3070. {
  3071. mtrace();
  3072. int result = FAIL;
  3073. char message[80]={0};
  3074. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3075. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3076. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3077. LWS_Send(message);
  3078. result = TRUE;
  3079. return result;
  3080. }
  3081. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3082. {
  3083. mtrace();
  3084. int result = FAIL;
  3085. char message[80]={0};
  3086. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3087. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3088. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3089. LWS_Send(message);
  3090. result = TRUE;
  3091. return result;
  3092. }
  3093. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3094. {
  3095. mtrace();
  3096. int result = FAIL;
  3097. char message[80]={0};
  3098. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3099. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3100. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3101. LWS_Send(message);
  3102. result = TRUE;
  3103. return result;
  3104. }
  3105. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3106. {
  3107. mtrace();
  3108. int result = FAIL;
  3109. char message[80]={0};
  3110. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3111. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3112. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3113. LWS_Send(message);
  3114. result = TRUE;
  3115. return result;
  3116. }
  3117. int sendResetConfirmation(char *uuid,char *payload)
  3118. {
  3119. mtrace();
  3120. int result = FAIL;
  3121. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3122. char message[80]={0};
  3123. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3124. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3125. LWS_Send(message);
  3126. result = TRUE;
  3127. return result;
  3128. }
  3129. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3130. {
  3131. mtrace();
  3132. int result = FAIL;
  3133. char message[500]={0};
  3134. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3135. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3136. LWS_Send(message);
  3137. result = TRUE;
  3138. return result;
  3139. }
  3140. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3141. {
  3142. mtrace();
  3143. int result = FAIL;
  3144. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3145. char message[80]={0};
  3146. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3147. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3148. LWS_Send(message);
  3149. result = TRUE;
  3150. return result;
  3151. }
  3152. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3153. {
  3154. mtrace();
  3155. int result = FAIL;
  3156. char message[80]={0};
  3157. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3158. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3159. LWS_Send(message);
  3160. result = TRUE;
  3161. return result;
  3162. }
  3163. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3164. {
  3165. mtrace();
  3166. int result = FAIL;
  3167. char message[80]={0};
  3168. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3169. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3170. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3171. LWS_Send(message);
  3172. result = TRUE;
  3173. return result;
  3174. }
  3175. int sendUpdateFirmwareConfirmation(char *uuid)
  3176. {
  3177. mtrace();
  3178. int result = FAIL;
  3179. char message[60]={0};
  3180. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3181. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3182. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3183. LWS_Send(message);
  3184. result = TRUE;
  3185. return result;
  3186. }
  3187. //==========================================
  3188. // send CallError routine
  3189. //==========================================
  3190. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3191. {
  3192. mtrace();
  3193. //int result = FAIL;
  3194. char message[220]={0};
  3195. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3196. #ifdef SystemLogMessage
  3197. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3198. uniqueId, action, errorCode, errorDescription);
  3199. #endif
  3200. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3201. LWS_Send(message);
  3202. //result = TRUE;
  3203. }
  3204. //==========================================
  3205. // Handle server request routine Start
  3206. //==========================================
  3207. #define GUN_NUM 1
  3208. int handleCancelReservationRequest(char *uuid, char *payload)
  3209. {
  3210. mtrace();
  3211. int result = FAIL;
  3212. int gunNO = 0;
  3213. int reservationIdInt =0;
  3214. char comfirmstr[20];
  3215. int c = 0;
  3216. char *loc;
  3217. char sstr[100]={0};
  3218. DEBUG_INFO("handle CancelReservationRequest\n");
  3219. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3220. c = 0;
  3221. loc = strstr(payload, "reservationId");
  3222. memset(sstr ,0, sizeof(sstr) );
  3223. while (loc[strlen("reservationId")+2+c] != '}')
  3224. {
  3225. sstr[c] = loc[strlen("reservationId")+2+c];
  3226. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3227. c++;
  3228. }
  3229. sstr[c] = '\0';
  3230. reservationIdInt = atoi(sstr);
  3231. memset(comfirmstr, 0, sizeof comfirmstr);
  3232. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3233. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3234. //check Transaction active
  3235. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3236. {
  3237. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3238. {
  3239. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3240. {
  3241. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3242. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3243. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3244. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3245. goto end;
  3246. }
  3247. }
  3248. for (int index = 0; index < CCS_QUANTITY; index++)
  3249. {
  3250. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3251. {
  3252. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3253. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3254. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3255. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3256. goto end;
  3257. }
  3258. }
  3259. for (int index = 0; index < GB_QUANTITY; index++)
  3260. {
  3261. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3262. {
  3263. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3264. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3265. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3266. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3267. goto end;
  3268. }
  3269. }
  3270. }
  3271. else
  3272. {
  3273. for (int index = 0; index < AC_QUANTITY; index++)
  3274. {
  3275. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3276. {
  3277. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3278. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3279. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3280. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3281. goto end;
  3282. }
  3283. }
  3284. }// END FOR AC ELSE
  3285. //The reservationId does NOT match the reservationId
  3286. sendCancelReservationConfirmation(uuid, comfirmstr);
  3287. end:
  3288. // Fill in ocpp packet uuid
  3289. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3290. return result;
  3291. }
  3292. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3293. {
  3294. mtrace();
  3295. int result = FAIL;
  3296. int gunIndex = 0;
  3297. char sstr[90]={0};
  3298. char typeStr[16]={0};
  3299. char comfirmstr[20];
  3300. int specificId = FALSE;
  3301. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3302. char *loc;
  3303. //int intervalInt = 0;
  3304. int c = 0;
  3305. /*** connectorId ****/
  3306. c = 0;
  3307. loc = strstr(payload, "connectorId");
  3308. memset(sstr ,0, sizeof(sstr) );
  3309. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3310. {
  3311. sstr[c] = loc[strlen("connectorId")+2+c];
  3312. c++;
  3313. }
  3314. sstr[c] = '\0';
  3315. gunIndex = atoi(sstr);
  3316. /***type ****/
  3317. loc = strstr(payload, "type");
  3318. memset(sstr ,0, sizeof(sstr) );
  3319. c = 0;
  3320. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3321. {
  3322. sstr[c] = loc[3+strlen("type")+c];
  3323. c++;
  3324. }
  3325. sstr[c] = '\0';
  3326. strcpy(typeStr, sstr);
  3327. if(gunIndex != 0)
  3328. {
  3329. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3330. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3331. }
  3332. else
  3333. {
  3334. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3335. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3336. }
  3337. memset(comfirmstr, 0, sizeof comfirmstr);
  3338. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3339. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3340. {
  3341. specificId = TRUE;
  3342. }
  3343. if(specificId == FALSE)
  3344. goto end;
  3345. if(gunIndex != 0)
  3346. {
  3347. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3348. }
  3349. else
  3350. {
  3351. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3352. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3353. }
  3354. /*
  3355. enum SYSTEM_STATUS
  3356. {
  3357. SYS_MODE_BOOTING = 0,
  3358. SYS_MODE_IDLE = 1,
  3359. SYS_MODE_AUTHORIZING = 2,
  3360. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3361. SYS_MODE_REASSIGN = 4,
  3362. SYS_MODE_PREPARING = 5,
  3363. SYS_MODE_PREPARE_FOR_EV = 6,
  3364. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3365. SYS_MODE_CHARGING = 8,
  3366. SYS_MODE_TERMINATING = 9,
  3367. SYS_MODE_COMPLETE = 10,
  3368. SYS_MODE_ALARM = 11,
  3369. SYS_MODE_FAULT = 12,
  3370. SYS_MODE_RESERVATION = 13,
  3371. SYS_MODE_BOOKING = 14,
  3372. SYS_MODE_MAINTAIN = 15,
  3373. SYS_MODE_DEBUG = 16,
  3374. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3375. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3376. SYS_MODE_UPDATE = 19
  3377. };
  3378. */
  3379. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3380. {
  3381. //check Transaction active
  3382. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3383. {
  3384. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3385. {
  3386. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3387. {
  3388. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3389. {
  3390. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3391. }
  3392. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3393. {
  3394. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3395. }
  3396. else
  3397. {
  3398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3399. }
  3400. goto end;
  3401. }
  3402. }//END FOR CHAdeMO_QUANTITY
  3403. for (int index = 0; index < CCS_QUANTITY; index++)
  3404. {
  3405. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3406. {
  3407. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3408. {
  3409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3410. }
  3411. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3412. {
  3413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3414. }
  3415. else
  3416. {
  3417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3418. }
  3419. goto end;
  3420. }
  3421. }//END FOR CCS_QUANTITY
  3422. for (int index = 0; index < GB_QUANTITY; index++)
  3423. {
  3424. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3425. {
  3426. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3427. {
  3428. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3429. }
  3430. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3431. {
  3432. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3433. }
  3434. else
  3435. {
  3436. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3437. }
  3438. goto end;
  3439. }
  3440. }// END FOR GB_QUANTITY
  3441. }
  3442. else
  3443. {
  3444. for (int index = 0; index < AC_QUANTITY; index++)
  3445. {
  3446. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3447. {
  3448. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3449. {
  3450. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3451. }
  3452. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3453. {
  3454. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3455. }
  3456. else
  3457. {
  3458. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3459. }
  3460. goto end;
  3461. }
  3462. }//END FOR AC_QUANTITY
  3463. }// END FOR AC ELSE
  3464. }//END FOR AvailabilityTypeStr[Inoperative]
  3465. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3466. {
  3467. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3468. //check Transaction active
  3469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3470. {
  3471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3472. {
  3473. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3474. {
  3475. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3476. goto end;
  3477. }
  3478. }//END FOR CHAdeMO_QUANTITY
  3479. for (int index = 0; index < CCS_QUANTITY; index++)
  3480. {
  3481. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3482. {
  3483. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3484. goto end;
  3485. }
  3486. }//END FOR CCS_QUANTITY
  3487. for (int index = 0; index < GB_QUANTITY; index++)
  3488. {
  3489. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3490. {
  3491. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3492. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3493. goto end;
  3494. }
  3495. }// END FOR GB_QUANTITY
  3496. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3497. }
  3498. else
  3499. {
  3500. for (int index = 0; index < AC_QUANTITY; index++)
  3501. {
  3502. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3503. {
  3504. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3505. goto end;
  3506. }
  3507. }//END FOR CHAdeMO_QUANTITY
  3508. }//END FOR AC ELSE
  3509. }//END FOR AvailabilityTypeStr[Operative]
  3510. end:
  3511. if(gunIndex != 0)
  3512. {
  3513. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3514. }
  3515. else
  3516. {
  3517. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3518. }
  3519. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3520. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3521. return result;
  3522. }
  3523. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3524. {
  3525. mtrace();
  3526. int result = FAIL;
  3527. char sstr[100]={0};
  3528. char keystr[40]={0};
  3529. char valuestr[100]={0};
  3530. char *loc;
  3531. int c = 0;
  3532. char comfirmstr[20]={0};
  3533. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3534. /***key ****/
  3535. loc = strstr(payload, "key");
  3536. memset(sstr ,0, sizeof(sstr) );
  3537. c = 0;
  3538. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3539. {
  3540. sstr[c] = loc[3+strlen("key")+c];
  3541. c++;
  3542. }
  3543. sstr[c] = '\0';
  3544. strcpy(keystr, sstr);
  3545. //DEBUG_INFO( "keystr=%s\n",keystr);
  3546. /***value ****/
  3547. loc = strstr(payload, "value");
  3548. memset(sstr ,0, sizeof(sstr) );
  3549. c = 0;
  3550. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3551. {
  3552. sstr[c] = loc[3+strlen("value")+c];
  3553. c++;
  3554. }
  3555. sstr[c] = '\0';
  3556. strcpy(valuestr, sstr);
  3557. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3558. if((uuid==NULL) || (payload ==NULL) )
  3559. {
  3560. #ifdef Debug
  3561. DEBUG_INFO("payload is null\n");
  3562. #endif
  3563. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3564. }
  3565. else
  3566. {
  3567. int status = setKeyValue(keystr, valuestr);
  3568. switch(status)
  3569. {
  3570. case ConfigurationStatus_Accepted:
  3571. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3572. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3573. StoreConfigurationTable();
  3574. break;
  3575. case ConfigurationStatus_Rejected:
  3576. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3577. break;
  3578. case RebootRequired:
  3579. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3580. StoreConfigurationTable();
  3581. break;
  3582. case NotSupported:
  3583. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3584. break;
  3585. default:
  3586. break;
  3587. }
  3588. }
  3589. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3590. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3591. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3592. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3593. {
  3594. ChageWebSocketPingInterval(atoi(valuestr));
  3595. }
  3596. return result;
  3597. }
  3598. int handleClearCacheRequest(char *uuid, char *payload)
  3599. {
  3600. mtrace();
  3601. int result = FAIL;
  3602. char comfirmstr[20];
  3603. int fd;
  3604. char rmFileCmd[100]={0};
  3605. struct stat stats;
  3606. DEBUG_INFO("handle ClearCacheRequest\n");
  3607. stat("/Storage/OCPP", &stats);
  3608. // Check for directory existence
  3609. if (S_ISDIR(stats.st_mode) == 1)
  3610. {
  3611. //DEBUG_ERROR("\n OCPP directory exist \n");
  3612. }
  3613. else
  3614. {
  3615. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3616. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3617. system(rmFileCmd);
  3618. }
  3619. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3620. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3621. {
  3622. DEBUG_INFO("AuthorizationCache file exist.\n");
  3623. }
  3624. else
  3625. {
  3626. DEBUG_INFO("AuthorizationCache file not exist\n");
  3627. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3628. if(log == NULL)
  3629. {
  3630. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3631. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3632. goto end;
  3633. }
  3634. else
  3635. {
  3636. fclose(log);
  3637. }
  3638. }
  3639. fd = open(AuthorizationCache_JSON,O_RDWR);
  3640. if(fd < 0)
  3641. {
  3642. DEBUG_INFO("open AuthorizationCache file failed\n");
  3643. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3644. }
  3645. else
  3646. {
  3647. DEBUG_INFO("open AuthorizationCache file successful\n");
  3648. //* 清空? 件 */
  3649. ftruncate(fd,0);
  3650. //* ? 新设置? 件? 移??*/
  3651. lseek(fd,0,SEEK_SET);
  3652. close(fd);
  3653. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3654. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3655. }
  3656. end:
  3657. sendClearCacheConfirmation(uuid, comfirmstr);
  3658. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3659. return result;
  3660. }
  3661. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3662. {
  3663. mtrace();
  3664. int result = FAIL;
  3665. int resultRename;
  3666. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3667. char chargingProfilePurposeStr[26]={0};
  3668. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3669. char tempchargingProfilePurposeStr[26]={0};
  3670. char sstr[160]={0};//sstr[200]={ 0 };
  3671. char str[100]={0};
  3672. int c = 0;
  3673. //int i = 0;
  3674. //char * pch;
  3675. char *loc;
  3676. char fname[200]={0};
  3677. char comfirmstr[20]={0};
  3678. char word[1600]={0};
  3679. int clearflag = FALSE;
  3680. int chargingProfileIdIsNULL = FALSE;
  3681. int connectorIsNULL = FALSE;
  3682. int chargingProfilePurposeIsNULL = FALSE;
  3683. int stackLevelIsNULL = FALSE;
  3684. //int GotoEnd = FALSE;
  3685. FILE *fptr1, *fptr2;
  3686. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3687. int n_chargingProfile=0;
  3688. int isEmptyFile = FALSE;
  3689. char sLineWord[1600]={0};
  3690. char chargingProfiles[10][100]={0};
  3691. int ChargeProfileCount = 0;
  3692. char ch;
  3693. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3694. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3695. //***id ****/
  3696. c = 0;
  3697. loc = strstr(payload, "id");
  3698. memset(sstr ,0, sizeof(sstr) );
  3699. if(loc == NULL)
  3700. {
  3701. chargingProfileIdIsNULL = TRUE;
  3702. }
  3703. else
  3704. {
  3705. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3706. {
  3707. sstr[c] = loc[strlen("id")+2+c];
  3708. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3709. c++;
  3710. }
  3711. sstr[c] = '\0';
  3712. chargingProfileIdInt = atoi(sstr);
  3713. }
  3714. //***connectorId ****/
  3715. c=0;
  3716. loc = strstr(payload, "connectorId");
  3717. memset(sstr ,0, sizeof(sstr) );
  3718. if(loc == NULL)
  3719. {
  3720. connectorIsNULL = TRUE;
  3721. }
  3722. else
  3723. {
  3724. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3725. {
  3726. sstr[c] = loc[strlen("connectorId")+2+c];
  3727. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3728. c++;
  3729. }
  3730. sstr[c] = '\0';
  3731. connectorIdInt = atoi(sstr);
  3732. }
  3733. //***chargingProfilePurpose ****/
  3734. loc = strstr(payload, "chargingProfilePurpose");
  3735. memset(sstr ,0, sizeof(sstr) );
  3736. c = 0;
  3737. if(loc == NULL)
  3738. {
  3739. chargingProfilePurposeIsNULL = TRUE;
  3740. }
  3741. else
  3742. {
  3743. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3744. {
  3745. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3746. c++;
  3747. }
  3748. sstr[c] = '\0';
  3749. strcpy(chargingProfilePurposeStr, sstr);
  3750. }
  3751. //***stackLevel ****/
  3752. c=0;
  3753. loc = strstr(payload, "stackLevel");
  3754. memset(sstr ,0, sizeof(sstr) );
  3755. if(loc == NULL)
  3756. {
  3757. stackLevelIsNULL = TRUE;
  3758. }
  3759. else
  3760. {
  3761. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3762. {
  3763. sstr[c] = loc[strlen("stackLevel")+2+c];
  3764. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3765. c++;
  3766. }
  3767. sstr[c] = '\0';
  3768. stackLevelInt = atoi(sstr);
  3769. }
  3770. if(connectorIsNULL == FALSE)
  3771. {
  3772. switch(connectorIdInt)
  3773. {
  3774. case 0:
  3775. if(chargingProfilePurposeIsNULL == TRUE)
  3776. {
  3777. int l = 0;
  3778. strcpy(fname, ChargePointMaxProfile_JSON);
  3779. if((access(fname,F_OK))!=-1)
  3780. {
  3781. strcpy(chargingProfiles[l], fname);
  3782. l = l + 1;
  3783. }
  3784. strcpy(fname, TxDefaultProfile_0_JSON);
  3785. if((access(fname,F_OK))!=-1)
  3786. {
  3787. strcpy(chargingProfiles[l], fname);
  3788. l = l + 1;
  3789. }
  3790. ChargeProfileCount = l;
  3791. }
  3792. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3793. {
  3794. strcpy(fname, ChargePointMaxProfile_JSON);
  3795. if((access(fname,F_OK))!=-1)
  3796. {
  3797. strcpy(chargingProfiles[0], fname);
  3798. ChargeProfileCount = 1;
  3799. }
  3800. }
  3801. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3802. {
  3803. strcpy(fname, TxDefaultProfile_0_JSON);
  3804. if((access(fname,F_OK))!=-1)
  3805. {
  3806. strcpy(chargingProfiles[0], fname);
  3807. ChargeProfileCount = 1;
  3808. }
  3809. }
  3810. break;
  3811. default:
  3812. if(chargingProfilePurposeIsNULL == TRUE)
  3813. {
  3814. int m = 0;
  3815. memset(fname, 0, sizeof fname);
  3816. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3817. if((access(fname,F_OK))!=-1)
  3818. {
  3819. strcpy(chargingProfiles[m], fname);
  3820. m = m + 1;
  3821. }
  3822. memset(fname, 0, sizeof fname);
  3823. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3824. if((access(fname,F_OK))!=-1)
  3825. {
  3826. strcpy(chargingProfiles[m], fname);
  3827. m = m + 1;
  3828. }
  3829. ChargeProfileCount = m;
  3830. }
  3831. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3832. {
  3833. //strcpy(fname, TxDefaultProfile_1_JSON);
  3834. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3835. if((access(fname,F_OK))!=-1)
  3836. {
  3837. strcpy(chargingProfiles[0], fname);
  3838. ChargeProfileCount = 1;
  3839. }
  3840. }
  3841. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3842. {
  3843. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3844. if((access(fname,F_OK))!=-1)
  3845. {
  3846. strcpy(chargingProfiles[0], fname);
  3847. ChargeProfileCount = 1;
  3848. }
  3849. //strcpy(fname, TxProfile_1_JSON);
  3850. }
  3851. //strcpy(fname, ChargePointMaxProfile_JSON );
  3852. break;
  3853. }
  3854. }
  3855. else // Check all Charging Profiles
  3856. {
  3857. int i = 0;
  3858. char fnametemp[200]={0};
  3859. ChargeProfileCount = 0;
  3860. //Check ChargePointMaxProfile.json exit
  3861. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3862. {
  3863. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3864. i = i + 1;
  3865. }
  3866. //Check TxDefaultProfile_0.json exit
  3867. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3868. {
  3869. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3870. i = i + 1;
  3871. }
  3872. //Check TxDefaultProfile_%d.json
  3873. for(int j=1; j <= gunTotalNumber; j++)
  3874. {
  3875. memset(fnametemp, 0, sizeof fnametemp);
  3876. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3877. if((access(fnametemp,F_OK))!=-1)
  3878. {
  3879. strcpy(chargingProfiles[i], fnametemp);
  3880. i = i + 1;
  3881. }
  3882. }
  3883. //Check TxProfile_%d.json
  3884. for(int j=1; j <= gunTotalNumber; j++)
  3885. {
  3886. memset(fnametemp, 0, sizeof fnametemp);
  3887. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3888. if((access(fnametemp,F_OK))!=-1)
  3889. {
  3890. strcpy(chargingProfiles[i], fnametemp);
  3891. i = i + 1;
  3892. }
  3893. }
  3894. ChargeProfileCount = i;
  3895. }// End connectorIsNULL is TRUE
  3896. if(ChargeProfileCount == 0)
  3897. {
  3898. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3899. goto end;
  3900. }
  3901. #if 0
  3902. fptr1 = fopen(fname, "r");
  3903. if (!fptr1)
  3904. {
  3905. //file not exist
  3906. DEBUG_INFO("Unable to open the input file!!\n");
  3907. fptr1 = fopen(fname, "w+");
  3908. }
  3909. fclose(fptr1);
  3910. #endif
  3911. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3912. {
  3913. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3914. goto end;
  3915. }
  3916. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3917. {
  3918. memset(str, 0, sizeof str);
  3919. // clear temp file
  3920. sprintf(str,"rm -f %s",temp);
  3921. system(str);
  3922. for(int k=0; k < ChargeProfileCount; k++)
  3923. {
  3924. memset(str, 0, sizeof str);
  3925. //clear file in C
  3926. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3927. system(str);
  3928. }
  3929. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3930. goto end;
  3931. }
  3932. else if(connectorIsNULL == TRUE)
  3933. {
  3934. for(int k=0; k < ChargeProfileCount; k++)
  3935. {
  3936. fptr1 = fopen(chargingProfiles[k], "r");
  3937. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  3938. //Check Charging Profile Count
  3939. while(fscanf(fptr1, "%s", word) != EOF)
  3940. {
  3941. //DEBUG_INFO("word=%s\n",word);
  3942. if(strstr(word, "chargingProfileId")!= NULL)
  3943. {
  3944. //DEBUG_INFO("test chargingProfileId \n");
  3945. n_chargingProfile = n_chargingProfile + 1;
  3946. //DEBUG_INFO("chargingProfileId Found\n");
  3947. }
  3948. }
  3949. rewind(fptr1);
  3950. //search Charging Profile Element
  3951. //int i= 0;
  3952. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3953. {
  3954. //------------------------tempconnectorIdInt------------------------//
  3955. loc = strstr(sLineWord, "connectorId");
  3956. c = 0;
  3957. memset(sstr ,0, sizeof(sstr) );
  3958. while (loc[strlen("connectorId")+2+c] != ',')
  3959. {
  3960. sstr[c] = loc[strlen("connectorId")+2+c];
  3961. c++;
  3962. }
  3963. sstr[c] = '\0';
  3964. tempconnectorIdInt = atoi(sstr);
  3965. printf("file's gun number is %d\n", tempconnectorIdInt);
  3966. //--------------------------chargingProfileId--------------------//
  3967. c = 0;
  3968. loc = strstr(sLineWord, "chargingProfileId");
  3969. memset(sstr ,0, sizeof(sstr) );
  3970. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3971. {
  3972. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3973. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3974. c++;
  3975. }
  3976. sstr[c] = '\0';
  3977. tempchargingProfileIdInt = atoi(sstr);
  3978. //stackLevel
  3979. c = 0;
  3980. loc = strstr(sLineWord, "stackLevel");
  3981. memset(sstr ,0, sizeof(sstr) );
  3982. while (loc[strlen("stackLevel")+2+c] != ',')
  3983. {
  3984. sstr[c] = loc[strlen("stackLevel")+2+c];
  3985. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3986. c++;
  3987. }
  3988. sstr[c] = '\0';
  3989. tempstackLevelInt = atoi(sstr);
  3990. c = 0;
  3991. loc = strstr(sLineWord, "chargingProfilePurpose");
  3992. memset(sstr ,0, sizeof(sstr) );
  3993. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3994. {
  3995. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3996. c++;
  3997. }
  3998. sstr[c] = '\0';
  3999. strcpy(tempchargingProfilePurposeStr, sstr);
  4000. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4001. {
  4002. //------- not write to fptr2-------//
  4003. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4004. //clearflag = TRUE;
  4005. }
  4006. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4007. {
  4008. //------- not write to fptr2-------//
  4009. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4010. }
  4011. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4012. {
  4013. //------- not write to fptr2-------//
  4014. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4015. }
  4016. else
  4017. {
  4018. fprintf(fptr2, sLineWord);//writing data into file
  4019. }
  4020. memset(sLineWord, 0, sizeof sLineWord);
  4021. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4022. if(clearflag == TRUE)
  4023. {
  4024. fclose(fptr1);
  4025. fclose(fptr2);
  4026. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4027. system(str);
  4028. // clear temp file
  4029. sprintf(str,"rm -f %s",temp);
  4030. system(str);
  4031. }
  4032. else
  4033. {
  4034. fclose(fptr1);
  4035. fclose(fptr2);
  4036. memset(str, 0, sizeof str);
  4037. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4038. system(str);
  4039. resultRename = rename(temp, chargingProfiles[k]);
  4040. if(resultRename == 0)
  4041. {
  4042. DEBUG_INFO("File ChargingProfile renamed successfully");
  4043. }
  4044. else
  4045. {
  4046. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4047. }
  4048. if(comfirmstr[0]== 0)
  4049. {
  4050. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4051. }
  4052. //Check chargingProfile is empty file
  4053. /*------ Read the file ----------------*/
  4054. fptr1=fopen(chargingProfiles[k],"r");
  4055. ch=fgetc(fptr1);
  4056. rewind(fptr1);
  4057. memset(sLineWord, 0, sizeof sLineWord);
  4058. if(ch!=EOF)
  4059. {
  4060. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4061. {
  4062. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4063. if(sLineWord[0]=='\0')
  4064. {
  4065. isEmptyFile = TRUE;
  4066. break;
  4067. }
  4068. else
  4069. {
  4070. isEmptyFile = FALSE;
  4071. break;
  4072. }
  4073. }
  4074. }
  4075. fclose(fptr1);
  4076. if(isEmptyFile == TRUE)
  4077. {
  4078. memset(str, 0, sizeof str);
  4079. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4080. system(str);
  4081. }
  4082. }
  4083. }// End of while(int k=0; k < ChargePointCount; k++)
  4084. }
  4085. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4086. {
  4087. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4088. for(int k=0; k < ChargeProfileCount; k++)
  4089. {
  4090. fptr1 = fopen(chargingProfiles[k], "r");
  4091. fptr2 = fopen(temp, "w+");
  4092. //Check Charging Profile Count
  4093. while(fscanf(fptr1, "%s", word) != EOF)
  4094. {
  4095. //DEBUG_INFO("word=%s\n",word);
  4096. if(strstr(word, "chargingProfileId")!= NULL)
  4097. {
  4098. //DEBUG_INFO("test chargingProfileId \n");
  4099. n_chargingProfile = n_chargingProfile + 1;
  4100. //DEBUG_INFO("chargingProfileId Found\n");
  4101. }
  4102. }
  4103. rewind(fptr1);
  4104. //search Charging Profile Element
  4105. //int i= 0;
  4106. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4107. {
  4108. //*************************tempconnectorIdInt*********************************/
  4109. loc = strstr(sLineWord, "connectorId");
  4110. c = 0;
  4111. memset(sstr ,0, sizeof(sstr) );
  4112. while (loc[strlen("connectorId")+2+c] != ',')
  4113. {
  4114. sstr[c] = loc[strlen("connectorId")+2+c];
  4115. c++;
  4116. }
  4117. sstr[c] = '\0';
  4118. tempconnectorIdInt = atoi(sstr);
  4119. //chargingProfileId
  4120. c = 0;
  4121. loc = strstr(sLineWord, "chargingProfileId");
  4122. memset(sstr ,0, sizeof(sstr) );
  4123. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4124. {
  4125. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4126. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4127. c++;
  4128. }
  4129. sstr[c] = '\0';
  4130. tempchargingProfileIdInt = atoi(sstr);
  4131. //stackLevel
  4132. c = 0;
  4133. loc = strstr(sLineWord, "stackLevel");
  4134. memset(sstr ,0, sizeof(sstr) );
  4135. while (loc[strlen("stackLevel")+2+c] != ',')
  4136. {
  4137. sstr[c] = loc[strlen("stackLevel")+2+c];
  4138. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4139. c++;
  4140. }
  4141. sstr[c] = '\0';
  4142. tempstackLevelInt = atoi(sstr);
  4143. c = 0;
  4144. loc = strstr(sLineWord, "chargingProfilePurpose");
  4145. memset(sstr ,0, sizeof(sstr) );
  4146. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4147. {
  4148. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4149. c++;
  4150. }
  4151. sstr[c] = '\0';
  4152. strcpy(tempchargingProfilePurposeStr, sstr);
  4153. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4154. {
  4155. //------- not write to fptr2-------//
  4156. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4157. //clearflag = TRUE;
  4158. }
  4159. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4160. {
  4161. //------- not write to fptr2-------//
  4162. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4163. }
  4164. else if(stackLevelIsNULL == TRUE)
  4165. {
  4166. //Clear Whole File
  4167. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4168. clearflag = TRUE;
  4169. break;
  4170. }
  4171. else
  4172. {
  4173. fprintf(fptr2, sLineWord);//writing data into file
  4174. }
  4175. memset(sLineWord, 0, sizeof sLineWord);
  4176. }
  4177. if(clearflag == TRUE)
  4178. {
  4179. fclose(fptr1);
  4180. fclose(fptr2);
  4181. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4182. system(str);
  4183. // clear temp file
  4184. sprintf(str,"rm -f %s",temp);
  4185. system(str);
  4186. }
  4187. else
  4188. {
  4189. fclose(fptr1);
  4190. fclose(fptr2);
  4191. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4192. system(str);
  4193. resultRename = rename(temp, chargingProfiles[k]);
  4194. if(resultRename == 0)
  4195. {
  4196. DEBUG_INFO("File ChargingProfile renamed successfully");
  4197. }
  4198. else
  4199. {
  4200. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4201. }
  4202. if(comfirmstr[0]== 0)
  4203. {
  4204. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4205. }
  4206. //Check chargingProfile is empty file
  4207. /*------ Read the file ----------------*/
  4208. fptr1=fopen(chargingProfiles[k],"r");
  4209. ch=fgetc(fptr1);
  4210. rewind(fptr1);
  4211. memset(sLineWord, 0, sizeof sLineWord);
  4212. if(ch!=EOF)
  4213. {
  4214. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4215. {
  4216. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4217. if(sLineWord[0]=='\0')
  4218. {
  4219. isEmptyFile = TRUE;
  4220. break;
  4221. }
  4222. else
  4223. {
  4224. isEmptyFile = FALSE;
  4225. break;
  4226. }
  4227. }
  4228. }
  4229. fclose(fptr1);
  4230. if(isEmptyFile == TRUE)
  4231. {
  4232. memset(str, 0, sizeof str);
  4233. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4234. system(str);
  4235. }
  4236. /*------- End of reading ---------------*/
  4237. }
  4238. } // while(int k=0; k < ChargeProfileCount; k++)
  4239. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4240. end:
  4241. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4242. return result;
  4243. }
  4244. int handleDataTransferRequest(char *uuid, char *payload)
  4245. {
  4246. mtrace();
  4247. int result = FAIL;
  4248. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4249. char tempvendorId[255]={0};
  4250. char tempmessageId[50]={0};
  4251. char tempdata[50]={0};
  4252. char sstr[160]={0};//sstr[200]={ 0 };
  4253. char message[80]={0};
  4254. int c = 0;
  4255. char *loc;
  4256. DEBUG_INFO("handle DataTransferRequest\n");
  4257. if((uuid != NULL) && (payload != NULL))
  4258. {
  4259. //===============================
  4260. // vendorId
  4261. //===============================
  4262. c = 0;
  4263. loc = strstr(payload, "vendorId");
  4264. while (loc[strlen("vendorId")+3+c] != '\"')
  4265. {
  4266. sstr[c] = loc[strlen("vendorId")+3+c];
  4267. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4268. c++;
  4269. }
  4270. sstr[c] = '\0';
  4271. strcpy(tempvendorId,sstr);
  4272. //===============================
  4273. // messageId
  4274. //===============================
  4275. memset(sstr ,0, sizeof(sstr) );
  4276. c = 0;
  4277. loc = strstr(payload, "messageId");
  4278. while (loc[strlen("messageId")+3+c] != '\"')
  4279. {
  4280. sstr[c] = loc[strlen("messageId")+3+c];
  4281. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4282. c++;
  4283. }
  4284. sstr[c] = '\0';
  4285. strcpy(tempmessageId,sstr);
  4286. //===============================
  4287. // data
  4288. //===============================
  4289. memset(sstr ,0, sizeof(sstr) );
  4290. c = 0;
  4291. loc = strstr(payload, "data");
  4292. printf("loc=%s\n",loc);
  4293. while (loc[strlen("data")+3+c] != '\"')
  4294. {
  4295. sstr[c] = loc[strlen("data")+3+c];
  4296. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4297. c++;
  4298. }
  4299. sstr[c] = '\0';
  4300. strcpy(tempdata,sstr);
  4301. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4302. }
  4303. else
  4304. {
  4305. char guid[37]={0};
  4306. random_uuid(guid);
  4307. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4308. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4309. }
  4310. LWS_Send(message);
  4311. return result;
  4312. }
  4313. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4314. {
  4315. mtrace();
  4316. int result = FAIL;
  4317. int connectorIdInt, durationInt;
  4318. char chargingRateUnitStr[4]={0};
  4319. //int tempconnectorIdInt,
  4320. int tempdurationInt;
  4321. float tempminChargingRateFloat = 0.0;
  4322. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4323. int tempStartPeriodInt=0;
  4324. float tempLimitInt=0.0;//0.1;
  4325. int tempNumberPhasesInt=0;
  4326. char fname[200];
  4327. char comfirmstr[20];
  4328. //float totallimit =0.0;
  4329. float MinChargingRate =0.0;
  4330. //double diff_t;
  4331. //struct tm tp;
  4332. FILE *fptr1;
  4333. int c = 0;
  4334. //int i = 0;
  4335. char * pch;
  4336. char *loc;
  4337. char sstr[200]={ 0 };
  4338. int n_chargingProfile = 0;
  4339. int n_SchedulePeriods = 0;
  4340. char SchedulePeriodList[10][200]={0};
  4341. char sLineWord[1600]={0};
  4342. //int n_periods = 0;
  4343. char word[1000]={0};
  4344. int confirmPeriods = 0;
  4345. struct StructProfile ChargePointMaxProfile;
  4346. struct StructProfile TxDefaultProfile;
  4347. struct StructProfile TxProfile;
  4348. struct StructProfile TxDefaultProfiletemp[2]={0};
  4349. int TxDefaultProfileFileIsNull=FALSE;
  4350. int ChargePointMaxProfileIsNull=FALSE;
  4351. int TxProfileIsNull=FALSE;
  4352. int CompositeSceduleIndex = 0;
  4353. char ChargePointMaxProfileScheduleStr[30]={0};
  4354. char TxDefaultProfileScheduleStr[30]={0};
  4355. char TxProfileScheduleStr[30]={0};
  4356. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4357. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4358. memset(&TxProfile,0,sizeof(struct StructProfile));
  4359. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4360. c=0;
  4361. loc = strstr(payload, "connectorId");
  4362. memset(sstr ,0, sizeof(sstr) );
  4363. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4364. {
  4365. sstr[c] = loc[strlen("connectorId")+2+c];
  4366. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4367. c++;
  4368. }
  4369. sstr[c] = '\0';
  4370. connectorIdInt = atoi(sstr);
  4371. c=0;
  4372. loc = strstr(payload, "duration");
  4373. memset(sstr ,0, sizeof(sstr) );
  4374. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4375. {
  4376. sstr[c] = loc[strlen("duration")+2+c];
  4377. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4378. c++;
  4379. }
  4380. sstr[c] = '\0';
  4381. durationInt = atoi(sstr);
  4382. c = 0;
  4383. loc = strstr(payload, "chargingRateUnit");
  4384. memset(sstr ,0, sizeof(sstr) );
  4385. if(loc == NULL)
  4386. {
  4387. }
  4388. else
  4389. {
  4390. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4391. {
  4392. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4393. c++;
  4394. }
  4395. sstr[c] = '\0';
  4396. strcpy(chargingRateUnitStr, sstr);
  4397. }
  4398. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4399. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4400. if(connectorIdInt==0) // connectorId is 0
  4401. {
  4402. //******************************ChargePointMaxProfile*****************************************************/
  4403. strcpy(fname, ChargePointMaxProfile_JSON );
  4404. char word[30]={0};
  4405. char sLineWord[1060]={0};
  4406. int n_chargingProfile=0;
  4407. ChargePointMaxProfileIsNull=TRUE;
  4408. if((access(fname,F_OK))!=-1)
  4409. {
  4410. fptr1 = fopen(fname, "r");
  4411. int c;
  4412. c = fgetc(fptr1);
  4413. //DEBUG_INFO("c:%d\n",c);
  4414. rewind(fptr1);
  4415. if(c == EOF)
  4416. {
  4417. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4418. ChargePointMaxProfileIsNull=TRUE;
  4419. fclose(fptr1);
  4420. }
  4421. else
  4422. {
  4423. ChargePointMaxProfileIsNull=FALSE;
  4424. while(fscanf(fptr1, "%s", word) != EOF)
  4425. {
  4426. if(strcmp(word, "chargingProfileId") == 0)
  4427. {
  4428. n_chargingProfile = n_chargingProfile + 1;
  4429. printf("Found\n");
  4430. }
  4431. }
  4432. rewind(fptr1);
  4433. //search Charging Profile Element
  4434. int i= 0;
  4435. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4436. #if 0
  4437. /***********connectorId****************/
  4438. c = 0;
  4439. loc = strstr(sLineWord, "connectorId");
  4440. // printf("loc=%s\n",loc);
  4441. memset(sstr ,0, sizeof(sstr) );
  4442. while (loc[strlen("connectorId")+2+c] != ',')
  4443. {
  4444. sstr[c] = loc[strlen("connectorId")+2+c];
  4445. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4446. c++;
  4447. }
  4448. sstr[c] = '\0';
  4449. tempconnectorIdInt = atoi(sstr);
  4450. #endif
  4451. //***********validFrom**************/
  4452. c = 0;
  4453. loc = strstr(sLineWord, "validFrom");
  4454. //DEBUG_INFO("loc=%s\n",loc);
  4455. memset(sstr ,0, sizeof(sstr) );
  4456. if(loc != NULL)
  4457. {
  4458. while (loc[3+strlen("validFrom")+c] != '\"')
  4459. {
  4460. sstr[c] = loc[3+strlen("validFrom")+c];
  4461. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4462. c++;
  4463. }
  4464. sstr[c] = '\0';
  4465. DEBUG_INFO("validFrom=%s\n",sstr);
  4466. strcpy(tempvalidFromStr,sstr);
  4467. }
  4468. else
  4469. {
  4470. strcpy(tempvalidFromStr,"");
  4471. }
  4472. //**********startSchedule**********/
  4473. c = 0;
  4474. loc = strstr(sLineWord, "startSchedule");
  4475. //DEBUG_INFO("loc=%s\n",loc);
  4476. memset(sstr ,0, sizeof(sstr) );
  4477. while (loc[3+strlen("startSchedule")+c] != '\"')
  4478. {
  4479. sstr[c] = loc[3+strlen("startSchedule")+c];
  4480. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4481. c++;
  4482. }
  4483. sstr[c] = '\0';
  4484. strcpy(tempstartScheduleStr, sstr);
  4485. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4486. //**********chargingRateUnit**********/
  4487. c = 0;
  4488. loc = strstr(sLineWord, "chargingRateUnit");
  4489. memset(sstr ,0, sizeof(sstr) );
  4490. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4491. {
  4492. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4493. c++;
  4494. }
  4495. sstr[c] = '\0';
  4496. strcpy(tempchargingRateUnitStr, sstr);
  4497. //**********minChargingRate*******/
  4498. c = 0;
  4499. loc = strstr(sLineWord, "minChargingRate");
  4500. //printf("loc=%s\n",loc);
  4501. if(loc != NULL)
  4502. {
  4503. memset(sstr ,0, sizeof(sstr) );
  4504. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4505. {
  4506. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4507. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4508. c++;
  4509. }
  4510. sstr[c] = '\0';
  4511. tempminChargingRateFloat = atof(sstr);
  4512. }
  4513. else
  4514. {
  4515. tempminChargingRateFloat = 0.0;
  4516. }
  4517. //
  4518. #if 0
  4519. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4520. tp.tm_isdst = -1;
  4521. time_t utc = mktime(&tp);
  4522. // current time
  4523. time_t t = time(NULL);
  4524. #endif
  4525. //diff_t = difftime(t, utc);
  4526. //parsing strings to words
  4527. i = 0;
  4528. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4529. loc = loc+3+strlen("chargingSchedulePeriod");
  4530. pch = strtok(loc ,"{");
  4531. while (pch != NULL)
  4532. {
  4533. strcpy(SchedulePeriodList[i], pch);
  4534. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4535. //printf ("%s\n",pch);
  4536. pch = strtok (NULL, "{");
  4537. i = i + 1;
  4538. }
  4539. n_SchedulePeriods = i;
  4540. for(int i=0;i<n_SchedulePeriods;i++)
  4541. {
  4542. //*************startPeriod****************/
  4543. c = 0;
  4544. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4545. memset(sstr ,0, sizeof(sstr) );
  4546. while (loc[strlen("startPeriod")+2+c] != ',')
  4547. {
  4548. sstr[c] = loc[strlen("startPeriod")+2+c];
  4549. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4550. c++;
  4551. }
  4552. sstr[c] = '\0';
  4553. tempStartPeriodInt = atoi(sstr);
  4554. //*************limit****************/
  4555. c = 0;
  4556. loc = strstr(SchedulePeriodList[i], "limit");
  4557. memset(sstr ,0, sizeof(sstr) );
  4558. while (loc[strlen("limit")+2+c] != ',')
  4559. {
  4560. sstr[c] = loc[strlen("limit")+2+c];
  4561. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4562. c++;
  4563. }
  4564. sstr[c] = '\0';
  4565. tempLimitInt = atof(sstr);
  4566. //*************numberPhases****************/
  4567. c = 0;
  4568. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4569. memset(sstr ,0, sizeof(sstr) );
  4570. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4571. {
  4572. sstr[c] = loc[strlen("numberPhases")+2+c];
  4573. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4574. c++;
  4575. }
  4576. sstr[c] = '\0';
  4577. tempNumberPhasesInt = atoi(sstr);
  4578. ChargePointMaxProfile.Duration = durationInt;
  4579. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4580. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4581. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4582. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4583. }
  4584. if(MinChargingRate < tempminChargingRateFloat)
  4585. MinChargingRate = tempminChargingRateFloat;
  4586. }
  4587. }// End of file ChargingProfile
  4588. } //THE END OF ACCESS ChargePointMaxProfile
  4589. //******************************TxDefaultProfile***********************************************/
  4590. strcpy(fname, TxDefaultProfile_0_JSON);
  4591. memset(word, 0, 30);
  4592. memset(sLineWord, 0, 1060);
  4593. //char word[30]={0};
  4594. //char sLineWord[1060]={0};
  4595. n_chargingProfile=0;
  4596. TxDefaultProfileFileIsNull=TRUE;
  4597. if((access(fname,F_OK))!=-1)
  4598. {
  4599. fptr1 = fopen(fname, "r");
  4600. c = 0;
  4601. c = fgetc(fptr1);
  4602. //DEBUG_INFO("c:%d\n",c);
  4603. rewind(fptr1);
  4604. if(c == EOF)
  4605. {
  4606. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4607. TxDefaultProfileFileIsNull=TRUE;
  4608. fclose(fptr1);
  4609. }
  4610. else
  4611. {
  4612. TxDefaultProfileFileIsNull=FALSE;
  4613. while(fscanf(fptr1, "%s", word) != EOF)
  4614. {
  4615. if(strcmp(word, "chargingProfileId") == 0)
  4616. {
  4617. n_chargingProfile = n_chargingProfile + 1;
  4618. printf("Found\n");
  4619. }
  4620. }
  4621. rewind(fptr1);
  4622. //search Charging Profile Element
  4623. int i= 0;
  4624. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4625. #if 0
  4626. /***********connectorId****************/
  4627. c = 0;
  4628. loc = strstr(sLineWord, "connectorId");
  4629. // printf("loc=%s\n",loc);
  4630. memset(sstr ,0, sizeof(sstr) );
  4631. while (loc[strlen("connectorId")+2+c] != ',')
  4632. {
  4633. sstr[c] = loc[strlen("connectorId")+2+c];
  4634. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4635. c++;
  4636. }
  4637. sstr[c] = '\0';
  4638. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4639. tempconnectorIdInt = atoi(sstr);
  4640. #endif
  4641. //***********validFrom**************/
  4642. c = 0;
  4643. loc = strstr(sLineWord, "validFrom");
  4644. //DEBUG_INFO("loc=%s\n",loc);
  4645. memset(sstr ,0, sizeof(sstr) );
  4646. if(loc != NULL)
  4647. {
  4648. while (loc[3+strlen("validFrom")+c] != '\"')
  4649. {
  4650. sstr[c] = loc[3+strlen("validFrom")+c];
  4651. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4652. c++;
  4653. }
  4654. sstr[c] = '\0';
  4655. DEBUG_INFO("validFrom=%s\n",sstr);
  4656. strcpy(tempvalidFromStr,sstr);
  4657. }
  4658. else
  4659. {
  4660. strcpy(tempvalidFromStr,"");
  4661. }
  4662. //**********startSchedule**********/
  4663. c = 0;
  4664. loc = strstr(sLineWord, "startSchedule");
  4665. //DEBUG_INFO("loc=%s\n",loc);
  4666. memset(sstr ,0, sizeof(sstr) );
  4667. while (loc[3+strlen("startSchedule")+c] != '\"')
  4668. {
  4669. sstr[c] = loc[3+strlen("startSchedule")+c];
  4670. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4671. c++;
  4672. }
  4673. sstr[c] = '\0';
  4674. strcpy(tempstartScheduleStr, sstr);
  4675. strcpy(TxDefaultProfileScheduleStr, sstr);
  4676. //**********chargingRateUnit**********/
  4677. c = 0;
  4678. loc = strstr(sLineWord, "chargingRateUnit");
  4679. memset(sstr ,0, sizeof(sstr) );
  4680. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4681. {
  4682. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4683. c++;
  4684. }
  4685. sstr[c] = '\0';
  4686. strcpy(tempchargingRateUnitStr, sstr);
  4687. //**********minChargingRate*******/
  4688. c = 0;
  4689. loc = strstr(sLineWord, "minChargingRate");
  4690. //printf("loc=%s\n",loc);
  4691. if(loc != NULL)
  4692. {
  4693. memset(sstr ,0, sizeof(sstr) );
  4694. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4695. {
  4696. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4697. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4698. c++;
  4699. }
  4700. sstr[c] = '\0';
  4701. tempminChargingRateFloat = atof(sstr);
  4702. }
  4703. else
  4704. {
  4705. tempminChargingRateFloat = 0.0;
  4706. }
  4707. #if 0
  4708. //
  4709. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4710. tp.tm_isdst = -1;
  4711. time_t utc = mktime(&tp);
  4712. // current time
  4713. time_t t = time(NULL);
  4714. //diff_t = difftime(t, utc);
  4715. #endif
  4716. //parsing strings to words
  4717. i = 0;
  4718. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4719. loc = loc+3+strlen("chargingSchedulePeriod");
  4720. pch = strtok(loc ,"{");
  4721. while (pch != NULL)
  4722. {
  4723. strcpy(SchedulePeriodList[i], pch);
  4724. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4725. //printf ("%s\n",pch);
  4726. pch = strtok (NULL, "{");
  4727. i = i + 1;
  4728. }
  4729. n_SchedulePeriods = i;
  4730. for(int i=0;i<n_SchedulePeriods;i++)
  4731. {
  4732. //*************startPeriod****************/
  4733. c = 0;
  4734. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4735. memset(sstr ,0, sizeof(sstr) );
  4736. while (loc[strlen("startPeriod")+2+c] != ',')
  4737. {
  4738. sstr[c] = loc[strlen("startPeriod")+2+c];
  4739. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4740. c++;
  4741. }
  4742. sstr[c] = '\0';
  4743. tempStartPeriodInt = atoi(sstr);
  4744. //*************limit****************/
  4745. c = 0;
  4746. loc = strstr(SchedulePeriodList[i], "limit");
  4747. memset(sstr ,0, sizeof(sstr) );
  4748. while (loc[strlen("limit")+2+c] != ',')
  4749. {
  4750. sstr[c] = loc[strlen("limit")+2+c];
  4751. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4752. c++;
  4753. }
  4754. sstr[c] = '\0';
  4755. tempLimitInt = atof(sstr);
  4756. //*************numberPhases****************/
  4757. c = 0;
  4758. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4759. memset(sstr ,0, sizeof(sstr) );
  4760. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4761. {
  4762. sstr[c] = loc[strlen("numberPhases")+2+c];
  4763. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4764. c++;
  4765. }
  4766. sstr[c] = '\0';
  4767. tempNumberPhasesInt = atoi(sstr);
  4768. TxDefaultProfile.Duration = durationInt;
  4769. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4770. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4771. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4772. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4773. }
  4774. if(MinChargingRate < tempminChargingRateFloat)
  4775. MinChargingRate = tempminChargingRateFloat;
  4776. }
  4777. }
  4778. }// the end of ACCESS TxDefaultProfile
  4779. //--------------------- Composite Schedule-----------------------------//
  4780. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4781. {
  4782. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4783. struct tm tp;
  4784. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4785. tp.tm_isdst = -1;
  4786. time_t utc = mktime(&tp);
  4787. time_t t = time(NULL);
  4788. double diff_f = difftime(t, utc);
  4789. int diff_i = (int)diff_f;
  4790. int quotient = diff_i / 86400;//86400 seconds/day
  4791. int period = 0;
  4792. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4793. {
  4794. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4795. {
  4796. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4797. {
  4798. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4799. }
  4800. else
  4801. {
  4802. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  4803. }
  4804. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4805. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4806. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4807. period = period + 1;
  4808. }
  4809. }
  4810. confirmPeriods = period;
  4811. }
  4812. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  4813. {
  4814. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4815. struct tm tp;
  4816. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4817. tp.tm_isdst = -1;
  4818. time_t utc = mktime(&tp);
  4819. time_t t = time(NULL);
  4820. double diff_f = difftime(t, utc);
  4821. int diff_i = (int)diff_f;
  4822. int quotient = diff_i / 86400;//86400 seconds/day
  4823. int period = 0;
  4824. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4825. {
  4826. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  4827. {
  4828. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  4829. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4830. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  4831. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4832. period = period + 1;
  4833. }
  4834. }
  4835. confirmPeriods = period;
  4836. }
  4837. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  4838. {
  4839. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  4840. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  4841. {
  4842. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  4843. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  4844. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  4845. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4846. }
  4847. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  4848. }
  4849. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  4850. {
  4851. confirmPeriods = 0;
  4852. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  4853. goto end;
  4854. }
  4855. //* Define temporary variables */
  4856. struct tm *gtime;
  4857. time_t now;
  4858. char buf[28];
  4859. /* Read the current system time */
  4860. time(&now);
  4861. /* Convert the system time to GMT (now UTC) */
  4862. gtime = gmtime(&now);
  4863. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4864. // make .conf
  4865. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4866. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  4867. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  4868. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4869. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4870. }
  4871. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4872. {
  4873. //*****************************ChargePointMaxProfile******************************************/
  4874. strcpy(fname, ChargePointMaxProfile_JSON);
  4875. ChargePointMaxProfileIsNull=TRUE;
  4876. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4877. {
  4878. fptr1 = fopen(fname, "r");
  4879. int c;
  4880. c = fgetc(fptr1);
  4881. //DEBUG_INFO("c:%d\n",c);
  4882. rewind(fptr1);
  4883. if(c == EOF)
  4884. {
  4885. DEBUG_INFO("\n End of file reached.");
  4886. ChargePointMaxProfileIsNull=TRUE;
  4887. fclose(fptr1);
  4888. }
  4889. else
  4890. {
  4891. ChargePointMaxProfileIsNull=FALSE;
  4892. while(fscanf(fptr1, "%s", word) != EOF)
  4893. {
  4894. if(strcmp(word, "chargingProfileId") == 0)
  4895. {
  4896. n_chargingProfile = n_chargingProfile + 1;
  4897. }
  4898. }
  4899. rewind(fptr1);
  4900. //search Charging Profile Element
  4901. int i = 0;
  4902. int j = 0;
  4903. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4904. #if 0
  4905. /***********connectorId****************/
  4906. c = 0;
  4907. loc = strstr(sLineWord, "connectorId");
  4908. memset(sstr ,0, sizeof(sstr) );
  4909. while (loc[strlen("connectorId")+2+c] != ',')
  4910. {
  4911. sstr[c] = loc[strlen("connectorId")+2+c];
  4912. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4913. c++;
  4914. }
  4915. sstr[c] = '\0';
  4916. tempconnectorIdInt = atoi(sstr);
  4917. #endif
  4918. //***********validFrom**************/
  4919. c = 0;
  4920. loc = strstr(sLineWord, "validFrom");
  4921. if(loc != NULL)
  4922. {
  4923. memset(sstr ,0, sizeof(sstr) );
  4924. while (loc[3+strlen("validFrom")+c] != '\"')
  4925. {
  4926. sstr[c] = loc[3+strlen("validFrom")+c];
  4927. c++;
  4928. }
  4929. sstr[c] = '\0';
  4930. strcpy(tempvalidFromStr,sstr);
  4931. }
  4932. else
  4933. {
  4934. strcpy(tempvalidFromStr,"");
  4935. }
  4936. //***********validFrom**************/
  4937. c = 0;
  4938. loc = strstr(sLineWord, "duration");
  4939. if(loc != NULL)
  4940. {
  4941. memset(sstr ,0, sizeof(sstr) );
  4942. while (loc[2+strlen("duration")+c] != ',')
  4943. {
  4944. sstr[c] = loc[2+strlen("duration")+c];
  4945. c++;
  4946. }
  4947. sstr[c] = '\0';
  4948. tempdurationInt = atoi(sstr);
  4949. }
  4950. else
  4951. {
  4952. tempdurationInt = 0;
  4953. }
  4954. //**********startSchedule**********/
  4955. c = 0;
  4956. loc = strstr(sLineWord, "startSchedule");
  4957. memset(sstr ,0, sizeof(sstr) );
  4958. while (loc[3+strlen("startSchedule")+c] != '\"')
  4959. {
  4960. sstr[c] = loc[3+strlen("startSchedule")+c];
  4961. c++;
  4962. }
  4963. sstr[c] = '\0';
  4964. strcpy(tempstartScheduleStr, sstr);
  4965. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4966. //**********chargingRateUnit**********/
  4967. c = 0;
  4968. loc = strstr(sLineWord, "chargingRateUnit");
  4969. memset(sstr ,0, sizeof(sstr) );
  4970. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4971. {
  4972. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4973. c++;
  4974. }
  4975. sstr[c] = '\0';
  4976. strcpy(tempchargingRateUnitStr, sstr);
  4977. //**********minChargingRate*******/
  4978. c = 0;
  4979. loc = strstr(sLineWord, "minChargingRate");
  4980. if(loc != NULL)
  4981. {
  4982. memset(sstr ,0, sizeof(sstr) );
  4983. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4984. {
  4985. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4986. c++;
  4987. }
  4988. sstr[c] = '\0';
  4989. tempminChargingRateFloat = atof(sstr);
  4990. }
  4991. else
  4992. {
  4993. tempminChargingRateFloat = 0.0;
  4994. }
  4995. #if 0
  4996. //
  4997. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4998. tp.tm_isdst = -1;
  4999. time_t utc = mktime(&tp);
  5000. time_t t = time(NULL);
  5001. //diff_t = difftime(t, utc);
  5002. #endif
  5003. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5004. //DEBUG_INFO(" debug 5 -1\n");
  5005. //parsing strings to words
  5006. i = 0;
  5007. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5008. loc = loc+3+strlen("chargingSchedulePeriod");
  5009. pch = strtok(loc ,"{");
  5010. while (pch != NULL)
  5011. {
  5012. strcpy(SchedulePeriodList[i], pch);
  5013. pch = strtok (NULL, "{");
  5014. i = i + 1;
  5015. }
  5016. n_SchedulePeriods = i;
  5017. for(int i=0;i<n_SchedulePeriods;i++)
  5018. {
  5019. //*************startPeriod****************/
  5020. c = 0;
  5021. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5022. memset(sstr ,0, sizeof(sstr) );
  5023. while (loc[strlen("startPeriod")+2+c] != ',')
  5024. {
  5025. sstr[c] = loc[strlen("startPeriod")+2+c];
  5026. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5027. c++;
  5028. }
  5029. sstr[c] = '\0';
  5030. tempStartPeriodInt = atoi(sstr);
  5031. //*************limit****************/
  5032. c = 0;
  5033. loc = strstr(SchedulePeriodList[i], "limit");
  5034. memset(sstr ,0, sizeof(sstr) );
  5035. while (loc[strlen("limit")+2+c] != ',')
  5036. {
  5037. sstr[c] = loc[strlen("limit")+2+c];
  5038. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5039. c++;
  5040. }
  5041. sstr[c] = '\0';
  5042. tempLimitInt = atof(sstr);
  5043. //*************numberPhases****************/
  5044. c = 0;
  5045. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5046. memset(sstr ,0, sizeof(sstr) );
  5047. while (loc[strlen("numberPhases")+2+c] != '}')
  5048. {
  5049. sstr[c] = loc[strlen("numberPhases")+2+c];
  5050. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5051. c++;
  5052. }
  5053. sstr[c] = '\0';
  5054. tempNumberPhasesInt = atoi(sstr);
  5055. if(j == 0)
  5056. {
  5057. ChargePointMaxProfile.Duration = tempdurationInt;
  5058. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5059. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5060. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5061. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5062. }
  5063. }
  5064. if(MinChargingRate < tempminChargingRateFloat)
  5065. {
  5066. MinChargingRate = tempminChargingRateFloat;
  5067. }
  5068. if(confirmPeriods < n_SchedulePeriods)
  5069. {
  5070. confirmPeriods = n_SchedulePeriods;
  5071. }
  5072. j = j + 1;
  5073. }
  5074. fclose(fptr1);
  5075. }
  5076. }// the end of access file ChargePointMaxProfile
  5077. //****************************TxDefaultProfile************************************************/
  5078. #if 0
  5079. switch(connectorIdInt)
  5080. {
  5081. case 0:
  5082. break;
  5083. case 1:
  5084. strcpy(fname, TxDefaultProfile_1_JSON );
  5085. break;
  5086. case 2:
  5087. strcpy(fname, TxDefaultProfile_2_JSON );
  5088. break;
  5089. default:
  5090. strcpy(fname, TxDefaultProfile_1_JSON );
  5091. break;
  5092. }
  5093. #endif
  5094. memset(fname, 0, sizeof fname);
  5095. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5096. TxDefaultProfileFileIsNull=TRUE;
  5097. if((access(fname,F_OK))!=-1)
  5098. {
  5099. fptr1 = fopen(fname, "r");
  5100. c = 0;
  5101. c = fgetc(fptr1);
  5102. //DEBUG_INFO("c:%d\n",c);
  5103. rewind(fptr1);
  5104. if(c == EOF)
  5105. {
  5106. DEBUG_INFO("\n End of file reached.");
  5107. TxDefaultProfileFileIsNull=TRUE;
  5108. fclose(fptr1);
  5109. }
  5110. else
  5111. {
  5112. TxDefaultProfileFileIsNull=FALSE;
  5113. while(fscanf(fptr1, "%s", word) != EOF)
  5114. {
  5115. if(strcmp(word, "chargingProfileId") == 0)
  5116. {
  5117. n_chargingProfile = n_chargingProfile + 1;
  5118. }
  5119. }
  5120. rewind(fptr1);
  5121. //search Charging Profile Element
  5122. int i = 0;
  5123. int j = 0;
  5124. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5125. //DEBUG_INFO(" 1-1\n");
  5126. #if 0
  5127. /***********connectorId****************/
  5128. c = 0;
  5129. loc = strstr(sLineWord, "connectorId");
  5130. memset(sstr ,0, sizeof(sstr) );
  5131. while (loc[strlen("connectorId")+2+c] != ',')
  5132. {
  5133. sstr[c] = loc[strlen("connectorId")+2+c];
  5134. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5135. c++;
  5136. }
  5137. sstr[c] = '\0';
  5138. tempconnectorIdInt = atoi(sstr);
  5139. #endif
  5140. //***********validFrom**************/
  5141. c = 0;
  5142. loc = strstr(sLineWord, "validFrom");
  5143. if(loc != NULL)
  5144. {
  5145. memset(sstr ,0, sizeof(sstr) );
  5146. while (loc[3+strlen("validFrom")+c] != '\"')
  5147. {
  5148. sstr[c] = loc[3+strlen("validFrom")+c];
  5149. c++;
  5150. }
  5151. sstr[c] = '\0';
  5152. strcpy(tempvalidFromStr,sstr);
  5153. }
  5154. else
  5155. {
  5156. strcpy(tempvalidFromStr,"");
  5157. }
  5158. //***********validFrom**************/
  5159. c = 0;
  5160. loc = strstr(sLineWord, "duration");
  5161. if(loc != NULL)
  5162. {
  5163. memset(sstr ,0, sizeof(sstr) );
  5164. while (loc[2+strlen("duration")+c] != ',')
  5165. {
  5166. sstr[c] = loc[2+strlen("duration")+c];
  5167. c++;
  5168. }
  5169. sstr[c] = '\0';
  5170. tempdurationInt = atoi(sstr);
  5171. }
  5172. else
  5173. {
  5174. tempdurationInt = 0;
  5175. }
  5176. //**********startSchedule**********/
  5177. c = 0;
  5178. loc = strstr(sLineWord, "startSchedule");
  5179. memset(sstr ,0, sizeof(sstr) );
  5180. while (loc[3+strlen("startSchedule")+c] != '\"')
  5181. {
  5182. sstr[c] = loc[3+strlen("startSchedule")+c];
  5183. c++;
  5184. }
  5185. sstr[c] = '\0';
  5186. strcpy(tempstartScheduleStr, sstr);
  5187. strcpy(TxDefaultProfileScheduleStr, sstr);
  5188. //**********chargingRateUnit**********/
  5189. c = 0;
  5190. loc = strstr(sLineWord, "chargingRateUnit");
  5191. memset(sstr ,0, sizeof(sstr) );
  5192. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5193. {
  5194. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5195. c++;
  5196. }
  5197. sstr[c] = '\0';
  5198. strcpy(tempchargingRateUnitStr, sstr);
  5199. //**********minChargingRate*******/
  5200. c = 0;
  5201. loc = strstr(sLineWord, "minChargingRate");
  5202. if(loc != NULL)
  5203. {
  5204. memset(sstr ,0, sizeof(sstr) );
  5205. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5206. {
  5207. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5208. c++;
  5209. }
  5210. sstr[c] = '\0';
  5211. tempminChargingRateFloat = atof(sstr);
  5212. }
  5213. else
  5214. {
  5215. tempminChargingRateFloat = 0.0;
  5216. }
  5217. #if 0
  5218. //
  5219. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5220. tp.tm_isdst = -1;
  5221. time_t utc = mktime(&tp);
  5222. time_t t = time(NULL);
  5223. //diff_t = difftime(t, utc);
  5224. #endif
  5225. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5226. //parsing strings to words
  5227. i = 0;
  5228. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5229. loc = loc+3+strlen("chargingSchedulePeriod");
  5230. pch = strtok(loc ,"{");
  5231. while (pch != NULL)
  5232. {
  5233. strcpy(SchedulePeriodList[i], pch);
  5234. pch = strtok (NULL, "{");
  5235. i = i + 1;
  5236. }
  5237. n_SchedulePeriods = i;
  5238. for(int i=0;i<n_SchedulePeriods;i++)
  5239. {
  5240. //*************startPeriod****************/
  5241. c = 0;
  5242. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5243. memset(sstr ,0, sizeof(sstr) );
  5244. while (loc[strlen("startPeriod")+2+c] != ',')
  5245. {
  5246. sstr[c] = loc[strlen("startPeriod")+2+c];
  5247. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5248. c++;
  5249. }
  5250. sstr[c] = '\0';
  5251. tempStartPeriodInt = atoi(sstr);
  5252. //*************limit****************/
  5253. c = 0;
  5254. loc = strstr(SchedulePeriodList[i], "limit");
  5255. memset(sstr ,0, sizeof(sstr) );
  5256. while (loc[strlen("limit")+2+c] != ',')
  5257. {
  5258. sstr[c] = loc[strlen("limit")+2+c];
  5259. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5260. c++;
  5261. }
  5262. sstr[c] = '\0';
  5263. tempLimitInt = atof(sstr);
  5264. //*************numberPhases****************/
  5265. c = 0;
  5266. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5267. memset(sstr ,0, sizeof(sstr) );
  5268. while (loc[strlen("numberPhases")+2+c] != '}')
  5269. {
  5270. sstr[c] = loc[strlen("numberPhases")+2+c];
  5271. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5272. c++;
  5273. }
  5274. sstr[c] = '\0';
  5275. tempNumberPhasesInt = atoi(sstr);
  5276. if(j == 0)
  5277. {
  5278. TxDefaultProfile.Duration = tempdurationInt;
  5279. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5280. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5281. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5282. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5283. }
  5284. else
  5285. {
  5286. //other stack level charging Profile
  5287. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5288. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5289. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5290. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5291. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5292. }
  5293. }
  5294. if(MinChargingRate < tempminChargingRateFloat)
  5295. MinChargingRate = tempminChargingRateFloat;
  5296. if(confirmPeriods < n_SchedulePeriods)
  5297. confirmPeriods = n_SchedulePeriods;
  5298. j = j + 1;
  5299. //DEBUG_INFO(" 1-2\n");
  5300. }
  5301. fclose(fptr1);
  5302. //Stacking Charging Profiles
  5303. for(int l=0; l <(j-1) ;l++)
  5304. {
  5305. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5306. {
  5307. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5308. {
  5309. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5310. {
  5311. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5312. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5313. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5314. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5315. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5316. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5317. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5318. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5319. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5320. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5321. }
  5322. else
  5323. {
  5324. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5325. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5326. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5327. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5328. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5329. }
  5330. }
  5331. }
  5332. }
  5333. //end of Stacking Charging Profiles
  5334. }
  5335. }// the end of ACCESS TxDefaultProfile
  5336. //****************************TxProfile************************************************/
  5337. #if 0
  5338. switch(connectorIdInt)
  5339. {
  5340. case 0:
  5341. break;
  5342. case 1:
  5343. strcpy(fname, TxProfile_1_JSON );
  5344. break;
  5345. case 2:
  5346. strcpy(fname, TxProfile_2_JSON );
  5347. break;
  5348. default:
  5349. strcpy(fname, TxProfile_1_JSON );
  5350. break;
  5351. }
  5352. #endif
  5353. memset(fname, 0, sizeof fname);
  5354. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5355. TxProfileIsNull=TRUE;
  5356. if((access(fname,F_OK))!=-1)
  5357. {
  5358. fptr1 = fopen(fname, "r");
  5359. c = 0;
  5360. c = fgetc(fptr1);
  5361. //DEBUG_INFO("c:%d\n",c);
  5362. rewind(fptr1);
  5363. if(c == EOF)
  5364. {
  5365. DEBUG_INFO("\n End of file reached.");
  5366. TxProfileIsNull=TRUE;
  5367. fclose(fptr1);
  5368. }
  5369. else
  5370. {
  5371. TxProfileIsNull=FALSE;
  5372. while(fscanf(fptr1, "%s", word) != EOF)
  5373. {
  5374. if(strcmp(word, "chargingProfileId") == 0)
  5375. {
  5376. n_chargingProfile = n_chargingProfile + 1;
  5377. }
  5378. }
  5379. rewind(fptr1);
  5380. //search Charging Profile Element
  5381. int i= 0;
  5382. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5383. #if 0
  5384. /***********connectorId****************/
  5385. c = 0;
  5386. loc = strstr(sLineWord, "connectorId");
  5387. memset(sstr ,0, sizeof(sstr) );
  5388. while (loc[strlen("connectorId")+2+c] != ',')
  5389. {
  5390. sstr[c] = loc[strlen("connectorId")+2+c];
  5391. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5392. c++;
  5393. }
  5394. sstr[c] = '\0';
  5395. tempconnectorIdInt = atoi(sstr);
  5396. #endif
  5397. //***********validFrom**************/
  5398. c = 0;
  5399. loc = strstr(sLineWord, "validFrom");
  5400. if(loc != NULL)
  5401. {
  5402. memset(sstr ,0, sizeof(sstr) );
  5403. while (loc[3+strlen("validFrom")+c] != '\"')
  5404. {
  5405. sstr[c] = loc[3+strlen("validFrom")+c];
  5406. c++;
  5407. }
  5408. sstr[c] = '\0';
  5409. strcpy(tempvalidFromStr,sstr);
  5410. }
  5411. else
  5412. {
  5413. strcpy(tempvalidFromStr,"");
  5414. }
  5415. //**********startSchedule**********/
  5416. c = 0;
  5417. loc = strstr(sLineWord, "startSchedule");
  5418. memset(sstr ,0, sizeof(sstr) );
  5419. while (loc[3+strlen("startSchedule")+c] != '\"')
  5420. {
  5421. sstr[c] = loc[3+strlen("startSchedule")+c];
  5422. c++;
  5423. }
  5424. sstr[c] = '\0';
  5425. strcpy(tempstartScheduleStr, sstr);
  5426. strcpy(TxProfileScheduleStr, sstr);
  5427. //**********chargingRateUnit**********/
  5428. c = 0;
  5429. loc = strstr(sLineWord, "chargingRateUnit");
  5430. memset(sstr ,0, sizeof(sstr) );
  5431. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5432. {
  5433. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5434. c++;
  5435. }
  5436. sstr[c] = '\0';
  5437. strcpy(tempchargingRateUnitStr, sstr);
  5438. //**********minChargingRate*******/
  5439. c = 0;
  5440. loc = strstr(sLineWord, "minChargingRate");
  5441. if(loc != NULL)
  5442. {
  5443. memset(sstr ,0, sizeof(sstr) );
  5444. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5445. {
  5446. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5447. c++;
  5448. }
  5449. sstr[c] = '\0';
  5450. tempminChargingRateFloat = atof(sstr);
  5451. }
  5452. else
  5453. {
  5454. tempminChargingRateFloat = 0.0;
  5455. }
  5456. #if 0
  5457. //
  5458. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5459. tp.tm_isdst = -1;
  5460. time_t utc = mktime(&tp);
  5461. time_t t = time(NULL);
  5462. //diff_t = difftime(t, utc);
  5463. #endif
  5464. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5465. //parsing strings to words
  5466. i = 0;
  5467. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5468. loc = loc+3+strlen("chargingSchedulePeriod");
  5469. pch = strtok(loc ,"{");
  5470. while (pch != NULL)
  5471. {
  5472. strcpy(SchedulePeriodList[i], pch);
  5473. pch = strtok (NULL, "{");
  5474. i = i + 1;
  5475. }
  5476. n_SchedulePeriods = i;
  5477. for(int i=0;i<n_SchedulePeriods;i++)
  5478. {
  5479. //*************startPeriod****************/
  5480. c = 0;
  5481. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5482. memset(sstr ,0, sizeof(sstr) );
  5483. while (loc[strlen("startPeriod")+2+c] != ',')
  5484. {
  5485. sstr[c] = loc[strlen("startPeriod")+2+c];
  5486. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5487. c++;
  5488. }
  5489. sstr[c] = '\0';
  5490. tempStartPeriodInt = atoi(sstr);
  5491. //*************limit****************/
  5492. c = 0;
  5493. loc = strstr(SchedulePeriodList[i], "limit");
  5494. memset(sstr ,0, sizeof(sstr) );
  5495. while (loc[strlen("limit")+2+c] != ',')
  5496. {
  5497. sstr[c] = loc[strlen("limit")+2+c];
  5498. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5499. c++;
  5500. }
  5501. sstr[c] = '\0';
  5502. tempLimitInt = atof(sstr);
  5503. //*************numberPhases****************/
  5504. c = 0;
  5505. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5506. memset(sstr ,0, sizeof(sstr) );
  5507. while (loc[strlen("numberPhases")+2+c] != '}')
  5508. {
  5509. sstr[c] = loc[strlen("numberPhases")+2+c];
  5510. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5511. c++;
  5512. }
  5513. sstr[c] = '\0';
  5514. tempNumberPhasesInt = atoi(sstr);
  5515. TxProfile.Duration = durationInt;
  5516. TxProfile.TotalPeriod = n_SchedulePeriods;
  5517. TxProfile.Period[i].Limit = tempLimitInt;
  5518. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5519. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5520. }
  5521. if(MinChargingRate < tempminChargingRateFloat)
  5522. MinChargingRate = tempminChargingRateFloat;
  5523. if(confirmPeriods < n_SchedulePeriods)
  5524. confirmPeriods = n_SchedulePeriods;
  5525. }
  5526. fclose(fptr1);
  5527. }
  5528. }// the end of ACCESS TxProfile
  5529. //CompositeSchedule
  5530. int period=0;
  5531. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5532. {
  5533. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5534. struct tm tp;
  5535. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5536. tp.tm_isdst = -1;
  5537. time_t utc = mktime(&tp);
  5538. time_t t = time(NULL);
  5539. double diff_f = difftime(t, utc);
  5540. int diff_i = (int)diff_f;
  5541. int quotient = diff_i / 86400;//86400 seconds/day
  5542. //int remainder = diff_i % 86400;
  5543. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5544. {
  5545. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5546. {
  5547. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5548. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5549. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5550. period = period + 1;
  5551. }
  5552. else
  5553. {
  5554. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5555. {
  5556. }
  5557. else
  5558. {
  5559. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5560. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5561. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5562. period = period + 1;
  5563. }
  5564. }
  5565. }
  5566. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5567. {
  5568. 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))
  5569. {
  5570. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5571. {
  5572. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5573. }
  5574. else
  5575. {
  5576. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5577. }
  5578. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5579. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  5580. period = period + 1;
  5581. }
  5582. }
  5583. // Check Last Period
  5584. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5585. {
  5586. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5587. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5588. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5589. period = period + 1;
  5590. }
  5591. }
  5592. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5593. {
  5594. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5595. struct tm tp;
  5596. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5597. tp.tm_isdst = -1;
  5598. time_t utc = mktime(&tp);
  5599. time_t t = time(NULL);
  5600. double diff_f = difftime(t, utc);
  5601. int diff_i = (int)diff_f;
  5602. int quotient = diff_i / 86400;//86400 seconds/day
  5603. //int remainder = diff_i % 86400;
  5604. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5605. {
  5606. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5607. {
  5608. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5609. {
  5610. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5611. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5612. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5613. period = period + 1;
  5614. }
  5615. else
  5616. {
  5617. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5618. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5619. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5620. period = period + 1;
  5621. }
  5622. }
  5623. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5624. {
  5625. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5626. {
  5627. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5628. {
  5629. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5630. {
  5631. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5632. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5633. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5634. period = period + 1;
  5635. }
  5636. else
  5637. {
  5638. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5639. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5640. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5641. period = period + 1;
  5642. }
  5643. }
  5644. }
  5645. }
  5646. }
  5647. }
  5648. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5649. {
  5650. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5651. struct tm tp;
  5652. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5653. tp.tm_isdst = -1;
  5654. time_t utc = mktime(&tp);
  5655. time_t t = time(NULL);
  5656. double diff_f = difftime(t, utc);
  5657. int diff_i = (int)diff_f;
  5658. int quotient = diff_i / 86400;//86400 seconds/day
  5659. //int remainder = diff_i % 86400;
  5660. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5661. {
  5662. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  5663. {
  5664. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5665. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5666. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5667. period = period + 1;
  5668. }
  5669. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  5670. {
  5671. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  5672. {
  5673. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  5674. {
  5675. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5676. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5677. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5678. period = period + 1;
  5679. }
  5680. }
  5681. }
  5682. }
  5683. }
  5684. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  5685. {
  5686. confirmPeriods = 0;
  5687. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5688. goto end;
  5689. }
  5690. confirmPeriods = period;
  5691. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5692. //* Define temporary variables */
  5693. struct tm *gtime;
  5694. time_t now;
  5695. char buf[28];
  5696. //* Read the current system time */
  5697. time(&now);
  5698. //* Convert the system time to GMT (now UTC) */
  5699. gtime = gmtime(&now);
  5700. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5701. // make .conf
  5702. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5703. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5704. //DEBUG_INFO(" debug 11\n");
  5705. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5706. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5707. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5708. }
  5709. else
  5710. {
  5711. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5712. }
  5713. end:
  5714. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5715. return result;
  5716. }
  5717. int handleGetConfigurationRequest(char *uuid, char *payload)
  5718. {
  5719. mtrace();
  5720. int result = FAIL;
  5721. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5722. //struct json_object *jsonitem;
  5723. int MaxKeySupported = 0;
  5724. int n_keys = 0;
  5725. char requestKey[43][50]={0};
  5726. char search[]="[";
  5727. char sstr[500]={ 0 };
  5728. //int pos;
  5729. int l, c = 0;
  5730. int i = 0;
  5731. char *delim = "\",\"";
  5732. char * pch;
  5733. char *loc = strstr(payload, search);
  5734. //********************* Parsing String ***********************************/
  5735. if(loc == NULL) {
  5736. DEBUG_INFO("no key match in Configuration \n");
  5737. }
  5738. else {
  5739. //pos = loc - payload;
  5740. l = strlen(loc)-4;
  5741. while (c < l)
  5742. {
  5743. sstr[c] = loc[c+2];
  5744. c++;
  5745. }
  5746. sstr[c] = '\0';
  5747. //parsing strings to words
  5748. pch = strtok(sstr,delim);
  5749. if(pch == NULL)
  5750. {
  5751. strcpy(requestKey[0], sstr);
  5752. }
  5753. else
  5754. {
  5755. while (pch != NULL)
  5756. {
  5757. strcpy(requestKey[i], pch);
  5758. pch = strtok (NULL, delim);
  5759. i = i + 1;
  5760. }
  5761. n_keys = i;
  5762. }
  5763. }
  5764. UnknownKeynum = 0;
  5765. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5766. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5767. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5768. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5769. if(n_keys != 0)
  5770. {
  5771. for(int i=0;i<n_keys;i++)
  5772. {
  5773. getKeyValue(requestKey[i]);
  5774. //json_object_put(jsonitem);
  5775. }
  5776. }
  5777. else
  5778. {
  5779. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5780. getKeyValue("");
  5781. }
  5782. processUnkownKey();
  5783. sendGetConfigurationConfirmation(uuid);
  5784. return result;
  5785. }
  5786. static char fnamePlusPath[100]={0};
  5787. static char fnamePWithNoPath[60]={0};
  5788. void checkUploadLog(void)
  5789. {
  5790. FILE *fp;
  5791. /* Open the command for reading. */
  5792. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5793. if (fp == NULL) {
  5794. printf("Failed to run command\n" );
  5795. exit(1);
  5796. }
  5797. int ftppathlen = 0;
  5798. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5799. int i = 0;
  5800. /* Read the output a line at a time - output it. */
  5801. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5802. if(i==0)
  5803. {
  5804. ftppathlen = strlen(fnamePlusPath);
  5805. printf("%s\n", fnamePlusPath);
  5806. fnamePlusPath[ftppathlen]='\0';
  5807. break;
  5808. }
  5809. i= i+1;
  5810. }
  5811. /* close */
  5812. pclose(fp);
  5813. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5814. {
  5815. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5816. {
  5817. fnamePlusPath[k]='\0';
  5818. }
  5819. }
  5820. i=1;
  5821. //char fname[60]={0};
  5822. while(i < ftppathlen)
  5823. {
  5824. int len=ftppathlen-i;
  5825. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5826. {
  5827. printf("compare '/' all right\n");
  5828. break;
  5829. }
  5830. i=i+1;
  5831. }
  5832. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5833. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5834. fnamePWithNoPath[i+1] = '\0';
  5835. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5836. {
  5837. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5838. {
  5839. fnamePWithNoPath[j]='\0';
  5840. }
  5841. }
  5842. FILE* fp1 = fopen(fnamePlusPath, "r");
  5843. if (fp1)
  5844. {
  5845. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5846. // file exists
  5847. fclose(fp1);
  5848. }
  5849. else
  5850. {
  5851. // file doesn't exist
  5852. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5853. }
  5854. }
  5855. static char GetDiagnosticspayloadData[300]={0};
  5856. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5857. {
  5858. mtrace();
  5859. int result = FAIL;
  5860. pthread_t t; // pthread 變數
  5861. system("exec /root/logPackTools 'log' 6");
  5862. #if 0
  5863. //char buffer [128];
  5864. time (&rawtime);
  5865. //printf("%ld\n", rawtime);
  5866. timeinfo = localtime (&rawtime);
  5867. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5868. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5869. if((access(fnamePlusPath,F_OK))!=-1)
  5870. {
  5871. DEBUG_INFO("fnamePlusPath exist.\n");
  5872. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5873. }
  5874. else
  5875. {
  5876. DEBUG_INFO("fnamePlusPath not exist!\n");
  5877. }
  5878. #endif
  5879. checkUploadLog();
  5880. memset(GetDiagnosticspayloadData, 0, 300);
  5881. strcpy(GetDiagnosticspayloadData, payload);
  5882. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5883. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5884. return result;
  5885. }
  5886. void* GetDiagnosticsProcess(void* data)
  5887. {
  5888. pthread_detach(pthread_self());
  5889. mtrace();
  5890. int retriesInt=0, retryIntervalInt=0;
  5891. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5892. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5893. 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};
  5894. int port=0;
  5895. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5896. int c = 0;
  5897. char *loc;
  5898. int isSuccess = FALSE;
  5899. char ftpbuf[200]={0};
  5900. //char temp[100]={0};
  5901. char * pch;
  5902. // [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"}]
  5903. char str[300]={ 0 };
  5904. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5905. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5906. DEBUG_INFO("GetDiagnosticsProcess\n");
  5907. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5908. //****************location*******************/
  5909. c = 0;
  5910. memset(sstr ,0, sizeof(sstr) );
  5911. loc = strstr(str, "location");
  5912. while (loc[3+strlen("location")+c] != '\"')
  5913. {
  5914. sstr[c] = loc[3+strlen("location")+c];
  5915. c++;
  5916. }
  5917. sstr[c] = '\0';
  5918. strcpy(locationstr,sstr);
  5919. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5920. if(strcmp(locationstr,"")==0)
  5921. {
  5922. DEBUG_INFO("location is <Empty>!\n");
  5923. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5924. goto end;
  5925. }
  5926. //****************retries*******************/
  5927. c = 0;
  5928. loc = strstr(str, "retries");
  5929. if(loc == NULL)
  5930. {
  5931. retriesIsNULL = TRUE;
  5932. }
  5933. else
  5934. {
  5935. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5936. {
  5937. sstr[c] = loc[strlen("retries")+2+c];
  5938. c++;
  5939. }
  5940. sstr[c] = '\0';
  5941. retriesInt = atoi(sstr);
  5942. }
  5943. if(retriesIsNULL == TRUE)
  5944. {
  5945. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5946. }
  5947. //****************retryInterval*******************/
  5948. c = 0;
  5949. loc = strstr(str, "retryInterval");
  5950. if(loc == NULL)
  5951. {
  5952. retryIntervalIsNULL = TRUE;
  5953. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5954. }
  5955. else
  5956. {
  5957. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5958. {
  5959. sstr[c] = loc[strlen("retryInterval")+2+c];
  5960. c++;
  5961. }
  5962. sstr[c] = '\0';
  5963. retryIntervalInt = atoi(sstr);
  5964. }
  5965. //****************startTime*******************/
  5966. c = 0;
  5967. memset(sstr ,0, sizeof(sstr) );
  5968. loc = strstr(str, "startTime");
  5969. if(loc == NULL)
  5970. {
  5971. startTimeIsNULL = TRUE;
  5972. }
  5973. else
  5974. {
  5975. while (loc[3+strlen("startTime")+c] != '\"')
  5976. {
  5977. sstr[c] = loc[3+strlen("startTime")+c];
  5978. c++;
  5979. }
  5980. sstr[c] = '\0';
  5981. strcpy(startTimestr,sstr);
  5982. }
  5983. //****************stopTime*******************/
  5984. c = 0;
  5985. memset(sstr ,0, sizeof(sstr) );
  5986. loc = strstr(str, "stopTime");
  5987. if(loc == NULL)
  5988. {
  5989. stopTimeIsNULL = TRUE;
  5990. }
  5991. else
  5992. {
  5993. while (loc[3+strlen("stopTime")+c] != '\"')
  5994. {
  5995. sstr[c] = loc[3+strlen("stopTime")+c];
  5996. c++;
  5997. }
  5998. sstr[c] = '\0';
  5999. strcpy(stopTimestr,sstr);
  6000. }
  6001. memset(protocol, 0, sizeof(protocol));
  6002. memset(user, 0, sizeof(user) );
  6003. memset(password, 0, sizeof(password));
  6004. memset(host, 0, sizeof(host));
  6005. memset(path, 0, sizeof(path));
  6006. memset(ftppath, 0, sizeof(ftppath));
  6007. memset(host1, 0, sizeof(host1));
  6008. memset(path1, 0, sizeof(path1));
  6009. /*location: ftp://user:password@host:port/path*/
  6010. #if 0
  6011. time_t rawtime;
  6012. struct tm * timeinfo;
  6013. //char buffer [128];
  6014. time (&rawtime);
  6015. //printf("%ld\n", rawtime);
  6016. timeinfo = localtime (&rawtime);
  6017. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6018. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6019. #endif
  6020. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6021. if((access(fnamePlusPath,F_OK))!=-1)
  6022. {
  6023. DEBUG_INFO("fnamePlusPath exist.\n");
  6024. }
  6025. else
  6026. {
  6027. DEBUG_INFO("fnamePlusPath not exist!\n");
  6028. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6029. goto end;
  6030. }
  6031. pch=strchr(locationstr,'@');
  6032. if(pch==NULL)
  6033. {
  6034. sscanf(locationstr,
  6035. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6036. protocol, host, &port, path);
  6037. strcpy(user,"anonymous");
  6038. strcpy(password,"");
  6039. }
  6040. else
  6041. {
  6042. //DEBUG_INFO("pch=%s\n", pch);
  6043. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6044. protocol, user, password, host, &port, path);
  6045. }
  6046. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6047. {
  6048. DEBUG_INFO("protocol is not ftp/http ! \n");
  6049. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6050. goto end;
  6051. }
  6052. if(strncmp(locationstr,"http", 4) == 0)
  6053. {
  6054. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6055. sprintf(ftppath,"/%s", path);
  6056. do{
  6057. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6058. sleep(retryIntervalInt);
  6059. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6060. if(!isSuccess)
  6061. {
  6062. DEBUG_INFO("Diagnostics fail.\n");
  6063. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6064. }
  6065. else
  6066. {
  6067. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6068. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6069. }
  6070. }
  6071. else
  6072. {
  6073. sscanf(host,"%[^/]%s",host1, path1);
  6074. sprintf(ftppath,"%s", path1);
  6075. int ftppathlen=strlen(ftppath);
  6076. int i=1;
  6077. char filenametemp[50];
  6078. while(i < ftppathlen)
  6079. {
  6080. int len=ftppathlen-i;
  6081. if(ftppath[len]== 47) // '/' ascll code: 47
  6082. {
  6083. DEBUG_INFO("find '/' all right\n");
  6084. break;
  6085. }
  6086. i=i+1;
  6087. }
  6088. memset(filenametemp, 0, sizeof(filenametemp));
  6089. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6090. filenametemp[i+1] = 0;
  6091. memset(ftpbuf, 0, sizeof(ftpbuf));
  6092. if(port == 0)
  6093. port = 21;
  6094. do{
  6095. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6096. sleep(retryIntervalInt);
  6097. }while((!isSuccess)&&(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. end:
  6110. DiagnosticsStatusNotificationStatus = 0; //Idle
  6111. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6112. }
  6113. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6114. {
  6115. mtrace();
  6116. int result = FAIL;
  6117. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6118. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6119. {
  6120. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6121. localversion = -1;
  6122. }
  6123. else
  6124. {
  6125. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6126. OCPP_getListVerion();
  6127. }
  6128. //from db.OCPP_getListVerion
  6129. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6130. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6131. sendGetLocalListVersionConfirmation(uuid,"");
  6132. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6133. return result;
  6134. }
  6135. int handleRemoteStartRequest(char *uuid, char *payload)
  6136. {
  6137. mtrace();
  6138. int result = FAIL;
  6139. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6140. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6141. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6142. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6143. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6144. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6145. int chargingSchedulePeriodCount = 0;
  6146. char sstr[30]={ 0 };//sstr[200]={ 0 };
  6147. int c = 0;
  6148. char *loc;
  6149. char comfirmstr[20]={0};
  6150. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6151. if(server_pending == TRUE)
  6152. {
  6153. return 0;
  6154. }
  6155. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6156. //**********connectorId****************/
  6157. c = 0;
  6158. memset(sstr ,0, sizeof(sstr) );
  6159. loc = strstr(payload, "connectorId");
  6160. if(loc == NULL)
  6161. {
  6162. connectorIdIsNULL = TRUE;
  6163. }
  6164. else
  6165. {
  6166. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6167. {
  6168. sstr[c] = loc[strlen("connectorId")+2+c];
  6169. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6170. c++;
  6171. }
  6172. sstr[c] = '\0';
  6173. connectorIdInt = atoi(sstr);
  6174. }
  6175. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6176. {
  6177. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6178. goto end;
  6179. }
  6180. //****************idTag*******************/
  6181. c = 0;
  6182. memset(sstr ,0, sizeof(sstr) );
  6183. loc = strstr(payload, "idTag");
  6184. while (loc[3+strlen("idTag")+c] != '\"')
  6185. {
  6186. sstr[c] = loc[3+strlen("idTag")+c];
  6187. c++;
  6188. }
  6189. sstr[c] = '\0';
  6190. strcpy(idTagstr,sstr);
  6191. //****************chargingProfile*******************/
  6192. c = 0;
  6193. memset(sstr ,0, sizeof(sstr) );
  6194. loc = strstr(payload, "chargingProfile");
  6195. if(loc == NULL)
  6196. {
  6197. chargingProfileIsNULL = TRUE;
  6198. }
  6199. else
  6200. {
  6201. //****************chargingProfileId*******************/
  6202. c=0;
  6203. loc = strstr(payload, "chargingProfileId");
  6204. memset(sstr ,0, sizeof(sstr) );
  6205. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6206. {
  6207. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6208. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6209. c++;
  6210. }
  6211. sstr[c] = '\0';
  6212. chargingProfileIdInt = atoi(sstr);
  6213. //****************transactionId*******************/
  6214. loc = strstr(payload, "transactionId");
  6215. if(loc == NULL)
  6216. {
  6217. transactionIdIsNULL = TRUE;
  6218. }
  6219. else
  6220. {
  6221. c=0;
  6222. memset(sstr ,0, sizeof(sstr) );
  6223. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6224. {
  6225. sstr[c] = loc[strlen("transactionId")+2+c];
  6226. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6227. c++;
  6228. }
  6229. sstr[c] = '\0';
  6230. transactionIdInt = atoi(sstr);
  6231. }
  6232. //****************stackLevel*******************/
  6233. c=0;
  6234. loc = strstr(payload, "stackLevel");
  6235. memset(sstr ,0, sizeof(sstr) );
  6236. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6237. {
  6238. sstr[c] = loc[strlen("stackLevel")+2+c];
  6239. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6240. c++;
  6241. }
  6242. sstr[c] = '\0';
  6243. stackLevelInt = atoi(sstr);
  6244. //****************chargingProfilePurpose*******************/
  6245. c = 0;
  6246. memset(sstr ,0, sizeof(sstr) );
  6247. loc = strstr(payload, "chargingProfilePurpose");
  6248. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6249. {
  6250. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6251. c++;
  6252. }
  6253. sstr[c] = '\0';
  6254. strcpy(chargingProfilePurposestr,sstr);
  6255. //****************chargingProfileKind*******************/
  6256. c = 0;
  6257. memset(sstr ,0, sizeof(sstr) );
  6258. loc = strstr(payload, "chargingProfileKind");
  6259. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6260. {
  6261. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6262. c++;
  6263. }
  6264. sstr[c] = '\0';
  6265. strcpy(chargingProfileKindstr,sstr);
  6266. //****************recurrencyKind*******************/
  6267. loc = strstr(payload, "recurrencyKind");
  6268. if(loc == NULL)
  6269. {
  6270. recurrencyKindIsNULL = TRUE;
  6271. }
  6272. else
  6273. {
  6274. c = 0;
  6275. memset(sstr ,0, sizeof(sstr) );
  6276. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6277. {
  6278. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6279. c++;
  6280. }
  6281. sstr[c] = '\0';
  6282. strcpy(recurrencyKindstr,sstr);
  6283. }
  6284. //****************validFrom*******************/
  6285. loc = strstr(payload, "validFrom");
  6286. if(loc == NULL)
  6287. {
  6288. validFromIsNULL = TRUE;
  6289. }
  6290. else
  6291. {
  6292. c = 0;
  6293. memset(sstr ,0, sizeof(sstr) );
  6294. while (loc[3+strlen("validFrom")+c] != '\"')
  6295. {
  6296. sstr[c] = loc[3+strlen("validFrom")+c];
  6297. c++;
  6298. }
  6299. sstr[c] = '\0';
  6300. strcpy(validFromstr,sstr);
  6301. }
  6302. //****************validTo*******************/
  6303. loc = strstr(payload, "validTo");
  6304. if(loc == NULL)
  6305. {
  6306. validToIsNULL = TRUE;
  6307. }
  6308. else
  6309. {
  6310. c = 0;
  6311. memset(sstr ,0, sizeof(sstr) );
  6312. while (loc[3+strlen("validTo")+c] != '\"')
  6313. {
  6314. sstr[c] = loc[3+strlen("validTo")+c];
  6315. c++;
  6316. }
  6317. sstr[c] = '\0';
  6318. strcpy(validTostr,sstr);
  6319. }
  6320. //****************chargingSchedule*******************/
  6321. loc = strstr(payload, "chargingSchedule");
  6322. if(loc != NULL)
  6323. {
  6324. //****************duration*******************/
  6325. loc = strstr(payload, "duration");
  6326. if(loc == NULL)
  6327. {
  6328. durationIsNULL = TRUE;
  6329. }
  6330. else
  6331. {
  6332. c=0;
  6333. memset(sstr ,0, sizeof(sstr) );
  6334. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6335. {
  6336. sstr[c] = loc[strlen("duration")+2+c];
  6337. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6338. c++;
  6339. }
  6340. sstr[c] = '\0';
  6341. durationInt = atoi(sstr);
  6342. }
  6343. //****************startSchedule******************/
  6344. loc = strstr(payload, "startSchedule");
  6345. if(loc == NULL)
  6346. {
  6347. startScheduleIsNULL = TRUE;
  6348. }
  6349. else
  6350. {
  6351. c = 0;
  6352. memset(sstr ,0, sizeof(sstr) );
  6353. while (loc[3+strlen("startSchedule")+c] != '\"')
  6354. {
  6355. sstr[c] = loc[3+strlen("startSchedule")+c];
  6356. c++;
  6357. }
  6358. sstr[c] = '\0';
  6359. strcpy(startSchedulestr,sstr);
  6360. }
  6361. //****************chargingRateUnit*******************/
  6362. c = 0;
  6363. memset(sstr ,0, sizeof(sstr) );
  6364. loc = strstr(payload, "chargingRateUnit");
  6365. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6366. {
  6367. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6368. c++;
  6369. }
  6370. sstr[c] = '\0';
  6371. strcpy(chargingRateUnitstr,sstr);
  6372. //****************minChargingRate*******************/
  6373. loc = strstr(payload, "minChargingRate");
  6374. if(loc == NULL)
  6375. {
  6376. minChargingRateIsNULL = TRUE;
  6377. }
  6378. else
  6379. {
  6380. c=0;
  6381. memset(sstr ,0, sizeof(sstr) );
  6382. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6383. {
  6384. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6385. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6386. c++;
  6387. }
  6388. sstr[c] = '\0';
  6389. minChargingRateflaot = atof(sstr);
  6390. }
  6391. //****************chargingSchedulePeriod count*******************/
  6392. int what_len = strlen("startPeriod");
  6393. char *where = payload;
  6394. while ((where = strstr(where, "startPeriod"))) {
  6395. where += what_len;
  6396. chargingSchedulePeriodCount++;
  6397. }
  6398. where = payload;
  6399. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6400. {
  6401. //****************startPeriod*******************/
  6402. c=0;
  6403. loc = strstr(where, "startPeriod");
  6404. memset(sstr ,0, sizeof(sstr) );
  6405. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6406. {
  6407. sstr[c] = loc[strlen("startPeriod")+2+c];
  6408. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6409. c++;
  6410. }
  6411. sstr[c] = '\0';
  6412. startPeriodInt[periodNums] = atoi(sstr);
  6413. //****************limit*******************/
  6414. c=0;
  6415. loc = strstr(where, "limit");
  6416. memset(sstr ,0, sizeof(sstr) );
  6417. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6418. {
  6419. sstr[c] = loc[strlen("limit")+2+c];
  6420. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6421. c++;
  6422. }
  6423. sstr[c] = '\0';
  6424. limitflaot[periodNums] = atof(sstr);
  6425. //****************numberPhases*******************/
  6426. loc = strstr(where, "numberPhases");
  6427. if(loc == NULL)
  6428. {
  6429. numberPhasesIsNULL = TRUE;
  6430. }
  6431. else
  6432. {
  6433. c=0;
  6434. memset(sstr ,0, sizeof(sstr) );
  6435. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6436. {
  6437. sstr[c] = loc[strlen("numberPhases")+2+c];
  6438. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6439. c++;
  6440. }
  6441. sstr[c] = '\0';
  6442. numberPhasesInt[periodNums] = atoi(sstr);
  6443. }
  6444. where = loc;
  6445. }
  6446. }
  6447. }
  6448. /*
  6449. enum _SYSTEM_STATUS
  6450. {
  6451. S_BOOTING = 0,
  6452. S_IDLE, = 1
  6453. S_AUTHORIZING, =2
  6454. S_REASSIGN_CHECK, =3
  6455. S_REASSIGN, =4
  6456. S_PRECHARGE, =5
  6457. S_PREPARING_FOR_EV, =6
  6458. S_PREPARING_FOR_EVSE, =7
  6459. S_CHARGING, =8
  6460. S_TERMINATING, =9
  6461. S_COMPLETE, =10
  6462. S_ALARM, =11
  6463. S_FAULT =12
  6464. }
  6465. */
  6466. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6467. {
  6468. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6469. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6470. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6471. //check Transaction active
  6472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6473. {
  6474. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6475. {
  6476. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6477. {
  6478. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6479. {
  6480. //Reserved
  6481. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6482. }
  6483. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6484. {
  6485. //Reserved
  6486. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6487. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6488. goto end;
  6489. }
  6490. else
  6491. {
  6492. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6493. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6494. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6495. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6496. {
  6497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6498. goto end;
  6499. }
  6500. }//END FOR ELSE
  6501. }
  6502. }// END FOR CHAdeMO_QUANTITY
  6503. for (int index = 0; index < CCS_QUANTITY; index++)
  6504. {
  6505. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6506. {
  6507. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6508. {
  6509. //Reserved
  6510. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6511. }
  6512. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6513. {
  6514. //Reserved
  6515. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6516. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6517. goto end;
  6518. }
  6519. else
  6520. {
  6521. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6522. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6523. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6524. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6525. {
  6526. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6527. goto end;
  6528. }
  6529. }// END FOR ELSE
  6530. }
  6531. }// END FOR CCS_QUANTITY
  6532. for (int index = 0; index < GB_QUANTITY; index++)
  6533. {
  6534. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6535. {
  6536. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6537. {
  6538. //Reserved
  6539. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6540. }
  6541. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6542. {
  6543. //Reserved
  6544. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6545. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6546. goto end;
  6547. }
  6548. else
  6549. {
  6550. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6551. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6552. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6553. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6554. {
  6555. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6556. goto end;
  6557. }
  6558. }// END FOR ELSE
  6559. }
  6560. } // END FOR GB_QUANTITY
  6561. }
  6562. else
  6563. {
  6564. for (int index = 0; index < AC_QUANTITY; index++)
  6565. {
  6566. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6567. {
  6568. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6569. {
  6570. //Reserved
  6571. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6572. }
  6573. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6574. {
  6575. //Reserved
  6576. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6577. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6578. goto end;
  6579. }
  6580. else
  6581. {
  6582. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6583. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6584. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6585. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6586. {
  6587. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6588. goto end;
  6589. }
  6590. }//END FOR ELSE
  6591. }
  6592. }// END FOR AC_QUANTITY
  6593. }
  6594. if(chargingProfileIsNULL == FALSE)
  6595. {
  6596. //ChargingProfile
  6597. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6598. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6599. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6600. if(recurrencyKindIsNULL == FALSE) //OPTION
  6601. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6602. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6603. if(transactionIdIsNULL == FALSE) // OPTION
  6604. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6605. if(validFromIsNULL == FALSE) // OPTION
  6606. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6607. if(validToIsNULL == FALSE) //OPTION
  6608. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6609. //ChargingSchedule
  6610. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6611. if(durationIsNULL == FALSE) //OPTION
  6612. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6613. if(minChargingRateIsNULL == FALSE) //OPTION
  6614. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6615. if(startScheduleIsNULL == FALSE) //OPTION
  6616. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6617. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6618. {
  6619. //ChargingSchedulePeriod
  6620. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6621. if(numberPhasesIsNULL == FALSE)
  6622. {
  6623. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6624. }
  6625. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6626. }
  6627. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6628. {
  6629. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6630. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6631. //memset idTag
  6632. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6633. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6634. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6635. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6636. }
  6637. else
  6638. {
  6639. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6640. }
  6641. }
  6642. else
  6643. {
  6644. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6645. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6646. //memset idTag
  6647. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6648. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6649. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6650. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6651. }
  6652. }
  6653. else
  6654. {
  6655. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6656. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6657. }
  6658. end:
  6659. if(connectorIdIsNULL == FALSE)
  6660. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6661. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6662. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6663. //OCPP send RemoteStartConfirmation by first.
  6664. sendRemoteStartConfirmation(uuid, comfirmstr);
  6665. return result;
  6666. }
  6667. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6668. {
  6669. mtrace();
  6670. int result = FAIL;
  6671. int match = FALSE;
  6672. int GunNO = 0;
  6673. int transactionIdInt=0;
  6674. int transactionIdIsNULL= FALSE;
  6675. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6676. int c = 0;
  6677. char *loc;
  6678. char comfirmstr[20];
  6679. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6680. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6681. if(server_pending == TRUE)
  6682. {
  6683. return 0;
  6684. }
  6685. c=0;
  6686. loc = strstr(payload, "transactionId");
  6687. if(loc == NULL)
  6688. {
  6689. transactionIdIsNULL= TRUE;
  6690. }
  6691. else
  6692. {
  6693. memset(sstr ,0, sizeof(sstr) );
  6694. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6695. {
  6696. sstr[c] = loc[strlen("transactionId")+2+c];
  6697. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6698. c++;
  6699. }
  6700. sstr[c] = '\0';
  6701. transactionIdInt = atoi(sstr);
  6702. }
  6703. if(transactionIdIsNULL == FALSE)
  6704. {
  6705. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6706. {
  6707. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6708. {
  6709. //check Transaction active
  6710. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6711. {
  6712. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6713. {
  6714. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6715. {
  6716. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6717. {
  6718. match = TRUE;
  6719. GunNO = gun_index;
  6720. }
  6721. }
  6722. }// END FOR CHAdeMO_QUANTITY
  6723. for (int index = 0; index < CCS_QUANTITY; index++)
  6724. {
  6725. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6726. {
  6727. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6728. {
  6729. match = TRUE;
  6730. GunNO = gun_index;
  6731. }
  6732. }
  6733. }// END FOR CCS_QUANTITY
  6734. for (int index = 0; index < GB_QUANTITY; index++)
  6735. {
  6736. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6737. {
  6738. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6739. {
  6740. match = TRUE;
  6741. GunNO = gun_index;
  6742. }
  6743. }
  6744. }// END FOR GB_QUANTITY
  6745. }
  6746. else
  6747. {
  6748. for (int index = 0; index < AC_QUANTITY; index++)
  6749. {
  6750. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6751. {
  6752. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6753. {
  6754. match = TRUE;
  6755. GunNO = gun_index;
  6756. }
  6757. }
  6758. }// END FOR CHAdeMO_QUANTITY
  6759. }// END FOR AC ELSE
  6760. }// CHECK IF ResponseTransactionId == transactionIdInt
  6761. }//END FOR
  6762. if( match == TRUE)
  6763. {
  6764. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6765. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6766. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6767. }
  6768. else
  6769. {
  6770. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6771. }
  6772. }
  6773. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6774. return result;
  6775. }
  6776. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6777. {
  6778. mtrace();
  6779. int result = FAIL;
  6780. int connectorIdInt=0, reservationIdInt=0;
  6781. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6782. char comfirmstr[20]={0};
  6783. char sstr[180]={ 0 };
  6784. int c = 0;
  6785. char *loc;
  6786. //char *ptr;
  6787. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6788. //***(1)connectorId ****/
  6789. c=0;
  6790. loc = strstr(payload, "connectorId");
  6791. memset(sstr ,0, sizeof(sstr) );
  6792. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6793. {
  6794. sstr[c] = loc[strlen("connectorId")+2+c];
  6795. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6796. c++;
  6797. }
  6798. sstr[c] = '\0';
  6799. connectorIdInt = atoi(sstr);
  6800. //***(2)expiryDate ****/
  6801. loc = strstr(payload, "expiryDate");
  6802. memset(sstr ,0, sizeof(sstr) );
  6803. c = 0;
  6804. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6805. {
  6806. sstr[c] = loc[3+strlen("expiryDate")+c];
  6807. c++;
  6808. }
  6809. sstr[c] = '\0';
  6810. strcpy(expiryDatestr, sstr);
  6811. //***(3)idTag ****/
  6812. loc = strstr(payload, "idTag");
  6813. memset(sstr ,0, sizeof(sstr) );
  6814. c = 0;
  6815. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6816. {
  6817. sstr[c] = loc[3+strlen("idTag")+c];
  6818. c++;
  6819. }
  6820. sstr[c] = '\0';
  6821. strcpy(idTagstr, sstr);
  6822. //***(4)parentIdTag ****/
  6823. loc = strstr(payload, "parentIdTag");
  6824. memset(sstr ,0, sizeof(sstr) );
  6825. c = 0;
  6826. if(loc == NULL)
  6827. {
  6828. strcpy(parentIdTagstr, "");
  6829. }
  6830. else
  6831. {
  6832. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6833. {
  6834. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6835. c++;
  6836. }
  6837. sstr[c] = '\0';
  6838. strcpy(parentIdTagstr, sstr);
  6839. }
  6840. //***(5)reservationId ****/
  6841. c=0;
  6842. loc = strstr(payload, "reservationId");
  6843. memset(sstr ,0, sizeof(sstr) );
  6844. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6845. {
  6846. sstr[c] = loc[strlen("reservationId")+2+c];
  6847. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6848. c++;
  6849. }
  6850. sstr[c] = '\0';
  6851. reservationIdInt = atoi(sstr);
  6852. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6853. /*
  6854. enum SYSTEM_STATUS
  6855. {
  6856. SYS_MODE_BOOTING = 0,
  6857. SYS_MODE_IDLE = 1,
  6858. SYS_MODE_AUTHORIZING = 2,
  6859. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6860. SYS_MODE_REASSIGN = 4,
  6861. SYS_MODE_PREPARING = 5,
  6862. SYS_MODE_PREPARE_FOR_EV = 6,
  6863. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6864. SYS_MODE_CHARGING = 8,
  6865. SYS_MODE_TERMINATING = 9,
  6866. SYS_MODE_COMPLETE = 10,
  6867. SYS_MODE_ALARM = 11,
  6868. SYS_MODE_FAULT = 12,
  6869. SYS_MODE_RESERVATION = 13,
  6870. SYS_MODE_BOOKING = 14,
  6871. SYS_MODE_MAINTAIN = 15,
  6872. SYS_MODE_DEBUG = 16,
  6873. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6874. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6875. SYS_MODE_UPDATE = 19
  6876. };
  6877. */
  6878. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6879. {
  6880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6881. goto end;
  6882. }
  6883. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6884. {
  6885. //check Transaction active
  6886. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6887. {
  6888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6889. {
  6890. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6891. {
  6892. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6893. {
  6894. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6895. {
  6896. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6897. {
  6898. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6899. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6900. }
  6901. 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'))
  6902. {
  6903. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6904. }
  6905. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6906. {
  6907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6908. }
  6909. else
  6910. {
  6911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6912. }
  6913. }
  6914. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6915. {
  6916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6917. }
  6918. }
  6919. else
  6920. {
  6921. //replace reservation
  6922. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6924. }
  6925. }
  6926. } // END FOR CHAdeMO_QUANTITY
  6927. for (int index = 0; index < CCS_QUANTITY; index++)
  6928. {
  6929. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6930. {
  6931. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6932. {
  6933. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6934. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6935. {
  6936. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6937. {
  6938. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6940. }
  6941. 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'))
  6942. {
  6943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6944. }
  6945. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6946. {
  6947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6948. }
  6949. else
  6950. {
  6951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6952. }
  6953. }
  6954. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6955. {
  6956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6957. }
  6958. }
  6959. else
  6960. {
  6961. //replace reservation
  6962. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6963. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6964. }
  6965. }
  6966. } // END FOR CCS_QUANTITY
  6967. for (int index = 0; index < GB_QUANTITY; index++)
  6968. {
  6969. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6970. {
  6971. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6972. {
  6973. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6974. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6975. {
  6976. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6977. {
  6978. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6980. }
  6981. 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'))
  6982. {
  6983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6984. }
  6985. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6986. {
  6987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6988. }
  6989. else
  6990. {
  6991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6992. }
  6993. }
  6994. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6995. {
  6996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6997. }
  6998. }
  6999. else
  7000. {
  7001. //replace reservation
  7002. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7004. }
  7005. }
  7006. }// END FOR GB_QUANTITY
  7007. }
  7008. else
  7009. {
  7010. for (int index = 0; index < AC_QUANTITY; index++)
  7011. {
  7012. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  7013. {
  7014. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7015. {
  7016. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7017. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  7018. {
  7019. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7020. {
  7021. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7023. }
  7024. 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'))
  7025. {
  7026. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7027. }
  7028. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7029. {
  7030. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7031. }
  7032. else
  7033. {
  7034. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7035. }
  7036. }
  7037. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7038. {
  7039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7040. }
  7041. }
  7042. else
  7043. {
  7044. //replace reservation
  7045. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7046. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7047. }
  7048. }
  7049. } // END FOR AC_QUANTITY
  7050. }//END FOR AC ELSE
  7051. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7052. }
  7053. else if(connectorIdInt == 0)
  7054. {
  7055. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7056. {
  7057. //check Transaction active
  7058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7059. {
  7060. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7061. {
  7062. 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'))
  7063. {
  7064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7065. goto end;
  7066. }
  7067. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7068. {
  7069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7070. goto end;
  7071. }
  7072. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7073. {
  7074. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7075. goto end;
  7076. }
  7077. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7078. {
  7079. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7080. goto end;
  7081. }
  7082. }
  7083. }// END FOR CHAdeMO_QUANTITY
  7084. for (int index = 0; index < CCS_QUANTITY; index++)
  7085. {
  7086. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7087. {
  7088. 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'))
  7089. {
  7090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7091. }
  7092. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7093. {
  7094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7095. }
  7096. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7097. {
  7098. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7099. }
  7100. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7101. {
  7102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7103. }
  7104. }
  7105. } // END FOR CCS_QUANTITY
  7106. for (int index = 0; index < GB_QUANTITY; index++)
  7107. {
  7108. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7109. {
  7110. 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'))
  7111. {
  7112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7113. }
  7114. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7115. {
  7116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7117. }
  7118. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7119. {
  7120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7121. }
  7122. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7123. {
  7124. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7125. }
  7126. }
  7127. } // END FOR GB_QUANTITY
  7128. }
  7129. else
  7130. {
  7131. for (int index = 0; index < AC_QUANTITY; index++)
  7132. {
  7133. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7134. {
  7135. 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'))
  7136. {
  7137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7138. goto end;
  7139. }
  7140. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7141. {
  7142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7143. goto end;
  7144. }
  7145. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7146. {
  7147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7148. goto end;
  7149. }
  7150. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7151. {
  7152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7153. goto end;
  7154. }
  7155. }
  7156. }// END FOR AC_QUANTITY
  7157. }
  7158. //The connectorId is 0
  7159. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7160. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7161. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7162. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7163. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7164. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7165. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7166. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7167. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7168. result = TRUE;
  7169. return result;
  7170. }
  7171. else
  7172. {
  7173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7174. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7175. }
  7176. if(strcmp(comfirmstr,"Accepted") == 0)
  7177. {
  7178. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7179. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7180. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7181. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7182. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7183. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7184. result = TRUE;
  7185. return result;
  7186. }
  7187. end:
  7188. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7189. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7190. return result;
  7191. }
  7192. int handleResetRequest(char *uuid, char *payload)
  7193. {
  7194. mtrace();
  7195. int result = FAIL;
  7196. char sstr[10]={0};
  7197. char typestr[10]={0};
  7198. char comfirmstr[20]={0};
  7199. int c = 0;
  7200. char *loc;
  7201. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7202. DEBUG_INFO("handleResetRequest ...\n");
  7203. loc = strstr(payload, "type");
  7204. memset(sstr ,0, sizeof(sstr) );
  7205. c = 0;
  7206. while (loc[3+strlen("type")+c] != '\"')
  7207. {
  7208. sstr[c] = loc[3+strlen("type")+c];
  7209. c++;
  7210. }
  7211. sstr[c] = '\0';
  7212. strcpy(typestr,sstr);
  7213. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7214. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7215. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7216. {
  7217. //check Transaction active
  7218. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7219. {
  7220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7221. {
  7222. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7223. {
  7224. //0: unplug, 1: Plug-in
  7225. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7226. }
  7227. }
  7228. for (int index = 0; index < CCS_QUANTITY; index++)
  7229. {
  7230. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7231. {
  7232. //0: unplug, 1: Plug-in
  7233. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7234. }
  7235. }
  7236. for (int index = 0; index < GB_QUANTITY; index++)
  7237. {
  7238. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7239. {
  7240. //0: unplug, 1: Plug-in
  7241. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7242. }
  7243. }
  7244. }
  7245. else
  7246. {
  7247. for (int index = 0; index < AC_QUANTITY; index++)
  7248. {
  7249. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7250. {
  7251. //0: unplug, 1: Plug-in
  7252. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7253. }
  7254. }
  7255. }// END FOR AC ELSE
  7256. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7257. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7258. result = TRUE;
  7259. return result;
  7260. }
  7261. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7262. {
  7263. //check Transaction active
  7264. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7265. {
  7266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7267. {
  7268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7269. {
  7270. //0: unplug, 1: Plug-in
  7271. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7272. }
  7273. }
  7274. for (int index = 0; index < CCS_QUANTITY; index++)
  7275. {
  7276. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7277. {
  7278. //0: unplug, 1: Plug-in
  7279. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7280. }
  7281. }
  7282. for (int index = 0; index < GB_QUANTITY; index++)
  7283. {
  7284. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7285. {
  7286. //0: unplug, 1: Plug-in
  7287. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7288. }
  7289. }
  7290. }
  7291. else
  7292. {
  7293. for (int index = 0; index < AC_QUANTITY; index++)
  7294. {
  7295. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7296. {
  7297. //0: unplug, 1: Plug-in
  7298. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7299. }
  7300. }
  7301. }// END FOR AC ELSE
  7302. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7303. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7304. result = TRUE;
  7305. return result;
  7306. }
  7307. else
  7308. {
  7309. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7310. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7311. goto errorend;
  7312. }
  7313. errorend:
  7314. sendResetConfirmation(uuid, comfirmstr);
  7315. return result;
  7316. }
  7317. int handleSendLocalListRequest(char *uuid, char *payload)
  7318. {
  7319. mtrace();
  7320. int result = FAIL;
  7321. int listVersionInt;
  7322. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7323. char listsearch[]="listVersion";
  7324. char updateTypesearch[]="updateType";
  7325. char localAuthorizationListsearch[]="localAuthorizationList";
  7326. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7327. char CardList[500][160]={0};
  7328. char updateTypestr[15]={0};
  7329. char idTagstr[20]={0};
  7330. char parentIdTag[20]={0};
  7331. char expiryDate[30]={0};
  7332. char idTagstatus[16]={0};
  7333. int c = 0;
  7334. int i = 0;
  7335. char *delim1 = "}";
  7336. char * pch;
  7337. char *loc;
  7338. //char *ptr;
  7339. char comfirmstr[20];
  7340. //int n_localAuthorizations = 0;
  7341. int checkState_Faulted = FALSE;
  7342. DEBUG_INFO("handleSendLocalListRequest\n");
  7343. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7344. {
  7345. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7346. goto end;
  7347. }
  7348. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7349. {
  7350. //check Charge Point state
  7351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7352. {
  7353. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7354. {
  7355. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7356. }
  7357. }
  7358. for (int index = 0; index < CCS_QUANTITY; index++)
  7359. {
  7360. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7361. {
  7362. checkState_Faulted = TRUE; //OCPP Status
  7363. }
  7364. }
  7365. for (int index = 0; index < GB_QUANTITY; index++)
  7366. {
  7367. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7368. {
  7369. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7370. }
  7371. }
  7372. }
  7373. else
  7374. {
  7375. //check Charge Point state
  7376. for (int index = 0; index < AC_QUANTITY; index++)
  7377. {
  7378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7379. {
  7380. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7381. }
  7382. }
  7383. }// END FOR AC ELSE
  7384. if(checkState_Faulted == TRUE)
  7385. {
  7386. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7387. goto end;
  7388. }
  7389. //listVersion
  7390. c = 0;
  7391. loc = strstr(payload, listsearch);
  7392. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7393. {
  7394. sstr[c] = loc[strlen("listVersion")+2+c];
  7395. c++;
  7396. }
  7397. sstr[c] = '\0';
  7398. listVersionInt = atoi(sstr);
  7399. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7400. //updateType
  7401. loc = strstr(payload, updateTypesearch);
  7402. c = 0;
  7403. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7404. {
  7405. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7406. c++;
  7407. }
  7408. sstr[c] = '\0';
  7409. strcpy(updateTypestr, sstr);
  7410. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7411. //localAuthorizationList
  7412. memset(sstr ,0, sizeof(sstr) );
  7413. loc = strstr(payload, localAuthorizationListsearch);
  7414. if(loc != NULL) // localAuthorizationList is not NULL
  7415. {
  7416. //Check UpdateType
  7417. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7418. {
  7419. //Local list full update
  7420. printf("Local list full update.\n");
  7421. OCPP_cleanLocalList();
  7422. }
  7423. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7424. {
  7425. //Local list different update
  7426. printf("Local list different update.\n");
  7427. OCPP_getListVerion();
  7428. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7429. {
  7430. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7431. goto end;
  7432. }
  7433. }
  7434. else
  7435. {
  7436. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7437. goto end;
  7438. }
  7439. c = 0;
  7440. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7441. {
  7442. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7443. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7444. c++;
  7445. }
  7446. sstr[c] = '\0';
  7447. //DEBUG_INFO("sstr=%s\n", sstr);
  7448. //parsing strings to words
  7449. i = 0;
  7450. pch = strtok(sstr,delim1);
  7451. while (pch != NULL)
  7452. {
  7453. strcpy(CardList[i], pch);
  7454. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7455. pch = strtok (NULL, delim1);
  7456. i = i + 1;
  7457. }
  7458. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7459. //local Authorizations List Numbers
  7460. //n_localAuthorizations = i;
  7461. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7462. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7463. c= 0;
  7464. while(c < i)
  7465. {
  7466. //Search "IdToken"
  7467. memset(sstr ,0, sizeof(sstr) );
  7468. loc = strstr(CardList[c], "idTag");
  7469. int j = 0;
  7470. while (loc[3+strlen("idTag")+j] != '\"')
  7471. {
  7472. sstr[j] = loc[3+strlen("idTag")+j];
  7473. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7474. j++;
  7475. }
  7476. sstr[j] = '\0';
  7477. strcpy(idTagstr, sstr);
  7478. DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7479. //Search "expiryDate"
  7480. memset(sstr ,0, sizeof(sstr) );
  7481. loc = strstr(CardList[c], "expiryDate");
  7482. j = 0;
  7483. if(loc != NULL)
  7484. {
  7485. while (loc[3+strlen("expiryDate")+j] != '\"')
  7486. {
  7487. sstr[j] = loc[3+strlen("expiryDate")+j];
  7488. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7489. j++;
  7490. }
  7491. sstr[j] = '\0';
  7492. strcpy(expiryDate, sstr);
  7493. }
  7494. else
  7495. {
  7496. strcpy(expiryDate, "");
  7497. }
  7498. DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7499. //Search "parentIdTag"
  7500. memset(sstr ,0, sizeof(sstr) );
  7501. loc = strstr(CardList[c], "parentIdTag");
  7502. j = 0;
  7503. if(loc != NULL)
  7504. {
  7505. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7506. {
  7507. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7508. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7509. j++;
  7510. }
  7511. sstr[j] = '\0';
  7512. strcpy(parentIdTag, sstr);
  7513. }
  7514. else
  7515. {
  7516. strcpy(parentIdTag, "");
  7517. }
  7518. DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7519. //Search "status"
  7520. memset(sstr ,0, sizeof(sstr) );
  7521. loc = strstr(CardList[c], "status");
  7522. j = 0;
  7523. while (loc[3+strlen("status")+j] != '\"')
  7524. {
  7525. sstr[j] = loc[3+strlen("status")+j];
  7526. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7527. j++;
  7528. }
  7529. sstr[j] = '\0';
  7530. strcpy(idTagstatus, sstr);
  7531. DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7532. OCPP_getIdTag(idTagstr);
  7533. //OCPP_getIdTag("test"); For Test
  7534. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7535. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7536. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7537. {
  7538. //Local list full update
  7539. DEBUG_INFO("Local list full update.\n");
  7540. // update list
  7541. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7542. //DEBUG_INFO("Local list full update. 1\n");
  7543. //OCPP_get_TableAuthlocalAllData();
  7544. //DEBUG_INFO("Local list full update. 2\n");
  7545. }
  7546. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7547. {
  7548. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7549. {
  7550. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7551. }
  7552. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7553. {
  7554. OCPP_deleteIdTag(idTagstr);
  7555. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7556. //OCPP_deleteIdTag(idTagstr);
  7557. }
  7558. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7559. {
  7560. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7561. }
  7562. }
  7563. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7564. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7565. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7566. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7567. c++;
  7568. }
  7569. }
  7570. else
  7571. {
  7572. //Check UpdateType
  7573. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7574. {
  7575. //Local list full update
  7576. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7577. OCPP_cleanLocalList();
  7578. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7579. goto end;
  7580. }
  7581. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7582. {
  7583. //Local list different update
  7584. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7585. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7586. goto end;
  7587. }
  7588. }
  7589. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7590. end:
  7591. sendSendLocalListConfirmation(uuid, comfirmstr);
  7592. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7593. return result;
  7594. }
  7595. #define MAX 200
  7596. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7597. {
  7598. mtrace();
  7599. int result = FAIL;
  7600. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7601. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7602. char chargingProfilePurposeStr[30]={0};
  7603. char chargingProfileKindStr[16]={0};
  7604. char recurrencyKindStr[10]={0};
  7605. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7606. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7607. int chargingSchedulePeriodCount = 0;
  7608. //int updateflag = FALSE;
  7609. char comfirmstr[20]={0};
  7610. int meet= FALSE;
  7611. char sstr[10]={0};
  7612. int c = 0;
  7613. char *loc;
  7614. FILE *fptr1;//, *fptr2;
  7615. //int lno=0;//, linectr = 0;
  7616. //int modifyflag = FALSE;
  7617. char filename[MAX]={0};
  7618. char tempfile[] = "/Storage/OCPP/temp.json";
  7619. //int resultRename=0;
  7620. char rmFileCmd[50]={0};
  7621. char tempchargingProfilePurposeStr[30]={0};
  7622. char word[1600]={0};
  7623. int n_chargingProfile = 0;
  7624. //[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}}}]
  7625. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7626. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7627. //*********************connectorId***************************/
  7628. loc = strstr(payload, "connectorId");
  7629. c = 0;
  7630. memset(sstr ,0, sizeof(sstr) );
  7631. while (loc[strlen("connectorId")+2+c] != ',')
  7632. {
  7633. sstr[c] = loc[strlen("connectorId")+2+c];
  7634. c++;
  7635. }
  7636. sstr[c] = '\0';
  7637. connectorIdInt = atoi(sstr);
  7638. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7639. {
  7640. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7641. }
  7642. else
  7643. {
  7644. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7645. }
  7646. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7647. //*********************chargingProfileId***************************/
  7648. loc = strstr(payload, "chargingProfileId");
  7649. c = 0;
  7650. memset(sstr ,0, sizeof(sstr) );
  7651. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7652. {
  7653. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7654. c++;
  7655. }
  7656. sstr[c] = '\0';
  7657. chargingProfileIdInt = atoi(sstr);
  7658. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7659. {
  7660. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7661. }
  7662. else
  7663. {
  7664. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7665. }
  7666. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7667. //*********************transactionId***************************/
  7668. loc = strstr(payload, "transactionId");
  7669. if(loc != NULL)
  7670. {
  7671. c = 0;
  7672. memset(sstr ,0, sizeof(sstr) );
  7673. while (loc[strlen("transactionId")+2+c] != ',')
  7674. {
  7675. sstr[c] = loc[strlen("transactionId")+2+c];
  7676. c++;
  7677. }
  7678. sstr[c] = '\0';
  7679. transactionIdInt = atoi(sstr);
  7680. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7681. {
  7682. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7683. }
  7684. else
  7685. {
  7686. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7687. }
  7688. }
  7689. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7690. //*********************stackLevel***************************/
  7691. loc = strstr(payload, "stackLevel");
  7692. c = 0;
  7693. memset(sstr ,0, sizeof(sstr) );
  7694. while (loc[strlen("stackLevel")+2+c] != ',')
  7695. {
  7696. sstr[c] = loc[strlen("stackLevel")+2+c];
  7697. c++;
  7698. }
  7699. sstr[c] = '\0';
  7700. stackLevelInt = atoi(sstr);
  7701. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7702. {
  7703. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7704. }
  7705. else
  7706. {
  7707. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7708. }
  7709. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7710. //*********************chargingProfilePurpose***************************/
  7711. loc = strstr(payload, "chargingProfilePurpose");
  7712. c = 0;
  7713. memset(sstr ,0, sizeof(sstr) );
  7714. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7715. {
  7716. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7717. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7718. c++;
  7719. }
  7720. sstr[c] = '\0';
  7721. strcpy(chargingProfilePurposeStr,sstr);
  7722. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7723. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7724. {
  7725. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7726. }
  7727. else
  7728. {
  7729. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7730. }
  7731. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7732. //*********************chargingProfileKind***************************/
  7733. loc = strstr(payload, "chargingProfileKind");
  7734. c = 0;
  7735. memset(sstr ,0, sizeof(sstr) );
  7736. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7737. {
  7738. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7739. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7740. c++;
  7741. }
  7742. sstr[c] = '\0';
  7743. strcpy(chargingProfileKindStr,sstr);
  7744. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7745. {
  7746. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7747. }
  7748. else
  7749. {
  7750. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7751. }
  7752. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7753. //*********************recurrencyKind***************************/
  7754. loc = strstr(payload, "recurrencyKind");
  7755. if(loc != NULL)
  7756. {
  7757. c = 0;
  7758. memset(sstr ,0, sizeof(sstr) );
  7759. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7760. {
  7761. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7762. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7763. c++;
  7764. }
  7765. sstr[c] = '\0';
  7766. strcpy(recurrencyKindStr,sstr);
  7767. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7768. {
  7769. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7770. }
  7771. else
  7772. {
  7773. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7774. }
  7775. }
  7776. else
  7777. {
  7778. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7779. {
  7780. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7781. }
  7782. else
  7783. {
  7784. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7785. }
  7786. }
  7787. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7788. //*********************validFrom***************************/
  7789. loc = strstr(payload, "validFrom");
  7790. if(loc != NULL)
  7791. {
  7792. c = 0;
  7793. memset(sstr ,0, sizeof(sstr) );
  7794. while (loc[3+strlen("validFrom")+c] != '\"')
  7795. {
  7796. sstr[c] = loc[3+strlen("validFrom")+c];
  7797. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7798. c++;
  7799. }
  7800. sstr[c] = '\0';
  7801. strcpy(validFromStr,sstr);
  7802. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7803. {
  7804. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7805. }
  7806. else
  7807. {
  7808. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7809. }
  7810. }
  7811. else
  7812. {
  7813. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7814. {
  7815. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7816. }
  7817. else
  7818. {
  7819. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7820. }
  7821. }
  7822. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7823. //*********************validTo***************************/
  7824. loc = strstr(payload, "validTo");
  7825. if(loc != NULL)
  7826. {
  7827. c = 0;
  7828. memset(sstr ,0, sizeof(sstr) );
  7829. while (loc[3+strlen("validTo")+c] != '\"')
  7830. {
  7831. sstr[c] = loc[3+strlen("validTo")+c];
  7832. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7833. c++;
  7834. }
  7835. sstr[c] = '\0';
  7836. strcpy(validToStr,sstr);
  7837. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7838. {
  7839. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7840. }
  7841. else
  7842. {
  7843. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7844. }
  7845. }
  7846. else
  7847. {
  7848. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7849. {
  7850. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7851. }
  7852. else
  7853. {
  7854. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7855. }
  7856. }
  7857. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7858. //*********************duration***************************/
  7859. loc = strstr(payload, "duration");
  7860. if(loc != NULL)
  7861. {
  7862. c = 0;
  7863. memset(sstr ,0, sizeof(sstr) );
  7864. while (loc[strlen("duration")+2+c] != ',')
  7865. {
  7866. sstr[c] = loc[strlen("duration")+2+c];
  7867. c++;
  7868. }
  7869. sstr[c] = '\0';
  7870. durationInt = atoi(sstr);
  7871. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7872. {
  7873. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7874. }
  7875. else
  7876. {
  7877. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7878. }
  7879. }
  7880. else
  7881. {
  7882. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7883. {
  7884. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7885. }
  7886. else
  7887. {
  7888. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7889. }
  7890. }
  7891. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7892. //*********************startSchedule***************************/
  7893. loc = strstr(payload, "startSchedule");
  7894. if(loc != NULL)
  7895. {
  7896. c = 0;
  7897. memset(sstr ,0, sizeof(sstr) );
  7898. while (loc[3+strlen("startSchedule")+c] != '\"')
  7899. {
  7900. sstr[c] = loc[3+strlen("startSchedule")+c];
  7901. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7902. c++;
  7903. }
  7904. sstr[c] = '\0';
  7905. strcpy(startScheduleStr,sstr);
  7906. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7907. {
  7908. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7909. }
  7910. else
  7911. {
  7912. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7913. }
  7914. }
  7915. else
  7916. {
  7917. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7918. {
  7919. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7920. }
  7921. else
  7922. {
  7923. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7924. }
  7925. }
  7926. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7927. //*********************chargingRateUnit***************************/
  7928. loc = strstr(payload, "chargingRateUnit");
  7929. if(loc != NULL)
  7930. {
  7931. c = 0;
  7932. memset(sstr ,0, sizeof(sstr) );
  7933. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7934. {
  7935. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7936. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7937. c++;
  7938. }
  7939. sstr[c] = '\0';
  7940. strcpy(chargingRateUnitStr,sstr);
  7941. #if 0
  7942. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  7943. {
  7944. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7945. goto end;
  7946. }
  7947. #endif
  7948. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7949. {
  7950. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7951. }
  7952. else
  7953. {
  7954. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7955. }
  7956. }
  7957. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7958. //****************chargingSchedulePeriod count start*******************/
  7959. int what_len = strlen("startPeriod");
  7960. char tempChargingProfile[1000]={0};
  7961. strcpy(tempChargingProfile,(const char*)payload);
  7962. char *where = tempChargingProfile;
  7963. if (what_len)
  7964. {
  7965. while ((where = strstr(where, "startPeriod"))) {
  7966. where += what_len;
  7967. chargingSchedulePeriodCount++;
  7968. }
  7969. }
  7970. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  7971. {
  7972. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7973. goto end;
  7974. }
  7975. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7976. //where = payload;
  7977. int templength = 0;
  7978. //int searchstart = 0;
  7979. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7980. {
  7981. //****************startPeriod*******************/
  7982. c=0;
  7983. loc = strstr(tempChargingProfile + templength, "startPeriod");
  7984. memset(sstr ,0, sizeof(sstr) );
  7985. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7986. {
  7987. sstr[c] = loc[strlen("startPeriod")+2+c];
  7988. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7989. c++;
  7990. }
  7991. sstr[c] = '\0';
  7992. startPeriodInt[periodNums] = atoi(sstr);
  7993. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7994. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7995. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7996. {
  7997. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7998. }
  7999. else
  8000. {
  8001. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8002. }
  8003. templength = strlen("startPeriod")+2+c;
  8004. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8005. //****************limit*******************/
  8006. c=0;
  8007. loc = strstr(tempChargingProfile + templength, "limit");
  8008. memset(sstr ,0, sizeof(sstr) );
  8009. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8010. {
  8011. sstr[c] = loc[strlen("limit")+2+c];
  8012. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8013. c++;
  8014. }
  8015. sstr[c] = '\0';
  8016. limitflaot[periodNums] = atof(sstr);
  8017. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8018. {
  8019. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8020. }
  8021. else
  8022. {
  8023. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8024. }
  8025. templength = templength + strlen("limit")+2+c;
  8026. //****************numberPhases*******************/
  8027. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8028. if(loc != NULL)
  8029. {
  8030. c=0;
  8031. memset(sstr ,0, sizeof(sstr) );
  8032. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8033. {
  8034. sstr[c] = loc[strlen("numberPhases")+2+c];
  8035. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8036. c++;
  8037. }
  8038. sstr[c] = '\0';
  8039. numberPhasesInt[periodNums] = atoi(sstr);
  8040. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8041. {
  8042. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8043. }
  8044. else
  8045. {
  8046. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8047. }
  8048. templength = templength + strlen("numberPhases")+2+c;
  8049. }
  8050. //where = loc;
  8051. }
  8052. //****************chargingSchedulePeriod count end*******************/
  8053. //*********************minChargingRate***************************/
  8054. loc = strstr(payload, "minChargingRate");
  8055. if(loc != NULL)
  8056. {
  8057. c = 0;
  8058. memset(sstr ,0, sizeof(sstr) );
  8059. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8060. {
  8061. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8062. c++;
  8063. }
  8064. sstr[c] = '\0';
  8065. minChargingRateFloat = atof(sstr);
  8066. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8067. {
  8068. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8069. }
  8070. else
  8071. {
  8072. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8073. }
  8074. }
  8075. else
  8076. {
  8077. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8078. {
  8079. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8080. }
  8081. else
  8082. {
  8083. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8084. }
  8085. }
  8086. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8087. {
  8088. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8089. if(connectorIdInt != 0)
  8090. {
  8091. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8092. goto end;
  8093. }
  8094. strcpy(filename, ChargePointMaxProfile_JSON );
  8095. fptr1 = fopen(filename, "r");
  8096. if (!fptr1)
  8097. {
  8098. //file not exist
  8099. DEBUG_INFO("Unable to open the input file!!\n");
  8100. fptr1 = fopen(filename, "w+");
  8101. }
  8102. else
  8103. {
  8104. //Check Charging Profile Count
  8105. while(fscanf(fptr1, "%s", word) != EOF)
  8106. {
  8107. //DEBUG_INFO("word=%s\n",word);
  8108. if(strstr(word, "chargingProfileId")!= NULL)
  8109. {
  8110. //DEBUG_INFO("test chargingProfileId \n");
  8111. n_chargingProfile = n_chargingProfile + 1;
  8112. //DEBUG_INFO("chargingProfileId Found\n");
  8113. }
  8114. }
  8115. }
  8116. fclose(fptr1);
  8117. }
  8118. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8119. {
  8120. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8121. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8122. {
  8123. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8124. goto end;
  8125. }
  8126. #if 0
  8127. switch(connectorIdInt)
  8128. {
  8129. case 0:
  8130. strcpy(filename, TxDefaultProfile_0_JSON );
  8131. break;
  8132. case 1:
  8133. strcpy(filename, TxDefaultProfile_1_JSON );
  8134. break;
  8135. case 2:
  8136. strcpy(filename, TxDefaultProfile_2_JSON );
  8137. break;
  8138. default:
  8139. strcpy(filename, TxDefaultProfile_0_JSON );
  8140. break;
  8141. }
  8142. #endif
  8143. memset(filename, 0, sizeof filename);
  8144. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8145. fptr1 = fopen(filename, "r");
  8146. if (!fptr1)
  8147. {
  8148. //file not exist
  8149. //DEBUG_INFO("Unable to open the input file!!\n");
  8150. fptr1 = fopen(filename, "w+");
  8151. }
  8152. else
  8153. {
  8154. //Check Charging Profile Count
  8155. while(fscanf(fptr1, "%s", word) != EOF)
  8156. {
  8157. //DEBUG_INFO("word=%s\n",word);
  8158. if(strstr(word, "chargingProfileId")!= NULL)
  8159. {
  8160. //DEBUG_INFO("test chargingProfileId \n");
  8161. n_chargingProfile = n_chargingProfile + 1;
  8162. //DEBUG_INFO("chargingProfileId Found\n");
  8163. }
  8164. }
  8165. }
  8166. fclose(fptr1);
  8167. }
  8168. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8169. {
  8170. //printf("set chargingProfile 1-4\n");
  8171. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8172. //check Transaction active
  8173. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8174. {
  8175. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8176. {
  8177. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8178. {
  8179. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8180. {
  8181. meet = TRUE;
  8182. break;
  8183. }
  8184. }
  8185. }
  8186. }
  8187. for (int index = 0; index < CCS_QUANTITY; index++)
  8188. {
  8189. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8190. {
  8191. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8192. {
  8193. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8194. {
  8195. meet = TRUE;
  8196. break;
  8197. }
  8198. }
  8199. }
  8200. }
  8201. for (int index = 0; index < GB_QUANTITY; index++)
  8202. {
  8203. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8204. {
  8205. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8206. {
  8207. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8208. {
  8209. meet = TRUE;
  8210. break;
  8211. }
  8212. }
  8213. }
  8214. }
  8215. if(meet == FALSE)
  8216. {
  8217. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8218. goto end;
  8219. }
  8220. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8221. {
  8222. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8223. goto end;
  8224. }
  8225. #if 0
  8226. switch(connectorIdInt)
  8227. {
  8228. case 0:
  8229. break;
  8230. case 1:
  8231. strcpy(filename, TxProfile_1_JSON);
  8232. break;
  8233. case 2:
  8234. strcpy(filename, TxProfile_2_JSON);
  8235. break;
  8236. default:
  8237. strcpy(filename, TxProfile_1_JSON);
  8238. break;
  8239. }
  8240. #endif
  8241. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8242. fptr1 = fopen(filename, "r");
  8243. if (!fptr1)
  8244. {
  8245. //file not exist
  8246. DEBUG_INFO("Unable to open the input file!!\n");
  8247. fptr1 = fopen(filename, "w+");
  8248. }
  8249. else
  8250. {
  8251. //Check Charging Profile Count
  8252. while(fscanf(fptr1, "%s", word) != EOF)
  8253. {
  8254. //DEBUG_INFO("word=%s\n",word);
  8255. if(strstr(word, "chargingProfileId")!= NULL)
  8256. {
  8257. //DEBUG_INFO("test chargingProfileId \n");
  8258. n_chargingProfile = n_chargingProfile + 1;
  8259. //DEBUG_INFO("chargingProfileId Found\n");
  8260. }
  8261. }
  8262. }
  8263. fclose(fptr1);
  8264. DEBUG_INFO("n_chargingProfile_3=%d\n",n_chargingProfile);
  8265. }
  8266. // Check ChargeProfileMaxStackLevel
  8267. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8268. {
  8269. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8270. goto end;
  8271. }
  8272. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8273. {
  8274. int i = 0;
  8275. char fnametemp[200]={0};
  8276. n_chargingProfile = 0;
  8277. //Check ChargePointMaxProfile.json exit
  8278. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8279. {
  8280. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8281. //Check Charging Profile Count
  8282. while(fscanf(fptr1, "%s", word) != EOF)
  8283. {
  8284. //DEBUG_INFO("word=%s\n",word);
  8285. if(strstr(word, "chargingProfileId")!= NULL)
  8286. {
  8287. //DEBUG_INFO("test chargingProfileId \n");
  8288. n_chargingProfile = n_chargingProfile + 1;
  8289. i = i + 1;
  8290. //DEBUG_INFO("chargingProfileId Found\n");
  8291. }
  8292. memset(word, 0, sizeof word);
  8293. }
  8294. fclose(fptr1);
  8295. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8296. }
  8297. //Check TxDefaultProfile_0.json exit
  8298. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8299. {
  8300. i = 0;
  8301. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8302. //Check Charging Profile Count
  8303. while(fscanf(fptr1, "%s", word) != EOF)
  8304. {
  8305. //DEBUG_INFO("word=%s\n",word);
  8306. if(strstr(word, "chargingProfileId")!= NULL)
  8307. {
  8308. //DEBUG_INFO("test chargingProfileId \n");
  8309. n_chargingProfile = n_chargingProfile + 1;
  8310. i = i + 1;
  8311. //DEBUG_INFO("chargingProfileId Found\n");
  8312. }
  8313. memset(word, 0, sizeof word);
  8314. }
  8315. fclose(fptr1);
  8316. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8317. }
  8318. //Check TxDefaultProfile_%d.json
  8319. for(int j=1; j <= gunTotalNumber; j++)
  8320. {
  8321. memset(fnametemp, 0, sizeof fnametemp);
  8322. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8323. if((access(fnametemp,F_OK))!=-1)
  8324. {
  8325. i = 0;
  8326. fptr1 = fopen(fnametemp, "r");
  8327. //Check Charging Profile Count
  8328. while(fscanf(fptr1, "%s", word) != EOF)
  8329. {
  8330. //DEBUG_INFO("word=%s\n",word);
  8331. if(strstr(word, "chargingProfileId")!= NULL)
  8332. {
  8333. //DEBUG_INFO("test chargingProfileId \n");
  8334. n_chargingProfile = n_chargingProfile + 1;
  8335. i = i + 1;
  8336. //DEBUG_INFO("chargingProfileId Found\n");
  8337. }
  8338. memset(word, 0, sizeof word);
  8339. }
  8340. fclose(fptr1);
  8341. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8342. }
  8343. }
  8344. //Check TxProfile_%d.json
  8345. for(int j=1; j <= gunTotalNumber; j++)
  8346. {
  8347. memset(fnametemp, 0, sizeof fnametemp);
  8348. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8349. if((access(fnametemp,F_OK))!=-1)
  8350. {
  8351. i = 0;
  8352. fptr1 = fopen(fnametemp, "r");
  8353. //Check Charging Profile Count
  8354. while(fscanf(fptr1, "%s", word) != EOF)
  8355. {
  8356. //DEBUG_INFO("word=%s\n",word);
  8357. if(strstr(word, "chargingProfileId")!= NULL)
  8358. {
  8359. //DEBUG_INFO("test chargingProfileId \n");
  8360. n_chargingProfile = n_chargingProfile + 1;
  8361. i = i + 1;
  8362. //DEBUG_INFO("chargingProfileId Found\n");
  8363. }
  8364. memset(word, 0, sizeof word);
  8365. }
  8366. fclose(fptr1);
  8367. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8368. }
  8369. }
  8370. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8371. {
  8372. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8373. goto end;
  8374. }
  8375. }
  8376. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8377. //**********************************Write to File********************************************************/
  8378. FILE *infile;
  8379. FILE *outfile;
  8380. // open file for writing
  8381. infile = fopen (filename, "r");
  8382. outfile = fopen (tempfile, "w");
  8383. int d =0;
  8384. d = fgetc(infile);
  8385. //DEBUG_INFO("d:%d\n",d);
  8386. rewind(infile);
  8387. //*检测到文件结束标识返回1,否则返回0。*/
  8388. if(d == EOF)
  8389. {
  8390. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8391. fprintf(outfile,"%s\n",payload);
  8392. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8393. fclose(infile);
  8394. fclose(outfile);
  8395. sprintf(rmFileCmd,"rm -f %s",filename);
  8396. system(rmFileCmd);
  8397. rename(tempfile, filename);
  8398. #if 0
  8399. resultRename = rename(tempfile, filename);
  8400. if(resultRename == 0)
  8401. {
  8402. DEBUG_INFO("File chargingProfile renamed successfully");
  8403. }
  8404. else
  8405. {
  8406. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8407. }
  8408. #endif
  8409. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8410. //system(rmFileCmd);
  8411. }
  8412. else
  8413. {
  8414. char buf[1000]={0};
  8415. int ChargingProfileAdded = FALSE;
  8416. while (fgets(buf, sizeof(buf), infile) != NULL)
  8417. {
  8418. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8419. //*************************tempconnectorIdInt*********************************/
  8420. loc = strstr(buf, "connectorId");
  8421. c = 0;
  8422. memset(sstr ,0, sizeof(sstr) );
  8423. while (loc[strlen("connectorId")+2+c] != ',')
  8424. {
  8425. sstr[c] = loc[strlen("connectorId")+2+c];
  8426. c++;
  8427. }
  8428. sstr[c] = '\0';
  8429. tempconnectorIdInt = atoi(sstr);
  8430. //*************************tempchargingProfileIdInt*********************************/
  8431. loc = strstr(buf, "chargingProfileId");
  8432. c = 0;
  8433. memset(sstr ,0, sizeof(sstr) );
  8434. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8435. {
  8436. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8437. c++;
  8438. }
  8439. sstr[c] = '\0';
  8440. tempchargingProfileIdInt = atoi(sstr);
  8441. //*************************tempstackLevelInt*********************************/
  8442. loc = strstr(buf, "stackLevel");
  8443. c = 0;
  8444. memset(sstr ,0, sizeof(sstr) );
  8445. while (loc[strlen("stackLevel")+2+c] != ',')
  8446. {
  8447. sstr[c] = loc[strlen("stackLevel")+2+c];
  8448. c++;
  8449. }
  8450. sstr[c] = '\0';
  8451. tempstackLevelInt = atoi(sstr);
  8452. //*************************tempchargingProfilePurposeStr*********************************/
  8453. loc = strstr(payload, "chargingProfilePurpose");
  8454. c = 0;
  8455. memset(sstr ,0, sizeof(sstr) );
  8456. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8457. {
  8458. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8459. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8460. c++;
  8461. }
  8462. sstr[c] = '\0';
  8463. strcpy(tempchargingProfilePurposeStr,sstr);
  8464. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8465. {
  8466. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8467. {
  8468. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8469. if(ChargingProfileAdded == FALSE)
  8470. {
  8471. fprintf(outfile,"%s\n",payload);
  8472. ChargingProfileAdded = TRUE;
  8473. }
  8474. }
  8475. else
  8476. {
  8477. if(tempstackLevelInt < stackLevelInt)
  8478. {
  8479. if(ChargingProfileAdded == FALSE)
  8480. {
  8481. fprintf(outfile,"%s\n",payload);
  8482. ChargingProfileAdded = TRUE;
  8483. fprintf(outfile,"%s\n",buf);
  8484. }
  8485. else
  8486. {
  8487. fprintf(outfile,"%s\n",buf);
  8488. }
  8489. }
  8490. else
  8491. {
  8492. if(ChargingProfileAdded == FALSE)
  8493. {
  8494. fprintf(outfile,"%s\n",buf);
  8495. fprintf(outfile,"%s\n",payload);
  8496. ChargingProfileAdded = TRUE;
  8497. }
  8498. else
  8499. {
  8500. fprintf(outfile,"%s\n",buf);
  8501. }
  8502. }
  8503. }
  8504. }
  8505. else
  8506. {
  8507. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8508. {
  8509. if(ChargingProfileAdded == FALSE)
  8510. {
  8511. fprintf(outfile,"%s\n",payload);
  8512. ChargingProfileAdded = TRUE;
  8513. fprintf(outfile,"%s\n",buf);
  8514. }
  8515. else
  8516. {
  8517. fprintf(outfile,"%s\n",buf);
  8518. }
  8519. }
  8520. else if(tempstackLevelInt < stackLevelInt)
  8521. {
  8522. if(ChargingProfileAdded == FALSE)
  8523. {
  8524. fprintf(outfile,"%s\n",payload);
  8525. ChargingProfileAdded = TRUE;
  8526. fprintf(outfile,"%s\n",buf);
  8527. }
  8528. else
  8529. {
  8530. fprintf(outfile,"%s\n",buf);
  8531. }
  8532. }
  8533. else
  8534. {
  8535. if(ChargingProfileAdded == FALSE)
  8536. {
  8537. fprintf(outfile,"%s\n",buf);
  8538. fprintf(outfile,"%s\n",payload);
  8539. ChargingProfileAdded = TRUE;
  8540. }
  8541. else
  8542. {
  8543. fprintf(outfile,"%s\n",buf);
  8544. }
  8545. }
  8546. }
  8547. } // end of while loop
  8548. fclose(infile);
  8549. fclose(outfile);
  8550. sprintf(rmFileCmd,"rm -f %s",filename);
  8551. system(rmFileCmd);
  8552. rename(tempfile, filename);
  8553. #if 0
  8554. resultRename = rename(tempfile, filename);
  8555. if(resultRename == 0)
  8556. {
  8557. DEBUG_INFO("File chargingProfile renamed successfully");
  8558. }
  8559. else
  8560. {
  8561. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8562. }
  8563. #endif
  8564. result = TRUE;
  8565. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8566. }
  8567. end:
  8568. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8569. return result;
  8570. return result;
  8571. }
  8572. int handleTriggerMessageRequest(char *uuid, char *payload)
  8573. {
  8574. mtrace();
  8575. int result = FAIL;
  8576. int connectorIdIsNULL = FALSE;
  8577. int connectorIdInt =0;
  8578. char sstr[40]={0};
  8579. char requestedMessagestr[40]={0};
  8580. char comfirmstr[20]={0};
  8581. int c = 0;
  8582. char *loc;
  8583. DEBUG_INFO("handleTriggerMessageRequest\n");
  8584. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8585. c = 0;
  8586. loc = strstr(payload, "requestedMessage");
  8587. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8588. {
  8589. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8590. c++;
  8591. }
  8592. sstr[c] = '\0';
  8593. strcpy(requestedMessagestr, sstr);
  8594. c = 0;
  8595. loc = strstr(payload, "connectorId");
  8596. if(loc == NULL)
  8597. {
  8598. connectorIdIsNULL = TRUE;
  8599. }
  8600. else
  8601. {
  8602. memset(sstr ,0, sizeof(sstr) );
  8603. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8604. {
  8605. sstr[c] = loc[strlen("connectorId")+2+c];
  8606. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8607. c++;
  8608. }
  8609. sstr[c] = '\0';
  8610. connectorIdInt = atoi(sstr);
  8611. }
  8612. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8613. {
  8614. //connectorIdInt = json_object_get_int(connectorId);
  8615. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8616. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8617. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8618. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8619. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8620. }
  8621. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8622. {
  8623. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8624. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8625. return TRUE;
  8626. }
  8627. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8628. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8629. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8630. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8631. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8632. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8633. {
  8634. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8635. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8636. return TRUE;
  8637. }
  8638. else
  8639. {
  8640. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8641. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8642. }
  8643. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8644. {
  8645. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8646. {
  8647. FirmwareStatusNotificationStatus = 3;
  8648. }
  8649. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8650. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8651. }
  8652. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8653. {
  8654. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8655. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8656. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8657. }
  8658. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8659. {
  8660. sendBootNotificationRequest();
  8661. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8662. }
  8663. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8664. {
  8665. sendHeartbeatRequest(connectorIdInt);
  8666. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8667. }
  8668. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8669. {
  8670. if(connectorIdIsNULL == FALSE)
  8671. {
  8672. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8673. {
  8674. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8675. sendMeterValuesRequest(connectorIdInt -1);
  8676. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8677. }
  8678. }
  8679. else
  8680. {
  8681. for(int idx=0;idx< gunTotalNumber;idx++)
  8682. {
  8683. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8684. sendMeterValuesRequest(idx);
  8685. }
  8686. }
  8687. }
  8688. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8689. {
  8690. if(connectorIdIsNULL == FALSE)
  8691. {
  8692. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8693. {
  8694. sendStatusNotificationRequest(connectorIdInt -1);
  8695. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8696. }
  8697. }
  8698. else
  8699. {
  8700. for(int idx=0;idx< gunTotalNumber;idx++)
  8701. sendStatusNotificationRequest(idx);
  8702. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8703. }
  8704. }
  8705. return result;
  8706. }
  8707. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8708. {
  8709. mtrace();
  8710. int result = FAIL;
  8711. char sstr[6]={0};
  8712. int connectorIdInt =0;
  8713. char comfirmstr[20]={0};
  8714. int c = 0;
  8715. char *loc;
  8716. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8717. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8718. c = 0;
  8719. loc = strstr(payload, "connectorId");
  8720. memset(sstr ,0, sizeof(sstr) );
  8721. while (loc[strlen("connectorId")+2+c] != '}')
  8722. {
  8723. sstr[c] = loc[strlen("connectorId")+2+c];
  8724. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8725. c++;
  8726. }
  8727. sstr[c] = '\0';
  8728. connectorIdInt = atoi(sstr);
  8729. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8730. if(gunTotalNumber == 0)
  8731. {
  8732. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8733. goto end;
  8734. }
  8735. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8736. {
  8737. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8738. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8739. goto end;
  8740. }
  8741. else
  8742. {
  8743. //check Transaction active
  8744. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8745. {
  8746. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8747. {
  8748. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8749. {
  8750. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8751. }
  8752. }
  8753. for (int index = 0; index < CCS_QUANTITY; index++)
  8754. {
  8755. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8756. {
  8757. //stop Transaction
  8758. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8759. }
  8760. }
  8761. for (int index = 0; index < GB_QUANTITY; index++)
  8762. {
  8763. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8764. {
  8765. //stop Transaction
  8766. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8767. }
  8768. }
  8769. }
  8770. else
  8771. {
  8772. for (int index = 0; index < AC_QUANTITY; index++)
  8773. {
  8774. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8775. {
  8776. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8777. }
  8778. }
  8779. }// END FOR AC ELSE
  8780. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8781. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8782. result = TRUE;
  8783. return result;
  8784. }
  8785. end:
  8786. //json_object_put(obj); --- remove temporally
  8787. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8788. return result;
  8789. }
  8790. static char UpdateFirmwarepayloadData[300]={0};
  8791. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8792. {
  8793. mtrace();
  8794. int result = FAIL;
  8795. pthread_t t;
  8796. sendUpdateFirmwareConfirmation(uuid);
  8797. memset(UpdateFirmwarepayloadData, 0, 300);
  8798. strcpy(UpdateFirmwarepayloadData, payload);
  8799. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8800. ////pthread_join(t, NULL); //
  8801. //pthread_detach(t);
  8802. //sendUpdateFirmwareConfirmation(uuid);
  8803. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8804. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8805. return result;
  8806. }
  8807. void *UpdateFirmwareProcess(void *data)
  8808. {
  8809. pthread_detach(pthread_self());
  8810. mtrace();
  8811. int retriesInt =0, retryIntervalInt=0;
  8812. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8813. int port=0;
  8814. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8815. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8816. //char comfirmstr[20];
  8817. int isSuccess = 0;
  8818. char ftpbuf[200];
  8819. char temp[100];
  8820. char * pch;
  8821. int retriesISNULL=FALSE;
  8822. int retryInterval=FALSE;
  8823. int c = 0;
  8824. //int i = 0;
  8825. char *loc;
  8826. char sstr[300]={ 0 };
  8827. char str[300]={ 0 };
  8828. //char *str = (char*) data; // ? ?輸入資 ?
  8829. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8830. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8831. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8832. //***************location **************/
  8833. loc = strstr(str, "location");
  8834. memset(sstr ,0, sizeof(sstr) );
  8835. c = 0;
  8836. while (loc[3+strlen("location")+c] != '\"')
  8837. {
  8838. sstr[c] = loc[3+strlen("location")+c];
  8839. c++;
  8840. }
  8841. sstr[c] = '\0';
  8842. strcpy(locationstr, sstr);
  8843. //***************retries**************/
  8844. c = 0;
  8845. loc = strstr(str, "retries");
  8846. if(loc == NULL)
  8847. {
  8848. retriesISNULL=TRUE;
  8849. }
  8850. else
  8851. {
  8852. memset(sstr ,0, sizeof(sstr) );
  8853. while (loc[strlen("retries")+2+c] != ',')
  8854. {
  8855. sstr[c] = loc[strlen("retries")+2+c];
  8856. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8857. c++;
  8858. }
  8859. sstr[c] = '\0';
  8860. }
  8861. if(retriesISNULL == FALSE)
  8862. {
  8863. retriesInt = atoi(sstr);
  8864. }
  8865. //***************retrieveDate **************/
  8866. loc = strstr(str, "retrieveDate");
  8867. memset(sstr ,0, sizeof(sstr) );
  8868. c = 0;
  8869. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8870. {
  8871. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8872. c++;
  8873. }
  8874. sstr[c] = '\0';
  8875. strcpy(retrieveDatestr, sstr);
  8876. //***************retryInterval **************/
  8877. c = 0;
  8878. loc = strstr(str, "retryInterval");
  8879. memset(sstr ,0, sizeof(sstr) );
  8880. if(loc == NULL)
  8881. {
  8882. retryInterval=TRUE;
  8883. }
  8884. else
  8885. {
  8886. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8887. {
  8888. sstr[c] = loc[strlen("retryInterval")+2+c];
  8889. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8890. c++;
  8891. }
  8892. sstr[c] = '\0';
  8893. }
  8894. if(retryInterval==FALSE)
  8895. {
  8896. retryIntervalInt = atoi(sstr);
  8897. }
  8898. memset(ftppath, 0, sizeof(ftppath));
  8899. memset(path, 0, sizeof(path));
  8900. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8901. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8902. if(strncmp(locationstr,"http", 4) == 0)
  8903. {
  8904. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8905. protocol, host, path);
  8906. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8907. // protocol, user, password, host, path);
  8908. sprintf(ftppath,"/%s", path);
  8909. //DEBUG_INFO("protocol =%s\n",protocol);
  8910. //DEBUG_INFO("host =%s\n",host);
  8911. //DEBUG_INFO("path =%s\n",path);
  8912. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8913. int ftppathlen=strlen(ftppath);
  8914. int i=1;
  8915. char filenametemp[50];
  8916. while(i < ftppathlen)
  8917. {
  8918. int len=ftppathlen-i;
  8919. if(ftppath[len]== 47) // '/' ascll code: 47
  8920. {
  8921. DEBUG_INFO("compare '/' all right\n");
  8922. break;
  8923. }
  8924. i=i+1;
  8925. }
  8926. memset(filenametemp, 0, sizeof(filenametemp));
  8927. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8928. filenametemp[i+1] = 0;
  8929. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8930. do{
  8931. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8932. sleep(retryIntervalInt);
  8933. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8934. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8935. if(!isSuccess)
  8936. {
  8937. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8938. }
  8939. else
  8940. {
  8941. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8942. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8943. isUpdateRequest = TRUE;
  8944. }
  8945. }
  8946. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8947. {
  8948. memset(ftpbuf, 0, sizeof(ftpbuf));
  8949. memset(temp, 0, sizeof(temp));
  8950. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8951. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8952. int ftppathlen=strlen(ftpbuf);
  8953. int i=1;
  8954. char filenametemp[50];
  8955. while(i < ftppathlen)
  8956. {
  8957. int len=ftppathlen-i;
  8958. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8959. {
  8960. DEBUG_INFO(" compare '/' all right\n");
  8961. break;
  8962. }
  8963. i=i+1;
  8964. }
  8965. memset(filenametemp, 0, sizeof(filenametemp));
  8966. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8967. filenametemp[i+1] = 0;
  8968. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8969. pch=strchr(temp,'@');
  8970. if(pch==NULL)
  8971. {
  8972. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8973. protocol, host, &port, path);
  8974. strcpy(user,"anonymous");
  8975. strcpy(password,"");
  8976. }
  8977. else
  8978. {
  8979. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8980. protocol, user, password, host, &port, path);
  8981. }
  8982. sscanf(host,"%[^/]%s",host1, path1);
  8983. sprintf(ftppath,"%s", path1);
  8984. //DEBUG_INFO("protocol =%s\n",protocol);
  8985. //DEBUG_INFO("user =%s\n",user);
  8986. //DEBUG_INFO("password =%s\n",password);
  8987. //DEBUG_INFO("host1 =%s\n",host1);
  8988. //DEBUG_INFO("port =%d\n",port);
  8989. //DEBUG_INFO("path1 =%s\n",path1);
  8990. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8991. //ftpFile(host, user, password, port, ftppath, fname);
  8992. //download firmware pthred
  8993. if(port == 0)
  8994. {
  8995. port = 21;
  8996. }
  8997. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8998. do{
  8999. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9000. sleep(retryIntervalInt);
  9001. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9002. if(!isSuccess)
  9003. {
  9004. //BulldogUtil.sleepMs(interval*1000);
  9005. DEBUG_INFO("Update firmware request and download file fail.\n");
  9006. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9007. }
  9008. else
  9009. {
  9010. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9011. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9012. isUpdateRequest = TRUE;
  9013. }
  9014. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9015. }
  9016. else
  9017. {
  9018. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9019. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9020. }
  9021. pthread_exit(NULL);
  9022. }
  9023. //==========================================
  9024. // Handle server response routine
  9025. //==========================================
  9026. void handleAuthorizeResponse(char *payload, int gun_index)
  9027. {
  9028. mtrace();
  9029. char expiryDatestr[30]={0};
  9030. char parentIdTagstr[20]={0};
  9031. char statusstr[20]={0};
  9032. char expiryDatestrtemp[30]={0};
  9033. char parentIdTagstrtemp[20]={0};
  9034. char IdTagstrtemp[20]={0};
  9035. char statusstrtemp[20]={0};
  9036. int expiryDateISNULL=FALSE;
  9037. int parentIdTagISNULL=FALSE;
  9038. char sstr[160]={ 0 };
  9039. char* filename = AuthorizationCache_JSON;
  9040. char tempfile[] = "/Storage/OCPP/temp.json";
  9041. int c = 0;
  9042. char *loc;
  9043. int resultRename=0;
  9044. int responseIdTagInfoAsZero= 0;
  9045. char rmFileCmd[50]={0};
  9046. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9047. //***********expiryDate*************/
  9048. loc = strstr(payload, "expiryDate");
  9049. memset(sstr ,0, sizeof(sstr) );
  9050. c = 0;
  9051. if(loc == NULL)
  9052. {
  9053. expiryDateISNULL = TRUE;
  9054. }
  9055. else
  9056. {
  9057. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9058. {
  9059. sstr[c] = loc[3+strlen("expiryDate")+c];
  9060. c++;
  9061. }
  9062. sstr[c] = '\0';
  9063. strcpy(expiryDatestr, sstr);
  9064. }
  9065. //***********parentIdTag*************/
  9066. loc = strstr(payload, "parentIdTag");
  9067. memset(sstr ,0, sizeof(sstr) );
  9068. c = 0;
  9069. if(loc == NULL)
  9070. {
  9071. parentIdTagISNULL = TRUE;
  9072. }
  9073. else
  9074. {
  9075. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9076. {
  9077. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9078. c++;
  9079. }
  9080. sstr[c] = '\0';
  9081. strcpy(parentIdTagstr, sstr);
  9082. }
  9083. //***********status*************/
  9084. loc = strstr(payload, "status");
  9085. memset(sstr ,0, sizeof(sstr) );
  9086. c = 0;
  9087. while (loc[3+strlen("status")+c] != '\"')
  9088. {
  9089. sstr[c] = loc[3+strlen("status")+c];
  9090. c++;
  9091. }
  9092. sstr[c] = '\0';
  9093. strcpy(statusstr, sstr);
  9094. if(expiryDateISNULL == FALSE)
  9095. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9096. if(parentIdTagISNULL == FALSE)
  9097. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9098. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9099. //Update idTag information to authorization cache if supproted
  9100. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9101. {
  9102. if((access(filename,F_OK))!=-1)
  9103. {
  9104. printf("AuthorizationCache exist.\n");
  9105. }
  9106. else
  9107. {
  9108. printf("AuthorizationCache not exist\n");
  9109. FILE *log = fopen(filename, "w+");
  9110. if(log == NULL)
  9111. {
  9112. printf("log is NULL\n");
  9113. goto out;
  9114. }
  9115. else
  9116. {
  9117. fclose(log);
  9118. }
  9119. }
  9120. FILE *infile;
  9121. FILE *outfile;
  9122. // open file for writing
  9123. infile = fopen (filename, "r");
  9124. outfile = fopen (tempfile, "w");
  9125. //*检测到文件结束标识返回1,否则返回0。*/
  9126. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9127. int c;
  9128. c = fgetc(infile);
  9129. //DEBUG_INFO("c:%d\n",c);
  9130. rewind(infile);
  9131. if(c == EOF)
  9132. {
  9133. DEBUG_INFO("Orignal File is NULL\n");
  9134. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9135. {
  9136. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9137. }
  9138. else
  9139. {
  9140. strcpy(expiryDatestrtemp, "");
  9141. }
  9142. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9143. {
  9144. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9145. }
  9146. else
  9147. {
  9148. //write Authorize IdTag
  9149. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9150. }
  9151. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9152. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9153. fclose(infile);
  9154. fclose(outfile);
  9155. sprintf(rmFileCmd,"rm -f %s",filename);
  9156. system(rmFileCmd);
  9157. resultRename = rename(tempfile, filename);
  9158. if(resultRename == 0)
  9159. {
  9160. printf("File renamed successfully");
  9161. }
  9162. else
  9163. {
  9164. printf("Error: unable to rename the file");
  9165. }
  9166. }
  9167. else
  9168. {
  9169. char buf[160]={0};
  9170. while (fgets(buf, sizeof(buf), infile) != NULL)
  9171. {
  9172. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9173. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9174. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9175. memset(statusstr, 0, sizeof(statusstrtemp));
  9176. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9177. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9178. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9179. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9180. //------------------IdTag-----------------------
  9181. loc = strstr(buf, "idTag");
  9182. memset(sstr ,0, sizeof(sstr) );
  9183. c = 0;
  9184. while (loc[3+strlen("idTag")+c] != '\"')
  9185. {
  9186. sstr[c] = loc[3+strlen("idTag")+c];
  9187. c++;
  9188. }
  9189. sstr[c] = '\0';
  9190. strcpy(IdTagstrtemp,sstr);
  9191. //*********************expiryDate***************/
  9192. loc = strstr(buf, "expiryDate");
  9193. memset(sstr ,0, sizeof(sstr) );
  9194. c = 0;
  9195. while (loc[3+strlen("expiryDate")+c] != '\"')
  9196. {
  9197. sstr[c] = loc[3+strlen("expiryDate")+c];
  9198. c++;
  9199. }
  9200. sstr[c] = '\0';
  9201. strcpy(expiryDatestr,sstr);
  9202. //*********************parentIdTag***************/
  9203. loc = strstr(buf, "parentIdTag");
  9204. memset(sstr ,0, sizeof(sstr) );
  9205. c = 0;
  9206. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9207. {
  9208. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9209. c++;
  9210. }
  9211. sstr[c] = '\0';
  9212. strcpy(parentIdTagstr,sstr);
  9213. //*********************status***************/
  9214. loc = strstr(buf, "status");
  9215. memset(sstr ,0, sizeof(sstr) );
  9216. c = 0;
  9217. while (loc[3+strlen("status")+c] != '\"')
  9218. {
  9219. sstr[c] = loc[3+strlen("status")+c];
  9220. c++;
  9221. }
  9222. sstr[c] = '\0';
  9223. strcpy(statusstr,sstr);
  9224. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9225. {
  9226. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9227. responseIdTagInfoAsZero = 1;
  9228. }
  9229. else
  9230. {
  9231. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9232. }
  9233. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9234. {
  9235. //modify item
  9236. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9237. {
  9238. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9239. }
  9240. else
  9241. {
  9242. strcpy(expiryDatestrtemp, "");
  9243. }
  9244. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9245. {
  9246. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9247. }
  9248. else
  9249. {
  9250. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9251. }
  9252. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9253. }
  9254. else
  9255. {
  9256. //wrie original item
  9257. strcpy(expiryDatestrtemp, expiryDatestr);
  9258. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9259. strcpy(statusstrtemp, statusstr);
  9260. }
  9261. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9262. }
  9263. fclose(infile);
  9264. fclose(outfile);
  9265. sprintf(rmFileCmd,"rm -f %s",filename);
  9266. system(rmFileCmd);
  9267. resultRename = rename(tempfile, filename);
  9268. if(resultRename == 0)
  9269. {
  9270. DEBUG_INFO("File renamed successfully");
  9271. }
  9272. else
  9273. {
  9274. DEBUG_INFO("Error: unable to rename the file");
  9275. }
  9276. }
  9277. }
  9278. out:
  9279. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9280. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9281. authorizeRetryTimes = 0;
  9282. }
  9283. void handleBootNotificationResponse(char *payload, int gun_index)
  9284. {
  9285. mtrace();
  9286. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9287. char statusStr[12]={0};
  9288. char currentTimeStr[30]={0};
  9289. char *loc;
  9290. int intervalInt = 0;
  9291. int c = 0;
  9292. //double diff_t;
  9293. struct tm tp;
  9294. char buf[28]={0};
  9295. char timebuf[50]={0};
  9296. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9297. //*** interval ****/
  9298. c = 0;
  9299. loc = strstr(payload, "interval");
  9300. //printf("loc=%s\n",loc);
  9301. memset(sstr ,0, sizeof(sstr) );
  9302. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9303. {
  9304. sstr[c] = loc[strlen("interval")+2+c];
  9305. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9306. c++;
  9307. }
  9308. sstr[c] = '\0';
  9309. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9310. intervalInt = atoi(sstr);
  9311. //***status ****/
  9312. loc = strstr(payload, "status");
  9313. memset(sstr ,0, sizeof(sstr) );
  9314. c = 0;
  9315. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9316. {
  9317. sstr[c] = loc[3+strlen("status")+c];
  9318. c++;
  9319. }
  9320. sstr[c] = '\0';
  9321. strcpy(statusStr, sstr);
  9322. //***currentTime ****/
  9323. loc = strstr(payload, "currentTime");
  9324. //printf("loc=%s\n",loc);
  9325. memset(sstr ,0, sizeof(sstr) );
  9326. c = 0;
  9327. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9328. {
  9329. sstr[c] = loc[3+strlen("currentTime")+c];
  9330. c++;
  9331. }
  9332. sstr[c] = '\0';
  9333. strcpy(currentTimeStr, sstr);
  9334. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9335. HeartBeatWaitTime = BootNotificationInterval;
  9336. clientTime.Heartbeat=time((time_t*)NULL);
  9337. //write back to ShmOCPP16Data->BootNotification
  9338. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9339. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9340. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9341. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9342. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9343. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9344. {
  9345. server_sign = TRUE;
  9346. server_pending =FALSE;
  9347. }
  9348. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9349. {
  9350. server_pending = TRUE;
  9351. }
  9352. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9353. tp.tm_isdst = -1;
  9354. //time_t utc = mktime(&tp);
  9355. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9356. memset(timebuf, 0, sizeof timebuf);
  9357. sprintf(timebuf,"date -s '%s'",buf);
  9358. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9359. system(timebuf);
  9360. //==============================================
  9361. // RTC sync
  9362. //==============================================
  9363. system("/sbin/hwclock -w --systohc");
  9364. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9365. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9366. }
  9367. void handleDataTransferResponse(char *payload, int gun_index)
  9368. {
  9369. char sstr[160]={0};//sstr[200]={ 0 };
  9370. int c = 0;
  9371. char *loc;
  9372. DEBUG_INFO("handleDataTransferResponse ...\n");
  9373. loc = strstr(payload, "status");
  9374. printf("loc=%s\n",loc);
  9375. c = 0;
  9376. while (loc[3+strlen("status")+c] != '\"')
  9377. {
  9378. sstr[c] = loc[3+strlen("status")+c];
  9379. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9380. c++;
  9381. }
  9382. sstr[c] = '\0';
  9383. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9384. }
  9385. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9386. {
  9387. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9388. //struct json_object *obj;
  9389. // obj = json_tokener_parse(payload);
  9390. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9391. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9392. //No fields are defined.
  9393. }
  9394. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9395. {
  9396. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9397. //struct json_object *obj;
  9398. // obj = json_tokener_parse(payload);
  9399. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9400. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9401. //No fields are defined.
  9402. }
  9403. void handleHeartbeatResponse(char *payload, int gun_index)
  9404. {
  9405. mtrace();
  9406. //double diff_t;
  9407. struct tm tp;
  9408. char buf[28]={0};
  9409. char timebuf[50]={0};
  9410. char sstr[30]={ 0 };
  9411. int c = 0;
  9412. char *loc;
  9413. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9414. c = 0;
  9415. loc = strstr(payload, "currentTime");
  9416. memset(sstr ,0, sizeof(sstr) );
  9417. while (loc[3+strlen("currentTime")+c] != '\"')
  9418. {
  9419. sstr[c] = loc[3+strlen("currentTime")+c];
  9420. c++;
  9421. }
  9422. sstr[c] = '\0';
  9423. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9424. // #ifdef SystemLogMessage
  9425. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9426. // #endif
  9427. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9428. tp.tm_isdst = -1;
  9429. //time_t utc = mktime(&tp);
  9430. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9431. memset(timebuf, 0, sizeof timebuf);
  9432. sprintf(timebuf,"date -s '%s'",buf);
  9433. system(timebuf);
  9434. //==============================================
  9435. // RTC sync
  9436. //==============================================
  9437. system("/sbin/hwclock -w --systohc");
  9438. if(FirstHeartBeat == 0)
  9439. {
  9440. FirstHeartBeat = 1;
  9441. }
  9442. HeartBeatWithNOResponse = 0;
  9443. //--------Print Out HeartBeat log
  9444. {
  9445. double diff_t;
  9446. struct tm tp,tp1;
  9447. // BootNotification Receive Time
  9448. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9449. tp.tm_isdst = -1;
  9450. time_t BootNotificationReceiveTime = mktime(&tp);
  9451. //HeartBeat Receive Time
  9452. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9453. tp1.tm_isdst = -1;
  9454. time_t HeartBeatReceiveTime = mktime(&tp1);
  9455. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9456. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9457. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9458. {
  9459. HeartBeatCountPerHour = (int)diff_t / 3600;
  9460. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9461. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9462. }
  9463. }
  9464. }
  9465. void handleMeterValuesResponse(char *payload, int gun_index)
  9466. {
  9467. mtrace();
  9468. //struct json_object *obj;
  9469. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9470. //No fields are defined.
  9471. }
  9472. void handleStartTransactionResponse(char *payload, int gun_index)
  9473. {
  9474. mtrace();
  9475. char sstr[28]={ 0 };
  9476. int c = 0;
  9477. char *loc;
  9478. int transactionIdInt = 0;
  9479. FILE *outfile;
  9480. char data[100]={0};
  9481. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9482. DEBUG_INFO("handleStartTransactionResponse\n");
  9483. //****************expiryDate********************/
  9484. loc = strstr(payload, "expiryDate");
  9485. if(loc == NULL)
  9486. {
  9487. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9488. }
  9489. else
  9490. {
  9491. c = 0;
  9492. memset(sstr ,0, sizeof(sstr) );
  9493. while (loc[3+strlen("expiryDate")+c] != '\"')
  9494. {
  9495. sstr[c] = loc[3+strlen("expiryDate")+c];
  9496. c++;
  9497. }
  9498. sstr[c] = '\0';
  9499. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9500. }
  9501. //****************parentIdTag********************/
  9502. loc = strstr(payload, "parentIdTag");
  9503. if(loc == NULL)
  9504. {
  9505. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9506. }
  9507. else
  9508. {
  9509. c = 0;
  9510. memset(sstr ,0, sizeof(sstr) );
  9511. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9512. {
  9513. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9514. c++;
  9515. }
  9516. sstr[c] = '\0';
  9517. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9518. }
  9519. //****************status********************/
  9520. loc = strstr(payload, "status");
  9521. if(loc == NULL)
  9522. {
  9523. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9524. }
  9525. else
  9526. {
  9527. c = 0;
  9528. memset(sstr ,0, sizeof(sstr) );
  9529. while (loc[3+strlen("status")+c] != '\"')
  9530. {
  9531. sstr[c] = loc[3+strlen("status")+c];
  9532. c++;
  9533. }
  9534. sstr[c] = '\0';
  9535. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9536. }
  9537. //****************transactionId********************/
  9538. c=0;
  9539. loc = strstr(payload, "transactionId");
  9540. memset(sstr ,0, sizeof(sstr) );
  9541. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9542. {
  9543. sstr[c] = loc[strlen("transactionId")+2+c];
  9544. c++;
  9545. }
  9546. sstr[c] = '\0';
  9547. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9548. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9549. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9550. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9551. //-----------Start : write to the Queue TransactionId file -----------------//
  9552. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9553. {
  9554. //DEBUG_INFO("QueueTransactionId exist.\n");
  9555. }
  9556. else
  9557. {
  9558. //DEBUG_INFO("QueueTransactionId not exist\n");
  9559. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9560. if(log == NULL)
  9561. {
  9562. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9563. return ;
  9564. }
  9565. else
  9566. {
  9567. fclose(log);
  9568. }
  9569. }
  9570. // open file for writing
  9571. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9572. //DEBUG_INFO("data=%s\n",data);
  9573. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9574. fputs(data, outfile);
  9575. //fputs("\n", outfile);
  9576. fclose (outfile);
  9577. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9578. TransactionId[gun_index] = transactionIdInt;
  9579. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9580. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9581. #ifdef SystemLogMessage
  9582. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9583. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9584. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9585. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9586. #endif
  9587. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  9588. {
  9589. //add Charging Record
  9590. SettingChargingRecord(gun_index, transactionIdInt);
  9591. }
  9592. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  9593. }
  9594. void handleStatusNotificationResponse(char *payload, int gun_index)
  9595. {
  9596. mtrace();
  9597. printf("handleStatusNotificationResponse\n");
  9598. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9599. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9600. }
  9601. void handleStopTransactionnResponse(char *payload, int gun_index)
  9602. {
  9603. mtrace();
  9604. char sstr[30]={ 0 };
  9605. int c = 0;
  9606. char *loc;
  9607. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9608. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9609. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9610. loc = strstr(payload, "idTagInfo");
  9611. //***********************idTagInfo************************/
  9612. if(loc != NULL)
  9613. {
  9614. //***********************expiryDate************************/
  9615. loc = strstr(payload, "expiryDate");
  9616. if(loc != NULL)
  9617. {
  9618. memset(sstr ,0, sizeof(sstr) );
  9619. c = 0;
  9620. while (loc[3+strlen("expiryDate")+c] != '\"')
  9621. {
  9622. sstr[c] = loc[3+strlen("expiryDate")+c];
  9623. c++;
  9624. }
  9625. sstr[c] = '\0';
  9626. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9627. }
  9628. //***********************parentIdTag************************/
  9629. loc = strstr(payload, "parentIdTag");
  9630. if(loc != NULL)
  9631. {
  9632. memset(sstr ,0, sizeof(sstr) );
  9633. c = 0;
  9634. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9635. {
  9636. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9637. c++;
  9638. }
  9639. sstr[c] = '\0';
  9640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9641. }
  9642. //***********************status************************/
  9643. loc = strstr(payload, "status");
  9644. memset(sstr ,0, sizeof(sstr) );
  9645. c = 0;
  9646. while (loc[3+strlen("status")+c] != '\"')
  9647. {
  9648. sstr[c] = loc[3+strlen("status")+c];
  9649. c++;
  9650. }
  9651. sstr[c] = '\0';
  9652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9653. }
  9654. #ifdef SystemLogMessage
  9655. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9656. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9657. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9658. #endif
  9659. }
  9660. //==========================================
  9661. // Handle Error routine
  9662. //==========================================
  9663. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9664. {
  9665. mtrace();
  9666. #ifdef SystemLogMessage
  9667. DEBUG_INFO("errorCode: %s\n", errorCode);
  9668. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9669. DEBUG_INFO("errorDetails: %s\n", payload);
  9670. #endif
  9671. }
  9672. //===============================================
  9673. // Common routine
  9674. //===============================================
  9675. int initialConfigurationTable(void)
  9676. {
  9677. FILE *fp;
  9678. FILE *outfile;
  9679. char str[200]={0};
  9680. char sstr[100]={0};
  9681. int c = 0;
  9682. char *loc;
  9683. printf("initialConfigurationTable \n");
  9684. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9685. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9686. {
  9687. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9688. if(outfile == NULL) {
  9689. DEBUG_INFO("Error opening file");
  9690. return FALSE;
  9691. }
  9692. /*Core Profile*/
  9693. //AllowOfflineTxForUnknownId
  9694. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9695. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  9699. //AuthorizationCacheEnabled
  9700. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9704. //AuthorizeRemoteTxRequests
  9705. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9709. //BlinkRepeat
  9710. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9714. //ClockAlignedDataInterval
  9715. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9719. //ConnectionTimeOut
  9720. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9724. //GetConfigurationMaxKeys
  9725. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9729. // HeartbeatInterval
  9730. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9734. // LightIntensity
  9735. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9739. // LocalAuthorizeOffline
  9740. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9744. // LocalPreAuthorize
  9745. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9749. // MaxEnergyOnInvalidId
  9750. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9753. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9755. // MeterValuesAlignedData
  9756. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9760. // MeterValuesAlignedDataMaxLength
  9761. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9765. // MeterValuesSampledData
  9766. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9770. // MeterValuesSampledDataMaxLength
  9771. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9775. // MeterValueSampleInterval
  9776. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9780. // MinimumStatusDuration
  9781. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9785. // NumberOfConnectors
  9786. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9788. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9789. {
  9790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9791. }
  9792. else
  9793. {
  9794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9795. }
  9796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9797. // ResetRetries
  9798. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9802. // ConnectorPhaseRotation
  9803. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9807. // ConnectorPhaseRotationMaxLength
  9808. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9812. // StopTransactionOnEVSideDisconnect
  9813. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9817. // StopTransactionOnInvalidId
  9818. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9822. // StopTxnAlignedData
  9823. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9827. // StopTxnAlignedDataMaxLength
  9828. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9832. // StopTxnSampledData
  9833. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9837. // StopTxnSampledDataMaxLength
  9838. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9840. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9841. {
  9842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9843. }
  9844. else
  9845. {
  9846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9847. }
  9848. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9850. // SupportedFeatureProfiles
  9851. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9855. // SupportedFeatureProfilesMaxLength
  9856. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9860. // TransactionMessageAttempts
  9861. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9864. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9866. // TransactionMessageRetryInterval
  9867. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9870. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9872. // UnlockConnectorOnEVSideDisconnect
  9873. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9877. // WebSocketPingInterval
  9878. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9882. //* Local Auth List Management Profile*/
  9883. #if 0
  9884. //For OCTT Test Case
  9885. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9888. #endif
  9889. #if 1
  9890. //LocalAuthListEnabled
  9891. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9895. #endif
  9896. //LocalAuthListMaxLength
  9897. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9901. //SendLocalListMaxLength
  9902. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9906. //ReserveConnectorZeroSupported
  9907. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9911. //* Smart Charging Profile */
  9912. //ChargeProfileMaxStackLevel
  9913. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9917. // ChargingScheduleAllowedChargingRateUnit
  9918. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9922. // ChargingScheduleMaxPeriods
  9923. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9927. // ConnectorSwitch3to1PhaseSupported
  9928. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9932. // MaxChargingProfilesInstalled
  9933. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9937. fclose(outfile);
  9938. }
  9939. else
  9940. {
  9941. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9942. char keystr[60]={0};
  9943. char readonlystr[10]={0};
  9944. char valuestr[100]={0};
  9945. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9946. if(fp == NULL) {
  9947. DEBUG_INFO("Error opening file");
  9948. return FALSE;
  9949. }
  9950. while( fgets (str, sizeof(str), fp)!=NULL )
  9951. {
  9952. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9953. //*************************key*********************************/
  9954. loc = strstr(str, "key");
  9955. c = 0;
  9956. memset(sstr ,0, sizeof(sstr) );
  9957. while (loc[strlen("key")+3+c] != '\"')
  9958. {
  9959. sstr[c] = loc[strlen("key")+3+c];
  9960. c++;
  9961. }
  9962. sstr[c] = '\0';
  9963. strcpy(keystr,sstr);
  9964. //*************************readonly*********************************/
  9965. loc = strstr(str, "readonly");
  9966. c = 0;
  9967. memset(sstr ,0, sizeof(sstr) );
  9968. while (loc[strlen("readonly")+2+c] != ',')
  9969. {
  9970. sstr[c] = loc[strlen("readonly")+2+c];
  9971. c++;
  9972. }
  9973. sstr[c] = '\0';
  9974. strcpy(readonlystr,sstr);
  9975. //*************************value*********************************/
  9976. loc = strstr(str, "value");
  9977. c = 0;
  9978. memset(sstr ,0, sizeof(sstr) );
  9979. while (loc[strlen("value")+3+c] != '\"')
  9980. {
  9981. sstr[c] = loc[strlen("value")+3+c];
  9982. c++;
  9983. }
  9984. sstr[c] = '\0';
  9985. strcpy(valuestr,sstr);
  9986. // DEBUG_INFO("keystr=%s\n",keystr);
  9987. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9988. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9989. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9990. {
  9991. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9992. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9994. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9995. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9996. }
  9997. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9998. {
  9999. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10000. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10002. }
  10003. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10004. {
  10005. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10007. }
  10008. if(strcmp(keystr, "BlinkRepeat") == 0)
  10009. {
  10010. //Charger.BlinkRepeat = Integer.parseInt(value);
  10011. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10013. }
  10014. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10015. {
  10016. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10018. }
  10019. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10020. {
  10021. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10023. }
  10024. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10025. {
  10026. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10028. }
  10029. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10030. {
  10031. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10033. HeartBeatWaitTime = atoi(valuestr);
  10034. }
  10035. if(strcmp(keystr, "LightIntensity") == 0)
  10036. {
  10037. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10039. }
  10040. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10041. {
  10042. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10044. }
  10045. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10046. {
  10047. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10049. }
  10050. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10051. {
  10052. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10054. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10055. }
  10056. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10057. {
  10058. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10060. }
  10061. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10062. {
  10063. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10065. }
  10066. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10067. {
  10068. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10070. }
  10071. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10072. {
  10073. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10075. }
  10076. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10077. {
  10078. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10080. }
  10081. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10082. {
  10083. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10085. }
  10086. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10087. {
  10088. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10090. }
  10091. if(strcmp(keystr, "ResetRetries") == 0)
  10092. {
  10093. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10095. }
  10096. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10097. {
  10098. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10100. }
  10101. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10102. {
  10103. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10105. }
  10106. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10107. {
  10108. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10110. }
  10111. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10112. {
  10113. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10115. }
  10116. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10117. {
  10118. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10120. }
  10121. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10122. {
  10123. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10125. }
  10126. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10127. {
  10128. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10130. }
  10131. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10132. {
  10133. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10135. }
  10136. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10137. {
  10138. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10140. }
  10141. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10142. {
  10143. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10145. }
  10146. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10147. {
  10148. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10150. TransactionMessageAttemptsValue = atoi(valuestr);
  10151. }
  10152. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10153. {
  10154. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10156. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10157. }
  10158. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10159. {
  10160. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10162. }
  10163. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10164. {
  10165. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10167. }
  10168. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10169. {
  10170. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10172. }
  10173. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10174. {
  10175. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10177. }
  10178. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10179. {
  10180. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10182. }
  10183. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10184. {
  10185. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10187. }
  10188. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10189. {
  10190. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10192. }
  10193. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10194. {
  10195. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10197. }
  10198. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10199. {
  10200. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10202. }
  10203. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10204. {
  10205. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10207. }
  10208. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10209. {
  10210. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10212. }
  10213. }
  10214. fclose(fp);
  10215. }
  10216. return 0;
  10217. }
  10218. void StoreConfigurationTable(void)
  10219. {
  10220. FILE *outfile;
  10221. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10222. if(outfile == NULL)
  10223. {
  10224. DEBUG_INFO("Error opening file");
  10225. return ;
  10226. }
  10227. /*Core Profile*/
  10228. //AllowOfflineTxForUnknownId
  10229. /*
  10230. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10231. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10234. */
  10235. //DEBUG_INFO("data=%s\n",data);
  10236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10237. //AuthorizationCacheEnabled
  10238. /*
  10239. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10242. */
  10243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10244. //AuthorizeRemoteTxRequests
  10245. /*
  10246. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10249. */
  10250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10251. //BlinkRepeat
  10252. /*
  10253. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10256. */
  10257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10258. //ClockAlignedDataInterval
  10259. /*
  10260. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10263. */
  10264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10265. //ConnectionTimeOut
  10266. /*
  10267. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10270. */
  10271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10272. //GetConfigurationMaxKeys
  10273. /*
  10274. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10277. */
  10278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10279. // HeartbeatInterval
  10280. /*
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10284. */
  10285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10286. // LightIntensity
  10287. /*
  10288. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10291. */
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10293. // LocalAuthorizeOffline
  10294. /*
  10295. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10298. */
  10299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10300. // LocalPreAuthorize
  10301. /*
  10302. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10305. */
  10306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10307. // MaxEnergyOnInvalidId
  10308. /*
  10309. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10312. */
  10313. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10315. // MeterValuesAlignedData
  10316. /*
  10317. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10320. */
  10321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10322. // MeterValuesAlignedDataMaxLength
  10323. /*
  10324. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10327. */
  10328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10329. // MeterValuesSampledData
  10330. /*
  10331. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10334. */
  10335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10336. // MeterValuesSampledDataMaxLength
  10337. /*
  10338. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10341. */
  10342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10343. // MeterValueSampleInterval
  10344. /*
  10345. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10348. */
  10349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10350. // MinimumStatusDuration
  10351. /*
  10352. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10355. */
  10356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10357. // NumberOfConnectors
  10358. /*
  10359. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10361. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10362. {
  10363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10364. }
  10365. else
  10366. {
  10367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10368. }
  10369. */
  10370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10371. // ResetRetries
  10372. /*
  10373. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10376. */
  10377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10378. // ConnectorPhaseRotation
  10379. /*
  10380. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10383. */
  10384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10385. // ConnectorPhaseRotationMaxLength
  10386. /*
  10387. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10390. */
  10391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10392. // StopTransactionOnEVSideDisconnect
  10393. /*
  10394. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10397. */
  10398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10399. // StopTransactionOnInvalidId
  10400. /*
  10401. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  10402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10404. */
  10405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10406. // StopTxnAlignedData
  10407. /*
  10408. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10411. */
  10412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10413. // StopTxnAlignedDataMaxLength
  10414. /*
  10415. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10418. */
  10419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10420. // StopTxnSampledData
  10421. /*
  10422. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10425. */
  10426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10427. // StopTxnSampledDataMaxLength
  10428. /*
  10429. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10432. */
  10433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10434. // SupportedFeatureProfiles
  10435. /*
  10436. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10439. */
  10440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10441. // SupportedFeatureProfilesMaxLength
  10442. /*
  10443. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10446. */
  10447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10448. // TransactionMessageAttempts
  10449. /*
  10450. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10453. */
  10454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10455. // TransactionMessageRetryInterval
  10456. /*
  10457. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10460. */
  10461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10462. // UnlockConnectorOnEVSideDisconnect
  10463. /*
  10464. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10467. */
  10468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10469. // WebSocketPingInterval
  10470. /*
  10471. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10474. */
  10475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10476. //* Local Auth List Management Profile*/
  10477. //LocalAuthListEnabled
  10478. /*
  10479. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10482. */
  10483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10484. //LocalAuthListMaxLength
  10485. /*
  10486. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10489. */
  10490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10491. //SendLocalListMaxLength
  10492. /*
  10493. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10496. */
  10497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10498. //ReserveConnectorZeroSupported
  10499. /*
  10500. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10503. */
  10504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10505. //* Smart Charging Profile */
  10506. //ChargeProfileMaxStackLevel
  10507. /*
  10508. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10511. */
  10512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10513. // ChargingScheduleAllowedChargingRateUnit
  10514. /*
  10515. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10518. */
  10519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10520. // ChargingScheduleMaxPeriods
  10521. /*
  10522. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10525. */
  10526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10527. // ConnectorSwitch3to1PhaseSupported
  10528. /*
  10529. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10532. */
  10533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10534. // MaxChargingProfilesInstalled
  10535. /*
  10536. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10539. */
  10540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10541. fclose(outfile);
  10542. }
  10543. void getKeyValue(char *keyReq)
  10544. {
  10545. int isEmpty = FALSE;
  10546. int isKnowKey = FALSE;
  10547. //int unKnowIndex = 0;
  10548. DEBUG_INFO("getKeyValue \n");
  10549. DEBUG_INFO("keyReq=%s \n",keyReq);
  10550. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10551. isEmpty = TRUE;
  10552. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10553. {
  10554. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  10555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10558. {
  10559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10560. }
  10561. else
  10562. {
  10563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10564. }
  10565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10566. isKnowKey = TRUE;
  10567. }
  10568. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10569. {
  10570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10573. {
  10574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10575. }
  10576. else
  10577. {
  10578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10579. }
  10580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10581. isKnowKey = TRUE;
  10582. }
  10583. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10584. {
  10585. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10588. {
  10589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10590. }
  10591. else
  10592. {
  10593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10594. }
  10595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10596. isKnowKey = TRUE;
  10597. }
  10598. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10599. {
  10600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10603. {
  10604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10605. }
  10606. else
  10607. {
  10608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10609. }
  10610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10611. isKnowKey = TRUE;
  10612. }
  10613. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10614. {
  10615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10618. {
  10619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10620. }
  10621. else
  10622. {
  10623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10624. }
  10625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10626. isKnowKey = TRUE;
  10627. }
  10628. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10629. {
  10630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10633. {
  10634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10635. }
  10636. else
  10637. {
  10638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10639. }
  10640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10641. isKnowKey = TRUE;
  10642. }
  10643. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10644. {
  10645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10648. {
  10649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10650. }
  10651. else
  10652. {
  10653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10654. }
  10655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10656. isKnowKey = TRUE;
  10657. }
  10658. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10659. {
  10660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10663. {
  10664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10665. }
  10666. else
  10667. {
  10668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10669. }
  10670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10671. isKnowKey = TRUE;
  10672. }
  10673. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10674. {
  10675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10678. {
  10679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10680. }
  10681. else
  10682. {
  10683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10684. }
  10685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10686. isKnowKey = TRUE;
  10687. }
  10688. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10689. {
  10690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10693. {
  10694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10695. }
  10696. else
  10697. {
  10698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10699. }
  10700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10701. isKnowKey = TRUE;
  10702. }
  10703. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10704. {
  10705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10708. {
  10709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10710. }
  10711. else
  10712. {
  10713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10714. }
  10715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10716. isKnowKey = TRUE;
  10717. }
  10718. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10719. {
  10720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10723. {
  10724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10725. }
  10726. else
  10727. {
  10728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10729. }
  10730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10731. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10732. isKnowKey = TRUE;
  10733. }
  10734. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10735. {
  10736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10739. {
  10740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10741. }
  10742. else
  10743. {
  10744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10745. }
  10746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10747. isKnowKey = TRUE;
  10748. }
  10749. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10750. {
  10751. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10754. {
  10755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10756. }
  10757. else
  10758. {
  10759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10760. }
  10761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10762. isKnowKey = TRUE;
  10763. }
  10764. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10765. {
  10766. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10768. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10769. {
  10770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10771. }
  10772. else
  10773. {
  10774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10775. }
  10776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10777. isKnowKey = TRUE;
  10778. }
  10779. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10780. {
  10781. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10783. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10784. {
  10785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10786. }
  10787. else
  10788. {
  10789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10790. }
  10791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10792. isKnowKey = TRUE;
  10793. }
  10794. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10795. {
  10796. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10798. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10799. {
  10800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10801. }
  10802. else
  10803. {
  10804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10805. }
  10806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10807. isKnowKey = TRUE;
  10808. }
  10809. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10810. {
  10811. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10814. {
  10815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10816. }
  10817. else
  10818. {
  10819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10820. }
  10821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10822. isKnowKey = TRUE;
  10823. }
  10824. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10825. {
  10826. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10829. {
  10830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10831. }
  10832. else
  10833. {
  10834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10835. }
  10836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10837. isKnowKey = TRUE;
  10838. }
  10839. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10840. {
  10841. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10844. {
  10845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10846. }
  10847. else
  10848. {
  10849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10850. }
  10851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10852. isKnowKey = TRUE;
  10853. }
  10854. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10855. {
  10856. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10859. {
  10860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10861. }
  10862. else
  10863. {
  10864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10865. }
  10866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10867. isKnowKey = TRUE;
  10868. }
  10869. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10870. {
  10871. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10874. {
  10875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10876. }
  10877. else
  10878. {
  10879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10880. }
  10881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10882. isKnowKey = TRUE;
  10883. }
  10884. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10885. {
  10886. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10889. {
  10890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10891. }
  10892. else
  10893. {
  10894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10895. }
  10896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10897. isKnowKey = TRUE;
  10898. }
  10899. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10900. {
  10901. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10904. {
  10905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10906. }
  10907. else
  10908. {
  10909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10910. }
  10911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10912. isKnowKey = TRUE;
  10913. }
  10914. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10915. {
  10916. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10919. {
  10920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10921. }
  10922. else
  10923. {
  10924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10925. }
  10926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10927. isKnowKey = TRUE;
  10928. }
  10929. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10930. {
  10931. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10934. {
  10935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10936. }
  10937. else
  10938. {
  10939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10940. }
  10941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10942. isKnowKey = TRUE;
  10943. }
  10944. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10945. {
  10946. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10949. {
  10950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10951. }
  10952. else
  10953. {
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10955. }
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10957. isKnowKey = TRUE;
  10958. }
  10959. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10960. {
  10961. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10964. {
  10965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10966. }
  10967. else
  10968. {
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10970. }
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10972. isKnowKey = TRUE;
  10973. }
  10974. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10975. {
  10976. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10979. {
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10981. }
  10982. else
  10983. {
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10985. }
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10987. isKnowKey = TRUE;
  10988. }
  10989. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10990. {
  10991. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10994. {
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10996. }
  10997. else
  10998. {
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11000. }
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11002. isKnowKey = TRUE;
  11003. }
  11004. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11005. {
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11009. {
  11010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11011. }
  11012. else
  11013. {
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11015. }
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11017. isKnowKey = TRUE;
  11018. }
  11019. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11020. {
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11024. {
  11025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11026. }
  11027. else
  11028. {
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11030. }
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11032. isKnowKey = TRUE;
  11033. }
  11034. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11035. {
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11038. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11039. {
  11040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11041. }
  11042. else
  11043. {
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11045. }
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11047. isKnowKey = TRUE;
  11048. }
  11049. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11050. {
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11054. {
  11055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11056. }
  11057. else
  11058. {
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11060. }
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11062. isKnowKey = TRUE;
  11063. }
  11064. #if 0
  11065. //For OCTT Test Case
  11066. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11067. {
  11068. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11070. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11071. {
  11072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11073. }
  11074. else
  11075. {
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11077. }
  11078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11079. isKnowKey = TRUE;
  11080. }
  11081. #endif
  11082. #if 1
  11083. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11084. {
  11085. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11087. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11088. {
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11090. }
  11091. else
  11092. {
  11093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11094. }
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11096. isKnowKey = TRUE;
  11097. }
  11098. #endif
  11099. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11100. {
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11103. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11104. {
  11105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11106. }
  11107. else
  11108. {
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11110. }
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11112. isKnowKey = TRUE;
  11113. }
  11114. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11115. {
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11118. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11119. {
  11120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11121. }
  11122. else
  11123. {
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11125. }
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11127. isKnowKey = TRUE;
  11128. }
  11129. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11130. {
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11133. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11134. {
  11135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11136. }
  11137. else
  11138. {
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11140. }
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11142. isKnowKey = TRUE;
  11143. }
  11144. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11145. {
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11148. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11149. {
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11151. }
  11152. else
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11155. }
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11157. isKnowKey = TRUE;
  11158. }
  11159. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11160. {
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11163. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11164. {
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11166. }
  11167. else
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11170. }
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11172. isKnowKey = TRUE;
  11173. }
  11174. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11175. {
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11178. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11179. {
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11181. }
  11182. else
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11185. }
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11187. isKnowKey = TRUE;
  11188. }
  11189. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11190. {
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11193. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11194. {
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11196. }
  11197. else
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11200. }
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11202. isKnowKey = TRUE;
  11203. }
  11204. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11205. {
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11208. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11209. {
  11210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11211. }
  11212. else
  11213. {
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11215. }
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11217. isKnowKey = TRUE;
  11218. }
  11219. //=========================================================
  11220. if(!isEmpty && !isKnowKey)
  11221. {
  11222. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11223. strcpy(unknownkey[UnknownKeynum], keyReq);
  11224. UnknownKeynum = UnknownKeynum + 1;
  11225. }
  11226. }
  11227. void processUnkownKey(void)
  11228. {
  11229. DEBUG_INFO("processUnkownKey\n");
  11230. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11231. for(int index=0; index < UnknownKeynum; index++)
  11232. {
  11233. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11234. {
  11235. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11236. }
  11237. }
  11238. }
  11239. int setKeyValue(char *key, char *value)
  11240. {
  11241. int isSuccess = NotSupported;
  11242. int check_ascii=0;
  11243. char str[10]={0};
  11244. #ifdef Debug
  11245. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11246. #endif
  11247. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11248. {
  11249. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11251. {
  11252. strcpy(str, (const char*)value);
  11253. for(int i = 0; str[i]; i++){
  11254. str[i] = tolower(str[i]);
  11255. }
  11256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11257. isSuccess = ConfigurationStatus_Accepted;
  11258. }
  11259. else
  11260. {
  11261. isSuccess = ConfigurationStatus_Rejected;
  11262. }
  11263. }
  11264. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11265. {
  11266. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11268. {
  11269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  11270. isSuccess = ConfigurationStatus_Accepted;
  11271. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11272. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11273. }
  11274. else
  11275. {
  11276. isSuccess = ConfigurationStatus_Rejected;
  11277. }
  11278. }
  11279. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11280. {
  11281. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11282. {
  11283. strcpy(str, (const char*)value);
  11284. for(int i = 0; str[i]; i++)
  11285. {
  11286. str[i] = tolower(str[i]);
  11287. }
  11288. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11290. isSuccess = ConfigurationStatus_Accepted;
  11291. }
  11292. else
  11293. {
  11294. isSuccess = ConfigurationStatus_Rejected;
  11295. }
  11296. }
  11297. if(strcmp(key, "BlinkRepeat") == 0)
  11298. {
  11299. //Charger.BlinkRepeat = Integer.parseInt(value);
  11300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11301. {
  11302. check_ascii = value[0];
  11303. if( (check_ascii < 48) || (check_ascii > 57) )
  11304. {
  11305. isSuccess = ConfigurationStatus_Rejected;
  11306. }
  11307. else
  11308. {
  11309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11310. isSuccess = ConfigurationStatus_Accepted;
  11311. }
  11312. }
  11313. else
  11314. {
  11315. isSuccess = ConfigurationStatus_Rejected;
  11316. }
  11317. }
  11318. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11319. {
  11320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11321. {
  11322. check_ascii = value[0];
  11323. if( (check_ascii < 48) || (check_ascii > 57) )
  11324. {
  11325. isSuccess = ConfigurationStatus_Rejected;
  11326. }
  11327. else
  11328. {
  11329. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11330. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11331. isSuccess = ConfigurationStatus_Accepted;
  11332. }
  11333. }
  11334. else
  11335. {
  11336. isSuccess = ConfigurationStatus_Rejected;
  11337. }
  11338. }
  11339. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11340. {
  11341. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11342. {
  11343. check_ascii = value[0];
  11344. if( (check_ascii < 48) || (check_ascii > 57) )
  11345. {
  11346. isSuccess = ConfigurationStatus_Rejected;
  11347. }
  11348. else
  11349. {
  11350. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11352. isSuccess = ConfigurationStatus_Accepted;
  11353. }
  11354. }
  11355. else
  11356. {
  11357. isSuccess = ConfigurationStatus_Rejected;
  11358. }
  11359. }
  11360. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11361. {
  11362. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11363. {
  11364. check_ascii = value[0];
  11365. if( (check_ascii < 48) || (check_ascii > 57) )
  11366. {
  11367. isSuccess = ConfigurationStatus_Rejected;
  11368. }
  11369. else
  11370. {
  11371. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11373. isSuccess = ConfigurationStatus_Accepted;
  11374. }
  11375. }
  11376. else
  11377. {
  11378. isSuccess = ConfigurationStatus_Rejected;
  11379. }
  11380. }
  11381. if(strcmp(key, "HeartbeatInterval") == 0)
  11382. {
  11383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11384. {
  11385. check_ascii = value[0];
  11386. if( (check_ascii < 48) || (check_ascii > 57) )
  11387. {
  11388. isSuccess = ConfigurationStatus_Rejected;
  11389. }
  11390. else
  11391. {
  11392. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11394. HeartBeatWaitTime = atoi(value);
  11395. isSuccess = ConfigurationStatus_Accepted;
  11396. }
  11397. }
  11398. else
  11399. {
  11400. isSuccess = ConfigurationStatus_Rejected;
  11401. }
  11402. }
  11403. if(strcmp(key, "LightIntensity") == 0)
  11404. {
  11405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11406. {
  11407. check_ascii = value[0];
  11408. if( (check_ascii < 48) || (check_ascii > 57) )
  11409. {
  11410. isSuccess = ConfigurationStatus_Rejected;
  11411. }
  11412. else
  11413. {
  11414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11415. isSuccess = ConfigurationStatus_Accepted;
  11416. }
  11417. }
  11418. else
  11419. {
  11420. isSuccess = ConfigurationStatus_Rejected;
  11421. }
  11422. }
  11423. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11424. {
  11425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11426. {
  11427. strcpy(str, (const char*)value);
  11428. for(int i = 0; str[i]; i++)
  11429. {
  11430. str[i] = tolower(str[i]);
  11431. }
  11432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11433. isSuccess = ConfigurationStatus_Accepted;
  11434. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11435. }
  11436. else
  11437. {
  11438. isSuccess = ConfigurationStatus_Rejected;
  11439. }
  11440. }
  11441. if(strcmp(key, "LocalPreAuthorize") == 0)
  11442. {
  11443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11444. {
  11445. strcpy(str, (const char*)value);
  11446. for(int i = 0; str[i]; i++)
  11447. {
  11448. str[i] = tolower(str[i]);
  11449. }
  11450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11451. isSuccess = ConfigurationStatus_Accepted;
  11452. }
  11453. else
  11454. {
  11455. isSuccess = ConfigurationStatus_Rejected;
  11456. }
  11457. }
  11458. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11459. {
  11460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11461. {
  11462. check_ascii = value[0];
  11463. if( (check_ascii < 48) || (check_ascii > 57) )
  11464. {
  11465. isSuccess = ConfigurationStatus_Rejected;
  11466. }
  11467. else
  11468. {
  11469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11470. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11471. isSuccess = ConfigurationStatus_Accepted;
  11472. }
  11473. }
  11474. else
  11475. {
  11476. isSuccess = ConfigurationStatus_Rejected;
  11477. }
  11478. }
  11479. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11480. {
  11481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11482. {
  11483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11484. isSuccess = ConfigurationStatus_Accepted;
  11485. }
  11486. else
  11487. {
  11488. isSuccess = ConfigurationStatus_Rejected;
  11489. }
  11490. }
  11491. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11492. {
  11493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11494. {
  11495. check_ascii = value[0];
  11496. if( (check_ascii < 48) || (check_ascii > 57) )
  11497. {
  11498. isSuccess = ConfigurationStatus_Rejected;
  11499. }
  11500. else
  11501. {
  11502. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11504. isSuccess = ConfigurationStatus_Accepted;
  11505. }
  11506. }
  11507. else
  11508. {
  11509. isSuccess = ConfigurationStatus_Rejected;
  11510. }
  11511. }
  11512. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11513. {
  11514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11515. {
  11516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11517. isSuccess = ConfigurationStatus_Accepted;
  11518. }
  11519. else
  11520. {
  11521. isSuccess = ConfigurationStatus_Rejected;
  11522. }
  11523. }
  11524. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11525. {
  11526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11527. {
  11528. check_ascii = value[0];
  11529. if( (check_ascii < 48) || (check_ascii > 57) )
  11530. {
  11531. isSuccess = ConfigurationStatus_Rejected;
  11532. }
  11533. else
  11534. {
  11535. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11537. isSuccess = ConfigurationStatus_Accepted;
  11538. }
  11539. }
  11540. else
  11541. {
  11542. isSuccess = ConfigurationStatus_Rejected;
  11543. }
  11544. }
  11545. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11546. {
  11547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11548. {
  11549. check_ascii = value[0];
  11550. if( (check_ascii < 48) || (check_ascii > 57) )
  11551. {
  11552. isSuccess = ConfigurationStatus_Rejected;
  11553. }
  11554. else
  11555. {
  11556. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11558. isSuccess = ConfigurationStatus_Accepted;
  11559. }
  11560. }
  11561. else
  11562. {
  11563. isSuccess = ConfigurationStatus_Rejected;
  11564. }
  11565. }
  11566. if(strcmp(key, "MinimumStatusDuration") == 0)
  11567. {
  11568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11569. {
  11570. check_ascii = value[0];
  11571. if( (check_ascii < 48) || (check_ascii > 57) )
  11572. {
  11573. isSuccess = ConfigurationStatus_Rejected;
  11574. }
  11575. else
  11576. {
  11577. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11579. isSuccess = ConfigurationStatus_Accepted;
  11580. }
  11581. }
  11582. else
  11583. {
  11584. isSuccess = ConfigurationStatus_Rejected;
  11585. }
  11586. }
  11587. if(strcmp(key, "NumberOfConnectors") == 0)
  11588. {
  11589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11590. {
  11591. check_ascii = value[0];
  11592. if( (check_ascii < 48) || (check_ascii > 57) )
  11593. {
  11594. isSuccess = ConfigurationStatus_Rejected;
  11595. }
  11596. else
  11597. {
  11598. //Charger.ResetRetries = Integer.parseInt(value);
  11599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11600. isSuccess = ConfigurationStatus_Accepted;
  11601. }
  11602. }
  11603. else
  11604. {
  11605. isSuccess = ConfigurationStatus_Rejected;
  11606. }
  11607. }
  11608. if(strcmp(key, "ResetRetries") == 0)
  11609. {
  11610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11611. {
  11612. check_ascii = value[0];
  11613. if( (check_ascii < 48) || (check_ascii > 57) )
  11614. {
  11615. isSuccess = ConfigurationStatus_Rejected;
  11616. }
  11617. else
  11618. {
  11619. //Charger.ResetRetries = Integer.parseInt(value);
  11620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11621. isSuccess = ConfigurationStatus_Accepted;
  11622. }
  11623. }
  11624. else
  11625. {
  11626. isSuccess = ConfigurationStatus_Rejected;
  11627. }
  11628. }
  11629. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11630. {
  11631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11632. {
  11633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  11634. isSuccess = ConfigurationStatus_Accepted;
  11635. }
  11636. else
  11637. {
  11638. isSuccess = ConfigurationStatus_Rejected;
  11639. }
  11640. }
  11641. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11642. {
  11643. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11644. {
  11645. check_ascii = value[0];
  11646. if( (check_ascii < 48) || (check_ascii > 57) )
  11647. {
  11648. isSuccess = ConfigurationStatus_Rejected;
  11649. }
  11650. else
  11651. {
  11652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11653. isSuccess = ConfigurationStatus_Accepted;
  11654. }
  11655. }
  11656. else
  11657. {
  11658. isSuccess = ConfigurationStatus_Rejected;
  11659. }
  11660. }
  11661. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11662. {
  11663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11664. {
  11665. strcpy(str, (const char*)value);
  11666. for(int i = 0; str[i]; i++)
  11667. {
  11668. str[i] = tolower(str[i]);
  11669. }
  11670. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11672. isSuccess = ConfigurationStatus_Accepted;
  11673. }
  11674. else
  11675. {
  11676. isSuccess = ConfigurationStatus_Rejected;
  11677. }
  11678. }
  11679. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11680. {
  11681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11682. {
  11683. strcpy(str, (const char*)value);
  11684. for(int i = 0; str[i]; i++)
  11685. {
  11686. str[i] = tolower(str[i]);
  11687. }
  11688. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11690. isSuccess = ConfigurationStatus_Accepted;
  11691. }
  11692. else
  11693. {
  11694. isSuccess = ConfigurationStatus_Rejected;
  11695. }
  11696. }
  11697. if(strcmp(key, "StopTxnAlignedData") == 0)
  11698. {
  11699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11700. {
  11701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11702. isSuccess = ConfigurationStatus_Accepted;
  11703. }
  11704. else
  11705. {
  11706. isSuccess = ConfigurationStatus_Rejected;
  11707. }
  11708. }
  11709. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11710. {
  11711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11712. {
  11713. check_ascii = value[0];
  11714. if( (check_ascii < 48) || (check_ascii > 57) )
  11715. {
  11716. isSuccess = ConfigurationStatus_Rejected;
  11717. }
  11718. else
  11719. {
  11720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11721. isSuccess = ConfigurationStatus_Accepted;
  11722. }
  11723. }
  11724. else
  11725. {
  11726. isSuccess = ConfigurationStatus_Rejected;
  11727. }
  11728. }
  11729. if(strcmp(key, "StopTxnSampledData") == 0)
  11730. {
  11731. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11732. {
  11733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11734. isSuccess = ConfigurationStatus_Accepted;
  11735. }
  11736. else
  11737. {
  11738. isSuccess = ConfigurationStatus_Rejected;
  11739. }
  11740. }
  11741. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11742. {
  11743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11744. {
  11745. check_ascii = value[0];
  11746. if( (check_ascii < 48) || (check_ascii > 57) )
  11747. {
  11748. isSuccess = ConfigurationStatus_Rejected;
  11749. }
  11750. else
  11751. {
  11752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11753. isSuccess = ConfigurationStatus_Accepted;
  11754. }
  11755. }
  11756. else
  11757. {
  11758. isSuccess = ConfigurationStatus_Rejected;
  11759. }
  11760. }
  11761. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11762. {
  11763. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11764. {
  11765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11766. isSuccess = ConfigurationStatus_Accepted;
  11767. }
  11768. else
  11769. {
  11770. isSuccess = ConfigurationStatus_Rejected;
  11771. }
  11772. }
  11773. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11774. {
  11775. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11776. {
  11777. check_ascii = value[0];
  11778. if( (check_ascii < 48) || (check_ascii > 57) )
  11779. {
  11780. isSuccess = ConfigurationStatus_Rejected;
  11781. }
  11782. else
  11783. {
  11784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11785. isSuccess = ConfigurationStatus_Accepted;
  11786. }
  11787. }
  11788. else
  11789. {
  11790. isSuccess = ConfigurationStatus_Rejected;
  11791. }
  11792. }
  11793. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11794. {
  11795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11796. {
  11797. check_ascii = value[0];
  11798. if( (check_ascii < 48) || (check_ascii > 57) )
  11799. {
  11800. isSuccess = ConfigurationStatus_Rejected;
  11801. }
  11802. else
  11803. {
  11804. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11806. TransactionMessageAttemptsValue = atoi(value);
  11807. isSuccess = ConfigurationStatus_Accepted;
  11808. }
  11809. }
  11810. else
  11811. {
  11812. isSuccess = ConfigurationStatus_Rejected;
  11813. }
  11814. }
  11815. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11816. {
  11817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11818. {
  11819. check_ascii = value[0];
  11820. if( (check_ascii < 48) || (check_ascii > 57) )
  11821. {
  11822. isSuccess = ConfigurationStatus_Rejected;
  11823. }
  11824. else
  11825. {
  11826. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11828. TransactionMessageRetryIntervalValue = atoi(value);
  11829. isSuccess = ConfigurationStatus_Accepted;
  11830. }
  11831. }
  11832. else
  11833. {
  11834. isSuccess = ConfigurationStatus_Rejected;
  11835. }
  11836. }
  11837. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11838. {
  11839. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11840. {
  11841. strcpy(str, (const char*)value);
  11842. for(int i = 0; str[i]; i++)
  11843. {
  11844. str[i] = tolower(str[i]);
  11845. }
  11846. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11848. isSuccess = ConfigurationStatus_Accepted;
  11849. }
  11850. else
  11851. {
  11852. isSuccess = ConfigurationStatus_Rejected;
  11853. }
  11854. }
  11855. if(strcmp(key, "WebSocketPingInterval") == 0)
  11856. {
  11857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11858. {
  11859. check_ascii = value[0];
  11860. if( (check_ascii < 48) || (check_ascii > 57) )
  11861. {
  11862. isSuccess = ConfigurationStatus_Rejected;
  11863. }
  11864. else
  11865. {
  11866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11867. isSuccess = ConfigurationStatus_Accepted;
  11868. }
  11869. }
  11870. else
  11871. {
  11872. isSuccess = ConfigurationStatus_Rejected;
  11873. }
  11874. }
  11875. #if 0
  11876. //For OCPP Test Case
  11877. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11878. {
  11879. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11880. {
  11881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11882. isSuccess = ConfigurationStatus_Accepted;
  11883. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11884. }
  11885. else
  11886. {
  11887. isSuccess = ConfigurationStatus_Rejected;
  11888. }
  11889. }
  11890. #endif
  11891. #if 1
  11892. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11893. {
  11894. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11895. {
  11896. strcpy(str, (const char*)value);
  11897. for(int i = 0; str[i]; i++)
  11898. {
  11899. str[i] = tolower(str[i]);
  11900. }
  11901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11902. isSuccess = ConfigurationStatus_Accepted;
  11903. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11904. }
  11905. else
  11906. {
  11907. isSuccess = ConfigurationStatus_Rejected;
  11908. }
  11909. }
  11910. #endif
  11911. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11912. {
  11913. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11914. {
  11915. check_ascii = value[0];
  11916. if( (check_ascii < 48) || (check_ascii > 57) )
  11917. {
  11918. isSuccess = ConfigurationStatus_Rejected;
  11919. }
  11920. else
  11921. {
  11922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11923. isSuccess = ConfigurationStatus_Accepted;
  11924. }
  11925. }
  11926. else
  11927. {
  11928. isSuccess = ConfigurationStatus_Rejected;
  11929. }
  11930. }
  11931. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11932. {
  11933. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11934. {
  11935. check_ascii = value[0];
  11936. if( (check_ascii < 48) || (check_ascii > 57) )
  11937. {
  11938. isSuccess = ConfigurationStatus_Rejected;
  11939. }
  11940. else
  11941. {
  11942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11943. isSuccess = ConfigurationStatus_Accepted;
  11944. }
  11945. }
  11946. else
  11947. {
  11948. isSuccess = ConfigurationStatus_Rejected;
  11949. }
  11950. }
  11951. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11952. {
  11953. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11954. {
  11955. strcpy(str, (const char*)value);
  11956. for(int i = 0; str[i]; i++)
  11957. {
  11958. str[i] = tolower(str[i]);
  11959. }
  11960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11961. isSuccess = ConfigurationStatus_Accepted;
  11962. }
  11963. else
  11964. {
  11965. isSuccess = ConfigurationStatus_Rejected;
  11966. }
  11967. }
  11968. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11969. {
  11970. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11971. {
  11972. check_ascii = value[0];
  11973. if( (check_ascii < 48) || (check_ascii > 57) )
  11974. {
  11975. isSuccess = ConfigurationStatus_Rejected;
  11976. }
  11977. else
  11978. {
  11979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11980. isSuccess = ConfigurationStatus_Accepted;
  11981. }
  11982. }
  11983. else
  11984. {
  11985. isSuccess = ConfigurationStatus_Rejected;
  11986. }
  11987. }
  11988. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11989. {
  11990. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11991. {
  11992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11993. isSuccess = ConfigurationStatus_Accepted;
  11994. }
  11995. else
  11996. {
  11997. isSuccess = ConfigurationStatus_Rejected;
  11998. }
  11999. }
  12000. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12001. {
  12002. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12003. {
  12004. check_ascii = value[0];
  12005. if( (check_ascii < 48) || (check_ascii > 57) )
  12006. {
  12007. isSuccess = ConfigurationStatus_Rejected;
  12008. }
  12009. else
  12010. {
  12011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12012. isSuccess = ConfigurationStatus_Accepted;
  12013. }
  12014. }
  12015. else
  12016. {
  12017. isSuccess = ConfigurationStatus_Rejected;
  12018. }
  12019. }
  12020. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12021. {
  12022. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12023. {
  12024. strcpy(str, (const char*)value);
  12025. for(int i = 0; str[i]; i++)
  12026. {
  12027. str[i] = tolower(str[i]);
  12028. }
  12029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12030. isSuccess = ConfigurationStatus_Accepted;
  12031. }
  12032. else
  12033. {
  12034. isSuccess = ConfigurationStatus_Rejected;
  12035. }
  12036. }
  12037. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12038. {
  12039. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12040. {
  12041. check_ascii = value[0];
  12042. if( (check_ascii < 48) || (check_ascii > 57) )
  12043. {
  12044. isSuccess = ConfigurationStatus_Rejected;
  12045. }
  12046. else
  12047. {
  12048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12049. isSuccess = ConfigurationStatus_Accepted;
  12050. }
  12051. }
  12052. else
  12053. {
  12054. isSuccess = ConfigurationStatus_Rejected;
  12055. }
  12056. }
  12057. return isSuccess;
  12058. }
  12059. int updateSetting(char *key, char *value)
  12060. {
  12061. mtrace();
  12062. int isSuccess = FALSE;
  12063. char string[1000]={0}, buffer[1000]={0};
  12064. char strtemp[50]={0};
  12065. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12066. int pos, c = 0;
  12067. char *loc;
  12068. int pos1=0;
  12069. FILE *f = fopen("/var/www/settings1", "r");
  12070. if(f == NULL)
  12071. {
  12072. #ifdef Debug
  12073. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12074. #endif
  12075. return isSuccess;
  12076. }
  12077. fseek(f, 0, SEEK_END);
  12078. long fsize = ftell(f);
  12079. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12080. fread(string, 1, fsize, f);
  12081. fclose(f);
  12082. string[fsize] = 0;
  12083. loc = strstr(string, key);
  12084. if(loc != NULL)
  12085. {
  12086. DEBUG_INFO("key exist!\n");
  12087. pos = loc - string-1;
  12088. f = fopen("/var/www/settings1", "w");
  12089. strncpy(buffer, string, pos);
  12090. fprintf(f, "%s", buffer);
  12091. memset(sstr ,0, sizeof(sstr) );
  12092. c = 0;
  12093. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12094. {
  12095. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12096. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12097. c++;
  12098. }
  12099. sstr[c] = '\0';
  12100. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12101. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12102. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12103. memset(buffer ,0, sizeof(buffer) );
  12104. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12105. //printf("buffer=%s",buffer);
  12106. fprintf(f, "%s", buffer);
  12107. fclose(f);
  12108. }
  12109. else
  12110. {
  12111. printf("key not exist!\n");
  12112. f = fopen("/var/www/settings1", "w+");
  12113. fputs(string, f);
  12114. fseek(f, -1, SEEK_CUR);
  12115. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12116. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12117. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12118. fclose(f);
  12119. }
  12120. isSuccess = TRUE;
  12121. return isSuccess;
  12122. }
  12123. int TransactionMessageAttemptsGet(void)
  12124. {
  12125. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12126. }
  12127. int FirstHeartBeatResponse(void)
  12128. {
  12129. return FirstHeartBeat;
  12130. }
  12131. int TransactionMessageRetryIntervalGet(void)
  12132. {
  12133. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12134. }
  12135. #define SA struct sockaddr
  12136. #define MAXBUF 1024
  12137. //static int m_socket_data;
  12138. //static int sockfd;
  12139. int ReadHttpStatus(int sock){
  12140. //char c;
  12141. char buff[1024]="",*ptr=buff+1;
  12142. int bytes_received, status;
  12143. DEBUG_INFO("Begin Response ..\n");
  12144. while((bytes_received = recv(sock, ptr, 1, 0))){
  12145. if(bytes_received==-1){
  12146. perror("ReadHttpStatus");
  12147. exit(1);
  12148. }
  12149. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12150. ptr++;
  12151. }
  12152. *ptr=0;
  12153. ptr=buff+1;
  12154. sscanf(ptr,"%*s %d ", &status);
  12155. DEBUG_INFO("%s\n",ptr);
  12156. DEBUG_INFO("status=%d\n",status);
  12157. DEBUG_INFO("End Response ..\n");
  12158. return (bytes_received>0)?status:0;
  12159. }
  12160. //the only filed that it parsed is 'Content-Length'
  12161. int ParseHeader(int sock){
  12162. //char c;
  12163. char buff[1024]="",*ptr=buff+4;
  12164. int bytes_received;
  12165. DEBUG_INFO("Begin HEADER ..\n");
  12166. while((bytes_received = recv(sock, ptr, 1, 0))){
  12167. if(bytes_received==-1){
  12168. perror("Parse Header");
  12169. exit(1);
  12170. }
  12171. if(
  12172. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12173. (ptr[-1]=='\r') && (*ptr=='\n' )
  12174. ) break;
  12175. ptr++;
  12176. }
  12177. *ptr=0;
  12178. ptr=buff+4;
  12179. //printf("%s",ptr);
  12180. if(bytes_received){
  12181. ptr=strstr(ptr,"Content-Length:");
  12182. if(ptr){
  12183. sscanf(ptr,"%*s %d",&bytes_received);
  12184. }else
  12185. bytes_received=-1; //unknown size
  12186. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12187. }
  12188. DEBUG_INFO("End HEADER ..\n");
  12189. return bytes_received ;
  12190. }
  12191. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12192. {
  12193. char rmFileCmd[100]={0};
  12194. char FilePath[100]={0};
  12195. char ftpbuf[200];
  12196. int systemresult;
  12197. //DEBUG_INFO("filename=%s\n",filename);
  12198. //DEBUG_INFO("url=%s\n",url);
  12199. sprintf(FilePath,"/mnt/%s",filename);
  12200. if((access(FilePath,F_OK))!=-1)
  12201. {
  12202. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12203. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12204. system(rmFileCmd);
  12205. }
  12206. memset(ftpbuf, 0, sizeof(ftpbuf));
  12207. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12208. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12209. systemresult = system(ftpbuf);
  12210. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12211. if(systemresult != 0)
  12212. {
  12213. DEBUG_INFO("http DownLoad error!\n");
  12214. return FALSE;
  12215. }
  12216. return TRUE;
  12217. }
  12218. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12219. {
  12220. char rmFileCmd[100]={0};
  12221. char FilePath[100]={0};
  12222. char ftpbuf[200];
  12223. int systemresult;
  12224. //char temp[100];
  12225. #if 0
  12226. struct hostent* server;
  12227. char *IPbuffer;
  12228. server = gethostbyname(location);
  12229. // To convert an Internet network
  12230. // address into ASCII string
  12231. IPbuffer = inet_ntoa(*((struct in_addr*)
  12232. server->h_addr_list[0]));
  12233. #endif
  12234. sprintf(FilePath,"/mnt/%s",filename);
  12235. if((access(FilePath,F_OK))!=-1)
  12236. {
  12237. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12238. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12239. system(rmFileCmd);
  12240. }
  12241. memset(ftpbuf, 0, sizeof(ftpbuf));
  12242. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12243. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12244. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12245. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12246. systemresult = system(ftpbuf);
  12247. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12248. if(systemresult != 0)
  12249. {
  12250. printf("wget error!\n");
  12251. return FALSE;
  12252. }
  12253. return TRUE;
  12254. }
  12255. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12256. {
  12257. char rmFileCmd[100]={0};
  12258. char FilePath[100]={0};
  12259. char ftpbuf[200];
  12260. char filenametemp[60]={0};
  12261. int systemresult;
  12262. //DEBUG_INFO("filename=%s\n",filename);
  12263. //DEBUG_INFO("url=%s\n",url);
  12264. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12265. if((access(FilePath,F_OK))!=-1)
  12266. {
  12267. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12268. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12269. system(rmFileCmd);
  12270. }
  12271. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12272. if(fp == NULL)
  12273. {
  12274. DEBUG_INFO("log is NULL\n");
  12275. return FALSE;
  12276. }
  12277. else
  12278. {
  12279. fprintf(fp, "%s\n", url);
  12280. sscanf(filename, "%*2[.]%s", filenametemp);
  12281. fprintf(fp, "%s\n", filenametemp);
  12282. fclose(fp);
  12283. }
  12284. memset(ftpbuf, 0, sizeof(ftpbuf));
  12285. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12286. systemresult = system(ftpbuf);
  12287. DEBUG_INFO("systemresult=%d\n",systemresult);
  12288. if(systemresult != 0)
  12289. {
  12290. DEBUG_INFO("http upload error!\n");
  12291. return FALSE;
  12292. }
  12293. return TRUE;
  12294. }
  12295. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12296. {
  12297. struct hostent* server;
  12298. char *IPbuffer;
  12299. char ftpbuf[200];
  12300. int systemresult;
  12301. // To retrieve host information
  12302. server = gethostbyname(location);
  12303. // To convert an Internet network
  12304. // address into ASCII string
  12305. IPbuffer = inet_ntoa(*((struct in_addr*)
  12306. server->h_addr_list[0]));
  12307. memset(ftpbuf, 0, sizeof(ftpbuf));
  12308. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12309. /* format : ftpput -u username -p passwd IP target source*/
  12310. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12311. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12312. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12313. systemresult = system(ftpbuf);
  12314. DEBUG_INFO("systemresult=%d\n",systemresult);
  12315. if(systemresult != 0)
  12316. {
  12317. DEBUG_INFO("ftpput error!\n");
  12318. return FALSE;
  12319. }
  12320. return TRUE;
  12321. }
  12322. int SettingChargingRecord(int target, int transactionId)
  12323. {
  12324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12325. {
  12326. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12327. {
  12328. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12329. {
  12330. addBuff(target, transactionId, 0);
  12331. return TRUE;
  12332. }
  12333. }
  12334. for (int index = 0; index < CCS_QUANTITY; index++)
  12335. {
  12336. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12337. {
  12338. addBuff(target, transactionId, 0);
  12339. return TRUE;
  12340. }
  12341. }
  12342. for (int index = 0; index < GB_QUANTITY; index++)
  12343. {
  12344. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12345. {
  12346. addBuff(target, transactionId, 0);
  12347. return TRUE;
  12348. }
  12349. }
  12350. }
  12351. else
  12352. {
  12353. for (int index = 0; index < AC_QUANTITY; index++)
  12354. {
  12355. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12356. {
  12357. addBuff(target, transactionId, 0);
  12358. return TRUE;
  12359. }
  12360. }
  12361. }
  12362. return FALSE;
  12363. }
  12364. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12365. {
  12366. int isSuccess = FALSE;
  12367. //char *query = NULL;
  12368. sqlite3_stmt *stmt;
  12369. int rc; // return code
  12370. char str[20];
  12371. sprintf(str,"%d",user_id);
  12372. 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 */
  12373. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12374. rc = sqlite3_step(stmt); /* 3 */
  12375. if (rc != SQLITE_DONE) {
  12376. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12377. goto out;
  12378. }
  12379. sqlite3_finalize(stmt);
  12380. // free(query);
  12381. out:
  12382. //----------------------
  12383. // close SQLite database
  12384. //----------------------
  12385. sqlite3_close(db);
  12386. printf("database closed.\n");
  12387. return isSuccess;
  12388. }
  12389. /**
  12390. * Place the contents of the specified file into a memory buffer
  12391. *
  12392. * @param[in] filename The path and name of the file to read
  12393. * @param[out] filebuffer A pointer to the contents in memory
  12394. * @return status 0 success, 1 on failure
  12395. */
  12396. int get_file_contents(const char* filename, char** outbuffer) {
  12397. FILE* file = NULL;
  12398. long filesize;
  12399. const int blocksize = 1;
  12400. size_t readsize;
  12401. char* filebuffer;
  12402. // Open the file
  12403. file = fopen(filename, "r");
  12404. if (NULL == file)
  12405. {
  12406. printf("'%s' not opened\n", filename);
  12407. exit(EXIT_FAILURE);
  12408. }
  12409. // Determine the file size
  12410. fseek(file, 0, SEEK_END);
  12411. filesize = ftell(file);
  12412. rewind (file);
  12413. // Allocate memory for the file contents
  12414. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12415. *outbuffer = filebuffer;
  12416. if (filebuffer == NULL)
  12417. {
  12418. fputs ("malloc out-of-memory", stderr);
  12419. exit(EXIT_FAILURE);
  12420. }
  12421. // Read in the file
  12422. readsize = fread(filebuffer, blocksize, filesize, file);
  12423. if (readsize != filesize)
  12424. {
  12425. fputs ("didn't read file completely",stderr);
  12426. exit(EXIT_FAILURE);
  12427. }
  12428. // Clean exit
  12429. fclose(file);
  12430. return EXIT_SUCCESS;
  12431. }
  12432. static int selectSqlCount = 0;
  12433. static int callback(void *data, int argc, char **argv, char **azColName){
  12434. int i;
  12435. printf("%s: ", (const char*)data);
  12436. selectSqlCount = argc;
  12437. for(i = 0; i<argc; i++){
  12438. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12439. }
  12440. printf("\n");
  12441. return 0;
  12442. }
  12443. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12444. //int i;
  12445. //printf("%s:\n", (const char*)data);
  12446. localversion = argv[5] ? atoi(argv[5]) : 0;
  12447. printf("localversion=%d\n", localversion);
  12448. return 0;
  12449. }
  12450. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12451. //int i;
  12452. //printf("%s:\n", (const char*)data);
  12453. //idTag
  12454. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12455. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12456. //parentIdTag
  12457. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12458. //expir_date
  12459. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12460. //status
  12461. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12462. //version
  12463. idTagQuery.listVersionInt = atoi(argv[5]);
  12464. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12465. return 0;
  12466. }
  12467. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12468. int i;
  12469. //printf("%s:\n", (const char*)data);
  12470. #if 1
  12471. for(i=0; i<argc; i++){
  12472. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12473. }
  12474. //printf("");
  12475. #endif
  12476. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12477. // printf("localversion=%d\n", localversion);
  12478. return 0;
  12479. }
  12480. /** sqlite3_exec的回调。
  12481. *
  12482. * 向控制台打印查询的结果。
  12483. *
  12484. * @param in data 传递给回调函数的数据。
  12485. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12486. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12487. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12488. * @return 状态码。
  12489. */
  12490. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12491. {
  12492. for (int i = 0; i < n_columns; i++)
  12493. {
  12494. DEBUG_INFO("%s/t", col_values[i]);
  12495. }
  12496. DEBUG_INFO("/n");
  12497. return 0;
  12498. }
  12499. void OCPP_getListVerion()
  12500. {
  12501. int rc = 0;
  12502. // const char* data = "Callback function called";
  12503. char sql[100];
  12504. char zErrMsg[100];
  12505. memset(sql, 0, 100);
  12506. memset(zErrMsg, 0, 100);
  12507. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12508. /* Execute SQL statement */
  12509. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12510. DEBUG_INFO("rc=%d\n",rc);
  12511. if( rc != SQLITE_OK ){
  12512. DEBUG_INFO("SQL error: %s", zErrMsg);
  12513. //sqlite3_free(zErrMsg);
  12514. }else{
  12515. DEBUG_INFO("Operation done successfully");
  12516. }
  12517. }
  12518. void OCPP_getIdTag(char idTag[])
  12519. {
  12520. int rc = 0;
  12521. // const char* data = "Callback function called";
  12522. char sql[100];
  12523. char zErrMsg[100];
  12524. memset(sql, 0, 100);
  12525. memset(zErrMsg, 0, 100);
  12526. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12527. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12528. DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12529. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12530. /* Execute SQL statement */
  12531. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12532. if( rc != SQLITE_OK ){
  12533. DEBUG_INFO("SQL error: %s", zErrMsg);
  12534. //sqlite3_free(zErrMsg);
  12535. }else{
  12536. printf("Operation done successfully");
  12537. }
  12538. //return ver;
  12539. }
  12540. void OCPP_get_TableAuthlocalAllData(void)
  12541. {
  12542. int rc = 0;
  12543. // const char* data = "Callback function called";
  12544. char sql[100];
  12545. char zErrMsg[100];
  12546. memset(sql, 0, 100);
  12547. memset(zErrMsg, 0, 100);
  12548. sprintf(sql,"select * from ocpp_auth_local ");
  12549. /* Execute SQL statement */
  12550. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12551. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12552. if( rc != SQLITE_OK ){
  12553. DEBUG_INFO("SQL error: %s", zErrMsg);
  12554. //sqlite3_free(zErrMsg);
  12555. }else{
  12556. DEBUG_INFO("Operation done successfully");
  12557. }
  12558. //return ver;
  12559. }
  12560. int OCPP_cleanLocalList()
  12561. {
  12562. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12563. char *errMsg = 0;
  12564. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12565. if (SQLITE_OK != rc)
  12566. {
  12567. DEBUG_INFO("%s\n",errMsg);
  12568. return FALSE;
  12569. }
  12570. else
  12571. {
  12572. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12573. }
  12574. return TRUE;
  12575. }
  12576. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12577. {
  12578. int isSuccess = FALSE;
  12579. int ret = 0;
  12580. //const char* data = "Callback function called";
  12581. char sql[300];
  12582. char zErrMsg[200];
  12583. memset(sql, 0, 300);
  12584. memset(zErrMsg, 0, 200);
  12585. 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);
  12586. //* Execute SQL statement */
  12587. //zErrMsg = 0;
  12588. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12589. if( ret != SQLITE_OK ){
  12590. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12591. // free(zErrMsg);
  12592. // free(sql);
  12593. return isSuccess;
  12594. }
  12595. DEBUG_INFO("successfully Insert records created\n");
  12596. isSuccess = TRUE;
  12597. return isSuccess;
  12598. }
  12599. void OCPP_deleteIdTag(char idTag[])
  12600. {
  12601. //int ver = 0;
  12602. //int isSuccess = FALSE;
  12603. int rc = 0;
  12604. char sql[100];
  12605. char zErrMsg[100];
  12606. memset(sql, 0, 100);
  12607. memset(zErrMsg, 0, 100);
  12608. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12609. //* Execute SQL statement */
  12610. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12611. if( rc != SQLITE_OK ){
  12612. DEBUG_INFO("SQL error: %s", zErrMsg);
  12613. //sqlite3_free(zErrMsg);
  12614. }else{
  12615. DEBUG_INFO("Operation done successfully");
  12616. }
  12617. }
  12618. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12619. {
  12620. int isSuccess = FALSE;
  12621. int ret = 0;
  12622. const char* data = "Callback function called";
  12623. char sql[200];
  12624. char zErrMsg[100];
  12625. memset(sql, 0, 200);
  12626. memset(zErrMsg, 0, 100);
  12627. //* selectFromTable */
  12628. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12629. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12630. //* Execute SQL statement */
  12631. selectSqlCount = 0;
  12632. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12633. if( ret != SQLITE_OK ){
  12634. printf("Error SQL: %s\n", zErrMsg);
  12635. }
  12636. printf("successfully select operation done\n");
  12637. memset(sql, 0, 200);
  12638. memset(zErrMsg, 0, 100);
  12639. if(selectSqlCount == 0)
  12640. {
  12641. //Insert
  12642. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12643. 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);
  12644. DEBUG_INFO("sql:%s\n", sql);
  12645. //* Execute SQL statement */
  12646. //zErrMsg = 0;
  12647. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12648. if( ret != SQLITE_OK ){
  12649. printf("SQL error: %s\n", zErrMsg);
  12650. return isSuccess;
  12651. }
  12652. DEBUG_INFO("successfully Insert records created\n");
  12653. isSuccess = TRUE;
  12654. }
  12655. else
  12656. {
  12657. //Update
  12658. //* Create merged SQL statement */
  12659. 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);
  12660. /* Execute SQL statement */
  12661. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12662. if( ret != SQLITE_OK ){
  12663. printf("SQL error: %s\n", zErrMsg);
  12664. //sqlite3_free(zErrMsg);
  12665. //sqlite3_free(sql);
  12666. return isSuccess;
  12667. }
  12668. DEBUG_INFO("Successfully operation done \n");
  12669. isSuccess = TRUE;
  12670. }
  12671. return isSuccess;
  12672. }
  12673. int GetOcppServerURL()
  12674. {
  12675. int result = FALSE;
  12676. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12677. memset(OcppHost, 0, sizeof(OcppHost));
  12678. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12679. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12680. {
  12681. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12682. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12683. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12684. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12685. result = TRUE;
  12686. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12687. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12688. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12689. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12690. goto End;
  12691. }
  12692. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12693. {
  12694. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12695. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12696. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12697. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12698. result = TRUE;
  12699. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12700. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12701. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12702. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12703. goto End;
  12704. }
  12705. else
  12706. {
  12707. strcpy(OcppHost,"");
  12708. }
  12709. End:
  12710. return result;
  12711. }
  12712. int GetOcppPath()
  12713. {
  12714. int result = FALSE;
  12715. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12716. {
  12717. if(OcppTempPath == NULL)
  12718. {
  12719. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12720. }
  12721. else
  12722. {
  12723. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12724. }
  12725. result = TRUE;
  12726. goto End;
  12727. }
  12728. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12729. {
  12730. if(OcppTempPath == NULL)
  12731. {
  12732. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12733. }
  12734. else
  12735. {
  12736. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12737. }
  12738. result = TRUE;
  12739. goto End;
  12740. }
  12741. else
  12742. {
  12743. strcpy(OcppPath,"");
  12744. }
  12745. End:
  12746. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12747. return result;
  12748. }
  12749. int GetOcppPort()
  12750. {
  12751. return OcppPort;
  12752. }
  12753. int GetOcppConnStatus(void)
  12754. {
  12755. return ShmOCPP16Data->OcppConnStatus;
  12756. }
  12757. void SetOcppConnStatus(uint8_t status)
  12758. {
  12759. ShmOCPP16Data->OcppConnStatus = status;
  12760. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12761. if(status == FALSE)
  12762. {
  12763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12764. {
  12765. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12766. }
  12767. else
  12768. {
  12769. SystemInitial = AC_QUANTITY;
  12770. }
  12771. }
  12772. }
  12773. int GetHeartBeatWithNOResponse(void)
  12774. {
  12775. return HeartBeatWithNOResponse;
  12776. }
  12777. void SetHeartBeatWithNOResponse(void)
  12778. {
  12779. HeartBeatWithNOResponse = 0;
  12780. }
  12781. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12782. /*
  12783. src 源字串的首地址(buf的地址)
  12784. separator 指定的分割字元
  12785. dest 接收子字串的陣列
  12786. num 分割後子字串的個數
  12787. */
  12788. char *pNext;
  12789. int count = 0;
  12790. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12791. return;
  12792. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12793. return;
  12794. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12795. while(pNext != NULL) {
  12796. *dest++ = pNext;
  12797. ++count;
  12798. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12799. }
  12800. *num = count;
  12801. }
  12802. int GetTransactionId(int gunindex, unsigned char idTag[])
  12803. {
  12804. char ch;
  12805. FILE *fptr1;
  12806. int temptransactionId;
  12807. char str[100]={0};
  12808. temptransactionId = 0;
  12809. /*------ Read the file ----------------*/
  12810. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12811. ch=fgetc(fptr1);
  12812. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12813. rewind(fptr1);
  12814. if(ch!=EOF)
  12815. {
  12816. // printf("%c",ch);
  12817. while (fgets(str, 100, fptr1) != NULL)
  12818. {
  12819. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12820. if(str[0]=='\0')
  12821. {
  12822. break;
  12823. }
  12824. char *revbuf[8] = {0}; //存放分割後的子字串
  12825. int num = 0;//分割後子字串的個數
  12826. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12827. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12828. {
  12829. temptransactionId = atoi(revbuf[2]);
  12830. break;
  12831. }
  12832. }
  12833. }
  12834. fclose(fptr1);
  12835. /*------- End of reading ---------------*/
  12836. return temptransactionId;
  12837. }
  12838. void SetTransactionIdZero(int transactionId)
  12839. {
  12840. //TransactionId[gunindex] = 0;
  12841. char ch;
  12842. FILE *fptr1, *fptr2;
  12843. int temptransactionId;
  12844. char str[100]={0}, temp[] = "/Storage/OCPP/temp.txt";
  12845. printf("\n\n Delete a specific line from a file :\n");
  12846. printf("-----------------------------------------\n");
  12847. //scanf("%s",fname);
  12848. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12849. if (!fptr1)
  12850. {
  12851. printf(" File not found or unable to open the input file!!\n");
  12852. return ;
  12853. }
  12854. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12855. if (!fptr2)
  12856. {
  12857. printf("Unable to open a temporary file to write!!\n");
  12858. fclose(fptr1);
  12859. return ;
  12860. }
  12861. ch=fgetc(fptr1);
  12862. //printf(" Now the content of the file %s is : \n",fname);
  12863. rewind(fptr1);
  12864. if(ch!=EOF)
  12865. {
  12866. // copy all contents to the temporary file except the specific line
  12867. while (fgets(str, 100, fptr1) != NULL)
  12868. {
  12869. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12870. if(str[0]=='\0')
  12871. {
  12872. break;
  12873. }
  12874. char *revbuf[8] = {0}; //存放分割後的子字串
  12875. int num = 0;//分割後子字串的個數
  12876. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12877. temptransactionId = atoi(revbuf[2]);
  12878. if(transactionId != temptransactionId)
  12879. {
  12880. fprintf(fptr2, "%s", str);
  12881. }
  12882. }
  12883. }
  12884. fclose(fptr1);
  12885. fclose(fptr2);
  12886. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12887. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12888. /*------ Read the file ----------------*/
  12889. }
  12890. int InternetDisconnect(void)
  12891. {
  12892. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12893. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12894. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12895. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12896. }
  12897. void GetChargingProfileRequest(int gunindex)
  12898. {
  12899. mtrace();
  12900. //int connectorIdInt, durationInt;
  12901. //char chargingRateUnitStr[4]={0};
  12902. int tempdurationInt = 0;
  12903. int tempchargingProfileId = 0;
  12904. int tempstackLevel = 0;
  12905. int temptransactionId = 0;
  12906. float tempminChargingRateFloat = 0.0;
  12907. char tempchargingProfilePurposeStr[24]={0};
  12908. char tempchargingProfileKindStr[12]={0};
  12909. char temprecurrencyKindStr[8]={0};
  12910. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12911. char tempvalidToStr[28]={0};
  12912. int tempStartPeriodInt = 0;
  12913. float tempLimitInt = 0.0;//0.1;
  12914. int tempNumberPhasesInt=0;
  12915. char fname[200];
  12916. //char comfirmstr[20];
  12917. float MinChargingRate =0.0;
  12918. double diff_t;
  12919. struct tm tp;
  12920. FILE *fptr1;//, *fptr2;
  12921. int c = 0;
  12922. char * pch;
  12923. char *loc;
  12924. char sstr[200]={ 0 };
  12925. int n_chargingProfile = 0;
  12926. int n_SchedulePeriods = 0;
  12927. char SchedulePeriodList[10][200]={0};
  12928. char sLineWord[1600]={0};
  12929. char word[1000]={0};
  12930. int confirmPeriods = 0;
  12931. struct StructProfile ChargePointMaxProfile;
  12932. struct StructProfile TxDefaultProfile;
  12933. struct StructProfile TxProfile;
  12934. struct StructProfile TxDefaultProfiletemp[2]={0};
  12935. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12936. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12937. struct StructChargingProfile TxProfile_TEMP={0};
  12938. int TxDefaultProfileFileIsNull=FALSE;
  12939. int ChargePointMaxProfileIsNull=FALSE;
  12940. int TxProfileIsNull=FALSE;
  12941. // int CompositeSceduleIndex = 0;
  12942. char ChargePointMaxProfileScheduleStr[30]={0};
  12943. char TxDefaultProfileScheduleStr[30]={0};
  12944. char TxProfileScheduleStr[30]={0};
  12945. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12946. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12947. memset(&TxProfile,0,sizeof(struct StructProfile));
  12948. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  12949. DEBUG_INFO("GetChargingProfileRequest\n");
  12950. //*****************************ChargePointMaxProfile******************************************/
  12951. strcpy(fname, ChargePointMaxProfile_JSON);
  12952. ChargePointMaxProfileIsNull=TRUE;
  12953. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12954. {
  12955. fptr1 = fopen(fname, "r");
  12956. int c;
  12957. c = fgetc(fptr1);
  12958. //DEBUG_INFO("c:%d\n",c);
  12959. rewind(fptr1);
  12960. if(c == EOF)
  12961. {
  12962. DEBUG_INFO("\n End of file reached.");
  12963. ChargePointMaxProfileIsNull=TRUE;
  12964. fclose(fptr1);
  12965. }
  12966. else
  12967. {
  12968. ChargePointMaxProfileIsNull=FALSE;
  12969. while(fscanf(fptr1, "%s", word) != EOF)
  12970. {
  12971. if(strcmp(word, "chargingProfileId") == 0)
  12972. {
  12973. n_chargingProfile = n_chargingProfile + 1;
  12974. }
  12975. }
  12976. rewind(fptr1);
  12977. //search Charging Profile Element
  12978. int i = 0;
  12979. int j = 0;
  12980. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12981. //***********chargingProfileId**************/
  12982. c = 0;
  12983. loc = strstr(sLineWord, "chargingProfileId");
  12984. //DEBUG_INFO("loc=%s\n",loc);
  12985. memset(sstr ,0, sizeof(sstr) );
  12986. if(loc != NULL)
  12987. {
  12988. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12989. {
  12990. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12991. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12992. c++;
  12993. }
  12994. sstr[c] = '\0';
  12995. tempchargingProfileId = atoi(sstr);
  12996. }
  12997. else
  12998. {
  12999. tempchargingProfileId = 0;
  13000. }
  13001. //***********stackLevel**************/
  13002. c = 0;
  13003. loc = strstr(sLineWord, "stackLevel");
  13004. //DEBUG_INFO("loc=%s\n",loc);
  13005. memset(sstr ,0, sizeof(sstr) );
  13006. if(loc != NULL)
  13007. {
  13008. while (loc[2+strlen("stackLevel")+c] != '\"')
  13009. {
  13010. sstr[c] = loc[2+strlen("stackLevel")+c];
  13011. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13012. c++;
  13013. }
  13014. sstr[c] = '\0';
  13015. tempstackLevel = atoi(sstr);
  13016. }
  13017. else
  13018. {
  13019. tempstackLevel = 0;
  13020. }
  13021. //***********chargingProfilePurpose **************/
  13022. c = 0;
  13023. loc = strstr(sLineWord, "chargingProfilePurpose");
  13024. //DEBUG_INFO("loc=%s\n",loc);
  13025. memset(sstr ,0, sizeof(sstr) );
  13026. if(loc != NULL)
  13027. {
  13028. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13029. {
  13030. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13031. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13032. c++;
  13033. }
  13034. sstr[c] = '\0';
  13035. strcpy(tempchargingProfilePurposeStr,sstr);
  13036. }
  13037. else
  13038. {
  13039. strcpy(tempchargingProfilePurposeStr,"");
  13040. }
  13041. //***********chargingProfileKind **************/
  13042. c = 0;
  13043. loc = strstr(sLineWord, "chargingProfileKind");
  13044. //DEBUG_INFO("loc=%s\n",loc);
  13045. memset(sstr ,0, sizeof(sstr) );
  13046. if(loc != NULL)
  13047. {
  13048. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13049. {
  13050. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13051. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13052. c++;
  13053. }
  13054. sstr[c] = '\0';
  13055. strcpy(tempchargingProfileKindStr,sstr);
  13056. }
  13057. else
  13058. {
  13059. strcpy(tempchargingProfileKindStr,"");
  13060. }
  13061. //***********recurrencyKind **************/
  13062. c = 0;
  13063. loc = strstr(sLineWord, "recurrencyKind");
  13064. //DEBUG_INFO("loc=%s\n",loc);
  13065. memset(sstr ,0, sizeof(sstr) );
  13066. if(loc != NULL)
  13067. {
  13068. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13069. {
  13070. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13071. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13072. c++;
  13073. }
  13074. sstr[c] = '\0';
  13075. strcpy(temprecurrencyKindStr,sstr);
  13076. }
  13077. else
  13078. {
  13079. strcpy(temprecurrencyKindStr,"");
  13080. }
  13081. //***********validFrom**************/
  13082. c = 0;
  13083. loc = strstr(sLineWord, "validFrom");
  13084. //DEBUG_INFO("loc=%s\n",loc);
  13085. memset(sstr ,0, sizeof(sstr) );
  13086. if(loc != NULL)
  13087. {
  13088. while (loc[3+strlen("validFrom")+c] != '\"')
  13089. {
  13090. sstr[c] = loc[3+strlen("validFrom")+c];
  13091. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13092. c++;
  13093. }
  13094. sstr[c] = '\0';
  13095. strcpy(tempvalidFromStr,sstr);
  13096. }
  13097. else
  13098. {
  13099. strcpy(tempvalidFromStr,"");
  13100. }
  13101. //***********validTo **************/
  13102. c = 0;
  13103. loc = strstr(sLineWord, "validTo");
  13104. //DEBUG_INFO("loc=%s\n",loc);
  13105. memset(sstr ,0, sizeof(sstr) );
  13106. if(loc != NULL)
  13107. {
  13108. while (loc[3+strlen("validTo")+c] != '\"')
  13109. {
  13110. sstr[c] = loc[3+strlen("validTo")+c];
  13111. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13112. c++;
  13113. }
  13114. sstr[c] = '\0';
  13115. strcpy(tempvalidToStr,sstr);
  13116. }
  13117. else
  13118. {
  13119. strcpy(tempvalidToStr,"");
  13120. }
  13121. //***********validFrom**************/
  13122. c = 0;
  13123. loc = strstr(sLineWord, "validFrom");
  13124. if(loc != NULL)
  13125. {
  13126. memset(sstr ,0, sizeof(sstr) );
  13127. while (loc[3+strlen("validFrom")+c] != '\"')
  13128. {
  13129. sstr[c] = loc[3+strlen("validFrom")+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. if(loc != NULL)
  13143. {
  13144. memset(sstr ,0, sizeof(sstr) );
  13145. while (loc[3+strlen("validTo")+c] != '\"')
  13146. {
  13147. sstr[c] = loc[3+strlen("validTo")+c];
  13148. c++;
  13149. }
  13150. sstr[c] = '\0';
  13151. strcpy(tempvalidToStr,sstr);
  13152. }
  13153. else
  13154. {
  13155. strcpy(tempvalidToStr,"");
  13156. }
  13157. //***********duration**************/
  13158. c = 0;
  13159. loc = strstr(sLineWord, "duration");
  13160. if(loc != NULL)
  13161. {
  13162. memset(sstr ,0, sizeof(sstr) );
  13163. while (loc[2+strlen("duration")+c] != ',')
  13164. {
  13165. sstr[c] = loc[2+strlen("duration")+c];
  13166. c++;
  13167. }
  13168. sstr[c] = '\0';
  13169. tempdurationInt = atoi(sstr);
  13170. }
  13171. else
  13172. {
  13173. tempdurationInt = 0;
  13174. }
  13175. //**********startSchedule**********/
  13176. c = 0;
  13177. loc = strstr(sLineWord, "startSchedule");
  13178. memset(sstr ,0, sizeof(sstr) );
  13179. while (loc[3+strlen("startSchedule")+c] != '\"')
  13180. {
  13181. sstr[c] = loc[3+strlen("startSchedule")+c];
  13182. c++;
  13183. }
  13184. sstr[c] = '\0';
  13185. strcpy(tempstartScheduleStr, sstr);
  13186. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  13187. //**********chargingRateUnit**********/
  13188. c = 0;
  13189. loc = strstr(sLineWord, "chargingRateUnit");
  13190. memset(sstr ,0, sizeof(sstr) );
  13191. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13192. {
  13193. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13194. c++;
  13195. }
  13196. sstr[c] = '\0';
  13197. strcpy(tempchargingRateUnitStr, sstr);
  13198. //**********minChargingRate*******/
  13199. c = 0;
  13200. loc = strstr(sLineWord, "minChargingRate");
  13201. if(loc != NULL)
  13202. {
  13203. memset(sstr ,0, sizeof(sstr) );
  13204. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13205. {
  13206. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13207. c++;
  13208. }
  13209. sstr[c] = '\0';
  13210. tempminChargingRateFloat = atof(sstr);
  13211. }
  13212. else
  13213. {
  13214. tempminChargingRateFloat = 0.0;
  13215. }
  13216. //
  13217. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13218. tp.tm_isdst = -1;
  13219. time_t utc = mktime(&tp);
  13220. time_t t = time(NULL);
  13221. diff_t = difftime(t, utc);
  13222. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13223. //parsing strings to words
  13224. i = 0;
  13225. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13226. loc = loc+3+strlen("chargingSchedulePeriod");
  13227. pch = strtok(loc ,"{");
  13228. while (pch != NULL)
  13229. {
  13230. strcpy(SchedulePeriodList[i], pch);
  13231. pch = strtok (NULL, "{");
  13232. i = i + 1;
  13233. }
  13234. n_SchedulePeriods = i;
  13235. for(int i=0;i<n_SchedulePeriods;i++)
  13236. {
  13237. //*************startPeriod****************/
  13238. c = 0;
  13239. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13240. memset(sstr ,0, sizeof(sstr) );
  13241. while (loc[strlen("startPeriod")+2+c] != ',')
  13242. {
  13243. sstr[c] = loc[strlen("startPeriod")+2+c];
  13244. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13245. c++;
  13246. }
  13247. sstr[c] = '\0';
  13248. tempStartPeriodInt = atoi(sstr);
  13249. //*************limit****************/
  13250. c = 0;
  13251. loc = strstr(SchedulePeriodList[i], "limit");
  13252. memset(sstr ,0, sizeof(sstr) );
  13253. while (loc[strlen("limit")+2+c] != ',')
  13254. {
  13255. sstr[c] = loc[strlen("limit")+2+c];
  13256. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13257. c++;
  13258. }
  13259. sstr[c] = '\0';
  13260. tempLimitInt = atof(sstr);
  13261. //*************numberPhases****************/
  13262. c = 0;
  13263. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13264. memset(sstr ,0, sizeof(sstr) );
  13265. while (loc[strlen("numberPhases")+2+c] != '}')
  13266. {
  13267. sstr[c] = loc[strlen("numberPhases")+2+c];
  13268. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13269. c++;
  13270. }
  13271. sstr[c] = '\0';
  13272. tempNumberPhasesInt = atoi(sstr);
  13273. if(j == 0)
  13274. {
  13275. ChargePointMaxProfile.Duration = tempdurationInt;
  13276. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13277. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13278. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13279. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13280. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13281. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13282. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13283. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13284. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13285. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13286. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13287. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13288. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13289. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13290. }
  13291. }
  13292. if(MinChargingRate < tempminChargingRateFloat)
  13293. {
  13294. MinChargingRate = tempminChargingRateFloat;
  13295. }
  13296. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13297. if(confirmPeriods < n_SchedulePeriods)
  13298. {
  13299. confirmPeriods = n_SchedulePeriods;
  13300. }
  13301. j = j + 1;
  13302. }
  13303. fclose(fptr1);
  13304. }
  13305. }// the end of access file ChargePointMaxProfile
  13306. //****************************TxDefaultProfile************************************************/
  13307. #if 0
  13308. switch(gunindex + 1)
  13309. {
  13310. case 0:
  13311. strcpy(fname, TxDefaultProfile_0_JSON );
  13312. break;
  13313. case 1:
  13314. strcpy(fname, TxDefaultProfile_1_JSON );
  13315. break;
  13316. case 2:
  13317. strcpy(fname, TxDefaultProfile_2_JSON );
  13318. break;
  13319. default:
  13320. strcpy(fname, TxDefaultProfile_1_JSON );
  13321. break;
  13322. }
  13323. #endif
  13324. memset(fname, 0, sizeof fname);
  13325. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13326. TxDefaultProfileFileIsNull=TRUE;
  13327. if((access(fname,F_OK))!=-1)
  13328. {
  13329. fptr1 = fopen(fname, "r");
  13330. c = 0;
  13331. c = fgetc(fptr1);
  13332. //DEBUG_INFO("c:%d\n",c);
  13333. rewind(fptr1);
  13334. if(c == EOF)
  13335. {
  13336. DEBUG_INFO("\n End of file reached.");
  13337. TxDefaultProfileFileIsNull=TRUE;
  13338. fclose(fptr1);
  13339. }
  13340. else
  13341. {
  13342. TxDefaultProfileFileIsNull=FALSE;
  13343. while(fscanf(fptr1, "%s", word) != EOF)
  13344. {
  13345. if(strcmp(word, "chargingProfileId") == 0)
  13346. {
  13347. n_chargingProfile = n_chargingProfile + 1;
  13348. }
  13349. }
  13350. rewind(fptr1);
  13351. //search Charging Profile Element
  13352. int i = 0;
  13353. int j = 0;
  13354. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13355. #if 0
  13356. /***********connectorId****************/
  13357. c = 0;
  13358. loc = strstr(sLineWord, "connectorId");
  13359. memset(sstr ,0, sizeof(sstr) );
  13360. while (loc[strlen("connectorId")+2+c] != ',')
  13361. {
  13362. sstr[c] = loc[strlen("connectorId")+2+c];
  13363. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13364. c++;
  13365. }
  13366. sstr[c] = '\0';
  13367. tempconnectorIdInt = atoi(sstr);
  13368. #endif
  13369. //***********chargingProfileId**************/
  13370. c = 0;
  13371. loc = strstr(sLineWord, "chargingProfileId");
  13372. //DEBUG_INFO("loc=%s\n",loc);
  13373. memset(sstr ,0, sizeof(sstr) );
  13374. if(loc != NULL)
  13375. {
  13376. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13377. {
  13378. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13379. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13380. c++;
  13381. }
  13382. sstr[c] = '\0';
  13383. tempchargingProfileId = atoi(sstr);
  13384. }
  13385. else
  13386. {
  13387. tempchargingProfileId = 0;
  13388. }
  13389. //***********stackLevel**************/
  13390. c = 0;
  13391. loc = strstr(sLineWord, "stackLevel");
  13392. //DEBUG_INFO("loc=%s\n",loc);
  13393. memset(sstr ,0, sizeof(sstr) );
  13394. if(loc != NULL)
  13395. {
  13396. while (loc[2+strlen("stackLevel")+c] != '\"')
  13397. {
  13398. sstr[c] = loc[2+strlen("stackLevel")+c];
  13399. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13400. c++;
  13401. }
  13402. sstr[c] = '\0';
  13403. tempstackLevel = atoi(sstr);
  13404. }
  13405. else
  13406. {
  13407. tempstackLevel = 0;
  13408. }
  13409. //***********chargingProfilePurpose **************/
  13410. c = 0;
  13411. loc = strstr(sLineWord, "chargingProfilePurpose");
  13412. //DEBUG_INFO("loc=%s\n",loc);
  13413. memset(sstr ,0, sizeof(sstr) );
  13414. if(loc != NULL)
  13415. {
  13416. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13417. {
  13418. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13419. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13420. c++;
  13421. }
  13422. sstr[c] = '\0';
  13423. strcpy(tempchargingProfilePurposeStr,sstr);
  13424. }
  13425. else
  13426. {
  13427. strcpy(tempchargingProfilePurposeStr,"");
  13428. }
  13429. //***********chargingProfileKind **************/
  13430. c = 0;
  13431. loc = strstr(sLineWord, "chargingProfileKind");
  13432. //DEBUG_INFO("loc=%s\n",loc);
  13433. memset(sstr ,0, sizeof(sstr) );
  13434. if(loc != NULL)
  13435. {
  13436. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13437. {
  13438. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13439. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13440. c++;
  13441. }
  13442. sstr[c] = '\0';
  13443. strcpy(tempchargingProfileKindStr,sstr);
  13444. }
  13445. else
  13446. {
  13447. strcpy(tempchargingProfileKindStr,"");
  13448. }
  13449. //***********recurrencyKind **************/
  13450. c = 0;
  13451. loc = strstr(sLineWord, "recurrencyKind");
  13452. //DEBUG_INFO("loc=%s\n",loc);
  13453. memset(sstr ,0, sizeof(sstr) );
  13454. if(loc != NULL)
  13455. {
  13456. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13457. {
  13458. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13459. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13460. c++;
  13461. }
  13462. sstr[c] = '\0';
  13463. strcpy(temprecurrencyKindStr,sstr);
  13464. }
  13465. else
  13466. {
  13467. strcpy(temprecurrencyKindStr,"");
  13468. }
  13469. //***********validFrom**************/
  13470. c = 0;
  13471. loc = strstr(sLineWord, "validFrom");
  13472. if(loc != NULL)
  13473. {
  13474. memset(sstr ,0, sizeof(sstr) );
  13475. while (loc[3+strlen("validFrom")+c] != '\"')
  13476. {
  13477. sstr[c] = loc[3+strlen("validFrom")+c];
  13478. c++;
  13479. }
  13480. sstr[c] = '\0';
  13481. strcpy(tempvalidFromStr,sstr);
  13482. }
  13483. else
  13484. {
  13485. strcpy(tempvalidFromStr,"");
  13486. }
  13487. //***********validTo **************/
  13488. c = 0;
  13489. loc = strstr(sLineWord, "validTo");
  13490. if(loc != NULL)
  13491. {
  13492. memset(sstr ,0, sizeof(sstr) );
  13493. while (loc[3+strlen("validTo")+c] != '\"')
  13494. {
  13495. sstr[c] = loc[3+strlen("validTo")+c];
  13496. c++;
  13497. }
  13498. sstr[c] = '\0';
  13499. strcpy(tempvalidToStr,sstr);
  13500. }
  13501. else
  13502. {
  13503. strcpy(tempvalidToStr,"");
  13504. }
  13505. //***********duration**************/
  13506. c = 0;
  13507. loc = strstr(sLineWord, "duration");
  13508. if(loc != NULL)
  13509. {
  13510. memset(sstr ,0, sizeof(sstr) );
  13511. while (loc[2+strlen("duration")+c] != ',')
  13512. {
  13513. sstr[c] = loc[2+strlen("duration")+c];
  13514. c++;
  13515. }
  13516. sstr[c] = '\0';
  13517. tempdurationInt = atoi(sstr);
  13518. }
  13519. else
  13520. {
  13521. tempdurationInt = 0;
  13522. }
  13523. //**********startSchedule**********/
  13524. c = 0;
  13525. loc = strstr(sLineWord, "startSchedule");
  13526. memset(sstr ,0, sizeof(sstr) );
  13527. while (loc[3+strlen("startSchedule")+c] != '\"')
  13528. {
  13529. sstr[c] = loc[3+strlen("startSchedule")+c];
  13530. c++;
  13531. }
  13532. sstr[c] = '\0';
  13533. strcpy(tempstartScheduleStr, sstr);
  13534. strcpy(TxDefaultProfileScheduleStr, sstr);
  13535. //**********chargingRateUnit**********/
  13536. c = 0;
  13537. loc = strstr(sLineWord, "chargingRateUnit");
  13538. memset(sstr ,0, sizeof(sstr) );
  13539. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13540. {
  13541. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13542. c++;
  13543. }
  13544. sstr[c] = '\0';
  13545. strcpy(tempchargingRateUnitStr, sstr);
  13546. //**********minChargingRate*******/
  13547. c = 0;
  13548. loc = strstr(sLineWord, "minChargingRate");
  13549. if(loc != NULL)
  13550. {
  13551. memset(sstr ,0, sizeof(sstr) );
  13552. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13553. {
  13554. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13555. c++;
  13556. }
  13557. sstr[c] = '\0';
  13558. tempminChargingRateFloat = atof(sstr);
  13559. }
  13560. else
  13561. {
  13562. tempminChargingRateFloat = 0.0;
  13563. }
  13564. //
  13565. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13566. tp.tm_isdst = -1;
  13567. time_t utc = mktime(&tp);
  13568. time_t t = time(NULL);
  13569. diff_t = difftime(t, utc);
  13570. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13571. //parsing strings to words
  13572. i = 0;
  13573. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13574. loc = loc+3+strlen("chargingSchedulePeriod");
  13575. pch = strtok(loc ,"{");
  13576. while (pch != NULL)
  13577. {
  13578. strcpy(SchedulePeriodList[i], pch);
  13579. pch = strtok (NULL, "{");
  13580. i = i + 1;
  13581. }
  13582. n_SchedulePeriods = i;
  13583. for(int i=0;i<n_SchedulePeriods;i++)
  13584. {
  13585. //*************startPeriod****************/
  13586. c = 0;
  13587. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13588. memset(sstr ,0, sizeof(sstr) );
  13589. while (loc[strlen("startPeriod")+2+c] != ',')
  13590. {
  13591. sstr[c] = loc[strlen("startPeriod")+2+c];
  13592. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13593. c++;
  13594. }
  13595. sstr[c] = '\0';
  13596. tempStartPeriodInt = atoi(sstr);
  13597. //*************limit****************/
  13598. c = 0;
  13599. loc = strstr(SchedulePeriodList[i], "limit");
  13600. memset(sstr ,0, sizeof(sstr) );
  13601. while (loc[strlen("limit")+2+c] != ',')
  13602. {
  13603. sstr[c] = loc[strlen("limit")+2+c];
  13604. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13605. c++;
  13606. }
  13607. sstr[c] = '\0';
  13608. tempLimitInt = atof(sstr);
  13609. //*************numberPhases****************/
  13610. c = 0;
  13611. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13612. memset(sstr ,0, sizeof(sstr) );
  13613. while (loc[strlen("numberPhases")+2+c] != '}')
  13614. {
  13615. sstr[c] = loc[strlen("numberPhases")+2+c];
  13616. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13617. c++;
  13618. }
  13619. sstr[c] = '\0';
  13620. tempNumberPhasesInt = atoi(sstr);
  13621. if(j == 0)
  13622. {
  13623. TxDefaultProfile.Duration = tempdurationInt;
  13624. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13625. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13626. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13627. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13628. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13629. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13630. TxDefaultProfile_TEMP.TransactionId = 0;
  13631. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13632. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13633. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13634. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13635. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13636. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13637. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13638. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13639. }
  13640. else
  13641. {
  13642. //other stack level charging Profile
  13643. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13644. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13645. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13646. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13647. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13648. }
  13649. }
  13650. if(MinChargingRate < tempminChargingRateFloat)
  13651. {
  13652. MinChargingRate = tempminChargingRateFloat;
  13653. }
  13654. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13655. if(confirmPeriods < n_SchedulePeriods)
  13656. confirmPeriods = n_SchedulePeriods;
  13657. j = j + 1;
  13658. }
  13659. fclose(fptr1);
  13660. //Stacking Charging Profiles
  13661. for(int l=0; l <(j-1) ;l++)
  13662. {
  13663. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13664. {
  13665. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13666. {
  13667. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13668. {
  13669. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13670. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13671. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13672. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13673. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13674. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13675. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13676. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13677. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13678. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13679. }
  13680. else
  13681. {
  13682. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13683. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13684. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13685. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13686. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13687. }
  13688. }
  13689. }
  13690. }
  13691. //end of Stacking Charging Profiles
  13692. }
  13693. }// the end of ACCESS TxDefaultProfile
  13694. //****************************TxProfile************************************************/
  13695. #if 0
  13696. switch(gunindex + 1)
  13697. {
  13698. case 0:
  13699. break;
  13700. case 1:
  13701. strcpy(fname, TxProfile_1_JSON );
  13702. break;
  13703. case 2:
  13704. strcpy(fname, TxProfile_2_JSON );
  13705. break;
  13706. default:
  13707. strcpy(fname, TxProfile_1_JSON );
  13708. break;
  13709. }
  13710. #endif
  13711. memset(fname, 0, sizeof fname);
  13712. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  13713. TxProfileIsNull=TRUE;
  13714. if((access(fname,F_OK))!=-1)
  13715. {
  13716. fptr1 = fopen(fname, "r");
  13717. c = 0;
  13718. c = fgetc(fptr1);
  13719. //DEBUG_INFO("c:%d\n",c);
  13720. rewind(fptr1);
  13721. if(c == EOF)
  13722. {
  13723. DEBUG_INFO("\n End of file reached.");
  13724. TxProfileIsNull=TRUE;
  13725. fclose(fptr1);
  13726. }
  13727. else
  13728. {
  13729. TxProfileIsNull=FALSE;
  13730. while(fscanf(fptr1, "%s", word) != EOF)
  13731. {
  13732. if(strcmp(word, "chargingProfileId") == 0)
  13733. {
  13734. n_chargingProfile = n_chargingProfile + 1;
  13735. }
  13736. }
  13737. rewind(fptr1);
  13738. //search Charging Profile Element
  13739. int i= 0;
  13740. int j= 0;
  13741. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13742. #if 0
  13743. /***********connectorId****************/
  13744. c = 0;
  13745. loc = strstr(sLineWord, "connectorId");
  13746. memset(sstr ,0, sizeof(sstr) );
  13747. while (loc[strlen("connectorId")+2+c] != ',')
  13748. {
  13749. sstr[c] = loc[strlen("connectorId")+2+c];
  13750. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13751. c++;
  13752. }
  13753. sstr[c] = '\0';
  13754. tempconnectorIdInt = atoi(sstr);
  13755. #endif
  13756. //***********chargingProfileId**************/
  13757. c = 0;
  13758. loc = strstr(sLineWord, "chargingProfileId");
  13759. memset(sstr ,0, sizeof(sstr) );
  13760. if(loc != NULL)
  13761. {
  13762. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13763. {
  13764. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13765. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13766. c++;
  13767. }
  13768. sstr[c] = '\0';
  13769. tempchargingProfileId = atoi(sstr);
  13770. }
  13771. else
  13772. {
  13773. tempchargingProfileId = 0;
  13774. }
  13775. //***********transactionId **************/
  13776. c = 0;
  13777. loc = strstr(sLineWord, "transactionId");
  13778. //DEBUG_INFO("loc=%s\n",loc);
  13779. memset(sstr ,0, sizeof(sstr) );
  13780. if(loc != NULL)
  13781. {
  13782. while (loc[2+strlen("transactionId")+c] != '\"')
  13783. {
  13784. sstr[c] = loc[2+strlen("transactionId")+c];
  13785. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13786. c++;
  13787. }
  13788. sstr[c] = '\0';
  13789. temptransactionId = atoi(sstr);
  13790. }
  13791. else
  13792. {
  13793. temptransactionId = 0;
  13794. }
  13795. //***********stackLevel**************/
  13796. c = 0;
  13797. loc = strstr(sLineWord, "stackLevel");
  13798. //DEBUG_INFO("loc=%s\n",loc);
  13799. memset(sstr ,0, sizeof(sstr) );
  13800. if(loc != NULL)
  13801. {
  13802. while (loc[2+strlen("stackLevel")+c] != '\"')
  13803. {
  13804. sstr[c] = loc[2+strlen("stackLevel")+c];
  13805. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13806. c++;
  13807. }
  13808. sstr[c] = '\0';
  13809. tempstackLevel = atoi(sstr);
  13810. }
  13811. else
  13812. {
  13813. tempstackLevel = 0;
  13814. }
  13815. //***********chargingProfilePurpose **************/
  13816. c = 0;
  13817. loc = strstr(sLineWord, "chargingProfilePurpose");
  13818. //DEBUG_INFO("loc=%s\n",loc);
  13819. memset(sstr ,0, sizeof(sstr) );
  13820. if(loc != NULL)
  13821. {
  13822. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13823. {
  13824. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13825. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13826. c++;
  13827. }
  13828. sstr[c] = '\0';
  13829. strcpy(tempchargingProfilePurposeStr,sstr);
  13830. }
  13831. else
  13832. {
  13833. strcpy(tempchargingProfilePurposeStr,"");
  13834. }
  13835. //***********chargingProfileKind **************/
  13836. c = 0;
  13837. loc = strstr(sLineWord, "chargingProfileKind");
  13838. //DEBUG_INFO("loc=%s\n",loc);
  13839. memset(sstr ,0, sizeof(sstr) );
  13840. if(loc != NULL)
  13841. {
  13842. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13843. {
  13844. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13845. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13846. c++;
  13847. }
  13848. sstr[c] = '\0';
  13849. strcpy(tempchargingProfileKindStr,sstr);
  13850. }
  13851. else
  13852. {
  13853. strcpy(tempchargingProfileKindStr,"");
  13854. }
  13855. //***********recurrencyKind **************/
  13856. c = 0;
  13857. loc = strstr(sLineWord, "recurrencyKind");
  13858. //DEBUG_INFO("loc=%s\n",loc);
  13859. memset(sstr ,0, sizeof(sstr) );
  13860. if(loc != NULL)
  13861. {
  13862. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13863. {
  13864. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13865. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13866. c++;
  13867. }
  13868. sstr[c] = '\0';
  13869. strcpy(temprecurrencyKindStr,sstr);
  13870. }
  13871. else
  13872. {
  13873. strcpy(temprecurrencyKindStr,"");
  13874. }
  13875. //***********validFrom**************/
  13876. c = 0;
  13877. loc = strstr(sLineWord, "validFrom");
  13878. if(loc != NULL)
  13879. {
  13880. memset(sstr ,0, sizeof(sstr) );
  13881. while (loc[3+strlen("validFrom")+c] != '\"')
  13882. {
  13883. sstr[c] = loc[3+strlen("validFrom")+c];
  13884. c++;
  13885. }
  13886. sstr[c] = '\0';
  13887. strcpy(tempvalidFromStr,sstr);
  13888. }
  13889. else
  13890. {
  13891. strcpy(tempvalidFromStr,"");
  13892. }
  13893. //***********validTo**************/
  13894. c = 0;
  13895. loc = strstr(sLineWord, "validTo");
  13896. if(loc != NULL)
  13897. {
  13898. memset(sstr ,0, sizeof(sstr) );
  13899. while (loc[3+strlen("validTo")+c] != '\"')
  13900. {
  13901. sstr[c] = loc[3+strlen("validTo")+c];
  13902. c++;
  13903. }
  13904. sstr[c] = '\0';
  13905. strcpy(tempvalidToStr,sstr);
  13906. }
  13907. else
  13908. {
  13909. strcpy(tempvalidToStr,"");
  13910. }
  13911. //***********duration**************/
  13912. c = 0;
  13913. loc = strstr(sLineWord, "duration");
  13914. //DEBUG_INFO("loc=%s\n",loc);
  13915. memset(sstr ,0, sizeof(sstr) );
  13916. if(loc != NULL)
  13917. {
  13918. while (loc[2+strlen("duration")+c] != '\"')
  13919. {
  13920. sstr[c] = loc[2+strlen("duration")+c];
  13921. c++;
  13922. }
  13923. sstr[c] = '\0';
  13924. tempdurationInt = atoi(sstr);
  13925. }
  13926. else
  13927. {
  13928. tempdurationInt = 0;
  13929. }
  13930. //**********startSchedule**********/
  13931. c = 0;
  13932. loc = strstr(sLineWord, "startSchedule");
  13933. memset(sstr ,0, sizeof(sstr) );
  13934. while (loc[3+strlen("startSchedule")+c] != '\"')
  13935. {
  13936. sstr[c] = loc[3+strlen("startSchedule")+c];
  13937. c++;
  13938. }
  13939. sstr[c] = '\0';
  13940. strcpy(tempstartScheduleStr, sstr);
  13941. strcpy(TxProfileScheduleStr, sstr);
  13942. //**********chargingRateUnit**********/
  13943. c = 0;
  13944. loc = strstr(sLineWord, "chargingRateUnit");
  13945. memset(sstr ,0, sizeof(sstr) );
  13946. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13947. {
  13948. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13949. c++;
  13950. }
  13951. sstr[c] = '\0';
  13952. strcpy(tempchargingRateUnitStr, sstr);
  13953. //**********minChargingRate*******/
  13954. c = 0;
  13955. loc = strstr(sLineWord, "minChargingRate");
  13956. if(loc != NULL)
  13957. {
  13958. memset(sstr ,0, sizeof(sstr) );
  13959. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13960. {
  13961. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13962. c++;
  13963. }
  13964. sstr[c] = '\0';
  13965. tempminChargingRateFloat = atof(sstr);
  13966. }
  13967. else
  13968. {
  13969. tempminChargingRateFloat = 0.0;
  13970. }
  13971. //
  13972. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13973. tp.tm_isdst = -1;
  13974. time_t utc = mktime(&tp);
  13975. time_t t = time(NULL);
  13976. diff_t = difftime(t, utc);
  13977. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13978. //parsing strings to words
  13979. i = 0;
  13980. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13981. loc = loc+3+strlen("chargingSchedulePeriod");
  13982. pch = strtok(loc ,"{");
  13983. while (pch != NULL)
  13984. {
  13985. strcpy(SchedulePeriodList[i], pch);
  13986. pch = strtok (NULL, "{");
  13987. i = i + 1;
  13988. }
  13989. n_SchedulePeriods = i;
  13990. for(int i=0;i<n_SchedulePeriods;i++)
  13991. {
  13992. //*************startPeriod****************/
  13993. c = 0;
  13994. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13995. memset(sstr ,0, sizeof(sstr) );
  13996. while (loc[strlen("startPeriod")+2+c] != ',')
  13997. {
  13998. sstr[c] = loc[strlen("startPeriod")+2+c];
  13999. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14000. c++;
  14001. }
  14002. sstr[c] = '\0';
  14003. tempStartPeriodInt = atoi(sstr);
  14004. //*************limit****************/
  14005. c = 0;
  14006. loc = strstr(SchedulePeriodList[i], "limit");
  14007. memset(sstr ,0, sizeof(sstr) );
  14008. while (loc[strlen("limit")+2+c] != ',')
  14009. {
  14010. sstr[c] = loc[strlen("limit")+2+c];
  14011. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14012. c++;
  14013. }
  14014. sstr[c] = '\0';
  14015. tempLimitInt = atof(sstr);
  14016. //*************numberPhases****************/
  14017. c = 0;
  14018. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14019. memset(sstr ,0, sizeof(sstr) );
  14020. while (loc[strlen("numberPhases")+2+c] != '}')
  14021. {
  14022. sstr[c] = loc[strlen("numberPhases")+2+c];
  14023. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14024. c++;
  14025. }
  14026. sstr[c] = '\0';
  14027. tempNumberPhasesInt = atoi(sstr);
  14028. //TxProfile.Duration = durationInt;
  14029. TxProfile.TotalPeriod = n_SchedulePeriods;
  14030. TxProfile.Period[i].Limit = tempLimitInt;
  14031. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14032. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14033. }
  14034. if(MinChargingRate < tempminChargingRateFloat)
  14035. {
  14036. MinChargingRate = tempminChargingRateFloat;
  14037. }
  14038. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14039. if(confirmPeriods < n_SchedulePeriods)
  14040. confirmPeriods = n_SchedulePeriods;
  14041. if(j == 0)
  14042. {
  14043. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14044. TxProfile_TEMP.StackLevel = tempstackLevel;
  14045. TxProfile_TEMP.TransactionId = 0;
  14046. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14047. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14048. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14049. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14050. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14051. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14052. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14053. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14054. }
  14055. }
  14056. fclose(fptr1);
  14057. }
  14058. }// the end of ACCESS TxProfile
  14059. //CompositeSchedule
  14060. int period=0;
  14061. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14062. {
  14063. //TxProfile
  14064. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14065. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14066. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14067. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14068. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14069. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14070. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14071. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14072. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14073. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14074. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14075. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14076. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14077. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14078. {
  14079. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14080. {
  14081. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14082. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14083. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14084. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14085. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14086. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14087. period = period + 1;
  14088. }
  14089. else
  14090. {
  14091. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14092. {
  14093. }
  14094. else
  14095. {
  14096. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14097. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14098. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14099. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14100. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14101. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14102. period = period + 1;
  14103. }
  14104. }
  14105. }
  14106. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14107. {
  14108. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  14109. {
  14110. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14111. {
  14112. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14113. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14114. }
  14115. else
  14116. {
  14117. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14118. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14119. }
  14120. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14121. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14122. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14123. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14124. period = period + 1;
  14125. }
  14126. }
  14127. }
  14128. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14129. {
  14130. //TxDefaultProfile
  14131. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14132. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14133. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14134. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14135. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  14136. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14137. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14138. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14139. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14140. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14141. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14142. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14143. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14144. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14145. {
  14146. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14147. {
  14148. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14149. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14150. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14151. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14152. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14153. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14154. period = period + 1;
  14155. }
  14156. else
  14157. {
  14158. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14159. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14160. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14161. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14162. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14163. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14164. period = period + 1;
  14165. }
  14166. }
  14167. }
  14168. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14169. {
  14170. //TxDefaultProfile
  14171. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14172. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14173. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14174. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14175. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14176. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14177. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14178. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14179. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14180. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14181. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14182. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14183. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14184. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14185. {
  14186. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14187. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14188. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14189. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14190. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14191. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14192. period = period + 1;
  14193. }
  14194. }
  14195. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14196. {
  14197. //ChargePointMaxProfile
  14198. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14199. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14200. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14201. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14202. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14203. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14204. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14205. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14206. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14207. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14208. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14209. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14210. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14211. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  14212. {
  14213. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14214. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14215. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14216. period = period + 1;
  14217. }
  14218. }
  14219. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14220. {
  14221. //TxProfile
  14222. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14223. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14224. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14225. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14226. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14227. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14228. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14229. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14230. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14231. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14232. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14233. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14234. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14235. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14236. {
  14237. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  14238. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  14239. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  14240. }
  14241. }
  14242. confirmPeriods = period;
  14243. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14244. 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,"
  14245. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14246. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14247. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14248. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14249. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14250. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14251. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14252. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14253. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14254. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14255. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14256. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14257. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14258. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14259. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14260. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14261. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14262. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14263. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14264. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14265. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14266. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14267. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14268. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14269. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14270. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14271. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14272. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14273. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14274. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14275. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14276. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14277. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14278. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14279. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14280. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14281. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14282. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14283. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14284. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14285. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14286. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14287. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14288. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14289. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14290. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14291. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14292. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14293. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14294. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14295. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14296. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14297. }
  14298. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14299. {
  14300. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14301. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14302. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14303. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14304. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14305. }
  14306. int GetWebSocketPingInterval(void)
  14307. {
  14308. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14309. }
  14310. void LWS_Send(char * str)
  14311. {
  14312. //=====================================================
  14313. // Check InternetConn 0: disconnected, 1: connected
  14314. //====================================================
  14315. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14316. {
  14317. DEBUG_INFO("\n offline now !!!\n");
  14318. return;
  14319. }
  14320. pthread_mutex_lock(&lock);
  14321. memset(SendBuffer,0,SendBufLen);
  14322. sprintf((char *)SendBuffer, "%s", str);
  14323. pthread_mutex_unlock(&lock);
  14324. lws_callback_on_writable(wsi_client);
  14325. lws_service(context, 10000);//timeout_ms
  14326. }