MessageHandler.c 601 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666
  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 pthread_mutex_t mutex1;
  172. extern struct Charger_Info Charger;
  173. extern sqlite3 *db;
  174. int TransactionMessageAttemptsGet(void);
  175. int TransactionMessageRetryIntervalGet(void);
  176. int GetOcppConnStatus(void);
  177. void SetOcppConnStatus(uint8_t status);
  178. int updateSetting(char *key, char *value);
  179. int setKeyValue(char *key, char *value);
  180. void OCPP_get_TableAuthlocalAllData(void);
  181. void processUnkownKey(void);
  182. struct StructOCPPMeterValue
  183. {
  184. unsigned char TimeStamp[28];
  185. struct StructSampledValue SampledValue[10];
  186. };
  187. struct ClientTime
  188. {
  189. unsigned int Heartbeat;
  190. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  191. unsigned int StartTransaction;
  192. unsigned int StopTransaction;
  193. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  194. }clientTime;
  195. typedef union
  196. {
  197. //Operations Initiated by Central System
  198. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  199. struct
  200. {
  201. //CsMsgValue[0]
  202. unsigned char StatusNotificationReq :1; //bit 0,
  203. unsigned char StatusNotificationConf :1; //bit 0,
  204. unsigned char :6; //bit 2~7
  205. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  206. }CpinitiateMsg;
  207. CpinitiateMsg cpinitateMsg;
  208. //==========================================
  209. // Init all Enumeration & Mapping String
  210. //==========================================
  211. /*ChargePointErrorCode*/
  212. typedef enum {
  213. ConnectorLockFailure,
  214. EVCommunicationError,
  215. GroundFailure,
  216. HighTemperature,
  217. InternalError,
  218. LocalListConflict,
  219. NoError,
  220. OtherError,
  221. OverCurrentFailure,
  222. OverVoltage,
  223. PowerMeterFailure,
  224. PowerSwitchFailure,
  225. ReaderFailure,
  226. ResetFailure,
  227. UnderVoltage,
  228. WeakSignal
  229. } ChargePointErrorCode;
  230. #if 0
  231. static char *ChargePointErrorCodeStr[] = {
  232. MACROSTR(ConnectorLockFailure),
  233. MACROSTR(EVCommunicationError),
  234. MACROSTR(GroundFailure),
  235. MACROSTR(HighTemperature),
  236. MACROSTR(InternalError),
  237. MACROSTR(LocalListConflict),
  238. MACROSTR(NoError),
  239. MACROSTR(OtherError),
  240. MACROSTR(OverCurrentFailure),
  241. MACROSTR(OverVoltage),
  242. MACROSTR(PowerMeterFailure),
  243. MACROSTR(PowerSwitchFailure),
  244. MACROSTR(ReaderFailure),
  245. MACROSTR(ResetFailure),
  246. MACROSTR(UnderVoltage),
  247. MACROSTR(WeakSignal)
  248. };
  249. #endif
  250. /*ChargePointStatus*/
  251. typedef enum {
  252. Available =0,
  253. Preparing,
  254. Charging,
  255. SuspendedEVSE,
  256. SuspendedEV,
  257. Finishing,
  258. Reserved,
  259. Unavailable,
  260. Faulted
  261. } ChargePointStatus;
  262. static char * ChargePointStatusStr[] = {
  263. MACROSTR(Available),
  264. MACROSTR(Preparing),
  265. MACROSTR(Charging),
  266. MACROSTR(SuspendedEVSE),
  267. MACROSTR(SuspendedEV),
  268. MACROSTR(Finishing),
  269. MACROSTR(Reserved),
  270. MACROSTR(Unavailable),
  271. MACROSTR(Faulted)
  272. };
  273. /*AvailabilityType*/
  274. typedef enum {
  275. RegistrationStatus_Accepted,
  276. RegistrationStatus_Pending,
  277. RegistrationStatus_Rejected
  278. } RegistrationStatus;
  279. static char *RegistrationStatusStr[] = {
  280. MACROSTR(Accepted),
  281. MACROSTR(Pending),
  282. MACROSTR(Rejected)
  283. };
  284. /*AvailabilityType*/
  285. typedef enum {
  286. Inoperative,
  287. Operative
  288. } AvailabilityType;
  289. static char *AvailabilityTypeStr[] = {
  290. MACROSTR(Inoperative),
  291. MACROSTR(Operative)
  292. };
  293. /*AvailabilityStatus*/
  294. typedef enum {
  295. Accepted,
  296. Rejected,
  297. Scheduled
  298. } AvailabilityStatus;
  299. static char *AvailabilityStatusStr[] = {
  300. MACROSTR(Accepted),
  301. MACROSTR(Rejected),
  302. MACROSTR(Scheduled)
  303. };
  304. /*ConfigurationStatus*/
  305. typedef enum {
  306. ConfigurationStatus_Accepted,
  307. ConfigurationStatus_Rejected,
  308. RebootRequired,
  309. NotSupported
  310. } ConfigurationStatus;
  311. static char *ConfigurationStatusStr[] = {
  312. MACROSTR(Accepted),
  313. MACROSTR(Rejected),
  314. MACROSTR(RebootRequired),
  315. MACROSTR(NotSupported)
  316. };
  317. /*ClearCacheStatus*/
  318. typedef enum {
  319. ClearCacheStatus_Accepted,
  320. ClearCacheStatus_Rejected
  321. } ClearCacheStatus;
  322. static char *ClearCacheStatusStr[] = {
  323. MACROSTR(Accepted),
  324. MACROSTR(Rejected)
  325. };
  326. /*ChargingProfilePurposeType*/
  327. typedef enum {
  328. ChargePointMaxProfile,
  329. TxDefaultProfile,
  330. TxProfile
  331. } ChargingProfilePurposeType;
  332. static char *ChargingProfilePurposeTypeStr[] = {
  333. MACROSTR(ChargePointMaxProfile),
  334. MACROSTR(TxDefaultProfile),
  335. MACROSTR(TxProfile)
  336. };
  337. /*ChargingProfileStatus*/
  338. typedef enum {
  339. ChargingProfileStatus_Accepted,
  340. ChargingProfileStatus_Rejected,
  341. ChargingProfileStatus_NotSupported
  342. } ChargingProfileStatus;
  343. static char *ChargingProfileStatusStr[] = {
  344. MACROSTR(Accepted),
  345. MACROSTR(Rejected),
  346. MACROSTR(NotSupported)
  347. };
  348. /*ClearChargingProfileStatus*/
  349. typedef enum {
  350. ClearChargingProfileStatus_Accepted,
  351. ClearChargingProfileStatus_Unknown
  352. } ClearChargingProfileStatus;
  353. static char *ClearChargingProfileStatusStr[] = {
  354. MACROSTR(Accepted),
  355. MACROSTR(Unknown)
  356. };
  357. /*GetCompositeScheduleStatus*/
  358. typedef enum {
  359. GetCompositeScheduleStatus_Accepted,
  360. GetCompositeScheduleStatus_Rejected
  361. } GetCompositeScheduleStatus;
  362. static char *GetCompositeScheduleStatusStr[] = {
  363. MACROSTR(Accepted),
  364. MACROSTR(Rejected)
  365. };
  366. /*ChargingRateUnitType*/
  367. typedef enum {
  368. ChargingRateUnitType_W,
  369. ChargingRateUnitType_A
  370. } ChargingRateUnitType;
  371. /*AuthorizationStatus*/
  372. typedef enum {
  373. AuthorizationStatus_Accepted ,
  374. AuthorizationStatus_Blocked ,
  375. AuthorizationStatus_Expired ,
  376. AuthorizationStatus_Invalid ,
  377. AuthorizationStatus_ConcurrentTx
  378. } AuthorizationStatus;
  379. /*UpdateType*/
  380. typedef enum {
  381. Differential ,
  382. Full
  383. } UpdateType;
  384. static char *UpdateTypeStr[] = {
  385. MACROSTR(Differential),
  386. MACROSTR(Full)
  387. };
  388. /*UpdateStatus*/
  389. typedef enum {
  390. UpdateStatus_Accepted ,
  391. UpdateStatus_Failed ,
  392. UpdateStatus_NotSupported ,
  393. UpdateStatus_VersionMismatch
  394. } UpdateStatus;
  395. static char *UpdateStatusStr[] = {
  396. MACROSTR(Accepted),
  397. MACROSTR(Failed),
  398. MACROSTR(NotSupported),
  399. MACROSTR(VersionMismatch)
  400. };
  401. /*RemoteStartStopStatus*/
  402. typedef enum {
  403. RemoteStartStopStatus_Accepted,
  404. RemoteStartStopStatus_Rejected
  405. } RemoteStartStopStatus;
  406. static char *RemoteStartStopStatusStr[] = {
  407. MACROSTR(Accepted),
  408. MACROSTR(Rejected)
  409. };
  410. /*ReservationStatus*/
  411. typedef enum {
  412. ReservationStatus_Accepted,
  413. ReservationStatus_Faulted,
  414. ReservationStatus_Occupied,
  415. ReservationStatus_Rejected,
  416. ReservationStatus_Unavailable
  417. } ReservationStatus;
  418. static char *ReservationStatusStr[] = {
  419. MACROSTR(Accepted),
  420. MACROSTR(Faulted),
  421. MACROSTR(Occupied),
  422. MACROSTR(Rejected),
  423. MACROSTR(Unavailable)
  424. };
  425. /*ResetType*/
  426. typedef enum {
  427. Hard,
  428. Soft
  429. } ResetType;
  430. static char *ResetTypeStr[] = {
  431. MACROSTR(Hard),
  432. MACROSTR(Soft)
  433. };
  434. /*ResetStatus*/
  435. typedef enum {
  436. ResetStatus_Accepted,
  437. ResetStatus_Rejected
  438. } ResetStatus;
  439. static char *ResetStatusStr[] = {
  440. MACROSTR(Accepted),
  441. MACROSTR(Rejected)
  442. };
  443. /*DiagnosticsStatus*/
  444. typedef enum {
  445. DiagnosticsStatus_Idle,
  446. DiagnosticsStatus_Uploaded,
  447. DiagnosticsStatus_UploadFailed,
  448. DiagnosticsStatus_Uploading
  449. } DiagnosticsStatus;
  450. static char * DiagnosticsStatusStr[] = {
  451. MACROSTR(Idle),
  452. MACROSTR(Uploaded),
  453. MACROSTR(UploadFailed),
  454. MACROSTR(Uploading)
  455. };
  456. /*FirmwareStatus*/
  457. typedef enum {
  458. FirmwareStatus_Downloaded,
  459. FirmwareStatus_DownloadFailed,
  460. FirmwareStatus_Downloading,
  461. FirmwareStatus_Idle,
  462. FirmwareStatus_InstallationFailed,
  463. FirmwareStatus_Installing,
  464. FirmwareStatus_Installed
  465. } FirmwareStatus;
  466. static char * FirmwareStatusStr[] = {
  467. MACROSTR(Downloaded),
  468. MACROSTR(DownloadFailed),
  469. MACROSTR(Downloading),
  470. MACROSTR(Idle),
  471. MACROSTR(InstallationFailed),
  472. MACROSTR(Installing),
  473. MACROSTR(Installed)
  474. };
  475. /*MessageTrigger*/
  476. typedef enum {
  477. BootNotification,
  478. DiagnosticsStatusNotification,
  479. FirmwareStatusNotification,
  480. Heartbeat,
  481. MeterValues,
  482. StatusNotification
  483. } MessageTrigger;
  484. static char * MessageTriggerStr[] = {
  485. MACROSTR(BootNotification),
  486. MACROSTR(DiagnosticsStatusNotification),
  487. MACROSTR(FirmwareStatusNotification),
  488. MACROSTR(Heartbeat),
  489. MACROSTR(MeterValues),
  490. MACROSTR(StatusNotification)
  491. };
  492. /*TriggerMessageStatus*/
  493. typedef enum {
  494. TriggerMessageStatus_Accepted ,
  495. TriggerMessageStatus_Rejected ,
  496. TriggerMessageStatus_NotImplemented
  497. } TriggerMessageStatus;
  498. static char * TriggerMessageStatusStr[] = {
  499. MACROSTR(Accepted),
  500. MACROSTR(Rejected),
  501. MACROSTR(NotImplemented)
  502. };
  503. /*UnlockStatus*/
  504. typedef enum {
  505. Unlocked,
  506. UnlockFailed,
  507. UnlockStatus_NotSupported
  508. } UnlockStatus;
  509. static char * UnlockStatusStr[] = {
  510. MACROSTR(Unlocked),
  511. MACROSTR(UnlockFailed),
  512. MACROSTR(NotSupported)
  513. };
  514. /*StopTransactionReason*/
  515. typedef enum {
  516. EmergencyStop,
  517. EVDisconnected,
  518. HardReset,
  519. Local,
  520. Other,
  521. PowerLoss,
  522. Reboot,
  523. Remote,
  524. SoftReset,
  525. UnlockCommand,
  526. DeAuthorized
  527. } StopTransactionReason;
  528. #if 0
  529. static char * StopTransactionReasonStr[] = {
  530. MACROSTR(EmergencyStop),
  531. MACROSTR(EVDisconnected),
  532. MACROSTR(HardReset),
  533. MACROSTR(Local),
  534. MACROSTR(Other),
  535. MACROSTR(PowerLoss),
  536. MACROSTR(Reboot),
  537. MACROSTR(Remote),
  538. MACROSTR(SoftReset),
  539. MACROSTR(UnlockCommand),
  540. MACROSTR(DeAuthorized)
  541. };
  542. #endif
  543. /*CancelReservationStatus*/
  544. typedef enum {
  545. CancelReservationStatus_Accepted,
  546. CancelReservationStatus_Rejected
  547. } CancelReservationStatus;
  548. static char * CancelReservationStatusStr[] = {
  549. MACROSTR(Accepted),
  550. MACROSTR(Rejected)
  551. };
  552. /*ReadingContext*/
  553. typedef enum {
  554. ReadingContext_Interruption_Begin,
  555. ReadingContext_Interruption_End,
  556. ReadingContext_Other,
  557. ReadingContext_Sample_Clock,
  558. ReadingContext_Sample_Periodic ,
  559. ReadingContext_Transaction_Begin ,
  560. ReadingContext_Transaction_End,
  561. ReadingContext_Trigger
  562. } ReadingContext;
  563. static char * ReadingContextStr[] = {
  564. MACROSTR(Interruption.Begin),
  565. MACROSTR(Interruption.End),
  566. MACROSTR(Other),
  567. MACROSTR(Sample.Clock),
  568. MACROSTR(Sample.Periodic),
  569. MACROSTR(Transaction.Begin),
  570. MACROSTR(Transaction.End),
  571. MACROSTR(Trigger)
  572. };
  573. /*ValueFormat*/
  574. typedef enum {
  575. Raw,
  576. SignedData
  577. } ValueFormat;
  578. static char * ValueFormatStr[] = {
  579. MACROSTR(Raw),
  580. MACROSTR(SignedData)
  581. };
  582. /*Measurand*/
  583. typedef enum {
  584. Current_Export ,
  585. Current_Import,
  586. Current_Offered,
  587. Energy_Active_Export_Register,
  588. Energy_Active_Import_Register,
  589. Energy_Reactive_Export_Register,
  590. Energy_Reactive_Import_Register,
  591. Energy_Active_Export_Interval,
  592. Energy_Active_Import_Interval,
  593. Energy_Reactive_Export_Interval,
  594. Energy_Reactive_Import_Interval,
  595. Frequency,
  596. Power_Active_Export ,
  597. Power_Active_Import,
  598. Power_Factor,
  599. Power_Offered,
  600. Power_Reactive_Export,
  601. Power_Reactive_Import,
  602. RPM,
  603. SoC,
  604. Temperature ,
  605. Voltage
  606. } Measurand;
  607. static char * MeasurandStr[] = {
  608. MACROSTR(Current.Export),
  609. MACROSTR(Current.Import),
  610. MACROSTR(Current.Offered),
  611. MACROSTR(Energy.Active.Export.Register),
  612. MACROSTR(Energy.Active.Import.Register),
  613. MACROSTR(Energy.Reactive.Export.Register),
  614. MACROSTR(Energy.Reactive.Import.Register),
  615. MACROSTR(Energy.Active.Export.Interval),
  616. MACROSTR(Energy.Active.Import.Interval),
  617. MACROSTR(Energy.Reactive.Export.Interval),
  618. MACROSTR(Energy.Reactive.Import.Interval),
  619. MACROSTR(Frequency),
  620. MACROSTR(Power.Active.Export),
  621. MACROSTR(Power.Active.Import),
  622. MACROSTR(Power.Factor),
  623. MACROSTR(Power.Offered),
  624. MACROSTR(Power.Reactive.ExportMACROSTR),
  625. MACROSTR(Power.Reactive.Import),
  626. MACROSTR(RPM),
  627. MACROSTR(SoC),
  628. MACROSTR(Temperature),
  629. MACROSTR(Voltage)
  630. };
  631. /*Location*/
  632. typedef enum {
  633. Location_Body,
  634. Location_Cable,
  635. Location_EV,
  636. Location_Inlet ,
  637. Location_Outlet
  638. } Location;
  639. static char * LocationStr[] = {
  640. MACROSTR(Body),
  641. MACROSTR(Cable),
  642. MACROSTR(EV),
  643. MACROSTR(Inlet),
  644. MACROSTR(Outlet)
  645. };
  646. /*Phase*/
  647. typedef enum {
  648. L1,
  649. L2,
  650. L3,
  651. N,
  652. L1_N,
  653. L2_N,
  654. L3_N,
  655. L1_L2,
  656. L2_L3,
  657. L3_L1
  658. } Phase;
  659. static char * PhaseStr[] = {
  660. MACROSTR(L1),
  661. MACROSTR(L2),
  662. MACROSTR(L3),
  663. MACROSTR(N),
  664. MACROSTR(L1-N),
  665. MACROSTR(L2-N),
  666. MACROSTR(L3-N),
  667. MACROSTR(L1-L2),
  668. MACROSTR(L2-L3),
  669. MACROSTR(L3-L1)
  670. };
  671. /*UnitOfMeasure*/
  672. typedef enum {
  673. UnitOfMeasure_Wh,
  674. UnitOfMeasure_kWh ,
  675. UnitOfMeasure_varh ,
  676. UnitOfMeasure_kvarh ,
  677. UnitOfMeasure_W ,
  678. UnitOfMeasure_kW ,
  679. UnitOfMeasure_VA ,
  680. UnitOfMeasure_kVA ,
  681. UnitOfMeasure_var ,
  682. UnitOfMeasure_kvar ,
  683. UnitOfMeasure_A ,
  684. UnitOfMeasure_V ,
  685. UnitOfMeasure_Celsius ,
  686. UnitOfMeasure_Fahrenheit ,
  687. UnitOfMeasure_K ,
  688. UnitOfMeasure_Percent
  689. } UnitOfMeasure;
  690. static char * UnitOfMeasureStr[] = {
  691. MACROSTR(Wh),
  692. MACROSTR(kWh),
  693. MACROSTR(varh),
  694. MACROSTR(kvarh),
  695. MACROSTR(W),
  696. MACROSTR(kW),
  697. MACROSTR(VA),
  698. MACROSTR(kVA),
  699. MACROSTR(var),
  700. MACROSTR(kvar),
  701. MACROSTR(A),
  702. MACROSTR(V),
  703. MACROSTR(Celsius),
  704. MACROSTR(Fahrenheit),
  705. MACROSTR(K),
  706. MACROSTR(Percent)
  707. };
  708. #if 0
  709. /*Configuration enum*/
  710. enum CoreProfile {
  711. AllowOfflineTxForUnknownId=0,
  712. AuthorizationCacheEnabled,
  713. AuthorizeRemoteTxRequests,
  714. BlinkRepeat,
  715. ClockAlignedDataInterval,
  716. ConnectionTimeOut,
  717. GetConfigurationMaxKeys,
  718. HeartbeatInterval,
  719. LightIntensity,
  720. LocalAuthorizeOffline,
  721. LocalPreAuthorize,
  722. MaxEnergyOnInvalidId,
  723. MeterValuesAlignedData,
  724. MeterValuesAlignedDataMaxLength,
  725. MeterValuesSampledData,
  726. MeterValuesSampledDataMaxLength,
  727. MeterValueSampleInterval,
  728. MinimumStatusDuration,
  729. NumberOfConnectors,
  730. ResetRetries,
  731. ConnectorPhaseRotation,
  732. ConnectorPhaseRotationMaxLength,
  733. StopTransactionOnEVSideDisconnect,
  734. StopTransactionOnInvalidId,
  735. StopTxnAlignedData,
  736. StopTxnAlignedDataMaxLength,
  737. StopTxnSampledData,
  738. StopTxnSampledDataMaxLength,
  739. SupportedFeatureProfiles,
  740. SupportedFeatureProfilesMaxLength,
  741. TransactionMessageAttempts,
  742. TransactionMessageRetryInterval,
  743. UnlockConnectorOnEVSideDisconnect,
  744. WebSocketPingInterval,
  745. _CoreProfile_CNT
  746. };
  747. #endif
  748. enum LocalAuthListManagementProfile{
  749. LocalAuthListEnabled=0,
  750. LocalAuthListMaxLength,
  751. SendLocalListMaxLength,
  752. _LocalAuthListManagementProfile_CNT
  753. };
  754. enum ReservationProfile{
  755. ReserveConnectorZeroSupported
  756. };
  757. enum SmartChargingProfile{
  758. ChargeProfileMaxStackLevel,
  759. ChargingScheduleAllowedChargingRateUnit,
  760. ChargingScheduleMaxPeriods,
  761. ConnectorSwitch3to1PhaseSupported,
  762. MaxChargingProfilesInstalled
  763. };
  764. enum ChargerSystemStatus{
  765. ChargerSystemStatus_Booting,
  766. ChargerSystemStatus_Idle,
  767. ChargerSystemStatus_Authorizing,
  768. ChargerSystemStatus_Preparing,
  769. ChargerSystemStatus_Charging,
  770. ChargerSystemStatus_Terminating,
  771. ChargerSystemStatus_Alarm,
  772. ChargerSystemStatus_Fault
  773. };
  774. enum GetConfigurationKey {
  775. GetConfiguration_AllowOfflineTxForUnknownId=0,
  776. GetConfiguration_AuthorizationCacheEnabled,
  777. GetConfiguration_AuthorizeRemoteTxRequests,
  778. GetConfiguration_BlinkRepeat,
  779. GetConfiguration_ClockAlignedDataInterval,
  780. GetConfiguration_ConnectionTimeOut,
  781. GetConfiguration_GetConfigurationMaxKeys,
  782. GetConfiguration_HeartbeatInterval,
  783. GetConfiguration_LightIntensity,
  784. GetConfiguration_LocalAuthorizeOffline,
  785. GetConfiguration_LocalPreAuthorize,
  786. GetConfiguration_MaxEnergyOnInvalidId,
  787. GetConfiguration_MeterValuesAlignedData,
  788. GetConfiguration_MeterValuesAlignedDataMaxLength,
  789. GetConfiguration_MeterValuesSampledData,
  790. GetConfiguration_MeterValuesSampledDataMaxLength,
  791. GetConfiguration_MeterValueSampleInterval,
  792. GetConfiguration_MinimumStatusDuration,
  793. GetConfiguration_NumberOfConnectors,
  794. GetConfiguration_ResetRetries,
  795. GetConfiguration_ConnectorPhaseRotation,
  796. GetConfiguration_ConnectorPhaseRotationMaxLength,
  797. GetConfiguration_StopTransactionOnEVSideDisconnect,
  798. GetConfiguration_StopTransactionOnInvalidId,
  799. GetConfiguration_StopTxnAlignedData,
  800. GetConfiguration_StopTxnAlignedDataMaxLength,
  801. GetConfiguration_StopTxnSampledData,
  802. GetConfiguration_StopTxnSampledDataMaxLength,
  803. GetConfiguration_SupportedFeatureProfiles,
  804. GetConfiguration_SupportedFeatureProfilesMaxLength,
  805. GetConfiguration_TransactionMessageAttempts,
  806. GetConfiguration_TransactionMessageRetryInterval,
  807. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  808. GetConfiguration_WebSocketPingInterval,
  809. GetConfiguration_LocalAuthListEnabled,
  810. GetConfiguration_LocalAuthListMaxLength,
  811. GetConfiguration_SendLocalListMaxLength,
  812. GetConfiguration_ReserveConnectorZeroSupported,
  813. GetConfiguration_ChargeProfileMaxStackLevel,
  814. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  815. GetConfiguration_ChargingScheduleMaxPeriods,
  816. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  817. GetConfiguration_MaxChargingProfilesInstalled,
  818. };
  819. //GetConfiguration Array
  820. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  821. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  822. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  823. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  824. //==========================================
  825. // Init all share memory
  826. //==========================================
  827. int InitShareMemory()
  828. {
  829. int result = PASS;
  830. int MeterSMId;
  831. //creat ShmSysConfigAndInfo
  832. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  833. {
  834. #ifdef SystemLogMessage
  835. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  836. #endif
  837. result = FAIL;
  838. }
  839. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  840. {
  841. #ifdef SystemLogMessage
  842. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  843. #endif
  844. result = FAIL;
  845. }
  846. else
  847. {}
  848. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  849. {
  850. #ifdef SystemLogMessage
  851. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  852. #endif
  853. result = FAIL;
  854. }
  855. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  856. {
  857. #ifdef SystemLogMessage
  858. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  859. #endif
  860. result = FAIL;
  861. }
  862. else
  863. {}
  864. //creat ShmPsuData
  865. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  866. {
  867. #ifdef SystemLogMessage
  868. DEBUG_ERROR("shmget ShmPsuData NG\n");
  869. #endif
  870. result = FAIL;
  871. }
  872. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  873. {
  874. #ifdef SystemLogMessage
  875. DEBUG_ERROR("shmat ShmPsuData NG\n");
  876. #endif
  877. result = FAIL;
  878. }
  879. else
  880. {}
  881. //creat ShmOCPP16Data
  882. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  883. {
  884. #ifdef SystemLogMessage
  885. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  886. #endif
  887. result = FAIL;
  888. }
  889. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  890. {
  891. #ifdef SystemLogMessage
  892. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  893. #endif
  894. result = FAIL;
  895. }
  896. else
  897. {}
  898. /****************************** For Initial Settings************************************************/
  899. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  900. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  901. {
  902. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  903. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  904. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  905. }
  906. // Charger PRE_SYS_MODE
  907. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  908. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  909. clientTime.Heartbeat=time((time_t*)NULL);
  910. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  911. {
  912. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  913. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  914. }
  915. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  916. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  917. // allocate Configuration memory address
  918. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  919. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  920. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  921. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  923. {
  924. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  925. DEBUG_INFO("DC ...\n");
  926. }
  927. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  928. {
  929. SystemInitial = AC_QUANTITY;
  930. DEBUG_INFO("AC ...\n");
  931. }
  932. //Status / ConnectorPlugIn Setting
  933. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  934. {
  935. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  936. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  937. }
  938. for (int index = 0; index < CCS_QUANTITY; index++)
  939. {
  940. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  941. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  942. }
  943. for (int index = 0; index < GB_QUANTITY; index++)
  944. {
  945. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  946. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  947. }
  948. for (int index = 0; index < AC_QUANTITY; index++)
  949. {
  950. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  951. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  952. }
  953. return result;
  954. }
  955. int ProcessShareMemory()
  956. {
  957. if(InitShareMemory() == FAIL)
  958. {
  959. #ifdef SystemLogMessage
  960. DEBUG_ERROR("InitShareMemory NG\n");
  961. #endif
  962. if(ShmStatusCodeData!=NULL)
  963. {
  964. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  965. }
  966. sleep(5);
  967. return FAIL;
  968. }
  969. return PASS;
  970. }
  971. //---------------------------------------------
  972. // new:
  973. // enum SYSTEM_STATUS
  974. // {
  975. // SYS_MODE_BOOTING = 0,
  976. // SYS_MODE_IDLE = 1,
  977. // SYS_MODE_AUTHORIZING = 2,
  978. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  979. // SYS_MODE_REASSIGN = 4,
  980. // SYS_MODE_PREPARING = 5,
  981. // SYS_MODE_PREPARE_FOR_EV = 6,
  982. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  983. // SYS_MODE_CHARGING = 8,
  984. // SYS_MODE_TERMINATING = 9,
  985. // SYS_MODE_COMPLETE = 10,
  986. // SYS_MODE_ALARM = 11,
  987. // SYS_MODE_FAULT = 12,
  988. // SYS_MODE_RESERVATION = 13,
  989. // SYS_MODE_BOOKING = 14,
  990. // SYS_MODE_MAINTAIN = 15,
  991. // SYS_MODE_DEBUG = 16,
  992. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  993. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  994. // SYS_MODE_UPDATE = 19
  995. // };
  996. //
  997. //
  998. //-----------------------------------------
  999. void CheckSystemValue(void)
  1000. {
  1001. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1002. int IdleModeCnt = 0;
  1003. char filenmae[100]={0};
  1004. char str[100]={0};
  1005. //===============================
  1006. // send Heartbeat
  1007. //===============================
  1008. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1009. {
  1010. printf("Heartbeat !!!\n");
  1011. //parameter for test
  1012. sendHeartbeatRequest(0);
  1013. //==============================================
  1014. // Reset Waiting Time
  1015. //==============================================
  1016. clientTime.Heartbeat=time((time_t*)NULL);
  1017. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1018. }
  1019. //==============================================
  1020. // Update firmware request
  1021. //==============================================
  1022. if(isUpdateRequest == TRUE )
  1023. {
  1024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1025. {
  1026. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1027. {
  1028. //check SystemStatus
  1029. /*************************DC*******************************/
  1030. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1031. {
  1032. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1033. {
  1034. IdleModeCnt = IdleModeCnt + 1;
  1035. }
  1036. }
  1037. for (int index = 0; index < CCS_QUANTITY; index++)
  1038. {
  1039. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1040. {
  1041. IdleModeCnt = IdleModeCnt + 1;
  1042. }
  1043. }
  1044. for (int index = 0; index < GB_QUANTITY; index++)
  1045. {
  1046. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1047. {
  1048. IdleModeCnt = IdleModeCnt + 1;
  1049. }
  1050. }
  1051. }
  1052. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1053. {
  1054. isUpdateRequest = FALSE;
  1055. }
  1056. }
  1057. else
  1058. {
  1059. /*************************AC*******************************/
  1060. for (int index = 0; index < AC_QUANTITY; index++)
  1061. {
  1062. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1063. {
  1064. IdleModeCnt = IdleModeCnt + 1;
  1065. }
  1066. }
  1067. if(IdleModeCnt == AC_QUANTITY)
  1068. {
  1069. isUpdateRequest = FALSE;
  1070. }
  1071. }
  1072. }
  1073. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1074. {
  1075. //===============================
  1076. // CSU Trigger Reset Conf
  1077. //===============================
  1078. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1079. {
  1080. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1081. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1082. {
  1083. server_sign = FALSE;
  1084. }
  1085. }
  1086. //===============================
  1087. // CSU Trigger Authorize Request
  1088. //===============================
  1089. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1090. {
  1091. sendAuthorizeRequest(0);
  1092. authorizeRetryTimes = authorizeRetryTimes + 1;
  1093. // authenrequest = TRUE
  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. LWS_Send(message);
  1738. #if 0
  1739. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1740. 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*/)
  1741. {
  1742. result = PASS;
  1743. }
  1744. strcpy(queuedata, message);
  1745. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1746. #endif
  1747. //#ifdef SystemLogMessage
  1748. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1749. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1750. //#endif
  1751. return result;
  1752. }
  1753. int sendStatusNotificationRequest(int gun_index)
  1754. {
  1755. mtrace();
  1756. int result = FAIL;
  1757. char message[600]={0};
  1758. char guid[37];
  1759. int currentStatus = 0;
  1760. struct timeval tmnow;
  1761. struct tm *tm;
  1762. char buf[28];//, usec_buf[6];
  1763. char tempdata[65]={0};
  1764. gettimeofday(&tmnow, NULL);
  1765. time_t t;
  1766. t = time(NULL);
  1767. /*UTC time and date*/
  1768. tm = gmtime(&t);
  1769. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1770. #if 0 // remove temporally
  1771. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1772. strcat(buf,".");
  1773. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1774. strcat(buf,usec_buf);
  1775. #endif
  1776. printf("%s",buf);
  1777. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1778. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1779. // it's option
  1780. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1781. /*
  1782. enum _SYSTEM_STATUS
  1783. {
  1784. S_BOOTING = 0,
  1785. S_IDLE, = 1
  1786. S_AUTHORIZING, =2
  1787. S_REASSIGN_CHECK, =3
  1788. S_REASSIGN, =4
  1789. S_PRECHARGE, =5
  1790. S_PREPARING_FOR_EV, =6
  1791. S_PREPARING_FOR_EVSE, =7
  1792. S_CHARGING, =8
  1793. S_TERMINATING, =9
  1794. S_COMPLETE, =10
  1795. S_ALARM, =11
  1796. S_FAULT =12
  1797. }
  1798. */
  1799. //check Transaction active
  1800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1801. {
  1802. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1803. {
  1804. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1805. {
  1806. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1807. {
  1808. currentStatus = 1; //OCPP Status: Preparing
  1809. }
  1810. else
  1811. {
  1812. currentStatus = 0; //OCPP Status: Available
  1813. }
  1814. }
  1815. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1816. {
  1817. currentStatus = 1; //OCPP Status: Preparing
  1818. }
  1819. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1820. {
  1821. currentStatus = 2; //OCPP Status: Charging
  1822. }
  1823. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1824. {
  1825. currentStatus = 5; //OCPP Status: Finishing
  1826. }
  1827. 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
  1828. {
  1829. currentStatus = 4; //OCPP Status: SuspendedEV
  1830. }
  1831. 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
  1832. {
  1833. currentStatus = 7; //OCPP Status: Unavailable
  1834. }
  1835. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1836. {
  1837. currentStatus = 8; //OCPP Status: Faulted
  1838. }
  1839. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1840. {
  1841. currentStatus = 6; //OCPP Status: Reserved
  1842. }
  1843. }//end of for CHAdeMO_QUANTITY
  1844. for (int index = 0; index < CCS_QUANTITY; index++)
  1845. {
  1846. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1847. {
  1848. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1849. {
  1850. currentStatus = 1; //OCPP Status: Preparing
  1851. }
  1852. else
  1853. {
  1854. currentStatus = 0; //OCPP Status: Available
  1855. }
  1856. }
  1857. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1858. {
  1859. currentStatus = 1; //OCPP Status: Preparing
  1860. }
  1861. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1862. {
  1863. currentStatus = 2; //OCPP Status: Charging
  1864. }
  1865. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1866. {
  1867. currentStatus = 5; //OCPP Status: Finishing
  1868. }
  1869. 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
  1870. {
  1871. currentStatus = 4; //OCPP Status: SuspendedEV
  1872. }
  1873. 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
  1874. {
  1875. currentStatus = 7; //OCPP Status : Unavailable
  1876. }
  1877. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1878. {
  1879. currentStatus = 8; //OCPP Status: Faulted
  1880. }
  1881. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1882. {
  1883. currentStatus = 6; //OCPP Status: Reserved
  1884. }
  1885. }
  1886. for (int index = 0; index < GB_QUANTITY; index++)
  1887. {
  1888. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1889. {
  1890. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1891. {
  1892. currentStatus = 1; //OCPP Status: Preparing
  1893. }
  1894. else
  1895. {
  1896. currentStatus = 0; //OCPP Status: Available
  1897. }
  1898. }
  1899. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1900. {
  1901. currentStatus = 1; //OCPP Status: Preparing
  1902. }
  1903. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1904. {
  1905. currentStatus = 2; //OCPP Status: Charging
  1906. }
  1907. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1908. {
  1909. currentStatus = 5; //OCPP Status: Finishing
  1910. }
  1911. 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
  1912. {
  1913. currentStatus = 4; //OCPP Status: SuspendedEV
  1914. }
  1915. 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
  1916. {
  1917. currentStatus = 7; //OCPP Status: Unavailable
  1918. }
  1919. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1920. {
  1921. currentStatus = 8; //OCPP Status: Faulted
  1922. }
  1923. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1924. {
  1925. currentStatus = 6; //OCPP Status: Reserved
  1926. }
  1927. }
  1928. }
  1929. else
  1930. {
  1931. for (int index = 0; index < AC_QUANTITY; index++)
  1932. {
  1933. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1934. {
  1935. 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))
  1936. {
  1937. currentStatus = 1; //OCPP Status: Preparing
  1938. }
  1939. else
  1940. {
  1941. currentStatus = 0; //OCPP Status: Available
  1942. }
  1943. }
  1944. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1945. {
  1946. currentStatus = 1; //OCPP Status: Preparing
  1947. }
  1948. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1949. {
  1950. currentStatus = 2; //OCPP Status: Charging
  1951. }
  1952. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1953. {
  1954. currentStatus = 5; //OCPP Status: Finishing
  1955. }
  1956. 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
  1957. {
  1958. currentStatus = 4; //OCPP Status: SuspendedEV
  1959. }
  1960. 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
  1961. {
  1962. currentStatus = 7; //OCPP Status: Unavailable
  1963. }
  1964. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1965. {
  1966. currentStatus = 8; //OCPP Status: Faulted
  1967. }
  1968. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1969. {
  1970. currentStatus = 6; //OCPP Status: Reserved
  1971. }
  1972. }//end of for AC_QUANTITY
  1973. }//END OF ELSE
  1974. //it's option
  1975. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1976. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1977. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1978. random_uuid(guid);
  1979. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1980. , MESSAGE_TYPE_CALL
  1981. , guid
  1982. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1983. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1984. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1985. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1986. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1987. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1988. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1989. LWS_Send(message);
  1990. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1991. 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*/)
  1992. {
  1993. //DEBUG_ERROR("statusNotification mapitem pass");
  1994. result = PASS;
  1995. }
  1996. return result;
  1997. }
  1998. int sendStopTransactionRequest(int gun_index)
  1999. {
  2000. mtrace();
  2001. int result = FAIL;
  2002. //char message[1500]={0};
  2003. char guid[37]={0};
  2004. char tempdata[65]={0};
  2005. //int idx_sample=0;
  2006. DEBUG_ERROR("sendStopTransactionRequest \n");
  2007. memset(queuedata, 0, sizeof(queuedata));
  2008. //ENERGY_ACTIVE_IMPORT_REGISTER
  2009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2010. {
  2011. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2012. {
  2013. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2014. {
  2015. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2016. }
  2017. }// END OF CHAdeMO_QUANTITY
  2018. for (int index = 0; index < CCS_QUANTITY; index++)
  2019. {
  2020. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2021. {
  2022. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2023. }
  2024. }// END OF CCS_QUANTITY
  2025. for (int index = 0; index < GB_QUANTITY; index++)
  2026. {
  2027. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2028. {
  2029. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2030. }
  2031. }// END OF GB_QUANTITY
  2032. }
  2033. else
  2034. {
  2035. for (int index = 0; index < AC_QUANTITY; index++)
  2036. {
  2037. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2038. {
  2039. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2040. }
  2041. }// END OF AC_QUANTITY
  2042. }//END OF ELSE
  2043. //Stop Transaction Time
  2044. struct timeval tmnow;
  2045. struct tm *tm;
  2046. char buf[28];//, usec_buf[6];
  2047. gettimeofday(&tmnow, NULL);
  2048. time_t t;
  2049. t = time(NULL);
  2050. /*UTC time and date*/
  2051. tm = gmtime(&t);
  2052. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2054. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2055. random_uuid(guid);
  2056. /***********************************transactionData******************************************************/
  2057. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2059. //=================================
  2060. // Transaction_Begin
  2061. //=================================
  2062. // Energy.Active.Export.Interval
  2063. //idx_sample=0;
  2064. 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
  2065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2067. 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*/]);
  2068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2069. {
  2070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2071. }
  2072. else
  2073. {
  2074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2075. }
  2076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2078. //=================================
  2079. // Transaction_End
  2080. //=================================
  2081. //Current.Export
  2082. //idx_sample=1;
  2083. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2084. {
  2085. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2086. {
  2087. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2088. {
  2089. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2090. }
  2091. }
  2092. for (int index = 0; index < CCS_QUANTITY; index++)
  2093. {
  2094. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2095. {
  2096. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2097. }
  2098. }
  2099. for (int index = 0; index < GB_QUANTITY; index++)
  2100. {
  2101. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2102. {
  2103. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2104. }
  2105. }
  2106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2107. }
  2108. else
  2109. {
  2110. for (int index = 0; index < AC_QUANTITY; index++)
  2111. {
  2112. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2113. {
  2114. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2115. }
  2116. }
  2117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2118. }// END FOR AC ELSE
  2119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2122. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2125. //Energy.Active.Export.Interval
  2126. //idx_sample=2;
  2127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2128. {
  2129. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2130. {
  2131. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2132. {
  2133. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2134. }
  2135. }
  2136. for (int index = 0; index < CCS_QUANTITY; index++)
  2137. {
  2138. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2139. {
  2140. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2141. }
  2142. }
  2143. for (int index = 0; index < GB_QUANTITY; index++)
  2144. {
  2145. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2146. {
  2147. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2148. }
  2149. }
  2150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2151. }
  2152. else
  2153. {
  2154. for (int index = 0; index < AC_QUANTITY; index++)
  2155. {
  2156. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2157. {
  2158. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2159. }
  2160. }
  2161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2162. }// END FOR AC ELSE
  2163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2166. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2169. //Power.Active.Export
  2170. //idx_sample=3;
  2171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2172. {
  2173. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2174. {
  2175. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2176. {
  2177. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2178. }
  2179. }
  2180. for (int index = 0; index < CCS_QUANTITY; index++)
  2181. {
  2182. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2183. {
  2184. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2185. }
  2186. }
  2187. for (int index = 0; index < GB_QUANTITY; index++)
  2188. {
  2189. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2190. {
  2191. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2192. }
  2193. }
  2194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2195. }
  2196. else
  2197. {
  2198. for (int index = 0; index < AC_QUANTITY; index++)
  2199. {
  2200. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2201. {
  2202. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2203. }
  2204. }
  2205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2206. }// END FOR AC ELSE
  2207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2210. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2213. //Voltage
  2214. //idx_sample=4;
  2215. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2216. {
  2217. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2218. {
  2219. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2220. {
  2221. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2222. }
  2223. }
  2224. for (int index = 0; index < CCS_QUANTITY; index++)
  2225. {
  2226. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2227. {
  2228. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2229. }
  2230. }
  2231. for (int index = 0; index < GB_QUANTITY; index++)
  2232. {
  2233. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2234. {
  2235. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2236. }
  2237. }
  2238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2239. }
  2240. else
  2241. {
  2242. for (int index = 0; index < AC_QUANTITY; index++)
  2243. {
  2244. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2245. {
  2246. 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
  2247. }
  2248. }
  2249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2250. }// END FOR AC ELSE
  2251. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2253. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2254. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2257. //SoC
  2258. //idx_sample=5;
  2259. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2260. {
  2261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2262. {
  2263. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2264. {
  2265. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2266. }
  2267. }
  2268. for (int index = 0; index < CCS_QUANTITY; index++)
  2269. {
  2270. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2271. {
  2272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2273. }
  2274. }
  2275. for (int index = 0; index < GB_QUANTITY; index++)
  2276. {
  2277. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2278. {
  2279. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2280. }
  2281. }
  2282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2288. } // END FOR DC CASE
  2289. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2290. {
  2291. 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\"}]}]}]"
  2292. ,MESSAGE_TYPE_CALL
  2293. ,guid
  2294. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2295. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2296. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2297. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2298. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2299. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2304. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2336. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2340. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2341. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2342. );
  2343. }
  2344. else
  2345. {
  2346. 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\"}]}]}]"
  2347. ,MESSAGE_TYPE_CALL
  2348. ,guid
  2349. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2354. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2364. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2366. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2367. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2368. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2369. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2370. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2385. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2386. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2387. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2388. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2390. );
  2391. }
  2392. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2393. if(hashmap_operation(0, guid, tempdata) == 1)
  2394. {
  2395. result = PASS;
  2396. DEBUG_INFO("StopTransaction mapitem pass\n");
  2397. }
  2398. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2399. LWS_Send(queuedata);
  2400. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2401. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2402. {
  2403. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2404. }
  2405. #if 0
  2406. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2407. if(hashmap_operation(0, guid, tempdata) == 1)
  2408. {
  2409. result = PASS;
  2410. DEBUG_INFO("StopTransaction mapitem pass\n");
  2411. }
  2412. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2413. #endif
  2414. //for test
  2415. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2416. return result;
  2417. }
  2418. int sendMeterValuesRequest(int gun_index)
  2419. {
  2420. mtrace();
  2421. int result = FAIL;
  2422. // char message[1500]={0};
  2423. char guid[37]={0};
  2424. //int idx_sample=0;
  2425. //int length = 0;
  2426. char tempdata[65]={0};
  2427. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2428. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2429. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2430. {
  2431. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2432. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2433. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2434. return result;
  2435. }
  2436. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2437. {
  2438. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2439. }
  2440. memset(queuedata, 0, sizeof(queuedata));
  2441. //set value
  2442. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2443. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2444. random_uuid(guid);
  2445. //UTC Date time
  2446. struct timeval tmnow;
  2447. struct tm *tm;
  2448. char buf[28];//, usec_buf[6];
  2449. gettimeofday(&tmnow, NULL);
  2450. time_t t;
  2451. t = time(NULL);
  2452. /*UTC time and date*/
  2453. tm = gmtime(&t);
  2454. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2455. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2456. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2457. //idx_sample=0;
  2458. //********************************(1)Current.Export************************************************/
  2459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2460. {
  2461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2462. {
  2463. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2464. {
  2465. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2466. }
  2467. }
  2468. for (int index = 0; index < CCS_QUANTITY; index++)
  2469. {
  2470. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2471. {
  2472. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2473. }
  2474. }
  2475. for (int index = 0; index < GB_QUANTITY; index++)
  2476. {
  2477. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2478. {
  2479. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2480. }
  2481. }
  2482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2483. }
  2484. else
  2485. {
  2486. for (int index = 0; index < AC_QUANTITY; index++)
  2487. {
  2488. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2489. {
  2490. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2491. }
  2492. }
  2493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2494. }// END FOR AC ELSE
  2495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2498. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2501. //idx_sample=1;
  2502. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2503. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2504. {
  2505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2506. {
  2507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2508. {
  2509. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2510. }
  2511. }
  2512. for (int index = 0; index < CCS_QUANTITY; index++)
  2513. {
  2514. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2515. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2516. {
  2517. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2518. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2519. }
  2520. }
  2521. for (int index = 0; index < GB_QUANTITY; index++)
  2522. {
  2523. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2524. {
  2525. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2526. }
  2527. }
  2528. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2529. }
  2530. else
  2531. {
  2532. for (int index = 0; index < AC_QUANTITY; index++)
  2533. {
  2534. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2535. {
  2536. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2537. }
  2538. }
  2539. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2540. }//END FOR AC ELSE
  2541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2543. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2544. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2547. //idx_sample=2;
  2548. //********************************(4)Power.Active.Export************************************************/
  2549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2550. {
  2551. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2552. {
  2553. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2554. {
  2555. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2556. }
  2557. }
  2558. for (int index = 0; index < CCS_QUANTITY; index++)
  2559. {
  2560. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2561. {
  2562. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2563. }
  2564. }
  2565. for (int index = 0; index < GB_QUANTITY; index++)
  2566. {
  2567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2568. {
  2569. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2570. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2571. }
  2572. }
  2573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2574. }
  2575. else
  2576. {
  2577. for (int index = 0; index < AC_QUANTITY; index++)
  2578. {
  2579. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2580. {
  2581. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2582. }
  2583. }
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2585. }// END FOR AC ELSE
  2586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2587. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2588. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2589. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2590. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2591. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2592. //idx_sample=3;
  2593. //***********************************************(5)VOLTAGE******************************************************/
  2594. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2595. {
  2596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2597. {
  2598. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2599. {
  2600. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2601. }
  2602. }
  2603. for (int index = 0; index < CCS_QUANTITY; index++)
  2604. {
  2605. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2606. {
  2607. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2608. }
  2609. }
  2610. for (int index = 0; index < GB_QUANTITY; index++)
  2611. {
  2612. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2613. {
  2614. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2615. }
  2616. }
  2617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2618. }
  2619. else
  2620. {
  2621. for (int index = 0; index < AC_QUANTITY; index++)
  2622. {
  2623. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2624. {
  2625. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2626. }
  2627. }
  2628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2629. }//END FOR AC ELSE
  2630. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2632. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2633. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2634. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2637. {
  2638. //idx_sample=4;
  2639. //sampledValue = NULL;
  2640. //***********************************************(6)SOC******************************************************/
  2641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2642. {
  2643. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2644. {
  2645. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2646. }
  2647. }
  2648. for (int index = 0; index < CCS_QUANTITY; index++)
  2649. {
  2650. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2651. {
  2652. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2653. }
  2654. }
  2655. for (int index = 0; index < GB_QUANTITY; index++)
  2656. {
  2657. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2658. {
  2659. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2660. }
  2661. }
  2662. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2666. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2668. }
  2669. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2670. {
  2671. 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\"}]}]}]"
  2672. ,MESSAGE_TYPE_CALL
  2673. ,guid
  2674. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2675. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2676. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2712. );
  2713. }
  2714. else
  2715. {
  2716. 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\"}]}]}]"
  2717. ,MESSAGE_TYPE_CALL
  2718. ,guid
  2719. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2720. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2721. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2750. );
  2751. }
  2752. // Put request guid to hash map
  2753. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2754. 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*/)
  2755. {
  2756. result = PASS;
  2757. DEBUG_INFO("MeterValues mapitem pass\n");
  2758. }
  2759. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2760. LWS_Send(queuedata);
  2761. #if 0
  2762. // Put request guid to hash map
  2763. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2764. 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*/)
  2765. {
  2766. result = PASS;
  2767. DEBUG_INFO("MeterValues mapitem pass\n");
  2768. }
  2769. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2770. #endif
  2771. return result;
  2772. }
  2773. //==========================================
  2774. // send confirm routine
  2775. //==========================================
  2776. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2777. {
  2778. mtrace();
  2779. int result = FAIL;
  2780. char message[100]={0};
  2781. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2782. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2783. LWS_Send(message);
  2784. result = TRUE;
  2785. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2786. return result;
  2787. }
  2788. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2789. {
  2790. mtrace();
  2791. int result = FAIL;
  2792. char message[100]={0};
  2793. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2794. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2795. LWS_Send(message);
  2796. result = TRUE;
  2797. return result;
  2798. }
  2799. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2800. {
  2801. mtrace();
  2802. int result = FAIL;
  2803. char message[100]={0};
  2804. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2805. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2806. LWS_Send(message);
  2807. result = TRUE;
  2808. return result;
  2809. }
  2810. int sendClearCacheConfirmation(char *uuid,char *payload)
  2811. {
  2812. mtrace();
  2813. int result = FAIL;
  2814. char message[500]={0};
  2815. // int count = 0;
  2816. // int gun_index = 0;
  2817. // char guid[37];
  2818. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2819. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2820. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2821. LWS_Send(message);
  2822. return result;
  2823. }
  2824. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2825. {
  2826. mtrace();
  2827. int result = FAIL;
  2828. char message[500]={0};
  2829. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2830. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2831. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2832. LWS_Send(message);
  2833. return result;
  2834. }
  2835. int sendDataTransferConfirmation(char *uuid,char *payload)
  2836. {
  2837. mtrace();
  2838. char statusStr[20]={0};
  2839. char dataStr[10]={0};
  2840. char sstr[20]={0};
  2841. int c = 0;
  2842. char *loc;
  2843. int result = FAIL;
  2844. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2845. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2846. /**********************status**************************/
  2847. loc = strstr(payload, "status");
  2848. memset(sstr ,0, sizeof(sstr) );
  2849. c = 0;
  2850. while (loc[3+strlen("status")+c] != '\"')
  2851. {
  2852. sstr[c] = loc[3+strlen("status")+c];
  2853. c++;
  2854. }
  2855. sstr[c] = '\0';
  2856. strcpy(statusStr, sstr);
  2857. /**********************data**************************/
  2858. loc = strstr(payload, "data");
  2859. memset(sstr ,0, sizeof(sstr) );
  2860. c = 0;
  2861. while (loc[3+strlen("data")+c] != '\"')
  2862. {
  2863. sstr[c] = loc[3+strlen("data")+c];
  2864. c++;
  2865. }
  2866. sstr[c] = '\0';
  2867. strcpy(dataStr, sstr);
  2868. return result;
  2869. }
  2870. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2871. {
  2872. mtrace();
  2873. int result = FAIL;
  2874. char message[1000]={0};
  2875. double diff_f = 0.0;
  2876. int diff_i = 0;
  2877. int diffSeconds = 0;
  2878. struct tm tp;
  2879. int TimeZero = FALSE;
  2880. int CompositeScheduleIndex = 0;
  2881. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2882. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2883. {
  2884. TimeZero = TRUE;
  2885. }
  2886. else
  2887. {
  2888. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2889. }
  2890. if(TimeZero == FALSE)
  2891. {
  2892. tp.tm_isdst = -1;
  2893. time_t utc = mktime(&tp);
  2894. time_t t = time(NULL);
  2895. diff_f = difftime(t, utc);
  2896. diff_i = (int)diff_f;
  2897. diffSeconds = diff_i % 86400;//86400 seconds/day
  2898. }
  2899. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2900. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2901. #if 0 //remove temporally
  2902. 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}"
  2903. ,MESSAGE_TYPE_CALLRESULT
  2904. ,uuid
  2905. ,payload
  2906. ,connectorIdInt
  2907. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2908. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2909. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2910. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2911. #endif
  2912. if(nPeriod == 0)
  2913. {
  2914. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  2915. {
  2916. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  2917. ,MESSAGE_TYPE_CALLRESULT
  2918. ,uuid
  2919. ,payload
  2920. ,connectorIdInt);
  2921. }
  2922. else
  2923. {
  2924. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2925. ,MESSAGE_TYPE_CALLRESULT
  2926. ,uuid
  2927. ,payload
  2928. ,connectorIdInt
  2929. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2930. }
  2931. }
  2932. else
  2933. {
  2934. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2935. ,MESSAGE_TYPE_CALLRESULT
  2936. ,uuid
  2937. ,payload
  2938. ,connectorIdInt
  2939. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2940. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2941. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2942. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2943. int len = nPeriod;
  2944. //Last Period StartPriod is less than diffSeconds
  2945. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2946. {
  2947. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2948. , 0
  2949. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2950. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2951. }
  2952. else
  2953. {
  2954. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2955. {
  2956. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2957. {
  2958. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2959. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2960. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2961. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2962. }
  2963. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2964. {
  2965. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2966. , (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)) //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
  2967. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2968. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2969. }
  2970. }
  2971. }
  2972. sprintf(message + strlen(message), "]}}]");
  2973. }
  2974. LWS_Send(message);
  2975. result = TRUE;
  2976. return result;
  2977. }
  2978. int sendGetConfigurationConfirmation(char *uuid)
  2979. {
  2980. mtrace();
  2981. int result = FAIL;
  2982. int MaxKeySupported = 0;
  2983. int sentConfigurationNumber= 0;
  2984. int sentunConfigurationNumber= 0;
  2985. char message[4000]={0};
  2986. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2987. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2988. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2989. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  2990. ,MESSAGE_TYPE_CALLRESULT
  2991. ,uuid );
  2992. //configuration key
  2993. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2994. {
  2995. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2996. {
  2997. if (sentConfigurationNumber == 0)
  2998. {
  2999. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3000. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3001. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3002. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3003. }
  3004. else
  3005. {
  3006. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3007. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3008. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3009. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3010. }
  3011. sentConfigurationNumber = sentConfigurationNumber + 1;
  3012. }
  3013. }
  3014. sprintf(message + strlen(message), "]");
  3015. if(UnknownKeynum != 0)
  3016. {
  3017. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3018. //unkown key
  3019. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3020. {
  3021. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3022. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3023. if(sentunConfigurationNumber == 0)
  3024. {
  3025. sprintf(message + strlen(message), "\"%s\""
  3026. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3027. }
  3028. else
  3029. {
  3030. sprintf(message + strlen(message), ",\"%s\""
  3031. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3032. }
  3033. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3034. }
  3035. sprintf(message + strlen(message), "]");
  3036. }
  3037. sprintf(message + strlen(message), "}]");
  3038. LWS_Send(message);
  3039. return result;
  3040. }
  3041. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3042. {
  3043. mtrace();
  3044. int result = FAIL;
  3045. char message[400]={0};
  3046. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3047. if(strcmp(payload,"")==0)
  3048. {
  3049. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3050. }
  3051. else
  3052. {
  3053. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3054. }
  3055. LWS_Send(message);
  3056. result = TRUE;
  3057. return result;
  3058. }
  3059. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3060. {
  3061. mtrace();
  3062. int result = FAIL;
  3063. char message[80]={0};
  3064. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3065. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3066. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3067. LWS_Send(message);
  3068. result = TRUE;
  3069. return result;
  3070. }
  3071. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3072. {
  3073. mtrace();
  3074. int result = FAIL;
  3075. char message[80]={0};
  3076. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3077. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3078. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3079. LWS_Send(message);
  3080. result = TRUE;
  3081. return result;
  3082. }
  3083. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3084. {
  3085. mtrace();
  3086. int result = FAIL;
  3087. char message[80]={0};
  3088. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3089. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3090. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3091. LWS_Send(message);
  3092. result = TRUE;
  3093. return result;
  3094. }
  3095. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3096. {
  3097. mtrace();
  3098. int result = FAIL;
  3099. char message[80]={0};
  3100. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3101. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3102. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3103. LWS_Send(message);
  3104. result = TRUE;
  3105. return result;
  3106. }
  3107. int sendResetConfirmation(char *uuid,char *payload)
  3108. {
  3109. mtrace();
  3110. int result = FAIL;
  3111. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3112. char message[80]={0};
  3113. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3114. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3115. LWS_Send(message);
  3116. result = TRUE;
  3117. return result;
  3118. }
  3119. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3120. {
  3121. mtrace();
  3122. int result = FAIL;
  3123. char message[500]={0};
  3124. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3125. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3126. LWS_Send(message);
  3127. result = TRUE;
  3128. return result;
  3129. }
  3130. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3131. {
  3132. mtrace();
  3133. int result = FAIL;
  3134. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3135. char message[80]={0};
  3136. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3137. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3138. LWS_Send(message);
  3139. result = TRUE;
  3140. return result;
  3141. }
  3142. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3143. {
  3144. mtrace();
  3145. int result = FAIL;
  3146. char message[80]={0};
  3147. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3148. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3149. LWS_Send(message);
  3150. result = TRUE;
  3151. return result;
  3152. }
  3153. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3154. {
  3155. mtrace();
  3156. int result = FAIL;
  3157. char message[80]={0};
  3158. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3159. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3160. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3161. LWS_Send(message);
  3162. result = TRUE;
  3163. return result;
  3164. }
  3165. int sendUpdateFirmwareConfirmation(char *uuid)
  3166. {
  3167. mtrace();
  3168. int result = FAIL;
  3169. char message[60]={0};
  3170. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3171. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3172. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3173. LWS_Send(message);
  3174. result = TRUE;
  3175. return result;
  3176. }
  3177. //==========================================
  3178. // send CallError routine
  3179. //==========================================
  3180. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3181. {
  3182. mtrace();
  3183. //int result = FAIL;
  3184. char message[220]={0};
  3185. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3186. #ifdef SystemLogMessage
  3187. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3188. uniqueId, action, errorCode, errorDescription);
  3189. #endif
  3190. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3191. LWS_Send(message);
  3192. //result = TRUE;
  3193. }
  3194. //==========================================
  3195. // Handle server request routine Start
  3196. //==========================================
  3197. #define GUN_NUM 1
  3198. int handleCancelReservationRequest(char *uuid, char *payload)
  3199. {
  3200. mtrace();
  3201. int result = FAIL;
  3202. int gunNO = 0;
  3203. int reservationIdInt =0;
  3204. char comfirmstr[20];
  3205. int c = 0;
  3206. char *loc;
  3207. char sstr[100]={0};
  3208. DEBUG_INFO("handle CancelReservationRequest\n");
  3209. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3210. c = 0;
  3211. loc = strstr(payload, "reservationId");
  3212. memset(sstr ,0, sizeof(sstr) );
  3213. while (loc[strlen("reservationId")+2+c] != '}')
  3214. {
  3215. sstr[c] = loc[strlen("reservationId")+2+c];
  3216. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3217. c++;
  3218. }
  3219. sstr[c] = '\0';
  3220. reservationIdInt = atoi(sstr);
  3221. memset(comfirmstr, 0, sizeof comfirmstr);
  3222. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3223. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3224. //check Transaction active
  3225. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3226. {
  3227. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3228. {
  3229. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3230. {
  3231. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3232. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3233. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3234. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3235. goto end;
  3236. }
  3237. }
  3238. for (int index = 0; index < CCS_QUANTITY; index++)
  3239. {
  3240. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3241. {
  3242. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3243. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3244. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3245. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3246. goto end;
  3247. }
  3248. }
  3249. for (int index = 0; index < GB_QUANTITY; index++)
  3250. {
  3251. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3252. {
  3253. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3254. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3255. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3256. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3257. goto end;
  3258. }
  3259. }
  3260. }
  3261. else
  3262. {
  3263. for (int index = 0; index < AC_QUANTITY; index++)
  3264. {
  3265. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3266. {
  3267. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3268. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3269. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3270. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3271. goto end;
  3272. }
  3273. }
  3274. }// END FOR AC ELSE
  3275. //The reservationId does NOT match the reservationId
  3276. sendCancelReservationConfirmation(uuid, comfirmstr);
  3277. end:
  3278. // Fill in ocpp packet uuid
  3279. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3280. return result;
  3281. }
  3282. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3283. {
  3284. mtrace();
  3285. int result = FAIL;
  3286. int gunIndex = 0;
  3287. char sstr[90]={0};
  3288. char typeStr[16]={0};
  3289. char comfirmstr[20];
  3290. int specificId = FALSE;
  3291. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3292. char *loc;
  3293. //int intervalInt = 0;
  3294. int c = 0;
  3295. /*** connectorId ****/
  3296. c = 0;
  3297. loc = strstr(payload, "connectorId");
  3298. memset(sstr ,0, sizeof(sstr) );
  3299. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3300. {
  3301. sstr[c] = loc[strlen("connectorId")+2+c];
  3302. c++;
  3303. }
  3304. sstr[c] = '\0';
  3305. gunIndex = atoi(sstr);
  3306. /***type ****/
  3307. loc = strstr(payload, "type");
  3308. memset(sstr ,0, sizeof(sstr) );
  3309. c = 0;
  3310. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3311. {
  3312. sstr[c] = loc[3+strlen("type")+c];
  3313. c++;
  3314. }
  3315. sstr[c] = '\0';
  3316. strcpy(typeStr, sstr);
  3317. if(gunIndex != 0)
  3318. {
  3319. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3320. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3321. }
  3322. else
  3323. {
  3324. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3325. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3326. }
  3327. memset(comfirmstr, 0, sizeof comfirmstr);
  3328. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3329. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3330. {
  3331. specificId = TRUE;
  3332. }
  3333. if(specificId == FALSE)
  3334. goto end;
  3335. if(gunIndex != 0)
  3336. {
  3337. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3338. }
  3339. else
  3340. {
  3341. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3342. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3343. }
  3344. /*
  3345. enum SYSTEM_STATUS
  3346. {
  3347. SYS_MODE_BOOTING = 0,
  3348. SYS_MODE_IDLE = 1,
  3349. SYS_MODE_AUTHORIZING = 2,
  3350. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3351. SYS_MODE_REASSIGN = 4,
  3352. SYS_MODE_PREPARING = 5,
  3353. SYS_MODE_PREPARE_FOR_EV = 6,
  3354. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3355. SYS_MODE_CHARGING = 8,
  3356. SYS_MODE_TERMINATING = 9,
  3357. SYS_MODE_COMPLETE = 10,
  3358. SYS_MODE_ALARM = 11,
  3359. SYS_MODE_FAULT = 12,
  3360. SYS_MODE_RESERVATION = 13,
  3361. SYS_MODE_BOOKING = 14,
  3362. SYS_MODE_MAINTAIN = 15,
  3363. SYS_MODE_DEBUG = 16,
  3364. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3365. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3366. SYS_MODE_UPDATE = 19
  3367. };
  3368. */
  3369. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3370. {
  3371. //check Transaction active
  3372. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3373. {
  3374. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3375. {
  3376. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3377. {
  3378. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3379. {
  3380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3381. }
  3382. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3383. {
  3384. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3385. }
  3386. else
  3387. {
  3388. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3389. }
  3390. goto end;
  3391. }
  3392. }//END FOR CHAdeMO_QUANTITY
  3393. for (int index = 0; index < CCS_QUANTITY; index++)
  3394. {
  3395. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3396. {
  3397. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3398. {
  3399. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3400. }
  3401. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3402. {
  3403. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3404. }
  3405. else
  3406. {
  3407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3408. }
  3409. goto end;
  3410. }
  3411. }//END FOR CCS_QUANTITY
  3412. for (int index = 0; index < GB_QUANTITY; index++)
  3413. {
  3414. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3415. {
  3416. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3417. {
  3418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3419. }
  3420. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3421. {
  3422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3423. }
  3424. else
  3425. {
  3426. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3427. }
  3428. goto end;
  3429. }
  3430. }// END FOR GB_QUANTITY
  3431. }
  3432. else
  3433. {
  3434. for (int index = 0; index < AC_QUANTITY; index++)
  3435. {
  3436. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3437. {
  3438. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3439. {
  3440. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3441. }
  3442. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3443. {
  3444. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3445. }
  3446. else
  3447. {
  3448. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3449. }
  3450. goto end;
  3451. }
  3452. }//END FOR AC_QUANTITY
  3453. }// END FOR AC ELSE
  3454. }//END FOR AvailabilityTypeStr[Inoperative]
  3455. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3456. {
  3457. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3458. //check Transaction active
  3459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3460. {
  3461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3462. {
  3463. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3464. {
  3465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3466. goto end;
  3467. }
  3468. }//END FOR CHAdeMO_QUANTITY
  3469. for (int index = 0; index < CCS_QUANTITY; index++)
  3470. {
  3471. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3472. {
  3473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3474. goto end;
  3475. }
  3476. }//END FOR CCS_QUANTITY
  3477. for (int index = 0; index < GB_QUANTITY; index++)
  3478. {
  3479. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3480. {
  3481. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3483. goto end;
  3484. }
  3485. }// END FOR GB_QUANTITY
  3486. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3487. }
  3488. else
  3489. {
  3490. for (int index = 0; index < AC_QUANTITY; index++)
  3491. {
  3492. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3493. {
  3494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3495. goto end;
  3496. }
  3497. }//END FOR CHAdeMO_QUANTITY
  3498. }//END FOR AC ELSE
  3499. }//END FOR AvailabilityTypeStr[Operative]
  3500. end:
  3501. if(gunIndex != 0)
  3502. {
  3503. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3504. }
  3505. else
  3506. {
  3507. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3508. }
  3509. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3510. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3511. return result;
  3512. }
  3513. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3514. {
  3515. mtrace();
  3516. int result = FAIL;
  3517. char sstr[100]={0};
  3518. char keystr[40]={0};
  3519. char valuestr[100]={0};
  3520. char *loc;
  3521. int c = 0;
  3522. char comfirmstr[20]={0};
  3523. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3524. /***key ****/
  3525. loc = strstr(payload, "key");
  3526. memset(sstr ,0, sizeof(sstr) );
  3527. c = 0;
  3528. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3529. {
  3530. sstr[c] = loc[3+strlen("key")+c];
  3531. c++;
  3532. }
  3533. sstr[c] = '\0';
  3534. strcpy(keystr, sstr);
  3535. //DEBUG_INFO( "keystr=%s\n",keystr);
  3536. /***value ****/
  3537. loc = strstr(payload, "value");
  3538. memset(sstr ,0, sizeof(sstr) );
  3539. c = 0;
  3540. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3541. {
  3542. sstr[c] = loc[3+strlen("value")+c];
  3543. c++;
  3544. }
  3545. sstr[c] = '\0';
  3546. strcpy(valuestr, sstr);
  3547. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3548. if((uuid==NULL) || (payload ==NULL) )
  3549. {
  3550. #ifdef Debug
  3551. DEBUG_INFO("payload is null\n");
  3552. #endif
  3553. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3554. }
  3555. else
  3556. {
  3557. int status = setKeyValue(keystr, valuestr);
  3558. switch(status)
  3559. {
  3560. case ConfigurationStatus_Accepted:
  3561. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3562. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3563. StoreConfigurationTable();
  3564. break;
  3565. case ConfigurationStatus_Rejected:
  3566. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3567. break;
  3568. case RebootRequired:
  3569. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3570. StoreConfigurationTable();
  3571. break;
  3572. case NotSupported:
  3573. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3574. break;
  3575. default:
  3576. break;
  3577. }
  3578. }
  3579. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3580. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3581. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3582. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3583. {
  3584. ChageWebSocketPingInterval(atoi(valuestr));
  3585. }
  3586. return result;
  3587. }
  3588. int handleClearCacheRequest(char *uuid, char *payload)
  3589. {
  3590. mtrace();
  3591. int result = FAIL;
  3592. char comfirmstr[20];
  3593. int fd;
  3594. char rmFileCmd[100]={0};
  3595. struct stat stats;
  3596. DEBUG_INFO("handle ClearCacheRequest\n");
  3597. stat("/Storage/OCPP", &stats);
  3598. // Check for directory existence
  3599. if (S_ISDIR(stats.st_mode) == 1)
  3600. {
  3601. //DEBUG_ERROR("\n OCPP directory exist \n");
  3602. }
  3603. else
  3604. {
  3605. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3606. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  3607. system(rmFileCmd);
  3608. }
  3609. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3610. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3611. {
  3612. DEBUG_INFO("AuthorizationCache file exist.\n");
  3613. }
  3614. else
  3615. {
  3616. DEBUG_INFO("AuthorizationCache file not exist\n");
  3617. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3618. if(log == NULL)
  3619. {
  3620. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3621. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3622. goto end;
  3623. }
  3624. else
  3625. {
  3626. fclose(log);
  3627. }
  3628. }
  3629. fd = open(AuthorizationCache_JSON,O_RDWR);
  3630. if(fd < 0)
  3631. {
  3632. DEBUG_INFO("open AuthorizationCache file failed\n");
  3633. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3634. }
  3635. else
  3636. {
  3637. DEBUG_INFO("open AuthorizationCache file successful\n");
  3638. //* 清空? 件 */
  3639. ftruncate(fd,0);
  3640. //* ? 新设置? 件? 移??*/
  3641. lseek(fd,0,SEEK_SET);
  3642. close(fd);
  3643. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3644. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3645. }
  3646. end:
  3647. sendClearCacheConfirmation(uuid, comfirmstr);
  3648. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3649. return result;
  3650. }
  3651. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3652. {
  3653. mtrace();
  3654. int result = FAIL;
  3655. int resultRename;
  3656. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3657. char chargingProfilePurposeStr[26]={0};
  3658. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3659. char tempchargingProfilePurposeStr[26]={0};
  3660. char sstr[160]={0};//sstr[200]={ 0 };
  3661. char str[100]={0};
  3662. int c = 0;
  3663. //int i = 0;
  3664. //char * pch;
  3665. char *loc;
  3666. char fname[200]={0};
  3667. char comfirmstr[20]={0};
  3668. char word[1600]={0};
  3669. int clearflag = FALSE;
  3670. int chargingProfileIdIsNULL = FALSE;
  3671. int connectorIsNULL = FALSE;
  3672. int chargingProfilePurposeIsNULL = FALSE;
  3673. int stackLevelIsNULL = FALSE;
  3674. //int GotoEnd = FALSE;
  3675. FILE *fptr1, *fptr2;
  3676. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  3677. int n_chargingProfile=0;
  3678. int isEmptyFile = FALSE;
  3679. char sLineWord[1600]={0};
  3680. char chargingProfiles[10][100]={0};
  3681. int ChargeProfileCount = 0;
  3682. char ch;
  3683. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3684. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3685. //***id ****/
  3686. c = 0;
  3687. loc = strstr(payload, "id");
  3688. memset(sstr ,0, sizeof(sstr) );
  3689. if(loc == NULL)
  3690. {
  3691. chargingProfileIdIsNULL = TRUE;
  3692. }
  3693. else
  3694. {
  3695. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3696. {
  3697. sstr[c] = loc[strlen("id")+2+c];
  3698. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3699. c++;
  3700. }
  3701. sstr[c] = '\0';
  3702. chargingProfileIdInt = atoi(sstr);
  3703. }
  3704. //***connectorId ****/
  3705. c=0;
  3706. loc = strstr(payload, "connectorId");
  3707. memset(sstr ,0, sizeof(sstr) );
  3708. if(loc == NULL)
  3709. {
  3710. connectorIsNULL = TRUE;
  3711. }
  3712. else
  3713. {
  3714. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3715. {
  3716. sstr[c] = loc[strlen("connectorId")+2+c];
  3717. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3718. c++;
  3719. }
  3720. sstr[c] = '\0';
  3721. connectorIdInt = atoi(sstr);
  3722. }
  3723. //***chargingProfilePurpose ****/
  3724. loc = strstr(payload, "chargingProfilePurpose");
  3725. memset(sstr ,0, sizeof(sstr) );
  3726. c = 0;
  3727. if(loc == NULL)
  3728. {
  3729. chargingProfilePurposeIsNULL = TRUE;
  3730. }
  3731. else
  3732. {
  3733. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3734. {
  3735. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3736. c++;
  3737. }
  3738. sstr[c] = '\0';
  3739. strcpy(chargingProfilePurposeStr, sstr);
  3740. }
  3741. //***stackLevel ****/
  3742. c=0;
  3743. loc = strstr(payload, "stackLevel");
  3744. memset(sstr ,0, sizeof(sstr) );
  3745. if(loc == NULL)
  3746. {
  3747. stackLevelIsNULL = TRUE;
  3748. }
  3749. else
  3750. {
  3751. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3752. {
  3753. sstr[c] = loc[strlen("stackLevel")+2+c];
  3754. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3755. c++;
  3756. }
  3757. sstr[c] = '\0';
  3758. stackLevelInt = atoi(sstr);
  3759. }
  3760. if(connectorIsNULL == FALSE)
  3761. {
  3762. switch(connectorIdInt)
  3763. {
  3764. case 0:
  3765. if(chargingProfilePurposeIsNULL == TRUE)
  3766. {
  3767. int l = 0;
  3768. strcpy(fname, ChargePointMaxProfile_JSON);
  3769. if((access(fname,F_OK))!=-1)
  3770. {
  3771. strcpy(chargingProfiles[l], fname);
  3772. l = l + 1;
  3773. }
  3774. strcpy(fname, TxDefaultProfile_0_JSON);
  3775. if((access(fname,F_OK))!=-1)
  3776. {
  3777. strcpy(chargingProfiles[l], fname);
  3778. l = l + 1;
  3779. }
  3780. ChargeProfileCount = l;
  3781. }
  3782. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  3783. {
  3784. strcpy(fname, ChargePointMaxProfile_JSON);
  3785. if((access(fname,F_OK))!=-1)
  3786. {
  3787. strcpy(chargingProfiles[0], fname);
  3788. ChargeProfileCount = 1;
  3789. }
  3790. }
  3791. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3792. {
  3793. strcpy(fname, TxDefaultProfile_0_JSON);
  3794. if((access(fname,F_OK))!=-1)
  3795. {
  3796. strcpy(chargingProfiles[0], fname);
  3797. ChargeProfileCount = 1;
  3798. }
  3799. }
  3800. break;
  3801. default:
  3802. if(chargingProfilePurposeIsNULL == TRUE)
  3803. {
  3804. int m = 0;
  3805. memset(fname, 0, sizeof fname);
  3806. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3807. if((access(fname,F_OK))!=-1)
  3808. {
  3809. strcpy(chargingProfiles[m], fname);
  3810. m = m + 1;
  3811. }
  3812. memset(fname, 0, sizeof fname);
  3813. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3814. if((access(fname,F_OK))!=-1)
  3815. {
  3816. strcpy(chargingProfiles[m], fname);
  3817. m = m + 1;
  3818. }
  3819. ChargeProfileCount = m;
  3820. }
  3821. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  3822. {
  3823. //strcpy(fname, TxDefaultProfile_1_JSON);
  3824. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  3825. if((access(fname,F_OK))!=-1)
  3826. {
  3827. strcpy(chargingProfiles[0], fname);
  3828. ChargeProfileCount = 1;
  3829. }
  3830. }
  3831. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  3832. {
  3833. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3834. if((access(fname,F_OK))!=-1)
  3835. {
  3836. strcpy(chargingProfiles[0], fname);
  3837. ChargeProfileCount = 1;
  3838. }
  3839. //strcpy(fname, TxProfile_1_JSON);
  3840. }
  3841. //strcpy(fname, ChargePointMaxProfile_JSON );
  3842. break;
  3843. }
  3844. }
  3845. else // Check all Charging Profiles
  3846. {
  3847. int i = 0;
  3848. char fnametemp[200]={0};
  3849. ChargeProfileCount = 0;
  3850. //Check ChargePointMaxProfile.json exit
  3851. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  3852. {
  3853. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  3854. i = i + 1;
  3855. }
  3856. //Check TxDefaultProfile_0.json exit
  3857. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  3858. {
  3859. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  3860. i = i + 1;
  3861. }
  3862. //Check TxDefaultProfile_%d.json
  3863. for(int j=1; j <= gunTotalNumber; j++)
  3864. {
  3865. memset(fnametemp, 0, sizeof fnametemp);
  3866. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  3867. if((access(fnametemp,F_OK))!=-1)
  3868. {
  3869. strcpy(chargingProfiles[i], fnametemp);
  3870. i = i + 1;
  3871. }
  3872. }
  3873. //Check TxProfile_%d.json
  3874. for(int j=1; j <= gunTotalNumber; j++)
  3875. {
  3876. memset(fnametemp, 0, sizeof fnametemp);
  3877. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  3878. if((access(fnametemp,F_OK))!=-1)
  3879. {
  3880. strcpy(chargingProfiles[i], fnametemp);
  3881. i = i + 1;
  3882. }
  3883. }
  3884. ChargeProfileCount = i;
  3885. }// End connectorIsNULL is TRUE
  3886. if(ChargeProfileCount == 0)
  3887. {
  3888. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3889. goto end;
  3890. }
  3891. #if 0
  3892. fptr1 = fopen(fname, "r");
  3893. if (!fptr1)
  3894. {
  3895. //file not exist
  3896. DEBUG_INFO("Unable to open the input file!!\n");
  3897. fptr1 = fopen(fname, "w+");
  3898. }
  3899. fclose(fptr1);
  3900. #endif
  3901. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3902. {
  3903. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3904. goto end;
  3905. }
  3906. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3907. {
  3908. memset(str, 0, sizeof str);
  3909. // clear temp file
  3910. sprintf(str,"rm -f %s",temp);
  3911. system(str);
  3912. for(int k=0; k < ChargeProfileCount; k++)
  3913. {
  3914. memset(str, 0, sizeof str);
  3915. //clear file in C
  3916. sprintf(str,"rm -f %s",chargingProfiles[k]);
  3917. system(str);
  3918. }
  3919. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3920. goto end;
  3921. }
  3922. else if(connectorIsNULL == TRUE)
  3923. {
  3924. for(int k=0; k < ChargeProfileCount; k++)
  3925. {
  3926. fptr1 = fopen(chargingProfiles[k], "r");
  3927. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  3928. //Check Charging Profile Count
  3929. while(fscanf(fptr1, "%s", word) != EOF)
  3930. {
  3931. //DEBUG_INFO("word=%s\n",word);
  3932. if(strstr(word, "chargingProfileId")!= NULL)
  3933. {
  3934. //DEBUG_INFO("test chargingProfileId \n");
  3935. n_chargingProfile = n_chargingProfile + 1;
  3936. //DEBUG_INFO("chargingProfileId Found\n");
  3937. }
  3938. }
  3939. rewind(fptr1);
  3940. //search Charging Profile Element
  3941. //int i= 0;
  3942. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3943. {
  3944. //------------------------tempconnectorIdInt------------------------//
  3945. loc = strstr(sLineWord, "connectorId");
  3946. c = 0;
  3947. memset(sstr ,0, sizeof(sstr) );
  3948. while (loc[strlen("connectorId")+2+c] != ',')
  3949. {
  3950. sstr[c] = loc[strlen("connectorId")+2+c];
  3951. c++;
  3952. }
  3953. sstr[c] = '\0';
  3954. tempconnectorIdInt = atoi(sstr);
  3955. printf("file's gun number is %d\n", tempconnectorIdInt);
  3956. //--------------------------chargingProfileId--------------------//
  3957. c = 0;
  3958. loc = strstr(sLineWord, "chargingProfileId");
  3959. memset(sstr ,0, sizeof(sstr) );
  3960. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3961. {
  3962. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3963. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3964. c++;
  3965. }
  3966. sstr[c] = '\0';
  3967. tempchargingProfileIdInt = atoi(sstr);
  3968. //stackLevel
  3969. c = 0;
  3970. loc = strstr(sLineWord, "stackLevel");
  3971. memset(sstr ,0, sizeof(sstr) );
  3972. while (loc[strlen("stackLevel")+2+c] != ',')
  3973. {
  3974. sstr[c] = loc[strlen("stackLevel")+2+c];
  3975. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3976. c++;
  3977. }
  3978. sstr[c] = '\0';
  3979. tempstackLevelInt = atoi(sstr);
  3980. c = 0;
  3981. loc = strstr(sLineWord, "chargingProfilePurpose");
  3982. memset(sstr ,0, sizeof(sstr) );
  3983. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3984. {
  3985. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3986. c++;
  3987. }
  3988. sstr[c] = '\0';
  3989. strcpy(tempchargingProfilePurposeStr, sstr);
  3990. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  3991. {
  3992. //------- not write to fptr2-------//
  3993. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3994. //clearflag = TRUE;
  3995. }
  3996. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  3997. {
  3998. //------- not write to fptr2-------//
  3999. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4000. }
  4001. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4002. {
  4003. //------- not write to fptr2-------//
  4004. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4005. }
  4006. else
  4007. {
  4008. fprintf(fptr2, sLineWord);//writing data into file
  4009. }
  4010. memset(sLineWord, 0, sizeof sLineWord);
  4011. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4012. if(clearflag == TRUE)
  4013. {
  4014. fclose(fptr1);
  4015. fclose(fptr2);
  4016. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4017. system(str);
  4018. // clear temp file
  4019. sprintf(str,"rm -f %s",temp);
  4020. system(str);
  4021. }
  4022. else
  4023. {
  4024. fclose(fptr1);
  4025. fclose(fptr2);
  4026. memset(str, 0, sizeof str);
  4027. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4028. system(str);
  4029. resultRename = rename(temp, chargingProfiles[k]);
  4030. if(resultRename == 0)
  4031. {
  4032. DEBUG_INFO("File ChargingProfile renamed successfully");
  4033. }
  4034. else
  4035. {
  4036. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4037. }
  4038. if(comfirmstr[0]== 0)
  4039. {
  4040. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4041. }
  4042. //Check chargingProfile is empty file
  4043. /*------ Read the file ----------------*/
  4044. fptr1=fopen(chargingProfiles[k],"r");
  4045. ch=fgetc(fptr1);
  4046. rewind(fptr1);
  4047. memset(sLineWord, 0, sizeof sLineWord);
  4048. if(ch!=EOF)
  4049. {
  4050. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4051. {
  4052. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4053. if(sLineWord[0]=='\0')
  4054. {
  4055. isEmptyFile = TRUE;
  4056. break;
  4057. }
  4058. else
  4059. {
  4060. isEmptyFile = FALSE;
  4061. break;
  4062. }
  4063. }
  4064. }
  4065. fclose(fptr1);
  4066. if(isEmptyFile == TRUE)
  4067. {
  4068. memset(str, 0, sizeof str);
  4069. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4070. system(str);
  4071. }
  4072. }
  4073. }// End of while(int k=0; k < ChargePointCount; k++)
  4074. }
  4075. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4076. {
  4077. for(int k=0; k < ChargeProfileCount; k++)
  4078. {
  4079. fptr1 = fopen(chargingProfiles[k], "r");
  4080. fptr2 = fopen(temp, "w+");
  4081. //Check Charging Profile Count
  4082. while(fscanf(fptr1, "%s", word) != EOF)
  4083. {
  4084. //DEBUG_INFO("word=%s\n",word);
  4085. if(strstr(word, "chargingProfileId")!= NULL)
  4086. {
  4087. //DEBUG_INFO("test chargingProfileId \n");
  4088. n_chargingProfile = n_chargingProfile + 1;
  4089. //DEBUG_INFO("chargingProfileId Found\n");
  4090. }
  4091. }
  4092. rewind(fptr1);
  4093. //search Charging Profile Element
  4094. //int i= 0;
  4095. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4096. {
  4097. //*************************tempconnectorIdInt*********************************/
  4098. loc = strstr(sLineWord, "connectorId");
  4099. c = 0;
  4100. memset(sstr ,0, sizeof(sstr) );
  4101. while (loc[strlen("connectorId")+2+c] != ',')
  4102. {
  4103. sstr[c] = loc[strlen("connectorId")+2+c];
  4104. c++;
  4105. }
  4106. sstr[c] = '\0';
  4107. tempconnectorIdInt = atoi(sstr);
  4108. //chargingProfileId
  4109. c = 0;
  4110. loc = strstr(sLineWord, "chargingProfileId");
  4111. memset(sstr ,0, sizeof(sstr) );
  4112. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4113. {
  4114. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4115. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4116. c++;
  4117. }
  4118. sstr[c] = '\0';
  4119. tempchargingProfileIdInt = atoi(sstr);
  4120. //stackLevel
  4121. c = 0;
  4122. loc = strstr(sLineWord, "stackLevel");
  4123. memset(sstr ,0, sizeof(sstr) );
  4124. while (loc[strlen("stackLevel")+2+c] != ',')
  4125. {
  4126. sstr[c] = loc[strlen("stackLevel")+2+c];
  4127. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4128. c++;
  4129. }
  4130. sstr[c] = '\0';
  4131. tempstackLevelInt = atoi(sstr);
  4132. c = 0;
  4133. loc = strstr(sLineWord, "chargingProfilePurpose");
  4134. memset(sstr ,0, sizeof(sstr) );
  4135. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4136. {
  4137. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4138. c++;
  4139. }
  4140. sstr[c] = '\0';
  4141. strcpy(tempchargingProfilePurposeStr, sstr);
  4142. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4143. {
  4144. //------- not write to fptr2-------//
  4145. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4146. //clearflag = TRUE;
  4147. }
  4148. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4149. {
  4150. //------- not write to fptr2-------//
  4151. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4152. }
  4153. else if(stackLevelIsNULL == TRUE)
  4154. {
  4155. //Clear Whole File
  4156. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4157. clearflag = TRUE;
  4158. break;
  4159. }
  4160. else
  4161. {
  4162. fprintf(fptr2, sLineWord);//writing data into file
  4163. }
  4164. memset(sLineWord, 0, sizeof sLineWord);
  4165. }
  4166. if(clearflag == TRUE)
  4167. {
  4168. fclose(fptr1);
  4169. fclose(fptr2);
  4170. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4171. system(str);
  4172. // clear temp file
  4173. sprintf(str,"rm -f %s",temp);
  4174. system(str);
  4175. }
  4176. else
  4177. {
  4178. fclose(fptr1);
  4179. fclose(fptr2);
  4180. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4181. system(str);
  4182. resultRename = rename(temp, chargingProfiles[k]);
  4183. if(resultRename == 0)
  4184. {
  4185. DEBUG_INFO("File ChargingProfile renamed successfully");
  4186. }
  4187. else
  4188. {
  4189. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4190. }
  4191. if(comfirmstr[0]== 0)
  4192. {
  4193. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4194. }
  4195. //Check chargingProfile is empty file
  4196. /*------ Read the file ----------------*/
  4197. fptr1=fopen(chargingProfiles[k],"r");
  4198. ch=fgetc(fptr1);
  4199. rewind(fptr1);
  4200. memset(sLineWord, 0, sizeof sLineWord);
  4201. if(ch!=EOF)
  4202. {
  4203. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4204. {
  4205. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4206. if(sLineWord[0]=='\0')
  4207. {
  4208. isEmptyFile = TRUE;
  4209. break;
  4210. }
  4211. else
  4212. {
  4213. isEmptyFile = FALSE;
  4214. break;
  4215. }
  4216. }
  4217. }
  4218. fclose(fptr1);
  4219. if(isEmptyFile == TRUE)
  4220. {
  4221. memset(str, 0, sizeof str);
  4222. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4223. system(str);
  4224. }
  4225. /*------- End of reading ---------------*/
  4226. }
  4227. } // while(int k=0; k < ChargeProfileCount; k++)
  4228. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4229. end:
  4230. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4231. return result;
  4232. }
  4233. int handleDataTransferRequest(char *uuid, char *payload)
  4234. {
  4235. mtrace();
  4236. int result = FAIL;
  4237. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4238. char tempvendorId[255]={0};
  4239. char tempmessageId[50]={0};
  4240. char tempdata[50]={0};
  4241. char sstr[160]={0};//sstr[200]={ 0 };
  4242. char message[80]={0};
  4243. int c = 0;
  4244. char *loc;
  4245. DEBUG_INFO("handle DataTransferRequest\n");
  4246. if((uuid != NULL) && (payload != NULL))
  4247. {
  4248. //===============================
  4249. // vendorId
  4250. //===============================
  4251. c = 0;
  4252. loc = strstr(payload, "vendorId");
  4253. while (loc[strlen("vendorId")+3+c] != '\"')
  4254. {
  4255. sstr[c] = loc[strlen("vendorId")+3+c];
  4256. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4257. c++;
  4258. }
  4259. sstr[c] = '\0';
  4260. strcpy(tempvendorId,sstr);
  4261. //===============================
  4262. // messageId
  4263. //===============================
  4264. memset(sstr ,0, sizeof(sstr) );
  4265. c = 0;
  4266. loc = strstr(payload, "messageId");
  4267. while (loc[strlen("messageId")+3+c] != '\"')
  4268. {
  4269. sstr[c] = loc[strlen("messageId")+3+c];
  4270. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4271. c++;
  4272. }
  4273. sstr[c] = '\0';
  4274. strcpy(tempmessageId,sstr);
  4275. //===============================
  4276. // data
  4277. //===============================
  4278. memset(sstr ,0, sizeof(sstr) );
  4279. c = 0;
  4280. loc = strstr(payload, "data");
  4281. printf("loc=%s\n",loc);
  4282. while (loc[strlen("data")+3+c] != '\"')
  4283. {
  4284. sstr[c] = loc[strlen("data")+3+c];
  4285. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4286. c++;
  4287. }
  4288. sstr[c] = '\0';
  4289. strcpy(tempdata,sstr);
  4290. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4291. }
  4292. else
  4293. {
  4294. char guid[37]={0};
  4295. random_uuid(guid);
  4296. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4297. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4298. }
  4299. LWS_Send(message);
  4300. return result;
  4301. }
  4302. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4303. {
  4304. mtrace();
  4305. int result = FAIL;
  4306. int connectorIdInt, durationInt;
  4307. char chargingRateUnitStr[4]={0};
  4308. //int tempconnectorIdInt,
  4309. int tempdurationInt;
  4310. float tempminChargingRateFloat = 0.0;
  4311. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4312. int tempStartPeriodInt=0;
  4313. float tempLimitInt=0.0;//0.1;
  4314. int tempNumberPhasesInt=0;
  4315. char fname[200];
  4316. char comfirmstr[20];
  4317. //float totallimit =0.0;
  4318. float MinChargingRate =0.0;
  4319. //double diff_t;
  4320. //struct tm tp;
  4321. FILE *fptr1;
  4322. int c = 0;
  4323. //int i = 0;
  4324. char * pch;
  4325. char *loc;
  4326. char sstr[200]={ 0 };
  4327. int n_chargingProfile = 0;
  4328. int n_SchedulePeriods = 0;
  4329. char SchedulePeriodList[10][200]={0};
  4330. char sLineWord[1600]={0};
  4331. //int n_periods = 0;
  4332. char word[1000]={0};
  4333. int confirmPeriods = 0;
  4334. struct StructProfile ChargePointMaxProfile;
  4335. struct StructProfile TxDefaultProfile;
  4336. struct StructProfile TxProfile;
  4337. struct StructProfile TxDefaultProfiletemp[2]={0};
  4338. int TxDefaultProfileFileIsNull=FALSE;
  4339. int ChargePointMaxProfileIsNull=FALSE;
  4340. int TxProfileIsNull=FALSE;
  4341. int CompositeSceduleIndex = 0;
  4342. char ChargePointMaxProfileScheduleStr[30]={0};
  4343. char TxDefaultProfileScheduleStr[30]={0};
  4344. char TxProfileScheduleStr[30]={0};
  4345. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4346. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4347. memset(&TxProfile,0,sizeof(struct StructProfile));
  4348. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4349. c=0;
  4350. loc = strstr(payload, "connectorId");
  4351. memset(sstr ,0, sizeof(sstr) );
  4352. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4353. {
  4354. sstr[c] = loc[strlen("connectorId")+2+c];
  4355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4356. c++;
  4357. }
  4358. sstr[c] = '\0';
  4359. connectorIdInt = atoi(sstr);
  4360. c=0;
  4361. loc = strstr(payload, "duration");
  4362. memset(sstr ,0, sizeof(sstr) );
  4363. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4364. {
  4365. sstr[c] = loc[strlen("duration")+2+c];
  4366. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4367. c++;
  4368. }
  4369. sstr[c] = '\0';
  4370. durationInt = atoi(sstr);
  4371. c = 0;
  4372. loc = strstr(payload, "chargingRateUnit");
  4373. memset(sstr ,0, sizeof(sstr) );
  4374. if(loc == NULL)
  4375. {
  4376. }
  4377. else
  4378. {
  4379. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4380. {
  4381. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4382. c++;
  4383. }
  4384. sstr[c] = '\0';
  4385. strcpy(chargingRateUnitStr, sstr);
  4386. }
  4387. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4388. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4389. if(connectorIdInt==0) // connectorId is 0
  4390. {
  4391. //******************************ChargePointMaxProfile*****************************************************/
  4392. strcpy(fname, ChargePointMaxProfile_JSON );
  4393. char word[30]={0};
  4394. char sLineWord[1060]={0};
  4395. int n_chargingProfile=0;
  4396. ChargePointMaxProfileIsNull=TRUE;
  4397. if((access(fname,F_OK))!=-1)
  4398. {
  4399. fptr1 = fopen(fname, "r");
  4400. int c;
  4401. c = fgetc(fptr1);
  4402. //DEBUG_INFO("c:%d\n",c);
  4403. rewind(fptr1);
  4404. if(c == EOF)
  4405. {
  4406. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4407. ChargePointMaxProfileIsNull=TRUE;
  4408. fclose(fptr1);
  4409. }
  4410. else
  4411. {
  4412. ChargePointMaxProfileIsNull=FALSE;
  4413. while(fscanf(fptr1, "%s", word) != EOF)
  4414. {
  4415. if(strcmp(word, "chargingProfileId") == 0)
  4416. {
  4417. n_chargingProfile = n_chargingProfile + 1;
  4418. printf("Found\n");
  4419. }
  4420. }
  4421. rewind(fptr1);
  4422. //search Charging Profile Element
  4423. int i= 0;
  4424. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4425. #if 0
  4426. /***********connectorId****************/
  4427. c = 0;
  4428. loc = strstr(sLineWord, "connectorId");
  4429. // printf("loc=%s\n",loc);
  4430. memset(sstr ,0, sizeof(sstr) );
  4431. while (loc[strlen("connectorId")+2+c] != ',')
  4432. {
  4433. sstr[c] = loc[strlen("connectorId")+2+c];
  4434. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4435. c++;
  4436. }
  4437. sstr[c] = '\0';
  4438. tempconnectorIdInt = atoi(sstr);
  4439. #endif
  4440. //***********validFrom**************/
  4441. c = 0;
  4442. loc = strstr(sLineWord, "validFrom");
  4443. //DEBUG_INFO("loc=%s\n",loc);
  4444. memset(sstr ,0, sizeof(sstr) );
  4445. if(loc != NULL)
  4446. {
  4447. while (loc[3+strlen("validFrom")+c] != '\"')
  4448. {
  4449. sstr[c] = loc[3+strlen("validFrom")+c];
  4450. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4451. c++;
  4452. }
  4453. sstr[c] = '\0';
  4454. DEBUG_INFO("validFrom=%s\n",sstr);
  4455. strcpy(tempvalidFromStr,sstr);
  4456. }
  4457. else
  4458. {
  4459. strcpy(tempvalidFromStr,"");
  4460. }
  4461. //**********startSchedule**********/
  4462. c = 0;
  4463. loc = strstr(sLineWord, "startSchedule");
  4464. //DEBUG_INFO("loc=%s\n",loc);
  4465. memset(sstr ,0, sizeof(sstr) );
  4466. while (loc[3+strlen("startSchedule")+c] != '\"')
  4467. {
  4468. sstr[c] = loc[3+strlen("startSchedule")+c];
  4469. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4470. c++;
  4471. }
  4472. sstr[c] = '\0';
  4473. strcpy(tempstartScheduleStr, sstr);
  4474. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4475. //**********chargingRateUnit**********/
  4476. c = 0;
  4477. loc = strstr(sLineWord, "chargingRateUnit");
  4478. memset(sstr ,0, sizeof(sstr) );
  4479. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4480. {
  4481. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4482. c++;
  4483. }
  4484. sstr[c] = '\0';
  4485. strcpy(tempchargingRateUnitStr, sstr);
  4486. //**********minChargingRate*******/
  4487. c = 0;
  4488. loc = strstr(sLineWord, "minChargingRate");
  4489. //printf("loc=%s\n",loc);
  4490. if(loc != NULL)
  4491. {
  4492. memset(sstr ,0, sizeof(sstr) );
  4493. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4494. {
  4495. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4496. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4497. c++;
  4498. }
  4499. sstr[c] = '\0';
  4500. tempminChargingRateFloat = atof(sstr);
  4501. }
  4502. else
  4503. {
  4504. tempminChargingRateFloat = 0.0;
  4505. }
  4506. //
  4507. #if 0
  4508. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4509. tp.tm_isdst = -1;
  4510. time_t utc = mktime(&tp);
  4511. // current time
  4512. time_t t = time(NULL);
  4513. #endif
  4514. //diff_t = difftime(t, utc);
  4515. //parsing strings to words
  4516. i = 0;
  4517. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4518. loc = loc+3+strlen("chargingSchedulePeriod");
  4519. pch = strtok(loc ,"{");
  4520. while (pch != NULL)
  4521. {
  4522. strcpy(SchedulePeriodList[i], pch);
  4523. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4524. //printf ("%s\n",pch);
  4525. pch = strtok (NULL, "{");
  4526. i = i + 1;
  4527. }
  4528. n_SchedulePeriods = i;
  4529. for(int i=0;i<n_SchedulePeriods;i++)
  4530. {
  4531. //*************startPeriod****************/
  4532. c = 0;
  4533. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4534. memset(sstr ,0, sizeof(sstr) );
  4535. while (loc[strlen("startPeriod")+2+c] != ',')
  4536. {
  4537. sstr[c] = loc[strlen("startPeriod")+2+c];
  4538. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4539. c++;
  4540. }
  4541. sstr[c] = '\0';
  4542. tempStartPeriodInt = atoi(sstr);
  4543. //*************limit****************/
  4544. c = 0;
  4545. loc = strstr(SchedulePeriodList[i], "limit");
  4546. memset(sstr ,0, sizeof(sstr) );
  4547. while (loc[strlen("limit")+2+c] != ',')
  4548. {
  4549. sstr[c] = loc[strlen("limit")+2+c];
  4550. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4551. c++;
  4552. }
  4553. sstr[c] = '\0';
  4554. tempLimitInt = atof(sstr);
  4555. //*************numberPhases****************/
  4556. c = 0;
  4557. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4558. memset(sstr ,0, sizeof(sstr) );
  4559. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4560. {
  4561. sstr[c] = loc[strlen("numberPhases")+2+c];
  4562. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4563. c++;
  4564. }
  4565. sstr[c] = '\0';
  4566. tempNumberPhasesInt = atoi(sstr);
  4567. ChargePointMaxProfile.Duration = durationInt;
  4568. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4569. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4570. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4571. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4572. }
  4573. if(MinChargingRate < tempminChargingRateFloat)
  4574. MinChargingRate = tempminChargingRateFloat;
  4575. }
  4576. }// End of file ChargingProfile
  4577. } //THE END OF ACCESS ChargePointMaxProfile
  4578. //******************************TxDefaultProfile***********************************************/
  4579. strcpy(fname, TxDefaultProfile_0_JSON);
  4580. memset(word, 0, 30);
  4581. memset(sLineWord, 0, 1060);
  4582. //char word[30]={0};
  4583. //char sLineWord[1060]={0};
  4584. n_chargingProfile=0;
  4585. TxDefaultProfileFileIsNull=TRUE;
  4586. if((access(fname,F_OK))!=-1)
  4587. {
  4588. fptr1 = fopen(fname, "r");
  4589. c = 0;
  4590. c = fgetc(fptr1);
  4591. //DEBUG_INFO("c:%d\n",c);
  4592. rewind(fptr1);
  4593. if(c == EOF)
  4594. {
  4595. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4596. TxDefaultProfileFileIsNull=TRUE;
  4597. fclose(fptr1);
  4598. }
  4599. else
  4600. {
  4601. TxDefaultProfileFileIsNull=FALSE;
  4602. while(fscanf(fptr1, "%s", word) != EOF)
  4603. {
  4604. if(strcmp(word, "chargingProfileId") == 0)
  4605. {
  4606. n_chargingProfile = n_chargingProfile + 1;
  4607. printf("Found\n");
  4608. }
  4609. }
  4610. rewind(fptr1);
  4611. //search Charging Profile Element
  4612. int i= 0;
  4613. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4614. #if 0
  4615. /***********connectorId****************/
  4616. c = 0;
  4617. loc = strstr(sLineWord, "connectorId");
  4618. // printf("loc=%s\n",loc);
  4619. memset(sstr ,0, sizeof(sstr) );
  4620. while (loc[strlen("connectorId")+2+c] != ',')
  4621. {
  4622. sstr[c] = loc[strlen("connectorId")+2+c];
  4623. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4624. c++;
  4625. }
  4626. sstr[c] = '\0';
  4627. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4628. tempconnectorIdInt = atoi(sstr);
  4629. #endif
  4630. //***********validFrom**************/
  4631. c = 0;
  4632. loc = strstr(sLineWord, "validFrom");
  4633. //DEBUG_INFO("loc=%s\n",loc);
  4634. memset(sstr ,0, sizeof(sstr) );
  4635. if(loc != NULL)
  4636. {
  4637. while (loc[3+strlen("validFrom")+c] != '\"')
  4638. {
  4639. sstr[c] = loc[3+strlen("validFrom")+c];
  4640. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4641. c++;
  4642. }
  4643. sstr[c] = '\0';
  4644. DEBUG_INFO("validFrom=%s\n",sstr);
  4645. strcpy(tempvalidFromStr,sstr);
  4646. }
  4647. else
  4648. {
  4649. strcpy(tempvalidFromStr,"");
  4650. }
  4651. //**********startSchedule**********/
  4652. c = 0;
  4653. loc = strstr(sLineWord, "startSchedule");
  4654. //DEBUG_INFO("loc=%s\n",loc);
  4655. memset(sstr ,0, sizeof(sstr) );
  4656. while (loc[3+strlen("startSchedule")+c] != '\"')
  4657. {
  4658. sstr[c] = loc[3+strlen("startSchedule")+c];
  4659. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4660. c++;
  4661. }
  4662. sstr[c] = '\0';
  4663. strcpy(tempstartScheduleStr, sstr);
  4664. strcpy(TxDefaultProfileScheduleStr, sstr);
  4665. //**********chargingRateUnit**********/
  4666. c = 0;
  4667. loc = strstr(sLineWord, "chargingRateUnit");
  4668. memset(sstr ,0, sizeof(sstr) );
  4669. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4670. {
  4671. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4672. c++;
  4673. }
  4674. sstr[c] = '\0';
  4675. strcpy(tempchargingRateUnitStr, sstr);
  4676. //**********minChargingRate*******/
  4677. c = 0;
  4678. loc = strstr(sLineWord, "minChargingRate");
  4679. //printf("loc=%s\n",loc);
  4680. if(loc != NULL)
  4681. {
  4682. memset(sstr ,0, sizeof(sstr) );
  4683. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4684. {
  4685. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4686. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4687. c++;
  4688. }
  4689. sstr[c] = '\0';
  4690. tempminChargingRateFloat = atof(sstr);
  4691. }
  4692. else
  4693. {
  4694. tempminChargingRateFloat = 0.0;
  4695. }
  4696. #if 0
  4697. //
  4698. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4699. tp.tm_isdst = -1;
  4700. time_t utc = mktime(&tp);
  4701. // current time
  4702. time_t t = time(NULL);
  4703. //diff_t = difftime(t, utc);
  4704. #endif
  4705. //parsing strings to words
  4706. i = 0;
  4707. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4708. loc = loc+3+strlen("chargingSchedulePeriod");
  4709. pch = strtok(loc ,"{");
  4710. while (pch != NULL)
  4711. {
  4712. strcpy(SchedulePeriodList[i], pch);
  4713. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4714. //printf ("%s\n",pch);
  4715. pch = strtok (NULL, "{");
  4716. i = i + 1;
  4717. }
  4718. n_SchedulePeriods = i;
  4719. for(int i=0;i<n_SchedulePeriods;i++)
  4720. {
  4721. //*************startPeriod****************/
  4722. c = 0;
  4723. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4724. memset(sstr ,0, sizeof(sstr) );
  4725. while (loc[strlen("startPeriod")+2+c] != ',')
  4726. {
  4727. sstr[c] = loc[strlen("startPeriod")+2+c];
  4728. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4729. c++;
  4730. }
  4731. sstr[c] = '\0';
  4732. tempStartPeriodInt = atoi(sstr);
  4733. //*************limit****************/
  4734. c = 0;
  4735. loc = strstr(SchedulePeriodList[i], "limit");
  4736. memset(sstr ,0, sizeof(sstr) );
  4737. while (loc[strlen("limit")+2+c] != ',')
  4738. {
  4739. sstr[c] = loc[strlen("limit")+2+c];
  4740. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4741. c++;
  4742. }
  4743. sstr[c] = '\0';
  4744. tempLimitInt = atof(sstr);
  4745. //*************numberPhases****************/
  4746. c = 0;
  4747. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4748. memset(sstr ,0, sizeof(sstr) );
  4749. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4750. {
  4751. sstr[c] = loc[strlen("numberPhases")+2+c];
  4752. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4753. c++;
  4754. }
  4755. sstr[c] = '\0';
  4756. tempNumberPhasesInt = atoi(sstr);
  4757. TxDefaultProfile.Duration = durationInt;
  4758. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4759. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4760. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4761. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4762. }
  4763. if(MinChargingRate < tempminChargingRateFloat)
  4764. MinChargingRate = tempminChargingRateFloat;
  4765. }
  4766. }
  4767. }// the end of ACCESS TxDefaultProfile
  4768. //--------------------- Composite Schedule-----------------------------//
  4769. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4770. {
  4771. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4772. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4773. {
  4774. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4775. {
  4776. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4777. }
  4778. else
  4779. {
  4780. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4781. }
  4782. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4783. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4784. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4785. }
  4786. confirmPeriods = TxDefaultProfile.TotalPeriod;
  4787. }
  4788. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  4789. {
  4790. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4791. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4792. {
  4793. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4794. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4795. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4796. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4797. }
  4798. confirmPeriods = TxDefaultProfile.TotalPeriod;
  4799. }
  4800. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  4801. {
  4802. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  4803. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  4804. {
  4805. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  4806. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  4807. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  4808. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4809. }
  4810. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  4811. }
  4812. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  4813. {
  4814. confirmPeriods = 0;
  4815. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  4816. goto end;
  4817. }
  4818. //* Define temporary variables */
  4819. struct tm *gtime;
  4820. time_t now;
  4821. char buf[28];
  4822. /* Read the current system time */
  4823. time(&now);
  4824. /* Convert the system time to GMT (now UTC) */
  4825. gtime = gmtime(&now);
  4826. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4827. // make .conf
  4828. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4829. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  4830. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  4831. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4832. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4833. }
  4834. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4835. {
  4836. //*****************************ChargePointMaxProfile******************************************/
  4837. strcpy(fname, ChargePointMaxProfile_JSON);
  4838. ChargePointMaxProfileIsNull=TRUE;
  4839. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4840. {
  4841. fptr1 = fopen(fname, "r");
  4842. int c;
  4843. c = fgetc(fptr1);
  4844. //DEBUG_INFO("c:%d\n",c);
  4845. rewind(fptr1);
  4846. if(c == EOF)
  4847. {
  4848. DEBUG_INFO("\n End of file reached.");
  4849. ChargePointMaxProfileIsNull=TRUE;
  4850. fclose(fptr1);
  4851. }
  4852. else
  4853. {
  4854. ChargePointMaxProfileIsNull=FALSE;
  4855. while(fscanf(fptr1, "%s", word) != EOF)
  4856. {
  4857. if(strcmp(word, "chargingProfileId") == 0)
  4858. {
  4859. n_chargingProfile = n_chargingProfile + 1;
  4860. }
  4861. }
  4862. rewind(fptr1);
  4863. //search Charging Profile Element
  4864. int i = 0;
  4865. int j = 0;
  4866. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4867. #if 0
  4868. /***********connectorId****************/
  4869. c = 0;
  4870. loc = strstr(sLineWord, "connectorId");
  4871. memset(sstr ,0, sizeof(sstr) );
  4872. while (loc[strlen("connectorId")+2+c] != ',')
  4873. {
  4874. sstr[c] = loc[strlen("connectorId")+2+c];
  4875. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4876. c++;
  4877. }
  4878. sstr[c] = '\0';
  4879. tempconnectorIdInt = atoi(sstr);
  4880. #endif
  4881. //***********validFrom**************/
  4882. c = 0;
  4883. loc = strstr(sLineWord, "validFrom");
  4884. if(loc != NULL)
  4885. {
  4886. memset(sstr ,0, sizeof(sstr) );
  4887. while (loc[3+strlen("validFrom")+c] != '\"')
  4888. {
  4889. sstr[c] = loc[3+strlen("validFrom")+c];
  4890. c++;
  4891. }
  4892. sstr[c] = '\0';
  4893. strcpy(tempvalidFromStr,sstr);
  4894. }
  4895. else
  4896. {
  4897. strcpy(tempvalidFromStr,"");
  4898. }
  4899. //***********validFrom**************/
  4900. c = 0;
  4901. loc = strstr(sLineWord, "duration");
  4902. if(loc != NULL)
  4903. {
  4904. memset(sstr ,0, sizeof(sstr) );
  4905. while (loc[2+strlen("duration")+c] != ',')
  4906. {
  4907. sstr[c] = loc[2+strlen("duration")+c];
  4908. c++;
  4909. }
  4910. sstr[c] = '\0';
  4911. tempdurationInt = atoi(sstr);
  4912. }
  4913. else
  4914. {
  4915. tempdurationInt = 0;
  4916. }
  4917. //**********startSchedule**********/
  4918. c = 0;
  4919. loc = strstr(sLineWord, "startSchedule");
  4920. memset(sstr ,0, sizeof(sstr) );
  4921. while (loc[3+strlen("startSchedule")+c] != '\"')
  4922. {
  4923. sstr[c] = loc[3+strlen("startSchedule")+c];
  4924. c++;
  4925. }
  4926. sstr[c] = '\0';
  4927. strcpy(tempstartScheduleStr, sstr);
  4928. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4929. //**********chargingRateUnit**********/
  4930. c = 0;
  4931. loc = strstr(sLineWord, "chargingRateUnit");
  4932. memset(sstr ,0, sizeof(sstr) );
  4933. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4934. {
  4935. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4936. c++;
  4937. }
  4938. sstr[c] = '\0';
  4939. strcpy(tempchargingRateUnitStr, sstr);
  4940. //**********minChargingRate*******/
  4941. c = 0;
  4942. loc = strstr(sLineWord, "minChargingRate");
  4943. if(loc != NULL)
  4944. {
  4945. memset(sstr ,0, sizeof(sstr) );
  4946. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4947. {
  4948. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4949. c++;
  4950. }
  4951. sstr[c] = '\0';
  4952. tempminChargingRateFloat = atof(sstr);
  4953. }
  4954. else
  4955. {
  4956. tempminChargingRateFloat = 0.0;
  4957. }
  4958. #if 0
  4959. //
  4960. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4961. tp.tm_isdst = -1;
  4962. time_t utc = mktime(&tp);
  4963. time_t t = time(NULL);
  4964. //diff_t = difftime(t, utc);
  4965. #endif
  4966. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4967. //DEBUG_INFO(" debug 5 -1\n");
  4968. //parsing strings to words
  4969. i = 0;
  4970. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4971. loc = loc+3+strlen("chargingSchedulePeriod");
  4972. pch = strtok(loc ,"{");
  4973. while (pch != NULL)
  4974. {
  4975. strcpy(SchedulePeriodList[i], pch);
  4976. pch = strtok (NULL, "{");
  4977. i = i + 1;
  4978. }
  4979. n_SchedulePeriods = i;
  4980. for(int i=0;i<n_SchedulePeriods;i++)
  4981. {
  4982. //*************startPeriod****************/
  4983. c = 0;
  4984. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4985. memset(sstr ,0, sizeof(sstr) );
  4986. while (loc[strlen("startPeriod")+2+c] != ',')
  4987. {
  4988. sstr[c] = loc[strlen("startPeriod")+2+c];
  4989. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4990. c++;
  4991. }
  4992. sstr[c] = '\0';
  4993. tempStartPeriodInt = atoi(sstr);
  4994. //*************limit****************/
  4995. c = 0;
  4996. loc = strstr(SchedulePeriodList[i], "limit");
  4997. memset(sstr ,0, sizeof(sstr) );
  4998. while (loc[strlen("limit")+2+c] != ',')
  4999. {
  5000. sstr[c] = loc[strlen("limit")+2+c];
  5001. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5002. c++;
  5003. }
  5004. sstr[c] = '\0';
  5005. tempLimitInt = atof(sstr);
  5006. //*************numberPhases****************/
  5007. c = 0;
  5008. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5009. memset(sstr ,0, sizeof(sstr) );
  5010. while (loc[strlen("numberPhases")+2+c] != '}')
  5011. {
  5012. sstr[c] = loc[strlen("numberPhases")+2+c];
  5013. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5014. c++;
  5015. }
  5016. sstr[c] = '\0';
  5017. tempNumberPhasesInt = atoi(sstr);
  5018. if(j == 0)
  5019. {
  5020. ChargePointMaxProfile.Duration = tempdurationInt;
  5021. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5022. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5023. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5024. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5025. }
  5026. }
  5027. if(MinChargingRate < tempminChargingRateFloat)
  5028. {
  5029. MinChargingRate = tempminChargingRateFloat;
  5030. }
  5031. if(confirmPeriods < n_SchedulePeriods)
  5032. {
  5033. confirmPeriods = n_SchedulePeriods;
  5034. }
  5035. j = j + 1;
  5036. }
  5037. fclose(fptr1);
  5038. }
  5039. }// the end of access file ChargePointMaxProfile
  5040. //****************************TxDefaultProfile************************************************/
  5041. #if 0
  5042. switch(connectorIdInt)
  5043. {
  5044. case 0:
  5045. break;
  5046. case 1:
  5047. strcpy(fname, TxDefaultProfile_1_JSON );
  5048. break;
  5049. case 2:
  5050. strcpy(fname, TxDefaultProfile_2_JSON );
  5051. break;
  5052. default:
  5053. strcpy(fname, TxDefaultProfile_1_JSON );
  5054. break;
  5055. }
  5056. #endif
  5057. memset(fname, 0, sizeof fname);
  5058. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5059. TxDefaultProfileFileIsNull=TRUE;
  5060. if((access(fname,F_OK))!=-1)
  5061. {
  5062. fptr1 = fopen(fname, "r");
  5063. c = 0;
  5064. c = fgetc(fptr1);
  5065. //DEBUG_INFO("c:%d\n",c);
  5066. rewind(fptr1);
  5067. if(c == EOF)
  5068. {
  5069. DEBUG_INFO("\n End of file reached.");
  5070. TxDefaultProfileFileIsNull=TRUE;
  5071. fclose(fptr1);
  5072. }
  5073. else
  5074. {
  5075. TxDefaultProfileFileIsNull=FALSE;
  5076. while(fscanf(fptr1, "%s", word) != EOF)
  5077. {
  5078. if(strcmp(word, "chargingProfileId") == 0)
  5079. {
  5080. n_chargingProfile = n_chargingProfile + 1;
  5081. }
  5082. }
  5083. rewind(fptr1);
  5084. //search Charging Profile Element
  5085. int i = 0;
  5086. int j = 0;
  5087. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5088. //DEBUG_INFO(" 1-1\n");
  5089. #if 0
  5090. /***********connectorId****************/
  5091. c = 0;
  5092. loc = strstr(sLineWord, "connectorId");
  5093. memset(sstr ,0, sizeof(sstr) );
  5094. while (loc[strlen("connectorId")+2+c] != ',')
  5095. {
  5096. sstr[c] = loc[strlen("connectorId")+2+c];
  5097. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5098. c++;
  5099. }
  5100. sstr[c] = '\0';
  5101. tempconnectorIdInt = atoi(sstr);
  5102. #endif
  5103. //***********validFrom**************/
  5104. c = 0;
  5105. loc = strstr(sLineWord, "validFrom");
  5106. if(loc != NULL)
  5107. {
  5108. memset(sstr ,0, sizeof(sstr) );
  5109. while (loc[3+strlen("validFrom")+c] != '\"')
  5110. {
  5111. sstr[c] = loc[3+strlen("validFrom")+c];
  5112. c++;
  5113. }
  5114. sstr[c] = '\0';
  5115. strcpy(tempvalidFromStr,sstr);
  5116. }
  5117. else
  5118. {
  5119. strcpy(tempvalidFromStr,"");
  5120. }
  5121. //***********validFrom**************/
  5122. c = 0;
  5123. loc = strstr(sLineWord, "duration");
  5124. if(loc != NULL)
  5125. {
  5126. memset(sstr ,0, sizeof(sstr) );
  5127. while (loc[2+strlen("duration")+c] != ',')
  5128. {
  5129. sstr[c] = loc[2+strlen("duration")+c];
  5130. c++;
  5131. }
  5132. sstr[c] = '\0';
  5133. tempdurationInt = atoi(sstr);
  5134. }
  5135. else
  5136. {
  5137. tempdurationInt = 0;
  5138. }
  5139. //**********startSchedule**********/
  5140. c = 0;
  5141. loc = strstr(sLineWord, "startSchedule");
  5142. memset(sstr ,0, sizeof(sstr) );
  5143. while (loc[3+strlen("startSchedule")+c] != '\"')
  5144. {
  5145. sstr[c] = loc[3+strlen("startSchedule")+c];
  5146. c++;
  5147. }
  5148. sstr[c] = '\0';
  5149. strcpy(tempstartScheduleStr, sstr);
  5150. strcpy(TxDefaultProfileScheduleStr, sstr);
  5151. //**********chargingRateUnit**********/
  5152. c = 0;
  5153. loc = strstr(sLineWord, "chargingRateUnit");
  5154. memset(sstr ,0, sizeof(sstr) );
  5155. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5156. {
  5157. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5158. c++;
  5159. }
  5160. sstr[c] = '\0';
  5161. strcpy(tempchargingRateUnitStr, sstr);
  5162. //**********minChargingRate*******/
  5163. c = 0;
  5164. loc = strstr(sLineWord, "minChargingRate");
  5165. if(loc != NULL)
  5166. {
  5167. memset(sstr ,0, sizeof(sstr) );
  5168. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5169. {
  5170. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5171. c++;
  5172. }
  5173. sstr[c] = '\0';
  5174. tempminChargingRateFloat = atof(sstr);
  5175. }
  5176. else
  5177. {
  5178. tempminChargingRateFloat = 0.0;
  5179. }
  5180. #if 0
  5181. //
  5182. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5183. tp.tm_isdst = -1;
  5184. time_t utc = mktime(&tp);
  5185. time_t t = time(NULL);
  5186. //diff_t = difftime(t, utc);
  5187. #endif
  5188. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5189. //parsing strings to words
  5190. i = 0;
  5191. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5192. loc = loc+3+strlen("chargingSchedulePeriod");
  5193. pch = strtok(loc ,"{");
  5194. while (pch != NULL)
  5195. {
  5196. strcpy(SchedulePeriodList[i], pch);
  5197. pch = strtok (NULL, "{");
  5198. i = i + 1;
  5199. }
  5200. n_SchedulePeriods = i;
  5201. for(int i=0;i<n_SchedulePeriods;i++)
  5202. {
  5203. //*************startPeriod****************/
  5204. c = 0;
  5205. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5206. memset(sstr ,0, sizeof(sstr) );
  5207. while (loc[strlen("startPeriod")+2+c] != ',')
  5208. {
  5209. sstr[c] = loc[strlen("startPeriod")+2+c];
  5210. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5211. c++;
  5212. }
  5213. sstr[c] = '\0';
  5214. tempStartPeriodInt = atoi(sstr);
  5215. //*************limit****************/
  5216. c = 0;
  5217. loc = strstr(SchedulePeriodList[i], "limit");
  5218. memset(sstr ,0, sizeof(sstr) );
  5219. while (loc[strlen("limit")+2+c] != ',')
  5220. {
  5221. sstr[c] = loc[strlen("limit")+2+c];
  5222. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5223. c++;
  5224. }
  5225. sstr[c] = '\0';
  5226. tempLimitInt = atof(sstr);
  5227. //*************numberPhases****************/
  5228. c = 0;
  5229. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5230. memset(sstr ,0, sizeof(sstr) );
  5231. while (loc[strlen("numberPhases")+2+c] != '}')
  5232. {
  5233. sstr[c] = loc[strlen("numberPhases")+2+c];
  5234. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5235. c++;
  5236. }
  5237. sstr[c] = '\0';
  5238. tempNumberPhasesInt = atoi(sstr);
  5239. if(j == 0)
  5240. {
  5241. TxDefaultProfile.Duration = tempdurationInt;
  5242. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5243. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5244. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5245. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5246. }
  5247. else
  5248. {
  5249. //other stack level charging Profile
  5250. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5251. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5252. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5253. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5254. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5255. }
  5256. }
  5257. if(MinChargingRate < tempminChargingRateFloat)
  5258. MinChargingRate = tempminChargingRateFloat;
  5259. if(confirmPeriods < n_SchedulePeriods)
  5260. confirmPeriods = n_SchedulePeriods;
  5261. j = j + 1;
  5262. //DEBUG_INFO(" 1-2\n");
  5263. }
  5264. fclose(fptr1);
  5265. //Stacking Charging Profiles
  5266. for(int l=0; l <(j-1) ;l++)
  5267. {
  5268. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5269. {
  5270. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5271. {
  5272. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5273. {
  5274. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5275. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5276. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5277. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5278. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5279. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5280. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5281. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5282. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5283. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5284. }
  5285. else
  5286. {
  5287. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5288. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5289. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5290. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5291. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5292. }
  5293. }
  5294. }
  5295. }
  5296. //end of Stacking Charging Profiles
  5297. }
  5298. }// the end of ACCESS TxDefaultProfile
  5299. //****************************TxProfile************************************************/
  5300. #if 0
  5301. switch(connectorIdInt)
  5302. {
  5303. case 0:
  5304. break;
  5305. case 1:
  5306. strcpy(fname, TxProfile_1_JSON );
  5307. break;
  5308. case 2:
  5309. strcpy(fname, TxProfile_2_JSON );
  5310. break;
  5311. default:
  5312. strcpy(fname, TxProfile_1_JSON );
  5313. break;
  5314. }
  5315. #endif
  5316. memset(fname, 0, sizeof fname);
  5317. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5318. TxProfileIsNull=TRUE;
  5319. if((access(fname,F_OK))!=-1)
  5320. {
  5321. fptr1 = fopen(fname, "r");
  5322. c = 0;
  5323. c = fgetc(fptr1);
  5324. //DEBUG_INFO("c:%d\n",c);
  5325. rewind(fptr1);
  5326. if(c == EOF)
  5327. {
  5328. DEBUG_INFO("\n End of file reached.");
  5329. TxProfileIsNull=TRUE;
  5330. fclose(fptr1);
  5331. }
  5332. else
  5333. {
  5334. TxProfileIsNull=FALSE;
  5335. while(fscanf(fptr1, "%s", word) != EOF)
  5336. {
  5337. if(strcmp(word, "chargingProfileId") == 0)
  5338. {
  5339. n_chargingProfile = n_chargingProfile + 1;
  5340. }
  5341. }
  5342. rewind(fptr1);
  5343. //search Charging Profile Element
  5344. int i= 0;
  5345. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5346. #if 0
  5347. /***********connectorId****************/
  5348. c = 0;
  5349. loc = strstr(sLineWord, "connectorId");
  5350. memset(sstr ,0, sizeof(sstr) );
  5351. while (loc[strlen("connectorId")+2+c] != ',')
  5352. {
  5353. sstr[c] = loc[strlen("connectorId")+2+c];
  5354. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5355. c++;
  5356. }
  5357. sstr[c] = '\0';
  5358. tempconnectorIdInt = atoi(sstr);
  5359. #endif
  5360. //***********validFrom**************/
  5361. c = 0;
  5362. loc = strstr(sLineWord, "validFrom");
  5363. if(loc != NULL)
  5364. {
  5365. memset(sstr ,0, sizeof(sstr) );
  5366. while (loc[3+strlen("validFrom")+c] != '\"')
  5367. {
  5368. sstr[c] = loc[3+strlen("validFrom")+c];
  5369. c++;
  5370. }
  5371. sstr[c] = '\0';
  5372. strcpy(tempvalidFromStr,sstr);
  5373. }
  5374. else
  5375. {
  5376. strcpy(tempvalidFromStr,"");
  5377. }
  5378. //**********startSchedule**********/
  5379. c = 0;
  5380. loc = strstr(sLineWord, "startSchedule");
  5381. memset(sstr ,0, sizeof(sstr) );
  5382. while (loc[3+strlen("startSchedule")+c] != '\"')
  5383. {
  5384. sstr[c] = loc[3+strlen("startSchedule")+c];
  5385. c++;
  5386. }
  5387. sstr[c] = '\0';
  5388. strcpy(tempstartScheduleStr, sstr);
  5389. strcpy(TxProfileScheduleStr, sstr);
  5390. //**********chargingRateUnit**********/
  5391. c = 0;
  5392. loc = strstr(sLineWord, "chargingRateUnit");
  5393. memset(sstr ,0, sizeof(sstr) );
  5394. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5395. {
  5396. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5397. c++;
  5398. }
  5399. sstr[c] = '\0';
  5400. strcpy(tempchargingRateUnitStr, sstr);
  5401. //**********minChargingRate*******/
  5402. c = 0;
  5403. loc = strstr(sLineWord, "minChargingRate");
  5404. if(loc != NULL)
  5405. {
  5406. memset(sstr ,0, sizeof(sstr) );
  5407. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5408. {
  5409. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5410. c++;
  5411. }
  5412. sstr[c] = '\0';
  5413. tempminChargingRateFloat = atof(sstr);
  5414. }
  5415. else
  5416. {
  5417. tempminChargingRateFloat = 0.0;
  5418. }
  5419. #if 0
  5420. //
  5421. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5422. tp.tm_isdst = -1;
  5423. time_t utc = mktime(&tp);
  5424. time_t t = time(NULL);
  5425. //diff_t = difftime(t, utc);
  5426. #endif
  5427. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5428. //parsing strings to words
  5429. i = 0;
  5430. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5431. loc = loc+3+strlen("chargingSchedulePeriod");
  5432. pch = strtok(loc ,"{");
  5433. while (pch != NULL)
  5434. {
  5435. strcpy(SchedulePeriodList[i], pch);
  5436. pch = strtok (NULL, "{");
  5437. i = i + 1;
  5438. }
  5439. n_SchedulePeriods = i;
  5440. for(int i=0;i<n_SchedulePeriods;i++)
  5441. {
  5442. //*************startPeriod****************/
  5443. c = 0;
  5444. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5445. memset(sstr ,0, sizeof(sstr) );
  5446. while (loc[strlen("startPeriod")+2+c] != ',')
  5447. {
  5448. sstr[c] = loc[strlen("startPeriod")+2+c];
  5449. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5450. c++;
  5451. }
  5452. sstr[c] = '\0';
  5453. tempStartPeriodInt = atoi(sstr);
  5454. //*************limit****************/
  5455. c = 0;
  5456. loc = strstr(SchedulePeriodList[i], "limit");
  5457. memset(sstr ,0, sizeof(sstr) );
  5458. while (loc[strlen("limit")+2+c] != ',')
  5459. {
  5460. sstr[c] = loc[strlen("limit")+2+c];
  5461. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5462. c++;
  5463. }
  5464. sstr[c] = '\0';
  5465. tempLimitInt = atof(sstr);
  5466. //*************numberPhases****************/
  5467. c = 0;
  5468. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5469. memset(sstr ,0, sizeof(sstr) );
  5470. while (loc[strlen("numberPhases")+2+c] != '}')
  5471. {
  5472. sstr[c] = loc[strlen("numberPhases")+2+c];
  5473. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5474. c++;
  5475. }
  5476. sstr[c] = '\0';
  5477. tempNumberPhasesInt = atoi(sstr);
  5478. TxProfile.Duration = durationInt;
  5479. TxProfile.TotalPeriod = n_SchedulePeriods;
  5480. TxProfile.Period[i].Limit = tempLimitInt;
  5481. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5482. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5483. }
  5484. if(MinChargingRate < tempminChargingRateFloat)
  5485. MinChargingRate = tempminChargingRateFloat;
  5486. if(confirmPeriods < n_SchedulePeriods)
  5487. confirmPeriods = n_SchedulePeriods;
  5488. }
  5489. fclose(fptr1);
  5490. }
  5491. }// the end of ACCESS TxProfile
  5492. //CompositeSchedule
  5493. int period=0;
  5494. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5495. {
  5496. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5497. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5498. {
  5499. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5500. {
  5501. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5502. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5503. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5504. period = period + 1;
  5505. }
  5506. else
  5507. {
  5508. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5509. {
  5510. }
  5511. else
  5512. {
  5513. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5514. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5515. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5516. period = period + 1;
  5517. }
  5518. }
  5519. }
  5520. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5521. {
  5522. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5523. {
  5524. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5525. {
  5526. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5527. }
  5528. else
  5529. {
  5530. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5531. }
  5532. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5533. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5534. period = period + 1;
  5535. }
  5536. }
  5537. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5538. {
  5539. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5540. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5541. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5542. period = period + 1;
  5543. }
  5544. }
  5545. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5546. {
  5547. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5548. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5549. {
  5550. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5551. {
  5552. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5553. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5554. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5555. period = period + 1;
  5556. }
  5557. else
  5558. {
  5559. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5560. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5561. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5562. period = period + 1;
  5563. }
  5564. }
  5565. }
  5566. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5567. {
  5568. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5569. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5570. {
  5571. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5572. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5573. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5574. period = period + 1;
  5575. }
  5576. }
  5577. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  5578. {
  5579. confirmPeriods = 0;
  5580. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5581. goto end;
  5582. }
  5583. confirmPeriods = period;
  5584. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5585. //* Define temporary variables */
  5586. struct tm *gtime;
  5587. time_t now;
  5588. char buf[28];
  5589. //* Read the current system time */
  5590. time(&now);
  5591. //* Convert the system time to GMT (now UTC) */
  5592. gtime = gmtime(&now);
  5593. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5594. // make .conf
  5595. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5596. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5597. //DEBUG_INFO(" debug 11\n");
  5598. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5599. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5600. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5601. }
  5602. else
  5603. {
  5604. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5605. }
  5606. end:
  5607. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5608. return result;
  5609. }
  5610. int handleGetConfigurationRequest(char *uuid, char *payload)
  5611. {
  5612. mtrace();
  5613. int result = FAIL;
  5614. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5615. //struct json_object *jsonitem;
  5616. int MaxKeySupported = 0;
  5617. int n_keys = 0;
  5618. char requestKey[43][50]={0};
  5619. char search[]="[";
  5620. char sstr[500]={ 0 };
  5621. //int pos;
  5622. int l, c = 0;
  5623. int i = 0;
  5624. char *delim = "\",\"";
  5625. char * pch;
  5626. char *loc = strstr(payload, search);
  5627. //********************* Parsing String ***********************************/
  5628. if(loc == NULL) {
  5629. DEBUG_INFO("no key match in Configuration \n");
  5630. }
  5631. else {
  5632. //pos = loc - payload;
  5633. l = strlen(loc)-4;
  5634. while (c < l)
  5635. {
  5636. sstr[c] = loc[c+2];
  5637. c++;
  5638. }
  5639. sstr[c] = '\0';
  5640. //parsing strings to words
  5641. pch = strtok(sstr,delim);
  5642. if(pch == NULL)
  5643. {
  5644. strcpy(requestKey[0], sstr);
  5645. }
  5646. else
  5647. {
  5648. while (pch != NULL)
  5649. {
  5650. strcpy(requestKey[i], pch);
  5651. pch = strtok (NULL, delim);
  5652. i = i + 1;
  5653. }
  5654. n_keys = i;
  5655. }
  5656. }
  5657. UnknownKeynum = 0;
  5658. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5659. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5660. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5661. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5662. if(n_keys != 0)
  5663. {
  5664. for(int i=0;i<n_keys;i++)
  5665. {
  5666. getKeyValue(requestKey[i]);
  5667. //json_object_put(jsonitem);
  5668. }
  5669. }
  5670. else
  5671. {
  5672. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5673. getKeyValue("");
  5674. }
  5675. processUnkownKey();
  5676. sendGetConfigurationConfirmation(uuid);
  5677. return result;
  5678. }
  5679. static char fnamePlusPath[100]={0};
  5680. static char fnamePWithNoPath[60]={0};
  5681. void checkUploadLog(void)
  5682. {
  5683. FILE *fp;
  5684. /* Open the command for reading. */
  5685. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5686. if (fp == NULL) {
  5687. printf("Failed to run command\n" );
  5688. exit(1);
  5689. }
  5690. int ftppathlen = 0;
  5691. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5692. int i = 0;
  5693. /* Read the output a line at a time - output it. */
  5694. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5695. if(i==0)
  5696. {
  5697. ftppathlen = strlen(fnamePlusPath);
  5698. printf("%s\n", fnamePlusPath);
  5699. fnamePlusPath[ftppathlen]='\0';
  5700. break;
  5701. }
  5702. i= i+1;
  5703. }
  5704. /* close */
  5705. pclose(fp);
  5706. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5707. {
  5708. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5709. {
  5710. fnamePlusPath[k]='\0';
  5711. }
  5712. }
  5713. i=1;
  5714. //char fname[60]={0};
  5715. while(i < ftppathlen)
  5716. {
  5717. int len=ftppathlen-i;
  5718. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5719. {
  5720. printf("compare '/' all right\n");
  5721. break;
  5722. }
  5723. i=i+1;
  5724. }
  5725. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5726. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5727. fnamePWithNoPath[i+1] = '\0';
  5728. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5729. {
  5730. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5731. {
  5732. fnamePWithNoPath[j]='\0';
  5733. }
  5734. }
  5735. FILE* fp1 = fopen(fnamePlusPath, "r");
  5736. if (fp1)
  5737. {
  5738. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5739. // file exists
  5740. fclose(fp1);
  5741. }
  5742. else
  5743. {
  5744. // file doesn't exist
  5745. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5746. }
  5747. }
  5748. static char GetDiagnosticspayloadData[300]={0};
  5749. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5750. {
  5751. mtrace();
  5752. int result = FAIL;
  5753. pthread_t t; // pthread 變數
  5754. system("exec /root/logPackTools 'log' 6");
  5755. #if 0
  5756. //char buffer [128];
  5757. time (&rawtime);
  5758. //printf("%ld\n", rawtime);
  5759. timeinfo = localtime (&rawtime);
  5760. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5761. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5762. if((access(fnamePlusPath,F_OK))!=-1)
  5763. {
  5764. DEBUG_INFO("fnamePlusPath exist.\n");
  5765. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5766. }
  5767. else
  5768. {
  5769. DEBUG_INFO("fnamePlusPath not exist!\n");
  5770. }
  5771. #endif
  5772. checkUploadLog();
  5773. memset(GetDiagnosticspayloadData, 0, 300);
  5774. strcpy(GetDiagnosticspayloadData, payload);
  5775. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5776. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5777. return result;
  5778. }
  5779. void* GetDiagnosticsProcess(void* data)
  5780. {
  5781. pthread_detach(pthread_self());
  5782. mtrace();
  5783. int retriesInt=0, retryIntervalInt=0;
  5784. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5785. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5786. 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};
  5787. int port=0;
  5788. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5789. int c = 0;
  5790. char *loc;
  5791. int isSuccess = FALSE;
  5792. char ftpbuf[200]={0};
  5793. //char temp[100]={0};
  5794. char * pch;
  5795. // [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"}]
  5796. char str[300]={ 0 };
  5797. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5798. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5799. DEBUG_INFO("GetDiagnosticsProcess\n");
  5800. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5801. //****************location*******************/
  5802. c = 0;
  5803. memset(sstr ,0, sizeof(sstr) );
  5804. loc = strstr(str, "location");
  5805. while (loc[3+strlen("location")+c] != '\"')
  5806. {
  5807. sstr[c] = loc[3+strlen("location")+c];
  5808. c++;
  5809. }
  5810. sstr[c] = '\0';
  5811. strcpy(locationstr,sstr);
  5812. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5813. if(strcmp(locationstr,"")==0)
  5814. {
  5815. DEBUG_INFO("location is <Empty>!\n");
  5816. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5817. goto end;
  5818. }
  5819. //****************retries*******************/
  5820. c = 0;
  5821. loc = strstr(str, "retries");
  5822. if(loc == NULL)
  5823. {
  5824. retriesIsNULL = TRUE;
  5825. }
  5826. else
  5827. {
  5828. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5829. {
  5830. sstr[c] = loc[strlen("retries")+2+c];
  5831. c++;
  5832. }
  5833. sstr[c] = '\0';
  5834. retriesInt = atoi(sstr);
  5835. }
  5836. if(retriesIsNULL == TRUE)
  5837. {
  5838. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5839. }
  5840. //****************retryInterval*******************/
  5841. c = 0;
  5842. loc = strstr(str, "retryInterval");
  5843. if(loc == NULL)
  5844. {
  5845. retryIntervalIsNULL = TRUE;
  5846. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5847. }
  5848. else
  5849. {
  5850. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5851. {
  5852. sstr[c] = loc[strlen("retryInterval")+2+c];
  5853. c++;
  5854. }
  5855. sstr[c] = '\0';
  5856. retryIntervalInt = atoi(sstr);
  5857. }
  5858. //****************startTime*******************/
  5859. c = 0;
  5860. memset(sstr ,0, sizeof(sstr) );
  5861. loc = strstr(str, "startTime");
  5862. if(loc == NULL)
  5863. {
  5864. startTimeIsNULL = TRUE;
  5865. }
  5866. else
  5867. {
  5868. while (loc[3+strlen("startTime")+c] != '\"')
  5869. {
  5870. sstr[c] = loc[3+strlen("startTime")+c];
  5871. c++;
  5872. }
  5873. sstr[c] = '\0';
  5874. strcpy(startTimestr,sstr);
  5875. }
  5876. //****************stopTime*******************/
  5877. c = 0;
  5878. memset(sstr ,0, sizeof(sstr) );
  5879. loc = strstr(str, "stopTime");
  5880. if(loc == NULL)
  5881. {
  5882. stopTimeIsNULL = TRUE;
  5883. }
  5884. else
  5885. {
  5886. while (loc[3+strlen("stopTime")+c] != '\"')
  5887. {
  5888. sstr[c] = loc[3+strlen("stopTime")+c];
  5889. c++;
  5890. }
  5891. sstr[c] = '\0';
  5892. strcpy(stopTimestr,sstr);
  5893. }
  5894. memset(protocol, 0, sizeof(protocol));
  5895. memset(user, 0, sizeof(user) );
  5896. memset(password, 0, sizeof(password));
  5897. memset(host, 0, sizeof(host));
  5898. memset(path, 0, sizeof(path));
  5899. memset(ftppath, 0, sizeof(ftppath));
  5900. memset(host1, 0, sizeof(host1));
  5901. memset(path1, 0, sizeof(path1));
  5902. /*location: ftp://user:password@host:port/path*/
  5903. #if 0
  5904. time_t rawtime;
  5905. struct tm * timeinfo;
  5906. //char buffer [128];
  5907. time (&rawtime);
  5908. //printf("%ld\n", rawtime);
  5909. timeinfo = localtime (&rawtime);
  5910. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5911. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5912. #endif
  5913. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5914. if((access(fnamePlusPath,F_OK))!=-1)
  5915. {
  5916. DEBUG_INFO("fnamePlusPath exist.\n");
  5917. }
  5918. else
  5919. {
  5920. DEBUG_INFO("fnamePlusPath not exist!\n");
  5921. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5922. goto end;
  5923. }
  5924. pch=strchr(locationstr,'@');
  5925. if(pch==NULL)
  5926. {
  5927. sscanf(locationstr,
  5928. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5929. protocol, host, &port, path);
  5930. strcpy(user,"anonymous");
  5931. strcpy(password,"");
  5932. }
  5933. else
  5934. {
  5935. //DEBUG_INFO("pch=%s\n", pch);
  5936. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5937. protocol, user, password, host, &port, path);
  5938. }
  5939. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5940. {
  5941. DEBUG_INFO("protocol is not ftp/http ! \n");
  5942. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5943. goto end;
  5944. }
  5945. if(strncmp(locationstr,"http", 4) == 0)
  5946. {
  5947. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  5948. sprintf(ftppath,"/%s", path);
  5949. do{
  5950. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5951. sleep(retryIntervalInt);
  5952. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5953. if(!isSuccess)
  5954. {
  5955. DEBUG_INFO("Diagnostics fail.\n");
  5956. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5957. }
  5958. else
  5959. {
  5960. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5961. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5962. }
  5963. }
  5964. else
  5965. {
  5966. sscanf(host,"%[^/]%s",host1, path1);
  5967. sprintf(ftppath,"%s", path1);
  5968. int ftppathlen=strlen(ftppath);
  5969. int i=1;
  5970. char filenametemp[50];
  5971. while(i < ftppathlen)
  5972. {
  5973. int len=ftppathlen-i;
  5974. if(ftppath[len]== 47) // '/' ascll code: 47
  5975. {
  5976. DEBUG_INFO("find '/' all right\n");
  5977. break;
  5978. }
  5979. i=i+1;
  5980. }
  5981. memset(filenametemp, 0, sizeof(filenametemp));
  5982. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5983. filenametemp[i+1] = 0;
  5984. memset(ftpbuf, 0, sizeof(ftpbuf));
  5985. if(port == 0)
  5986. port = 21;
  5987. do{
  5988. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  5989. sleep(retryIntervalInt);
  5990. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5991. if(!isSuccess)
  5992. {
  5993. DEBUG_INFO("Diagnostics fail.\n");
  5994. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5995. }
  5996. else
  5997. {
  5998. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5999. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6000. }
  6001. }
  6002. end:
  6003. DiagnosticsStatusNotificationStatus = 0; //Idle
  6004. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6005. }
  6006. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6007. {
  6008. mtrace();
  6009. int result = FAIL;
  6010. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6011. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6012. {
  6013. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6014. localversion = -1;
  6015. }
  6016. else
  6017. {
  6018. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6019. OCPP_getListVerion();
  6020. }
  6021. //from db.OCPP_getListVerion
  6022. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6023. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6024. sendGetLocalListVersionConfirmation(uuid,"");
  6025. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6026. return result;
  6027. }
  6028. int handleRemoteStartRequest(char *uuid, char *payload)
  6029. {
  6030. mtrace();
  6031. int result = FAIL;
  6032. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6033. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6034. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6035. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6036. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6037. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6038. int chargingSchedulePeriodCount = 0;
  6039. char sstr[30]={ 0 };//sstr[200]={ 0 };
  6040. int c = 0;
  6041. char *loc;
  6042. char comfirmstr[20]={0};
  6043. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6044. if(server_pending == TRUE)
  6045. {
  6046. return 0;
  6047. }
  6048. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6049. //**********connectorId****************/
  6050. c = 0;
  6051. memset(sstr ,0, sizeof(sstr) );
  6052. loc = strstr(payload, "connectorId");
  6053. if(loc == NULL)
  6054. {
  6055. connectorIdIsNULL = TRUE;
  6056. }
  6057. else
  6058. {
  6059. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6060. {
  6061. sstr[c] = loc[strlen("connectorId")+2+c];
  6062. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6063. c++;
  6064. }
  6065. sstr[c] = '\0';
  6066. connectorIdInt = atoi(sstr);
  6067. }
  6068. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6069. {
  6070. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6071. goto end;
  6072. }
  6073. //****************idTag*******************/
  6074. c = 0;
  6075. memset(sstr ,0, sizeof(sstr) );
  6076. loc = strstr(payload, "idTag");
  6077. while (loc[3+strlen("idTag")+c] != '\"')
  6078. {
  6079. sstr[c] = loc[3+strlen("idTag")+c];
  6080. c++;
  6081. }
  6082. sstr[c] = '\0';
  6083. strcpy(idTagstr,sstr);
  6084. //****************chargingProfile*******************/
  6085. c = 0;
  6086. memset(sstr ,0, sizeof(sstr) );
  6087. loc = strstr(payload, "chargingProfile");
  6088. if(loc == NULL)
  6089. {
  6090. chargingProfileIsNULL = TRUE;
  6091. }
  6092. else
  6093. {
  6094. //****************chargingProfileId*******************/
  6095. c=0;
  6096. loc = strstr(payload, "chargingProfileId");
  6097. memset(sstr ,0, sizeof(sstr) );
  6098. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6099. {
  6100. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6101. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6102. c++;
  6103. }
  6104. sstr[c] = '\0';
  6105. chargingProfileIdInt = atoi(sstr);
  6106. //****************transactionId*******************/
  6107. loc = strstr(payload, "transactionId");
  6108. if(loc == NULL)
  6109. {
  6110. transactionIdIsNULL = TRUE;
  6111. }
  6112. else
  6113. {
  6114. c=0;
  6115. memset(sstr ,0, sizeof(sstr) );
  6116. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6117. {
  6118. sstr[c] = loc[strlen("transactionId")+2+c];
  6119. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6120. c++;
  6121. }
  6122. sstr[c] = '\0';
  6123. transactionIdInt = atoi(sstr);
  6124. }
  6125. //****************stackLevel*******************/
  6126. c=0;
  6127. loc = strstr(payload, "stackLevel");
  6128. memset(sstr ,0, sizeof(sstr) );
  6129. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6130. {
  6131. sstr[c] = loc[strlen("stackLevel")+2+c];
  6132. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6133. c++;
  6134. }
  6135. sstr[c] = '\0';
  6136. stackLevelInt = atoi(sstr);
  6137. //****************chargingProfilePurpose*******************/
  6138. c = 0;
  6139. memset(sstr ,0, sizeof(sstr) );
  6140. loc = strstr(payload, "chargingProfilePurpose");
  6141. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6142. {
  6143. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6144. c++;
  6145. }
  6146. sstr[c] = '\0';
  6147. strcpy(chargingProfilePurposestr,sstr);
  6148. //****************chargingProfileKind*******************/
  6149. c = 0;
  6150. memset(sstr ,0, sizeof(sstr) );
  6151. loc = strstr(payload, "chargingProfileKind");
  6152. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6153. {
  6154. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6155. c++;
  6156. }
  6157. sstr[c] = '\0';
  6158. strcpy(chargingProfileKindstr,sstr);
  6159. //****************recurrencyKind*******************/
  6160. loc = strstr(payload, "recurrencyKind");
  6161. if(loc == NULL)
  6162. {
  6163. recurrencyKindIsNULL = TRUE;
  6164. }
  6165. else
  6166. {
  6167. c = 0;
  6168. memset(sstr ,0, sizeof(sstr) );
  6169. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6170. {
  6171. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6172. c++;
  6173. }
  6174. sstr[c] = '\0';
  6175. strcpy(recurrencyKindstr,sstr);
  6176. }
  6177. //****************validFrom*******************/
  6178. loc = strstr(payload, "validFrom");
  6179. if(loc == NULL)
  6180. {
  6181. validFromIsNULL = TRUE;
  6182. }
  6183. else
  6184. {
  6185. c = 0;
  6186. memset(sstr ,0, sizeof(sstr) );
  6187. while (loc[3+strlen("validFrom")+c] != '\"')
  6188. {
  6189. sstr[c] = loc[3+strlen("validFrom")+c];
  6190. c++;
  6191. }
  6192. sstr[c] = '\0';
  6193. strcpy(validFromstr,sstr);
  6194. }
  6195. //****************validTo*******************/
  6196. loc = strstr(payload, "validTo");
  6197. if(loc == NULL)
  6198. {
  6199. validToIsNULL = TRUE;
  6200. }
  6201. else
  6202. {
  6203. c = 0;
  6204. memset(sstr ,0, sizeof(sstr) );
  6205. while (loc[3+strlen("validTo")+c] != '\"')
  6206. {
  6207. sstr[c] = loc[3+strlen("validTo")+c];
  6208. c++;
  6209. }
  6210. sstr[c] = '\0';
  6211. strcpy(validTostr,sstr);
  6212. }
  6213. //****************chargingSchedule*******************/
  6214. loc = strstr(payload, "chargingSchedule");
  6215. if(loc != NULL)
  6216. {
  6217. //****************duration*******************/
  6218. loc = strstr(payload, "duration");
  6219. if(loc == NULL)
  6220. {
  6221. durationIsNULL = TRUE;
  6222. }
  6223. else
  6224. {
  6225. c=0;
  6226. memset(sstr ,0, sizeof(sstr) );
  6227. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6228. {
  6229. sstr[c] = loc[strlen("duration")+2+c];
  6230. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6231. c++;
  6232. }
  6233. sstr[c] = '\0';
  6234. durationInt = atoi(sstr);
  6235. }
  6236. //****************startSchedule******************/
  6237. loc = strstr(payload, "startSchedule");
  6238. if(loc == NULL)
  6239. {
  6240. startScheduleIsNULL = TRUE;
  6241. }
  6242. else
  6243. {
  6244. c = 0;
  6245. memset(sstr ,0, sizeof(sstr) );
  6246. while (loc[3+strlen("startSchedule")+c] != '\"')
  6247. {
  6248. sstr[c] = loc[3+strlen("startSchedule")+c];
  6249. c++;
  6250. }
  6251. sstr[c] = '\0';
  6252. strcpy(startSchedulestr,sstr);
  6253. }
  6254. //****************chargingRateUnit*******************/
  6255. c = 0;
  6256. memset(sstr ,0, sizeof(sstr) );
  6257. loc = strstr(payload, "chargingRateUnit");
  6258. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6259. {
  6260. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6261. c++;
  6262. }
  6263. sstr[c] = '\0';
  6264. strcpy(chargingRateUnitstr,sstr);
  6265. //****************minChargingRate*******************/
  6266. loc = strstr(payload, "minChargingRate");
  6267. if(loc == NULL)
  6268. {
  6269. minChargingRateIsNULL = TRUE;
  6270. }
  6271. else
  6272. {
  6273. c=0;
  6274. memset(sstr ,0, sizeof(sstr) );
  6275. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6276. {
  6277. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6278. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6279. c++;
  6280. }
  6281. sstr[c] = '\0';
  6282. minChargingRateflaot = atof(sstr);
  6283. }
  6284. //****************chargingSchedulePeriod count*******************/
  6285. int what_len = strlen("startPeriod");
  6286. char *where = payload;
  6287. while ((where = strstr(where, "startPeriod"))) {
  6288. where += what_len;
  6289. chargingSchedulePeriodCount++;
  6290. }
  6291. where = payload;
  6292. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6293. {
  6294. //****************startPeriod*******************/
  6295. c=0;
  6296. loc = strstr(where, "startPeriod");
  6297. memset(sstr ,0, sizeof(sstr) );
  6298. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6299. {
  6300. sstr[c] = loc[strlen("startPeriod")+2+c];
  6301. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6302. c++;
  6303. }
  6304. sstr[c] = '\0';
  6305. startPeriodInt[periodNums] = atoi(sstr);
  6306. //****************limit*******************/
  6307. c=0;
  6308. loc = strstr(where, "limit");
  6309. memset(sstr ,0, sizeof(sstr) );
  6310. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6311. {
  6312. sstr[c] = loc[strlen("limit")+2+c];
  6313. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6314. c++;
  6315. }
  6316. sstr[c] = '\0';
  6317. limitflaot[periodNums] = atof(sstr);
  6318. //****************numberPhases*******************/
  6319. loc = strstr(where, "numberPhases");
  6320. if(loc == NULL)
  6321. {
  6322. numberPhasesIsNULL = TRUE;
  6323. }
  6324. else
  6325. {
  6326. c=0;
  6327. memset(sstr ,0, sizeof(sstr) );
  6328. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6329. {
  6330. sstr[c] = loc[strlen("numberPhases")+2+c];
  6331. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6332. c++;
  6333. }
  6334. sstr[c] = '\0';
  6335. numberPhasesInt[periodNums] = atoi(sstr);
  6336. }
  6337. where = loc;
  6338. }
  6339. }
  6340. }
  6341. /*
  6342. enum _SYSTEM_STATUS
  6343. {
  6344. S_BOOTING = 0,
  6345. S_IDLE, = 1
  6346. S_AUTHORIZING, =2
  6347. S_REASSIGN_CHECK, =3
  6348. S_REASSIGN, =4
  6349. S_PRECHARGE, =5
  6350. S_PREPARING_FOR_EV, =6
  6351. S_PREPARING_FOR_EVSE, =7
  6352. S_CHARGING, =8
  6353. S_TERMINATING, =9
  6354. S_COMPLETE, =10
  6355. S_ALARM, =11
  6356. S_FAULT =12
  6357. }
  6358. */
  6359. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6360. {
  6361. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6362. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6363. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6364. //check Transaction active
  6365. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6366. {
  6367. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6368. {
  6369. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6370. {
  6371. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6372. {
  6373. //Reserved
  6374. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6375. }
  6376. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6377. {
  6378. //Reserved
  6379. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6380. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6381. goto end;
  6382. }
  6383. else
  6384. {
  6385. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6386. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6387. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6388. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6389. {
  6390. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6391. goto end;
  6392. }
  6393. }//END FOR ELSE
  6394. }
  6395. }// END FOR CHAdeMO_QUANTITY
  6396. for (int index = 0; index < CCS_QUANTITY; index++)
  6397. {
  6398. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6399. {
  6400. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6401. {
  6402. //Reserved
  6403. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6404. }
  6405. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6406. {
  6407. //Reserved
  6408. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6409. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6410. goto end;
  6411. }
  6412. else
  6413. {
  6414. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6415. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6416. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6417. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6418. {
  6419. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6420. goto end;
  6421. }
  6422. }// END FOR ELSE
  6423. }
  6424. }// END FOR CCS_QUANTITY
  6425. for (int index = 0; index < GB_QUANTITY; index++)
  6426. {
  6427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6428. {
  6429. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6430. {
  6431. //Reserved
  6432. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6433. }
  6434. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6435. {
  6436. //Reserved
  6437. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6438. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6439. goto end;
  6440. }
  6441. else
  6442. {
  6443. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6444. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6445. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6446. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6447. {
  6448. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6449. goto end;
  6450. }
  6451. }// END FOR ELSE
  6452. }
  6453. } // END FOR GB_QUANTITY
  6454. }
  6455. else
  6456. {
  6457. for (int index = 0; index < AC_QUANTITY; index++)
  6458. {
  6459. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6460. {
  6461. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6462. {
  6463. //Reserved
  6464. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6465. }
  6466. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6467. {
  6468. //Reserved
  6469. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6470. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6471. goto end;
  6472. }
  6473. else
  6474. {
  6475. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6476. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6477. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6478. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6479. {
  6480. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6481. goto end;
  6482. }
  6483. }//END FOR ELSE
  6484. }
  6485. }// END FOR AC_QUANTITY
  6486. }
  6487. if(chargingProfileIsNULL == FALSE)
  6488. {
  6489. //ChargingProfile
  6490. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6491. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6492. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6493. if(recurrencyKindIsNULL == FALSE) //OPTION
  6494. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6495. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6496. if(transactionIdIsNULL == FALSE) // OPTION
  6497. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6498. if(validFromIsNULL == FALSE) // OPTION
  6499. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6500. if(validToIsNULL == FALSE) //OPTION
  6501. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6502. //ChargingSchedule
  6503. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6504. if(durationIsNULL == FALSE) //OPTION
  6505. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6506. if(minChargingRateIsNULL == FALSE) //OPTION
  6507. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6508. if(startScheduleIsNULL == FALSE) //OPTION
  6509. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6510. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6511. {
  6512. //ChargingSchedulePeriod
  6513. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6514. if(numberPhasesIsNULL == FALSE)
  6515. {
  6516. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6517. }
  6518. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6519. }
  6520. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6521. {
  6522. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6523. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6524. //memset idTag
  6525. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6526. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6527. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6528. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6529. }
  6530. else
  6531. {
  6532. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6533. }
  6534. }
  6535. else
  6536. {
  6537. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6538. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6539. //memset idTag
  6540. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6541. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6542. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6543. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6544. }
  6545. }
  6546. else
  6547. {
  6548. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6549. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6550. }
  6551. end:
  6552. if(connectorIdIsNULL == FALSE)
  6553. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6554. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6555. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6556. //OCPP send RemoteStartConfirmation by first.
  6557. sendRemoteStartConfirmation(uuid, comfirmstr);
  6558. return result;
  6559. }
  6560. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6561. {
  6562. mtrace();
  6563. int result = FAIL;
  6564. int match = FALSE;
  6565. int GunNO = 0;
  6566. int transactionIdInt=0;
  6567. int transactionIdIsNULL= FALSE;
  6568. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6569. int c = 0;
  6570. char *loc;
  6571. char comfirmstr[20];
  6572. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6573. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6574. if(server_pending == TRUE)
  6575. {
  6576. return 0;
  6577. }
  6578. c=0;
  6579. loc = strstr(payload, "transactionId");
  6580. if(loc == NULL)
  6581. {
  6582. transactionIdIsNULL= TRUE;
  6583. }
  6584. else
  6585. {
  6586. memset(sstr ,0, sizeof(sstr) );
  6587. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6588. {
  6589. sstr[c] = loc[strlen("transactionId")+2+c];
  6590. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6591. c++;
  6592. }
  6593. sstr[c] = '\0';
  6594. transactionIdInt = atoi(sstr);
  6595. }
  6596. if(transactionIdIsNULL == FALSE)
  6597. {
  6598. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6599. {
  6600. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6601. {
  6602. //check Transaction active
  6603. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6604. {
  6605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6606. {
  6607. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6608. {
  6609. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6610. {
  6611. match = TRUE;
  6612. GunNO = gun_index;
  6613. }
  6614. }
  6615. }// END FOR CHAdeMO_QUANTITY
  6616. for (int index = 0; index < CCS_QUANTITY; index++)
  6617. {
  6618. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6619. {
  6620. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6621. {
  6622. match = TRUE;
  6623. GunNO = gun_index;
  6624. }
  6625. }
  6626. }// END FOR CCS_QUANTITY
  6627. for (int index = 0; index < GB_QUANTITY; index++)
  6628. {
  6629. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6630. {
  6631. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6632. {
  6633. match = TRUE;
  6634. GunNO = gun_index;
  6635. }
  6636. }
  6637. }// END FOR GB_QUANTITY
  6638. }
  6639. else
  6640. {
  6641. for (int index = 0; index < AC_QUANTITY; index++)
  6642. {
  6643. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6644. {
  6645. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6646. {
  6647. match = TRUE;
  6648. GunNO = gun_index;
  6649. }
  6650. }
  6651. }// END FOR CHAdeMO_QUANTITY
  6652. }// END FOR AC ELSE
  6653. }// CHECK IF ResponseTransactionId == transactionIdInt
  6654. }//END FOR
  6655. if( match == TRUE)
  6656. {
  6657. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6658. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6659. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6660. }
  6661. else
  6662. {
  6663. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6664. }
  6665. }
  6666. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6667. return result;
  6668. }
  6669. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6670. {
  6671. mtrace();
  6672. int result = FAIL;
  6673. int connectorIdInt=0, reservationIdInt=0;
  6674. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6675. char comfirmstr[20]={0};
  6676. char sstr[180]={ 0 };
  6677. int c = 0;
  6678. char *loc;
  6679. //char *ptr;
  6680. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6681. //***(1)connectorId ****/
  6682. c=0;
  6683. loc = strstr(payload, "connectorId");
  6684. memset(sstr ,0, sizeof(sstr) );
  6685. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6686. {
  6687. sstr[c] = loc[strlen("connectorId")+2+c];
  6688. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6689. c++;
  6690. }
  6691. sstr[c] = '\0';
  6692. connectorIdInt = atoi(sstr);
  6693. //***(2)expiryDate ****/
  6694. loc = strstr(payload, "expiryDate");
  6695. memset(sstr ,0, sizeof(sstr) );
  6696. c = 0;
  6697. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6698. {
  6699. sstr[c] = loc[3+strlen("expiryDate")+c];
  6700. c++;
  6701. }
  6702. sstr[c] = '\0';
  6703. strcpy(expiryDatestr, sstr);
  6704. //***(3)idTag ****/
  6705. loc = strstr(payload, "idTag");
  6706. memset(sstr ,0, sizeof(sstr) );
  6707. c = 0;
  6708. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6709. {
  6710. sstr[c] = loc[3+strlen("idTag")+c];
  6711. c++;
  6712. }
  6713. sstr[c] = '\0';
  6714. strcpy(idTagstr, sstr);
  6715. //***(4)parentIdTag ****/
  6716. loc = strstr(payload, "parentIdTag");
  6717. memset(sstr ,0, sizeof(sstr) );
  6718. c = 0;
  6719. if(loc == NULL)
  6720. {
  6721. strcpy(parentIdTagstr, "");
  6722. }
  6723. else
  6724. {
  6725. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6726. {
  6727. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6728. c++;
  6729. }
  6730. sstr[c] = '\0';
  6731. strcpy(parentIdTagstr, sstr);
  6732. }
  6733. //***(5)reservationId ****/
  6734. c=0;
  6735. loc = strstr(payload, "reservationId");
  6736. memset(sstr ,0, sizeof(sstr) );
  6737. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6738. {
  6739. sstr[c] = loc[strlen("reservationId")+2+c];
  6740. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6741. c++;
  6742. }
  6743. sstr[c] = '\0';
  6744. reservationIdInt = atoi(sstr);
  6745. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6746. /*
  6747. enum SYSTEM_STATUS
  6748. {
  6749. SYS_MODE_BOOTING = 0,
  6750. SYS_MODE_IDLE = 1,
  6751. SYS_MODE_AUTHORIZING = 2,
  6752. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6753. SYS_MODE_REASSIGN = 4,
  6754. SYS_MODE_PREPARING = 5,
  6755. SYS_MODE_PREPARE_FOR_EV = 6,
  6756. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6757. SYS_MODE_CHARGING = 8,
  6758. SYS_MODE_TERMINATING = 9,
  6759. SYS_MODE_COMPLETE = 10,
  6760. SYS_MODE_ALARM = 11,
  6761. SYS_MODE_FAULT = 12,
  6762. SYS_MODE_RESERVATION = 13,
  6763. SYS_MODE_BOOKING = 14,
  6764. SYS_MODE_MAINTAIN = 15,
  6765. SYS_MODE_DEBUG = 16,
  6766. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6767. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6768. SYS_MODE_UPDATE = 19
  6769. };
  6770. */
  6771. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6772. {
  6773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6774. goto end;
  6775. }
  6776. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6777. {
  6778. //check Transaction active
  6779. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6780. {
  6781. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6782. {
  6783. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6784. {
  6785. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6786. {
  6787. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6788. {
  6789. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6790. {
  6791. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6792. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6793. }
  6794. 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'))
  6795. {
  6796. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6797. }
  6798. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6799. {
  6800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6801. }
  6802. else
  6803. {
  6804. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6805. }
  6806. }
  6807. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6808. {
  6809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6810. }
  6811. }
  6812. else
  6813. {
  6814. //replace reservation
  6815. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6817. }
  6818. }
  6819. } // END FOR CHAdeMO_QUANTITY
  6820. for (int index = 0; index < CCS_QUANTITY; index++)
  6821. {
  6822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6823. {
  6824. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6825. {
  6826. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6827. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6828. {
  6829. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6830. {
  6831. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6832. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6833. }
  6834. 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'))
  6835. {
  6836. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6837. }
  6838. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6839. {
  6840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6841. }
  6842. else
  6843. {
  6844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6845. }
  6846. }
  6847. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6848. {
  6849. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6850. }
  6851. }
  6852. else
  6853. {
  6854. //replace reservation
  6855. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6856. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6857. }
  6858. }
  6859. } // END FOR CCS_QUANTITY
  6860. for (int index = 0; index < GB_QUANTITY; index++)
  6861. {
  6862. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6863. {
  6864. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6865. {
  6866. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6867. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6868. {
  6869. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6870. {
  6871. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6872. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6873. }
  6874. 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'))
  6875. {
  6876. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6877. }
  6878. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6879. {
  6880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6881. }
  6882. else
  6883. {
  6884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6885. }
  6886. }
  6887. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6888. {
  6889. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6890. }
  6891. }
  6892. else
  6893. {
  6894. //replace reservation
  6895. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6896. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6897. }
  6898. }
  6899. }// END FOR GB_QUANTITY
  6900. }
  6901. else
  6902. {
  6903. for (int index = 0; index < AC_QUANTITY; index++)
  6904. {
  6905. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6906. {
  6907. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6908. {
  6909. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6910. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6911. {
  6912. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6913. {
  6914. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6915. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6916. }
  6917. 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'))
  6918. {
  6919. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6920. }
  6921. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6922. {
  6923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6924. }
  6925. else
  6926. {
  6927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6928. }
  6929. }
  6930. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6931. {
  6932. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6933. }
  6934. }
  6935. else
  6936. {
  6937. //replace reservation
  6938. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6940. }
  6941. }
  6942. } // END FOR AC_QUANTITY
  6943. }//END FOR AC ELSE
  6944. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6945. }
  6946. else if(connectorIdInt == 0)
  6947. {
  6948. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6949. {
  6950. //check Transaction active
  6951. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6952. {
  6953. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6954. {
  6955. 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'))
  6956. {
  6957. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6958. goto end;
  6959. }
  6960. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6961. {
  6962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6963. goto end;
  6964. }
  6965. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6966. {
  6967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6968. goto end;
  6969. }
  6970. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6971. {
  6972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6973. goto end;
  6974. }
  6975. }
  6976. }// END FOR CHAdeMO_QUANTITY
  6977. for (int index = 0; index < CCS_QUANTITY; index++)
  6978. {
  6979. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6980. {
  6981. 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'))
  6982. {
  6983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6984. }
  6985. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6986. {
  6987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6988. }
  6989. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6990. {
  6991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6992. }
  6993. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6994. {
  6995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6996. }
  6997. }
  6998. } // END FOR CCS_QUANTITY
  6999. for (int index = 0; index < GB_QUANTITY; index++)
  7000. {
  7001. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7002. {
  7003. 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'))
  7004. {
  7005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7006. }
  7007. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7008. {
  7009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7010. }
  7011. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  7012. {
  7013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7014. }
  7015. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7016. {
  7017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7018. }
  7019. }
  7020. } // END FOR GB_QUANTITY
  7021. }
  7022. else
  7023. {
  7024. for (int index = 0; index < AC_QUANTITY; index++)
  7025. {
  7026. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7027. {
  7028. 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'))
  7029. {
  7030. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7031. goto end;
  7032. }
  7033. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7034. {
  7035. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7036. goto end;
  7037. }
  7038. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  7039. {
  7040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7041. goto end;
  7042. }
  7043. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7044. {
  7045. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7046. goto end;
  7047. }
  7048. }
  7049. }// END FOR AC_QUANTITY
  7050. }
  7051. //The connectorId is 0
  7052. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7053. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7054. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7055. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7056. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7057. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7058. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7059. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7060. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7061. result = TRUE;
  7062. return result;
  7063. }
  7064. else
  7065. {
  7066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7067. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7068. }
  7069. if(strcmp(comfirmstr,"Accepted") == 0)
  7070. {
  7071. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7072. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7073. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7074. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7075. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7076. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7077. result = TRUE;
  7078. return result;
  7079. }
  7080. end:
  7081. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7082. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7083. return result;
  7084. }
  7085. int handleResetRequest(char *uuid, char *payload)
  7086. {
  7087. mtrace();
  7088. int result = FAIL;
  7089. char sstr[10]={0};
  7090. char typestr[10]={0};
  7091. char comfirmstr[20]={0};
  7092. int c = 0;
  7093. char *loc;
  7094. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7095. DEBUG_INFO("handleResetRequest ...\n");
  7096. loc = strstr(payload, "type");
  7097. memset(sstr ,0, sizeof(sstr) );
  7098. c = 0;
  7099. while (loc[3+strlen("type")+c] != '\"')
  7100. {
  7101. sstr[c] = loc[3+strlen("type")+c];
  7102. c++;
  7103. }
  7104. sstr[c] = '\0';
  7105. strcpy(typestr,sstr);
  7106. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7107. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7108. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  7109. {
  7110. //check Transaction active
  7111. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7112. {
  7113. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7114. {
  7115. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7116. {
  7117. //0: unplug, 1: Plug-in
  7118. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7119. }
  7120. }
  7121. for (int index = 0; index < CCS_QUANTITY; index++)
  7122. {
  7123. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7124. {
  7125. //0: unplug, 1: Plug-in
  7126. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7127. }
  7128. }
  7129. for (int index = 0; index < GB_QUANTITY; index++)
  7130. {
  7131. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7132. {
  7133. //0: unplug, 1: Plug-in
  7134. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7135. }
  7136. }
  7137. }
  7138. else
  7139. {
  7140. for (int index = 0; index < AC_QUANTITY; index++)
  7141. {
  7142. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7143. {
  7144. //0: unplug, 1: Plug-in
  7145. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7146. }
  7147. }
  7148. }// END FOR AC ELSE
  7149. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7150. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7151. result = TRUE;
  7152. return result;
  7153. }
  7154. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  7155. {
  7156. //check Transaction active
  7157. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7158. {
  7159. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7160. {
  7161. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7162. {
  7163. //0: unplug, 1: Plug-in
  7164. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7165. }
  7166. }
  7167. for (int index = 0; index < CCS_QUANTITY; index++)
  7168. {
  7169. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7170. {
  7171. //0: unplug, 1: Plug-in
  7172. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  7173. }
  7174. }
  7175. for (int index = 0; index < GB_QUANTITY; index++)
  7176. {
  7177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7178. {
  7179. //0: unplug, 1: Plug-in
  7180. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  7181. }
  7182. }
  7183. }
  7184. else
  7185. {
  7186. for (int index = 0; index < AC_QUANTITY; index++)
  7187. {
  7188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7189. {
  7190. //0: unplug, 1: Plug-in
  7191. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  7192. }
  7193. }
  7194. }// END FOR AC ELSE
  7195. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7196. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7197. result = TRUE;
  7198. return result;
  7199. }
  7200. else
  7201. {
  7202. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7203. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7204. goto errorend;
  7205. }
  7206. errorend:
  7207. sendResetConfirmation(uuid, comfirmstr);
  7208. return result;
  7209. }
  7210. int handleSendLocalListRequest(char *uuid, char *payload)
  7211. {
  7212. mtrace();
  7213. int result = FAIL;
  7214. int listVersionInt;
  7215. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7216. char listsearch[]="listVersion";
  7217. char updateTypesearch[]="updateType";
  7218. char localAuthorizationListsearch[]="localAuthorizationList";
  7219. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7220. char CardList[500][160]={0};
  7221. char updateTypestr[15]={0};
  7222. char idTagstr[20]={0};
  7223. char parentIdTag[20]={0};
  7224. char expiryDate[30]={0};
  7225. char idTagstatus[16]={0};
  7226. int c = 0;
  7227. int i = 0;
  7228. char *delim1 = "}";
  7229. char * pch;
  7230. char *loc;
  7231. //char *ptr;
  7232. char comfirmstr[20];
  7233. //int n_localAuthorizations = 0;
  7234. int checkState_Faulted = FALSE;
  7235. DEBUG_INFO("handleSendLocalListRequest\n");
  7236. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7237. {
  7238. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7239. goto end;
  7240. }
  7241. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7242. {
  7243. //check Charge Point state
  7244. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7245. {
  7246. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7247. {
  7248. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7249. }
  7250. }
  7251. for (int index = 0; index < CCS_QUANTITY; index++)
  7252. {
  7253. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7254. {
  7255. checkState_Faulted = TRUE; //OCPP Status
  7256. }
  7257. }
  7258. for (int index = 0; index < GB_QUANTITY; index++)
  7259. {
  7260. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7261. {
  7262. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7263. }
  7264. }
  7265. }
  7266. else
  7267. {
  7268. //check Charge Point state
  7269. for (int index = 0; index < AC_QUANTITY; index++)
  7270. {
  7271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7272. {
  7273. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7274. }
  7275. }
  7276. }// END FOR AC ELSE
  7277. if(checkState_Faulted == TRUE)
  7278. {
  7279. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7280. goto end;
  7281. }
  7282. //listVersion
  7283. c = 0;
  7284. loc = strstr(payload, listsearch);
  7285. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7286. {
  7287. sstr[c] = loc[strlen("listVersion")+2+c];
  7288. c++;
  7289. }
  7290. sstr[c] = '\0';
  7291. listVersionInt = atoi(sstr);
  7292. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7293. //updateType
  7294. loc = strstr(payload, updateTypesearch);
  7295. c = 0;
  7296. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7297. {
  7298. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7299. c++;
  7300. }
  7301. sstr[c] = '\0';
  7302. strcpy(updateTypestr, sstr);
  7303. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7304. //localAuthorizationList
  7305. memset(sstr ,0, sizeof(sstr) );
  7306. loc = strstr(payload, localAuthorizationListsearch);
  7307. if(loc != NULL) // localAuthorizationList is not NULL
  7308. {
  7309. //Check UpdateType
  7310. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7311. {
  7312. //Local list full update
  7313. printf("Local list full update.\n");
  7314. OCPP_cleanLocalList();
  7315. }
  7316. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7317. {
  7318. //Local list different update
  7319. printf("Local list different update.\n");
  7320. OCPP_getListVerion();
  7321. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7322. {
  7323. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7324. goto end;
  7325. }
  7326. }
  7327. else
  7328. {
  7329. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7330. goto end;
  7331. }
  7332. c = 0;
  7333. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7334. {
  7335. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7336. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7337. c++;
  7338. }
  7339. sstr[c] = '\0';
  7340. //DEBUG_INFO("sstr=%s\n", sstr);
  7341. //parsing strings to words
  7342. i = 0;
  7343. pch = strtok(sstr,delim1);
  7344. while (pch != NULL)
  7345. {
  7346. strcpy(CardList[i], pch);
  7347. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7348. pch = strtok (NULL, delim1);
  7349. i = i + 1;
  7350. }
  7351. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7352. //local Authorizations List Numbers
  7353. //n_localAuthorizations = i;
  7354. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7355. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7356. c= 0;
  7357. while(c < i)
  7358. {
  7359. //Search "IdToken"
  7360. memset(sstr ,0, sizeof(sstr) );
  7361. loc = strstr(CardList[c], "idTag");
  7362. int j = 0;
  7363. while (loc[3+strlen("idTag")+j] != '\"')
  7364. {
  7365. sstr[j] = loc[3+strlen("idTag")+j];
  7366. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7367. j++;
  7368. }
  7369. sstr[j] = '\0';
  7370. strcpy(idTagstr, sstr);
  7371. DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7372. //Search "expiryDate"
  7373. memset(sstr ,0, sizeof(sstr) );
  7374. loc = strstr(CardList[c], "expiryDate");
  7375. j = 0;
  7376. if(loc != NULL)
  7377. {
  7378. while (loc[3+strlen("expiryDate")+j] != '\"')
  7379. {
  7380. sstr[j] = loc[3+strlen("expiryDate")+j];
  7381. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7382. j++;
  7383. }
  7384. sstr[j] = '\0';
  7385. strcpy(expiryDate, sstr);
  7386. }
  7387. else
  7388. {
  7389. strcpy(expiryDate, "");
  7390. }
  7391. DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7392. //Search "parentIdTag"
  7393. memset(sstr ,0, sizeof(sstr) );
  7394. loc = strstr(CardList[c], "parentIdTag");
  7395. j = 0;
  7396. if(loc != NULL)
  7397. {
  7398. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7399. {
  7400. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7401. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7402. j++;
  7403. }
  7404. sstr[j] = '\0';
  7405. strcpy(parentIdTag, sstr);
  7406. }
  7407. else
  7408. {
  7409. strcpy(parentIdTag, "");
  7410. }
  7411. DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7412. //Search "status"
  7413. memset(sstr ,0, sizeof(sstr) );
  7414. loc = strstr(CardList[c], "status");
  7415. j = 0;
  7416. while (loc[3+strlen("status")+j] != '\"')
  7417. {
  7418. sstr[j] = loc[3+strlen("status")+j];
  7419. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7420. j++;
  7421. }
  7422. sstr[j] = '\0';
  7423. strcpy(idTagstatus, sstr);
  7424. DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7425. OCPP_getIdTag(idTagstr);
  7426. //OCPP_getIdTag("test"); For Test
  7427. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7428. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7429. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7430. {
  7431. //Local list full update
  7432. DEBUG_INFO("Local list full update.\n");
  7433. // update list
  7434. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7435. //DEBUG_INFO("Local list full update. 1\n");
  7436. //OCPP_get_TableAuthlocalAllData();
  7437. //DEBUG_INFO("Local list full update. 2\n");
  7438. }
  7439. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7440. {
  7441. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7442. {
  7443. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7444. }
  7445. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7446. {
  7447. OCPP_deleteIdTag(idTagstr);
  7448. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  7449. //OCPP_deleteIdTag(idTagstr);
  7450. }
  7451. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7452. {
  7453. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  7454. }
  7455. }
  7456. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7457. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7458. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7459. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7460. c++;
  7461. }
  7462. }
  7463. else
  7464. {
  7465. //Check UpdateType
  7466. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7467. {
  7468. //Local list full update
  7469. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7470. OCPP_cleanLocalList();
  7471. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7472. goto end;
  7473. }
  7474. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7475. {
  7476. //Local list different update
  7477. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7478. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7479. goto end;
  7480. }
  7481. }
  7482. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7483. end:
  7484. sendSendLocalListConfirmation(uuid, comfirmstr);
  7485. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7486. return result;
  7487. }
  7488. #define MAX 200
  7489. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7490. {
  7491. mtrace();
  7492. int result = FAIL;
  7493. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7494. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7495. char chargingProfilePurposeStr[30]={0};
  7496. char chargingProfileKindStr[16]={0};
  7497. char recurrencyKindStr[10]={0};
  7498. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7499. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7500. int chargingSchedulePeriodCount = 0;
  7501. //int updateflag = FALSE;
  7502. char comfirmstr[20]={0};
  7503. int meet= FALSE;
  7504. char sstr[10]={0};
  7505. int c = 0;
  7506. char *loc;
  7507. FILE *fptr1;//, *fptr2;
  7508. //int lno=0;//, linectr = 0;
  7509. //int modifyflag = FALSE;
  7510. char filename[MAX]={0};
  7511. char tempfile[] = "/Storage/OCPP/temp.json";
  7512. //int resultRename=0;
  7513. char rmFileCmd[50]={0};
  7514. char tempchargingProfilePurposeStr[30]={0};
  7515. char word[1600]={0};
  7516. int n_chargingProfile = 0;
  7517. //[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}}}]
  7518. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7519. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7520. //*********************connectorId***************************/
  7521. loc = strstr(payload, "connectorId");
  7522. c = 0;
  7523. memset(sstr ,0, sizeof(sstr) );
  7524. while (loc[strlen("connectorId")+2+c] != ',')
  7525. {
  7526. sstr[c] = loc[strlen("connectorId")+2+c];
  7527. c++;
  7528. }
  7529. sstr[c] = '\0';
  7530. connectorIdInt = atoi(sstr);
  7531. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7532. {
  7533. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7534. }
  7535. else
  7536. {
  7537. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7538. }
  7539. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7540. //*********************chargingProfileId***************************/
  7541. loc = strstr(payload, "chargingProfileId");
  7542. c = 0;
  7543. memset(sstr ,0, sizeof(sstr) );
  7544. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7545. {
  7546. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7547. c++;
  7548. }
  7549. sstr[c] = '\0';
  7550. chargingProfileIdInt = atoi(sstr);
  7551. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7552. {
  7553. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7554. }
  7555. else
  7556. {
  7557. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7558. }
  7559. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7560. //*********************transactionId***************************/
  7561. loc = strstr(payload, "transactionId");
  7562. if(loc != NULL)
  7563. {
  7564. c = 0;
  7565. memset(sstr ,0, sizeof(sstr) );
  7566. while (loc[strlen("transactionId")+2+c] != ',')
  7567. {
  7568. sstr[c] = loc[strlen("transactionId")+2+c];
  7569. c++;
  7570. }
  7571. sstr[c] = '\0';
  7572. transactionIdInt = atoi(sstr);
  7573. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7574. {
  7575. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7576. }
  7577. else
  7578. {
  7579. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7580. }
  7581. }
  7582. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7583. //*********************stackLevel***************************/
  7584. loc = strstr(payload, "stackLevel");
  7585. c = 0;
  7586. memset(sstr ,0, sizeof(sstr) );
  7587. while (loc[strlen("stackLevel")+2+c] != ',')
  7588. {
  7589. sstr[c] = loc[strlen("stackLevel")+2+c];
  7590. c++;
  7591. }
  7592. sstr[c] = '\0';
  7593. stackLevelInt = atoi(sstr);
  7594. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7595. {
  7596. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7597. }
  7598. else
  7599. {
  7600. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7601. }
  7602. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7603. //*********************chargingProfilePurpose***************************/
  7604. loc = strstr(payload, "chargingProfilePurpose");
  7605. c = 0;
  7606. memset(sstr ,0, sizeof(sstr) );
  7607. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7608. {
  7609. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7610. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7611. c++;
  7612. }
  7613. sstr[c] = '\0';
  7614. strcpy(chargingProfilePurposeStr,sstr);
  7615. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7616. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7617. {
  7618. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7619. }
  7620. else
  7621. {
  7622. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7623. }
  7624. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7625. //*********************chargingProfileKind***************************/
  7626. loc = strstr(payload, "chargingProfileKind");
  7627. c = 0;
  7628. memset(sstr ,0, sizeof(sstr) );
  7629. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7630. {
  7631. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7632. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7633. c++;
  7634. }
  7635. sstr[c] = '\0';
  7636. strcpy(chargingProfileKindStr,sstr);
  7637. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7638. {
  7639. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7640. }
  7641. else
  7642. {
  7643. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7644. }
  7645. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7646. //*********************recurrencyKind***************************/
  7647. loc = strstr(payload, "recurrencyKind");
  7648. if(loc != NULL)
  7649. {
  7650. c = 0;
  7651. memset(sstr ,0, sizeof(sstr) );
  7652. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7653. {
  7654. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7655. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7656. c++;
  7657. }
  7658. sstr[c] = '\0';
  7659. strcpy(recurrencyKindStr,sstr);
  7660. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7661. {
  7662. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7663. }
  7664. else
  7665. {
  7666. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7667. }
  7668. }
  7669. else
  7670. {
  7671. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7672. {
  7673. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7674. }
  7675. else
  7676. {
  7677. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7678. }
  7679. }
  7680. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7681. //*********************validFrom***************************/
  7682. loc = strstr(payload, "validFrom");
  7683. if(loc != NULL)
  7684. {
  7685. c = 0;
  7686. memset(sstr ,0, sizeof(sstr) );
  7687. while (loc[3+strlen("validFrom")+c] != '\"')
  7688. {
  7689. sstr[c] = loc[3+strlen("validFrom")+c];
  7690. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7691. c++;
  7692. }
  7693. sstr[c] = '\0';
  7694. strcpy(validFromStr,sstr);
  7695. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7696. {
  7697. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7698. }
  7699. else
  7700. {
  7701. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7702. }
  7703. }
  7704. else
  7705. {
  7706. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7707. {
  7708. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7709. }
  7710. else
  7711. {
  7712. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7713. }
  7714. }
  7715. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7716. //*********************validTo***************************/
  7717. loc = strstr(payload, "validTo");
  7718. if(loc != NULL)
  7719. {
  7720. c = 0;
  7721. memset(sstr ,0, sizeof(sstr) );
  7722. while (loc[3+strlen("validTo")+c] != '\"')
  7723. {
  7724. sstr[c] = loc[3+strlen("validTo")+c];
  7725. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7726. c++;
  7727. }
  7728. sstr[c] = '\0';
  7729. strcpy(validToStr,sstr);
  7730. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7731. {
  7732. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7733. }
  7734. else
  7735. {
  7736. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7737. }
  7738. }
  7739. else
  7740. {
  7741. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7742. {
  7743. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7744. }
  7745. else
  7746. {
  7747. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7748. }
  7749. }
  7750. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7751. //*********************duration***************************/
  7752. loc = strstr(payload, "duration");
  7753. if(loc != NULL)
  7754. {
  7755. c = 0;
  7756. memset(sstr ,0, sizeof(sstr) );
  7757. while (loc[strlen("duration")+2+c] != ',')
  7758. {
  7759. sstr[c] = loc[strlen("duration")+2+c];
  7760. c++;
  7761. }
  7762. sstr[c] = '\0';
  7763. durationInt = atoi(sstr);
  7764. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7765. {
  7766. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7767. }
  7768. else
  7769. {
  7770. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7771. }
  7772. }
  7773. else
  7774. {
  7775. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7776. {
  7777. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7778. }
  7779. else
  7780. {
  7781. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7782. }
  7783. }
  7784. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7785. //*********************startSchedule***************************/
  7786. loc = strstr(payload, "startSchedule");
  7787. if(loc != NULL)
  7788. {
  7789. c = 0;
  7790. memset(sstr ,0, sizeof(sstr) );
  7791. while (loc[3+strlen("startSchedule")+c] != '\"')
  7792. {
  7793. sstr[c] = loc[3+strlen("startSchedule")+c];
  7794. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7795. c++;
  7796. }
  7797. sstr[c] = '\0';
  7798. strcpy(startScheduleStr,sstr);
  7799. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7800. {
  7801. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7802. }
  7803. else
  7804. {
  7805. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7806. }
  7807. }
  7808. else
  7809. {
  7810. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7811. {
  7812. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7813. }
  7814. else
  7815. {
  7816. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7817. }
  7818. }
  7819. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7820. //*********************chargingRateUnit***************************/
  7821. loc = strstr(payload, "chargingRateUnit");
  7822. if(loc != NULL)
  7823. {
  7824. c = 0;
  7825. memset(sstr ,0, sizeof(sstr) );
  7826. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7827. {
  7828. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7829. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7830. c++;
  7831. }
  7832. sstr[c] = '\0';
  7833. strcpy(chargingRateUnitStr,sstr);
  7834. #if 0
  7835. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  7836. {
  7837. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7838. goto end;
  7839. }
  7840. #endif
  7841. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7842. {
  7843. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7844. }
  7845. else
  7846. {
  7847. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7848. }
  7849. }
  7850. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7851. //****************chargingSchedulePeriod count start*******************/
  7852. int what_len = strlen("startPeriod");
  7853. char tempChargingProfile[1000]={0};
  7854. strcpy(tempChargingProfile,(const char*)payload);
  7855. char *where = tempChargingProfile;
  7856. if (what_len)
  7857. {
  7858. while ((where = strstr(where, "startPeriod"))) {
  7859. where += what_len;
  7860. chargingSchedulePeriodCount++;
  7861. }
  7862. }
  7863. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  7864. {
  7865. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7866. goto end;
  7867. }
  7868. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7869. //where = payload;
  7870. int templength = 0;
  7871. //int searchstart = 0;
  7872. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7873. {
  7874. //****************startPeriod*******************/
  7875. c=0;
  7876. loc = strstr(tempChargingProfile + templength, "startPeriod");
  7877. memset(sstr ,0, sizeof(sstr) );
  7878. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7879. {
  7880. sstr[c] = loc[strlen("startPeriod")+2+c];
  7881. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7882. c++;
  7883. }
  7884. sstr[c] = '\0';
  7885. startPeriodInt[periodNums] = atoi(sstr);
  7886. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7887. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7888. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7889. {
  7890. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7891. }
  7892. else
  7893. {
  7894. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7895. }
  7896. templength = strlen("startPeriod")+2+c;
  7897. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7898. //****************limit*******************/
  7899. c=0;
  7900. loc = strstr(tempChargingProfile + templength, "limit");
  7901. memset(sstr ,0, sizeof(sstr) );
  7902. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7903. {
  7904. sstr[c] = loc[strlen("limit")+2+c];
  7905. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7906. c++;
  7907. }
  7908. sstr[c] = '\0';
  7909. limitflaot[periodNums] = atof(sstr);
  7910. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7911. {
  7912. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7913. }
  7914. else
  7915. {
  7916. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7917. }
  7918. templength = templength + strlen("limit")+2+c;
  7919. //****************numberPhases*******************/
  7920. loc = strstr(tempChargingProfile + templength, "numberPhases");
  7921. if(loc != NULL)
  7922. {
  7923. c=0;
  7924. memset(sstr ,0, sizeof(sstr) );
  7925. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7926. {
  7927. sstr[c] = loc[strlen("numberPhases")+2+c];
  7928. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7929. c++;
  7930. }
  7931. sstr[c] = '\0';
  7932. numberPhasesInt[periodNums] = atoi(sstr);
  7933. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7934. {
  7935. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7936. }
  7937. else
  7938. {
  7939. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7940. }
  7941. templength = templength + strlen("numberPhases")+2+c;
  7942. }
  7943. //where = loc;
  7944. }
  7945. //****************chargingSchedulePeriod count end*******************/
  7946. //*********************minChargingRate***************************/
  7947. loc = strstr(payload, "minChargingRate");
  7948. if(loc != NULL)
  7949. {
  7950. c = 0;
  7951. memset(sstr ,0, sizeof(sstr) );
  7952. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7953. {
  7954. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7955. c++;
  7956. }
  7957. sstr[c] = '\0';
  7958. minChargingRateFloat = atof(sstr);
  7959. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7960. {
  7961. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7962. }
  7963. else
  7964. {
  7965. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7966. }
  7967. }
  7968. else
  7969. {
  7970. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7971. {
  7972. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7973. }
  7974. else
  7975. {
  7976. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7977. }
  7978. }
  7979. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7980. {
  7981. //printf("set chargingProfile 1-2\n");
  7982. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7983. if(connectorIdInt != 0)
  7984. {
  7985. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7986. goto end;
  7987. }
  7988. strcpy(filename, ChargePointMaxProfile_JSON );
  7989. fptr1 = fopen(filename, "r");
  7990. if (!fptr1)
  7991. {
  7992. //file not exist
  7993. DEBUG_INFO("Unable to open the input file!!\n");
  7994. fptr1 = fopen(filename, "w+");
  7995. }
  7996. else
  7997. {
  7998. //Check Charging Profile Count
  7999. while(fscanf(fptr1, "%s", word) != EOF)
  8000. {
  8001. //DEBUG_INFO("word=%s\n",word);
  8002. if(strstr(word, "chargingProfileId")!= NULL)
  8003. {
  8004. //DEBUG_INFO("test chargingProfileId \n");
  8005. n_chargingProfile = n_chargingProfile + 1;
  8006. //DEBUG_INFO("chargingProfileId Found\n");
  8007. }
  8008. }
  8009. }
  8010. fclose(fptr1);
  8011. }
  8012. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8013. {
  8014. //printf("set chargingProfile 1-3\n");
  8015. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8016. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8017. {
  8018. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8019. goto end;
  8020. }
  8021. #if 0
  8022. switch(connectorIdInt)
  8023. {
  8024. case 0:
  8025. strcpy(filename, TxDefaultProfile_0_JSON );
  8026. break;
  8027. case 1:
  8028. strcpy(filename, TxDefaultProfile_1_JSON );
  8029. break;
  8030. case 2:
  8031. strcpy(filename, TxDefaultProfile_2_JSON );
  8032. break;
  8033. default:
  8034. strcpy(filename, TxDefaultProfile_0_JSON );
  8035. break;
  8036. }
  8037. #endif
  8038. memset(filename, 0, sizeof filename);
  8039. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8040. fptr1 = fopen(filename, "r");
  8041. if (!fptr1)
  8042. {
  8043. //file not exist
  8044. //DEBUG_INFO("Unable to open the input file!!\n");
  8045. fptr1 = fopen(filename, "w+");
  8046. }
  8047. else
  8048. {
  8049. //Check Charging Profile Count
  8050. while(fscanf(fptr1, "%s", word) != EOF)
  8051. {
  8052. //DEBUG_INFO("word=%s\n",word);
  8053. if(strstr(word, "chargingProfileId")!= NULL)
  8054. {
  8055. //DEBUG_INFO("test chargingProfileId \n");
  8056. n_chargingProfile = n_chargingProfile + 1;
  8057. //DEBUG_INFO("chargingProfileId Found\n");
  8058. }
  8059. }
  8060. }
  8061. fclose(fptr1);
  8062. }
  8063. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8064. {
  8065. //printf("set chargingProfile 1-4\n");
  8066. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8067. //check Transaction active
  8068. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8069. {
  8070. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  8071. {
  8072. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8073. {
  8074. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8075. {
  8076. meet = TRUE;
  8077. break;
  8078. }
  8079. }
  8080. }
  8081. }
  8082. for (int index = 0; index < CCS_QUANTITY; index++)
  8083. {
  8084. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  8085. {
  8086. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8087. {
  8088. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8089. {
  8090. meet = TRUE;
  8091. break;
  8092. }
  8093. }
  8094. }
  8095. }
  8096. for (int index = 0; index < GB_QUANTITY; index++)
  8097. {
  8098. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  8099. {
  8100. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8101. {
  8102. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8103. {
  8104. meet = TRUE;
  8105. break;
  8106. }
  8107. }
  8108. }
  8109. }
  8110. if(meet == FALSE)
  8111. {
  8112. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8113. goto end;
  8114. }
  8115. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8116. {
  8117. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8118. goto end;
  8119. }
  8120. #if 0
  8121. switch(connectorIdInt)
  8122. {
  8123. case 0:
  8124. break;
  8125. case 1:
  8126. strcpy(filename, TxProfile_1_JSON);
  8127. break;
  8128. case 2:
  8129. strcpy(filename, TxProfile_2_JSON);
  8130. break;
  8131. default:
  8132. strcpy(filename, TxProfile_1_JSON);
  8133. break;
  8134. }
  8135. #endif
  8136. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8137. fptr1 = fopen(filename, "r");
  8138. if (!fptr1)
  8139. {
  8140. //file not exist
  8141. DEBUG_INFO("Unable to open the input file!!\n");
  8142. fptr1 = fopen(filename, "w+");
  8143. }
  8144. else
  8145. {
  8146. //Check Charging Profile Count
  8147. while(fscanf(fptr1, "%s", word) != EOF)
  8148. {
  8149. //DEBUG_INFO("word=%s\n",word);
  8150. if(strstr(word, "chargingProfileId")!= NULL)
  8151. {
  8152. //DEBUG_INFO("test chargingProfileId \n");
  8153. n_chargingProfile = n_chargingProfile + 1;
  8154. //DEBUG_INFO("chargingProfileId Found\n");
  8155. }
  8156. }
  8157. }
  8158. fclose(fptr1);
  8159. }
  8160. // Check ChargeProfileMaxStackLevel
  8161. if(n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8162. {
  8163. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8164. goto end;
  8165. }
  8166. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8167. {
  8168. int i = 0;
  8169. char fnametemp[200]={0};
  8170. n_chargingProfile = 0;
  8171. //Check ChargePointMaxProfile.json exit
  8172. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8173. {
  8174. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8175. //Check Charging Profile Count
  8176. while(fscanf(fptr1, "%s", word) != EOF)
  8177. {
  8178. //DEBUG_INFO("word=%s\n",word);
  8179. if(strstr(word, "chargingProfileId")!= NULL)
  8180. {
  8181. //DEBUG_INFO("test chargingProfileId \n");
  8182. n_chargingProfile = n_chargingProfile + 1;
  8183. i = i + 1;
  8184. //DEBUG_INFO("chargingProfileId Found\n");
  8185. }
  8186. memset(word, 0, sizeof word);
  8187. }
  8188. fclose(fptr1);
  8189. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8190. }
  8191. //Check TxDefaultProfile_0.json exit
  8192. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8193. {
  8194. i = 0;
  8195. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8196. //Check Charging Profile Count
  8197. while(fscanf(fptr1, "%s", word) != EOF)
  8198. {
  8199. //DEBUG_INFO("word=%s\n",word);
  8200. if(strstr(word, "chargingProfileId")!= NULL)
  8201. {
  8202. //DEBUG_INFO("test chargingProfileId \n");
  8203. n_chargingProfile = n_chargingProfile + 1;
  8204. i = i + 1;
  8205. //DEBUG_INFO("chargingProfileId Found\n");
  8206. }
  8207. memset(word, 0, sizeof word);
  8208. }
  8209. fclose(fptr1);
  8210. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8211. }
  8212. //Check TxDefaultProfile_%d.json
  8213. for(int j=1; j <= gunTotalNumber; j++)
  8214. {
  8215. memset(fnametemp, 0, sizeof fnametemp);
  8216. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8217. if((access(fnametemp,F_OK))!=-1)
  8218. {
  8219. i = 0;
  8220. fptr1 = fopen(fnametemp, "r");
  8221. //Check Charging Profile Count
  8222. while(fscanf(fptr1, "%s", word) != EOF)
  8223. {
  8224. //DEBUG_INFO("word=%s\n",word);
  8225. if(strstr(word, "chargingProfileId")!= NULL)
  8226. {
  8227. //DEBUG_INFO("test chargingProfileId \n");
  8228. n_chargingProfile = n_chargingProfile + 1;
  8229. i = i + 1;
  8230. //DEBUG_INFO("chargingProfileId Found\n");
  8231. }
  8232. memset(word, 0, sizeof word);
  8233. }
  8234. fclose(fptr1);
  8235. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8236. }
  8237. }
  8238. //Check TxProfile_%d.json
  8239. for(int j=1; j <= gunTotalNumber; j++)
  8240. {
  8241. memset(fnametemp, 0, sizeof fnametemp);
  8242. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8243. if((access(fnametemp,F_OK))!=-1)
  8244. {
  8245. i = 0;
  8246. fptr1 = fopen(fnametemp, "r");
  8247. //Check Charging Profile Count
  8248. while(fscanf(fptr1, "%s", word) != EOF)
  8249. {
  8250. //DEBUG_INFO("word=%s\n",word);
  8251. if(strstr(word, "chargingProfileId")!= NULL)
  8252. {
  8253. //DEBUG_INFO("test chargingProfileId \n");
  8254. n_chargingProfile = n_chargingProfile + 1;
  8255. i = i + 1;
  8256. //DEBUG_INFO("chargingProfileId Found\n");
  8257. }
  8258. memset(word, 0, sizeof word);
  8259. }
  8260. fclose(fptr1);
  8261. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8262. }
  8263. }
  8264. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8265. {
  8266. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8267. goto end;
  8268. }
  8269. }
  8270. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8271. //**********************************Write to File********************************************************/
  8272. FILE *infile;
  8273. FILE *outfile;
  8274. // open file for writing
  8275. infile = fopen (filename, "r");
  8276. outfile = fopen (tempfile, "w");
  8277. int d =0;
  8278. d = fgetc(infile);
  8279. //DEBUG_INFO("d:%d\n",d);
  8280. rewind(infile);
  8281. //*检测到文件结束标识返回1,否则返回0。*/
  8282. if(d == EOF)
  8283. {
  8284. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8285. fprintf(outfile,"%s\n",payload);
  8286. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8287. fclose(infile);
  8288. fclose(outfile);
  8289. sprintf(rmFileCmd,"rm -f %s",filename);
  8290. system(rmFileCmd);
  8291. rename(tempfile, filename);
  8292. #if 0
  8293. resultRename = rename(tempfile, filename);
  8294. if(resultRename == 0)
  8295. {
  8296. DEBUG_INFO("File chargingProfile renamed successfully");
  8297. }
  8298. else
  8299. {
  8300. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8301. }
  8302. #endif
  8303. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8304. //system(rmFileCmd);
  8305. }
  8306. else
  8307. {
  8308. char buf[1000]={0};
  8309. int ChargingProfileAdded = FALSE;
  8310. while (fgets(buf, sizeof(buf), infile) != NULL)
  8311. {
  8312. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8313. //*************************tempconnectorIdInt*********************************/
  8314. loc = strstr(buf, "connectorId");
  8315. c = 0;
  8316. memset(sstr ,0, sizeof(sstr) );
  8317. while (loc[strlen("connectorId")+2+c] != ',')
  8318. {
  8319. sstr[c] = loc[strlen("connectorId")+2+c];
  8320. c++;
  8321. }
  8322. sstr[c] = '\0';
  8323. tempconnectorIdInt = atoi(sstr);
  8324. //*************************tempchargingProfileIdInt*********************************/
  8325. loc = strstr(buf, "chargingProfileId");
  8326. c = 0;
  8327. memset(sstr ,0, sizeof(sstr) );
  8328. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8329. {
  8330. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8331. c++;
  8332. }
  8333. sstr[c] = '\0';
  8334. tempchargingProfileIdInt = atoi(sstr);
  8335. //*************************tempstackLevelInt*********************************/
  8336. loc = strstr(buf, "stackLevel");
  8337. c = 0;
  8338. memset(sstr ,0, sizeof(sstr) );
  8339. while (loc[strlen("stackLevel")+2+c] != ',')
  8340. {
  8341. sstr[c] = loc[strlen("stackLevel")+2+c];
  8342. c++;
  8343. }
  8344. sstr[c] = '\0';
  8345. tempstackLevelInt = atoi(sstr);
  8346. //*************************tempchargingProfilePurposeStr*********************************/
  8347. loc = strstr(payload, "chargingProfilePurpose");
  8348. c = 0;
  8349. memset(sstr ,0, sizeof(sstr) );
  8350. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8351. {
  8352. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8353. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8354. c++;
  8355. }
  8356. sstr[c] = '\0';
  8357. strcpy(tempchargingProfilePurposeStr,sstr);
  8358. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8359. {
  8360. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8361. {
  8362. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8363. if(ChargingProfileAdded == FALSE)
  8364. {
  8365. fprintf(outfile,"%s\n",payload);
  8366. ChargingProfileAdded = TRUE;
  8367. }
  8368. }
  8369. else
  8370. {
  8371. if(tempstackLevelInt < stackLevelInt)
  8372. {
  8373. if(ChargingProfileAdded == FALSE)
  8374. {
  8375. fprintf(outfile,"%s\n",payload);
  8376. ChargingProfileAdded = TRUE;
  8377. fprintf(outfile,"%s\n",buf);
  8378. }
  8379. else
  8380. {
  8381. fprintf(outfile,"%s\n",buf);
  8382. }
  8383. }
  8384. else
  8385. {
  8386. if(ChargingProfileAdded == FALSE)
  8387. {
  8388. fprintf(outfile,"%s\n",buf);
  8389. fprintf(outfile,"%s\n",payload);
  8390. ChargingProfileAdded = TRUE;
  8391. }
  8392. else
  8393. {
  8394. fprintf(outfile,"%s\n",buf);
  8395. }
  8396. }
  8397. }
  8398. }
  8399. else
  8400. {
  8401. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8402. {
  8403. if(ChargingProfileAdded == FALSE)
  8404. {
  8405. fprintf(outfile,"%s\n",payload);
  8406. ChargingProfileAdded = TRUE;
  8407. fprintf(outfile,"%s\n",buf);
  8408. }
  8409. else
  8410. {
  8411. fprintf(outfile,"%s\n",buf);
  8412. }
  8413. }
  8414. else if(tempstackLevelInt < stackLevelInt)
  8415. {
  8416. if(ChargingProfileAdded == FALSE)
  8417. {
  8418. fprintf(outfile,"%s\n",payload);
  8419. ChargingProfileAdded = TRUE;
  8420. fprintf(outfile,"%s\n",buf);
  8421. }
  8422. else
  8423. {
  8424. fprintf(outfile,"%s\n",buf);
  8425. }
  8426. }
  8427. else
  8428. {
  8429. if(ChargingProfileAdded == FALSE)
  8430. {
  8431. fprintf(outfile,"%s\n",buf);
  8432. fprintf(outfile,"%s\n",payload);
  8433. ChargingProfileAdded = TRUE;
  8434. }
  8435. else
  8436. {
  8437. fprintf(outfile,"%s\n",buf);
  8438. }
  8439. }
  8440. }
  8441. } // end of while loop
  8442. fclose(infile);
  8443. fclose(outfile);
  8444. sprintf(rmFileCmd,"rm -f %s",filename);
  8445. system(rmFileCmd);
  8446. rename(tempfile, filename);
  8447. #if 0
  8448. resultRename = rename(tempfile, filename);
  8449. if(resultRename == 0)
  8450. {
  8451. DEBUG_INFO("File chargingProfile renamed successfully");
  8452. }
  8453. else
  8454. {
  8455. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  8456. }
  8457. #endif
  8458. result = TRUE;
  8459. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8460. }
  8461. end:
  8462. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8463. return result;
  8464. return result;
  8465. }
  8466. int handleTriggerMessageRequest(char *uuid, char *payload)
  8467. {
  8468. mtrace();
  8469. int result = FAIL;
  8470. int connectorIdIsNULL = FALSE;
  8471. int connectorIdInt =0;
  8472. char sstr[40]={0};
  8473. char requestedMessagestr[40]={0};
  8474. char comfirmstr[20]={0};
  8475. int c = 0;
  8476. char *loc;
  8477. DEBUG_INFO("handleTriggerMessageRequest\n");
  8478. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8479. c = 0;
  8480. loc = strstr(payload, "requestedMessage");
  8481. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8482. {
  8483. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8484. c++;
  8485. }
  8486. sstr[c] = '\0';
  8487. strcpy(requestedMessagestr, sstr);
  8488. c = 0;
  8489. loc = strstr(payload, "connectorId");
  8490. if(loc == NULL)
  8491. {
  8492. connectorIdIsNULL = TRUE;
  8493. }
  8494. else
  8495. {
  8496. memset(sstr ,0, sizeof(sstr) );
  8497. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8498. {
  8499. sstr[c] = loc[strlen("connectorId")+2+c];
  8500. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8501. c++;
  8502. }
  8503. sstr[c] = '\0';
  8504. connectorIdInt = atoi(sstr);
  8505. }
  8506. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8507. {
  8508. //connectorIdInt = json_object_get_int(connectorId);
  8509. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8510. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8511. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8512. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8513. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8514. }
  8515. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8516. {
  8517. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8518. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8519. return TRUE;
  8520. }
  8521. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8522. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8523. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8524. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8525. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8526. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8527. {
  8528. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8529. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8530. return TRUE;
  8531. }
  8532. else
  8533. {
  8534. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8535. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8536. }
  8537. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8538. {
  8539. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8540. {
  8541. FirmwareStatusNotificationStatus = 3;
  8542. }
  8543. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8544. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8545. }
  8546. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8547. {
  8548. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8549. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8550. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8551. }
  8552. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8553. {
  8554. sendBootNotificationRequest();
  8555. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8556. }
  8557. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8558. {
  8559. sendHeartbeatRequest(connectorIdInt);
  8560. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8561. }
  8562. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8563. {
  8564. if(connectorIdIsNULL == FALSE)
  8565. {
  8566. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8567. {
  8568. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8569. sendMeterValuesRequest(connectorIdInt -1);
  8570. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8571. }
  8572. }
  8573. else
  8574. {
  8575. for(int idx=0;idx< gunTotalNumber;idx++)
  8576. {
  8577. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8578. sendMeterValuesRequest(idx);
  8579. }
  8580. }
  8581. }
  8582. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8583. {
  8584. if(connectorIdIsNULL == FALSE)
  8585. {
  8586. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8587. {
  8588. sendStatusNotificationRequest(connectorIdInt -1);
  8589. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8590. }
  8591. }
  8592. else
  8593. {
  8594. for(int idx=0;idx< gunTotalNumber;idx++)
  8595. sendStatusNotificationRequest(idx);
  8596. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8597. }
  8598. }
  8599. return result;
  8600. }
  8601. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8602. {
  8603. mtrace();
  8604. int result = FAIL;
  8605. char sstr[6]={0};
  8606. int connectorIdInt =0;
  8607. char comfirmstr[20]={0};
  8608. int c = 0;
  8609. char *loc;
  8610. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8611. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8612. c = 0;
  8613. loc = strstr(payload, "connectorId");
  8614. memset(sstr ,0, sizeof(sstr) );
  8615. while (loc[strlen("connectorId")+2+c] != '}')
  8616. {
  8617. sstr[c] = loc[strlen("connectorId")+2+c];
  8618. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8619. c++;
  8620. }
  8621. sstr[c] = '\0';
  8622. connectorIdInt = atoi(sstr);
  8623. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8624. if(gunTotalNumber == 0)
  8625. {
  8626. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8627. goto end;
  8628. }
  8629. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8630. {
  8631. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8632. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8633. goto end;
  8634. }
  8635. else
  8636. {
  8637. //check Transaction active
  8638. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8639. {
  8640. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8641. {
  8642. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8643. {
  8644. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8645. }
  8646. }
  8647. for (int index = 0; index < CCS_QUANTITY; index++)
  8648. {
  8649. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8650. {
  8651. //stop Transaction
  8652. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8653. }
  8654. }
  8655. for (int index = 0; index < GB_QUANTITY; index++)
  8656. {
  8657. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8658. {
  8659. //stop Transaction
  8660. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8661. }
  8662. }
  8663. }
  8664. else
  8665. {
  8666. for (int index = 0; index < AC_QUANTITY; index++)
  8667. {
  8668. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8669. {
  8670. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8671. }
  8672. }
  8673. }// END FOR AC ELSE
  8674. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8675. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8676. result = TRUE;
  8677. return result;
  8678. }
  8679. end:
  8680. //json_object_put(obj); --- remove temporally
  8681. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8682. return result;
  8683. }
  8684. static char UpdateFirmwarepayloadData[300]={0};
  8685. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8686. {
  8687. mtrace();
  8688. int result = FAIL;
  8689. pthread_t t;
  8690. sendUpdateFirmwareConfirmation(uuid);
  8691. memset(UpdateFirmwarepayloadData, 0, 300);
  8692. strcpy(UpdateFirmwarepayloadData, payload);
  8693. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8694. ////pthread_join(t, NULL); //
  8695. //pthread_detach(t);
  8696. //sendUpdateFirmwareConfirmation(uuid);
  8697. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8698. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8699. return result;
  8700. }
  8701. void *UpdateFirmwareProcess(void *data)
  8702. {
  8703. pthread_detach(pthread_self());
  8704. mtrace();
  8705. int retriesInt =0, retryIntervalInt=0;
  8706. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8707. int port=0;
  8708. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8709. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8710. //char comfirmstr[20];
  8711. int isSuccess = 0;
  8712. char ftpbuf[200];
  8713. char temp[100];
  8714. char * pch;
  8715. int retriesISNULL=FALSE;
  8716. int retryInterval=FALSE;
  8717. int c = 0;
  8718. //int i = 0;
  8719. char *loc;
  8720. char sstr[300]={ 0 };
  8721. char str[300]={ 0 };
  8722. //char *str = (char*) data; // ? ?輸入資 ?
  8723. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8724. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8725. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8726. //***************location **************/
  8727. loc = strstr(str, "location");
  8728. memset(sstr ,0, sizeof(sstr) );
  8729. c = 0;
  8730. while (loc[3+strlen("location")+c] != '\"')
  8731. {
  8732. sstr[c] = loc[3+strlen("location")+c];
  8733. c++;
  8734. }
  8735. sstr[c] = '\0';
  8736. strcpy(locationstr, sstr);
  8737. //***************retries**************/
  8738. c = 0;
  8739. loc = strstr(str, "retries");
  8740. if(loc == NULL)
  8741. {
  8742. retriesISNULL=TRUE;
  8743. }
  8744. else
  8745. {
  8746. memset(sstr ,0, sizeof(sstr) );
  8747. while (loc[strlen("retries")+2+c] != ',')
  8748. {
  8749. sstr[c] = loc[strlen("retries")+2+c];
  8750. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8751. c++;
  8752. }
  8753. sstr[c] = '\0';
  8754. }
  8755. if(retriesISNULL == FALSE)
  8756. {
  8757. retriesInt = atoi(sstr);
  8758. }
  8759. //***************retrieveDate **************/
  8760. loc = strstr(str, "retrieveDate");
  8761. memset(sstr ,0, sizeof(sstr) );
  8762. c = 0;
  8763. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8764. {
  8765. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8766. c++;
  8767. }
  8768. sstr[c] = '\0';
  8769. strcpy(retrieveDatestr, sstr);
  8770. //***************retryInterval **************/
  8771. c = 0;
  8772. loc = strstr(str, "retryInterval");
  8773. memset(sstr ,0, sizeof(sstr) );
  8774. if(loc == NULL)
  8775. {
  8776. retryInterval=TRUE;
  8777. }
  8778. else
  8779. {
  8780. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8781. {
  8782. sstr[c] = loc[strlen("retryInterval")+2+c];
  8783. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8784. c++;
  8785. }
  8786. sstr[c] = '\0';
  8787. }
  8788. if(retryInterval==FALSE)
  8789. {
  8790. retryIntervalInt = atoi(sstr);
  8791. }
  8792. memset(ftppath, 0, sizeof(ftppath));
  8793. memset(path, 0, sizeof(path));
  8794. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8795. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8796. if(strncmp(locationstr,"http", 4) == 0)
  8797. {
  8798. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8799. protocol, host, path);
  8800. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8801. // protocol, user, password, host, path);
  8802. sprintf(ftppath,"/%s", path);
  8803. //DEBUG_INFO("protocol =%s\n",protocol);
  8804. //DEBUG_INFO("host =%s\n",host);
  8805. //DEBUG_INFO("path =%s\n",path);
  8806. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8807. int ftppathlen=strlen(ftppath);
  8808. int i=1;
  8809. char filenametemp[50];
  8810. while(i < ftppathlen)
  8811. {
  8812. int len=ftppathlen-i;
  8813. if(ftppath[len]== 47) // '/' ascll code: 47
  8814. {
  8815. DEBUG_INFO("compare '/' all right\n");
  8816. break;
  8817. }
  8818. i=i+1;
  8819. }
  8820. memset(filenametemp, 0, sizeof(filenametemp));
  8821. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8822. filenametemp[i+1] = 0;
  8823. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8824. do{
  8825. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8826. sleep(retryIntervalInt);
  8827. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8828. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8829. if(!isSuccess)
  8830. {
  8831. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8832. }
  8833. else
  8834. {
  8835. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8836. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8837. isUpdateRequest = TRUE;
  8838. }
  8839. }
  8840. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8841. {
  8842. memset(ftpbuf, 0, sizeof(ftpbuf));
  8843. memset(temp, 0, sizeof(temp));
  8844. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8845. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8846. int ftppathlen=strlen(ftpbuf);
  8847. int i=1;
  8848. char filenametemp[50];
  8849. while(i < ftppathlen)
  8850. {
  8851. int len=ftppathlen-i;
  8852. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8853. {
  8854. DEBUG_INFO(" compare '/' all right\n");
  8855. break;
  8856. }
  8857. i=i+1;
  8858. }
  8859. memset(filenametemp, 0, sizeof(filenametemp));
  8860. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8861. filenametemp[i+1] = 0;
  8862. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8863. pch=strchr(temp,'@');
  8864. if(pch==NULL)
  8865. {
  8866. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8867. protocol, host, &port, path);
  8868. strcpy(user,"anonymous");
  8869. strcpy(password,"");
  8870. }
  8871. else
  8872. {
  8873. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8874. protocol, user, password, host, &port, path);
  8875. }
  8876. sscanf(host,"%[^/]%s",host1, path1);
  8877. sprintf(ftppath,"%s", path1);
  8878. //DEBUG_INFO("protocol =%s\n",protocol);
  8879. //DEBUG_INFO("user =%s\n",user);
  8880. //DEBUG_INFO("password =%s\n",password);
  8881. //DEBUG_INFO("host1 =%s\n",host1);
  8882. //DEBUG_INFO("port =%d\n",port);
  8883. //DEBUG_INFO("path1 =%s\n",path1);
  8884. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8885. //ftpFile(host, user, password, port, ftppath, fname);
  8886. //download firmware pthred
  8887. if(port == 0)
  8888. {
  8889. port = 21;
  8890. }
  8891. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8892. do{
  8893. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8894. sleep(retryIntervalInt);
  8895. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8896. if(!isSuccess)
  8897. {
  8898. //BulldogUtil.sleepMs(interval*1000);
  8899. DEBUG_INFO("Update firmware request and download file fail.\n");
  8900. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8901. }
  8902. else
  8903. {
  8904. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8905. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8906. isUpdateRequest = TRUE;
  8907. }
  8908. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8909. }
  8910. else
  8911. {
  8912. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8913. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8914. }
  8915. pthread_exit(NULL);
  8916. }
  8917. //==========================================
  8918. // Handle server response routine
  8919. //==========================================
  8920. void handleAuthorizeResponse(char *payload, int gun_index)
  8921. {
  8922. mtrace();
  8923. char expiryDatestr[30]={0};
  8924. char parentIdTagstr[20]={0};
  8925. char statusstr[20]={0};
  8926. char expiryDatestrtemp[30]={0};
  8927. char parentIdTagstrtemp[20]={0};
  8928. char IdTagstrtemp[20]={0};
  8929. char statusstrtemp[20]={0};
  8930. int expiryDateISNULL=FALSE;
  8931. int parentIdTagISNULL=FALSE;
  8932. char sstr[160]={ 0 };
  8933. char* filename = AuthorizationCache_JSON;
  8934. char tempfile[] = "/Storage/OCPP/temp.json";
  8935. int c = 0;
  8936. char *loc;
  8937. int resultRename=0;
  8938. int responseIdTagInfoAsZero= 0;
  8939. char rmFileCmd[50]={0};
  8940. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8941. //***********expiryDate*************/
  8942. loc = strstr(payload, "expiryDate");
  8943. memset(sstr ,0, sizeof(sstr) );
  8944. c = 0;
  8945. if(loc == NULL)
  8946. {
  8947. expiryDateISNULL = TRUE;
  8948. }
  8949. else
  8950. {
  8951. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8952. {
  8953. sstr[c] = loc[3+strlen("expiryDate")+c];
  8954. c++;
  8955. }
  8956. sstr[c] = '\0';
  8957. strcpy(expiryDatestr, sstr);
  8958. }
  8959. //***********parentIdTag*************/
  8960. loc = strstr(payload, "parentIdTag");
  8961. memset(sstr ,0, sizeof(sstr) );
  8962. c = 0;
  8963. if(loc == NULL)
  8964. {
  8965. parentIdTagISNULL = TRUE;
  8966. }
  8967. else
  8968. {
  8969. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8970. {
  8971. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8972. c++;
  8973. }
  8974. sstr[c] = '\0';
  8975. strcpy(parentIdTagstr, sstr);
  8976. }
  8977. //***********status*************/
  8978. loc = strstr(payload, "status");
  8979. memset(sstr ,0, sizeof(sstr) );
  8980. c = 0;
  8981. while (loc[3+strlen("status")+c] != '\"')
  8982. {
  8983. sstr[c] = loc[3+strlen("status")+c];
  8984. c++;
  8985. }
  8986. sstr[c] = '\0';
  8987. strcpy(statusstr, sstr);
  8988. if(expiryDateISNULL == FALSE)
  8989. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8990. if(parentIdTagISNULL == FALSE)
  8991. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8992. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8993. //Update idTag information to authorization cache if supproted
  8994. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8995. {
  8996. if((access(filename,F_OK))!=-1)
  8997. {
  8998. printf("AuthorizationCache exist.\n");
  8999. }
  9000. else
  9001. {
  9002. printf("AuthorizationCache not exist\n");
  9003. FILE *log = fopen(filename, "w+");
  9004. if(log == NULL)
  9005. {
  9006. printf("log is NULL\n");
  9007. goto out;
  9008. }
  9009. else
  9010. {
  9011. fclose(log);
  9012. }
  9013. }
  9014. FILE *infile;
  9015. FILE *outfile;
  9016. // open file for writing
  9017. infile = fopen (filename, "r");
  9018. outfile = fopen (tempfile, "w");
  9019. //*检测到文件结束标识返回1,否则返回0。*/
  9020. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9021. int c;
  9022. c = fgetc(infile);
  9023. //DEBUG_INFO("c:%d\n",c);
  9024. rewind(infile);
  9025. if(c == EOF)
  9026. {
  9027. DEBUG_INFO("Orignal File is NULL\n");
  9028. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9029. {
  9030. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9031. }
  9032. else
  9033. {
  9034. strcpy(expiryDatestrtemp, "");
  9035. }
  9036. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9037. {
  9038. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9039. }
  9040. else
  9041. {
  9042. //write Authorize IdTag
  9043. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9044. }
  9045. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9046. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9047. fclose(infile);
  9048. fclose(outfile);
  9049. sprintf(rmFileCmd,"rm -f %s",filename);
  9050. system(rmFileCmd);
  9051. resultRename = rename(tempfile, filename);
  9052. if(resultRename == 0)
  9053. {
  9054. printf("File renamed successfully");
  9055. }
  9056. else
  9057. {
  9058. printf("Error: unable to rename the file");
  9059. }
  9060. }
  9061. else
  9062. {
  9063. char buf[160]={0};
  9064. while (fgets(buf, sizeof(buf), infile) != NULL)
  9065. {
  9066. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9067. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9068. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9069. memset(statusstr, 0, sizeof(statusstrtemp));
  9070. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9071. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9072. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9073. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9074. //------------------IdTag-----------------------
  9075. loc = strstr(buf, "idTag");
  9076. memset(sstr ,0, sizeof(sstr) );
  9077. c = 0;
  9078. while (loc[3+strlen("idTag")+c] != '\"')
  9079. {
  9080. sstr[c] = loc[3+strlen("idTag")+c];
  9081. c++;
  9082. }
  9083. sstr[c] = '\0';
  9084. strcpy(IdTagstrtemp,sstr);
  9085. //*********************expiryDate***************/
  9086. loc = strstr(buf, "expiryDate");
  9087. memset(sstr ,0, sizeof(sstr) );
  9088. c = 0;
  9089. while (loc[3+strlen("expiryDate")+c] != '\"')
  9090. {
  9091. sstr[c] = loc[3+strlen("expiryDate")+c];
  9092. c++;
  9093. }
  9094. sstr[c] = '\0';
  9095. strcpy(expiryDatestr,sstr);
  9096. //*********************parentIdTag***************/
  9097. loc = strstr(buf, "parentIdTag");
  9098. memset(sstr ,0, sizeof(sstr) );
  9099. c = 0;
  9100. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9101. {
  9102. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9103. c++;
  9104. }
  9105. sstr[c] = '\0';
  9106. strcpy(parentIdTagstr,sstr);
  9107. //*********************status***************/
  9108. loc = strstr(buf, "status");
  9109. memset(sstr ,0, sizeof(sstr) );
  9110. c = 0;
  9111. while (loc[3+strlen("status")+c] != '\"')
  9112. {
  9113. sstr[c] = loc[3+strlen("status")+c];
  9114. c++;
  9115. }
  9116. sstr[c] = '\0';
  9117. strcpy(statusstr,sstr);
  9118. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9119. {
  9120. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9121. responseIdTagInfoAsZero = 1;
  9122. }
  9123. else
  9124. {
  9125. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9126. }
  9127. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9128. {
  9129. //modify item
  9130. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9131. {
  9132. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9133. }
  9134. else
  9135. {
  9136. strcpy(expiryDatestrtemp, "");
  9137. }
  9138. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9139. {
  9140. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9141. }
  9142. else
  9143. {
  9144. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9145. }
  9146. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9147. }
  9148. else
  9149. {
  9150. //wrie original item
  9151. strcpy(expiryDatestrtemp, expiryDatestr);
  9152. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9153. strcpy(statusstrtemp, statusstr);
  9154. }
  9155. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9156. }
  9157. fclose(infile);
  9158. fclose(outfile);
  9159. sprintf(rmFileCmd,"rm -f %s",filename);
  9160. system(rmFileCmd);
  9161. resultRename = rename(tempfile, filename);
  9162. if(resultRename == 0)
  9163. {
  9164. DEBUG_INFO("File renamed successfully");
  9165. }
  9166. else
  9167. {
  9168. DEBUG_INFO("Error: unable to rename the file");
  9169. }
  9170. }
  9171. }
  9172. out:
  9173. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9174. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9175. authorizeRetryTimes = 0;
  9176. }
  9177. void handleBootNotificationResponse(char *payload, int gun_index)
  9178. {
  9179. mtrace();
  9180. char sstr[140]={ 0 };//sstr[200]={ 0 };
  9181. char statusStr[12]={0};
  9182. char currentTimeStr[30]={0};
  9183. char *loc;
  9184. int intervalInt = 0;
  9185. int c = 0;
  9186. //double diff_t;
  9187. struct tm tp;
  9188. char buf[28]={0};
  9189. char timebuf[50]={0};
  9190. DEBUG_INFO("handleBootNotificationResponse ...\n");
  9191. //*** interval ****/
  9192. c = 0;
  9193. loc = strstr(payload, "interval");
  9194. //printf("loc=%s\n",loc);
  9195. memset(sstr ,0, sizeof(sstr) );
  9196. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  9197. {
  9198. sstr[c] = loc[strlen("interval")+2+c];
  9199. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9200. c++;
  9201. }
  9202. sstr[c] = '\0';
  9203. //DEBUG_INFO("id=%d\n",atoi(sstr));
  9204. intervalInt = atoi(sstr);
  9205. //***status ****/
  9206. loc = strstr(payload, "status");
  9207. memset(sstr ,0, sizeof(sstr) );
  9208. c = 0;
  9209. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  9210. {
  9211. sstr[c] = loc[3+strlen("status")+c];
  9212. c++;
  9213. }
  9214. sstr[c] = '\0';
  9215. strcpy(statusStr, sstr);
  9216. //***currentTime ****/
  9217. loc = strstr(payload, "currentTime");
  9218. //printf("loc=%s\n",loc);
  9219. memset(sstr ,0, sizeof(sstr) );
  9220. c = 0;
  9221. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  9222. {
  9223. sstr[c] = loc[3+strlen("currentTime")+c];
  9224. c++;
  9225. }
  9226. sstr[c] = '\0';
  9227. strcpy(currentTimeStr, sstr);
  9228. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9229. HeartBeatWaitTime = BootNotificationInterval;
  9230. clientTime.Heartbeat=time((time_t*)NULL);
  9231. //write back to ShmOCPP16Data->BootNotification
  9232. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9233. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9234. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9235. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  9236. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  9237. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  9238. {
  9239. server_sign = TRUE;
  9240. server_pending =FALSE;
  9241. }
  9242. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9243. {
  9244. server_pending = TRUE;
  9245. }
  9246. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9247. tp.tm_isdst = -1;
  9248. //time_t utc = mktime(&tp);
  9249. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9250. memset(timebuf, 0, sizeof timebuf);
  9251. sprintf(timebuf,"date -s '%s'",buf);
  9252. //DEBUG_INFO("timebuf=%s\n",timebuf);
  9253. system(timebuf);
  9254. //==============================================
  9255. // RTC sync
  9256. //==============================================
  9257. system("/sbin/hwclock -w --systohc");
  9258. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9259. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9260. }
  9261. void handleDataTransferResponse(char *payload, int gun_index)
  9262. {
  9263. char sstr[160]={0};//sstr[200]={ 0 };
  9264. int c = 0;
  9265. char *loc;
  9266. DEBUG_INFO("handleDataTransferResponse ...\n");
  9267. loc = strstr(payload, "status");
  9268. printf("loc=%s\n",loc);
  9269. c = 0;
  9270. while (loc[3+strlen("status")+c] != '\"')
  9271. {
  9272. sstr[c] = loc[3+strlen("status")+c];
  9273. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9274. c++;
  9275. }
  9276. sstr[c] = '\0';
  9277. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9278. }
  9279. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9280. {
  9281. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9282. //struct json_object *obj;
  9283. // obj = json_tokener_parse(payload);
  9284. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9285. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9286. //No fields are defined.
  9287. }
  9288. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9289. {
  9290. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9291. //struct json_object *obj;
  9292. // obj = json_tokener_parse(payload);
  9293. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9294. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9295. //No fields are defined.
  9296. }
  9297. void handleHeartbeatResponse(char *payload, int gun_index)
  9298. {
  9299. mtrace();
  9300. //double diff_t;
  9301. struct tm tp;
  9302. char buf[28]={0};
  9303. char timebuf[50]={0};
  9304. char sstr[30]={ 0 };
  9305. int c = 0;
  9306. char *loc;
  9307. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  9308. c = 0;
  9309. loc = strstr(payload, "currentTime");
  9310. memset(sstr ,0, sizeof(sstr) );
  9311. while (loc[3+strlen("currentTime")+c] != '\"')
  9312. {
  9313. sstr[c] = loc[3+strlen("currentTime")+c];
  9314. c++;
  9315. }
  9316. sstr[c] = '\0';
  9317. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  9318. // #ifdef SystemLogMessage
  9319. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  9320. // #endif
  9321. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9322. tp.tm_isdst = -1;
  9323. //time_t utc = mktime(&tp);
  9324. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9325. memset(timebuf, 0, sizeof timebuf);
  9326. sprintf(timebuf,"date -s '%s'",buf);
  9327. system(timebuf);
  9328. //==============================================
  9329. // RTC sync
  9330. //==============================================
  9331. system("/sbin/hwclock -w --systohc");
  9332. if(FirstHeartBeat == 0)
  9333. {
  9334. FirstHeartBeat = 1;
  9335. }
  9336. HeartBeatWithNOResponse = 0;
  9337. //--------Print Out HeartBeat log
  9338. {
  9339. double diff_t;
  9340. struct tm tp,tp1;
  9341. // BootNotification Receive Time
  9342. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9343. tp.tm_isdst = -1;
  9344. time_t BootNotificationReceiveTime = mktime(&tp);
  9345. //HeartBeat Receive Time
  9346. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9347. tp1.tm_isdst = -1;
  9348. time_t HeartBeatReceiveTime = mktime(&tp1);
  9349. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9350. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9351. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9352. {
  9353. HeartBeatCountPerHour = (int)diff_t / 3600;
  9354. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9355. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9356. }
  9357. }
  9358. }
  9359. void handleMeterValuesResponse(char *payload, int gun_index)
  9360. {
  9361. mtrace();
  9362. //struct json_object *obj;
  9363. DEBUG_INFO("handleMeterValuesResponse ...\n");
  9364. //No fields are defined.
  9365. }
  9366. void handleStartTransactionResponse(char *payload, int gun_index)
  9367. {
  9368. mtrace();
  9369. char sstr[28]={ 0 };
  9370. int c = 0;
  9371. char *loc;
  9372. int transactionIdInt = 0;
  9373. FILE *outfile;
  9374. char data[100]={0};
  9375. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  9376. DEBUG_INFO("handleStartTransactionResponse\n");
  9377. //****************expiryDate********************/
  9378. loc = strstr(payload, "expiryDate");
  9379. if(loc == NULL)
  9380. {
  9381. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  9382. }
  9383. else
  9384. {
  9385. c = 0;
  9386. memset(sstr ,0, sizeof(sstr) );
  9387. while (loc[3+strlen("expiryDate")+c] != '\"')
  9388. {
  9389. sstr[c] = loc[3+strlen("expiryDate")+c];
  9390. c++;
  9391. }
  9392. sstr[c] = '\0';
  9393. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9394. }
  9395. //****************parentIdTag********************/
  9396. loc = strstr(payload, "parentIdTag");
  9397. if(loc == NULL)
  9398. {
  9399. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  9400. }
  9401. else
  9402. {
  9403. c = 0;
  9404. memset(sstr ,0, sizeof(sstr) );
  9405. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9406. {
  9407. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9408. c++;
  9409. }
  9410. sstr[c] = '\0';
  9411. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9412. }
  9413. //****************status********************/
  9414. loc = strstr(payload, "status");
  9415. if(loc == NULL)
  9416. {
  9417. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  9418. }
  9419. else
  9420. {
  9421. c = 0;
  9422. memset(sstr ,0, sizeof(sstr) );
  9423. while (loc[3+strlen("status")+c] != '\"')
  9424. {
  9425. sstr[c] = loc[3+strlen("status")+c];
  9426. c++;
  9427. }
  9428. sstr[c] = '\0';
  9429. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9430. }
  9431. //****************transactionId********************/
  9432. c=0;
  9433. loc = strstr(payload, "transactionId");
  9434. memset(sstr ,0, sizeof(sstr) );
  9435. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  9436. {
  9437. sstr[c] = loc[strlen("transactionId")+2+c];
  9438. c++;
  9439. }
  9440. sstr[c] = '\0';
  9441. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  9442. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  9443. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9444. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9445. //-----------Start : write to the Queue TransactionId file -----------------//
  9446. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9447. {
  9448. //DEBUG_INFO("QueueTransactionId exist.\n");
  9449. }
  9450. else
  9451. {
  9452. //DEBUG_INFO("QueueTransactionId not exist\n");
  9453. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9454. if(log == NULL)
  9455. {
  9456. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9457. return ;
  9458. }
  9459. else
  9460. {
  9461. fclose(log);
  9462. }
  9463. }
  9464. // open file for writing
  9465. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9466. //DEBUG_INFO("data=%s\n",data);
  9467. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9468. fputs(data, outfile);
  9469. //fputs("\n", outfile);
  9470. fclose (outfile);
  9471. //-------------End: write to the Queue TransactionId file------------------------------------------//
  9472. TransactionId[gun_index] = transactionIdInt;
  9473. //DEBUG_INFO("gun_index: %d\n", gun_index);
  9474. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  9475. #ifdef SystemLogMessage
  9476. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9477. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9478. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9479. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9480. #endif
  9481. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  9482. {
  9483. //add Charging Record
  9484. SettingChargingRecord(gun_index, transactionIdInt);
  9485. }
  9486. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  9487. }
  9488. void handleStatusNotificationResponse(char *payload, int gun_index)
  9489. {
  9490. mtrace();
  9491. printf("handleStatusNotificationResponse\n");
  9492. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9493. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9494. }
  9495. void handleStopTransactionnResponse(char *payload, int gun_index)
  9496. {
  9497. mtrace();
  9498. char sstr[30]={ 0 };
  9499. int c = 0;
  9500. char *loc;
  9501. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  9502. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9503. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9504. loc = strstr(payload, "idTagInfo");
  9505. //***********************idTagInfo************************/
  9506. if(loc != NULL)
  9507. {
  9508. //***********************expiryDate************************/
  9509. loc = strstr(payload, "expiryDate");
  9510. if(loc != NULL)
  9511. {
  9512. memset(sstr ,0, sizeof(sstr) );
  9513. c = 0;
  9514. while (loc[3+strlen("expiryDate")+c] != '\"')
  9515. {
  9516. sstr[c] = loc[3+strlen("expiryDate")+c];
  9517. c++;
  9518. }
  9519. sstr[c] = '\0';
  9520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9521. }
  9522. //***********************parentIdTag************************/
  9523. loc = strstr(payload, "parentIdTag");
  9524. if(loc != NULL)
  9525. {
  9526. memset(sstr ,0, sizeof(sstr) );
  9527. c = 0;
  9528. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9529. {
  9530. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9531. c++;
  9532. }
  9533. sstr[c] = '\0';
  9534. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9535. }
  9536. //***********************status************************/
  9537. loc = strstr(payload, "status");
  9538. memset(sstr ,0, sizeof(sstr) );
  9539. c = 0;
  9540. while (loc[3+strlen("status")+c] != '\"')
  9541. {
  9542. sstr[c] = loc[3+strlen("status")+c];
  9543. c++;
  9544. }
  9545. sstr[c] = '\0';
  9546. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9547. }
  9548. #ifdef SystemLogMessage
  9549. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9550. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9551. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9552. #endif
  9553. }
  9554. //==========================================
  9555. // Handle Error routine
  9556. //==========================================
  9557. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9558. {
  9559. mtrace();
  9560. #ifdef SystemLogMessage
  9561. DEBUG_INFO("errorCode: %s\n", errorCode);
  9562. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9563. DEBUG_INFO("errorDetails: %s\n", payload);
  9564. #endif
  9565. }
  9566. //===============================================
  9567. // Common routine
  9568. //===============================================
  9569. int initialConfigurationTable(void)
  9570. {
  9571. FILE *fp;
  9572. FILE *outfile;
  9573. char str[200]={0};
  9574. char sstr[100]={0};
  9575. int c = 0;
  9576. char *loc;
  9577. printf("initialConfigurationTable \n");
  9578. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9579. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9580. {
  9581. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9582. if(outfile == NULL) {
  9583. DEBUG_INFO("Error opening file");
  9584. return FALSE;
  9585. }
  9586. /*Core Profile*/
  9587. //AllowOfflineTxForUnknownId
  9588. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9589. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  9593. //AuthorizationCacheEnabled
  9594. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9598. //AuthorizeRemoteTxRequests
  9599. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9603. //BlinkRepeat
  9604. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9608. //ClockAlignedDataInterval
  9609. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9613. //ConnectionTimeOut
  9614. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9618. //GetConfigurationMaxKeys
  9619. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9623. // HeartbeatInterval
  9624. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9628. // LightIntensity
  9629. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9633. // LocalAuthorizeOffline
  9634. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9638. // LocalPreAuthorize
  9639. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9643. // MaxEnergyOnInvalidId
  9644. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9647. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9649. // MeterValuesAlignedData
  9650. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9654. // MeterValuesAlignedDataMaxLength
  9655. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9659. // MeterValuesSampledData
  9660. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9664. // MeterValuesSampledDataMaxLength
  9665. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9669. // MeterValueSampleInterval
  9670. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9674. // MinimumStatusDuration
  9675. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9679. // NumberOfConnectors
  9680. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9682. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9683. {
  9684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9685. }
  9686. else
  9687. {
  9688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9689. }
  9690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9691. // ResetRetries
  9692. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9696. // ConnectorPhaseRotation
  9697. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9701. // ConnectorPhaseRotationMaxLength
  9702. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9706. // StopTransactionOnEVSideDisconnect
  9707. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9711. // StopTransactionOnInvalidId
  9712. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9716. // StopTxnAlignedData
  9717. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9721. // StopTxnAlignedDataMaxLength
  9722. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9726. // StopTxnSampledData
  9727. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9731. // StopTxnSampledDataMaxLength
  9732. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9734. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9735. {
  9736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9737. }
  9738. else
  9739. {
  9740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9741. }
  9742. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9744. // SupportedFeatureProfiles
  9745. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9749. // SupportedFeatureProfilesMaxLength
  9750. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9754. // TransactionMessageAttempts
  9755. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9758. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9760. // TransactionMessageRetryInterval
  9761. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9764. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9766. // UnlockConnectorOnEVSideDisconnect
  9767. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9771. // WebSocketPingInterval
  9772. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9776. //* Local Auth List Management Profile*/
  9777. #if 0
  9778. //For OCTT Test Case
  9779. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9782. #endif
  9783. #if 1
  9784. //LocalAuthListEnabled
  9785. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9789. #endif
  9790. //LocalAuthListMaxLength
  9791. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9795. //SendLocalListMaxLength
  9796. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9800. //ReserveConnectorZeroSupported
  9801. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9805. //* Smart Charging Profile */
  9806. //ChargeProfileMaxStackLevel
  9807. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9811. // ChargingScheduleAllowedChargingRateUnit
  9812. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9816. // ChargingScheduleMaxPeriods
  9817. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9821. // ConnectorSwitch3to1PhaseSupported
  9822. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9826. // MaxChargingProfilesInstalled
  9827. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9831. fclose(outfile);
  9832. }
  9833. else
  9834. {
  9835. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9836. char keystr[60]={0};
  9837. char readonlystr[10]={0};
  9838. char valuestr[100]={0};
  9839. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9840. if(fp == NULL) {
  9841. DEBUG_INFO("Error opening file");
  9842. return FALSE;
  9843. }
  9844. while( fgets (str, sizeof(str), fp)!=NULL )
  9845. {
  9846. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9847. //*************************key*********************************/
  9848. loc = strstr(str, "key");
  9849. c = 0;
  9850. memset(sstr ,0, sizeof(sstr) );
  9851. while (loc[strlen("key")+3+c] != '\"')
  9852. {
  9853. sstr[c] = loc[strlen("key")+3+c];
  9854. c++;
  9855. }
  9856. sstr[c] = '\0';
  9857. strcpy(keystr,sstr);
  9858. //*************************readonly*********************************/
  9859. loc = strstr(str, "readonly");
  9860. c = 0;
  9861. memset(sstr ,0, sizeof(sstr) );
  9862. while (loc[strlen("readonly")+2+c] != ',')
  9863. {
  9864. sstr[c] = loc[strlen("readonly")+2+c];
  9865. c++;
  9866. }
  9867. sstr[c] = '\0';
  9868. strcpy(readonlystr,sstr);
  9869. //*************************value*********************************/
  9870. loc = strstr(str, "value");
  9871. c = 0;
  9872. memset(sstr ,0, sizeof(sstr) );
  9873. while (loc[strlen("value")+3+c] != '\"')
  9874. {
  9875. sstr[c] = loc[strlen("value")+3+c];
  9876. c++;
  9877. }
  9878. sstr[c] = '\0';
  9879. strcpy(valuestr,sstr);
  9880. // DEBUG_INFO("keystr=%s\n",keystr);
  9881. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9882. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9883. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9884. {
  9885. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9886. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9888. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9889. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9890. }
  9891. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9892. {
  9893. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9894. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9896. }
  9897. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9898. {
  9899. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9901. }
  9902. if(strcmp(keystr, "BlinkRepeat") == 0)
  9903. {
  9904. //Charger.BlinkRepeat = Integer.parseInt(value);
  9905. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9907. }
  9908. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9909. {
  9910. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9912. }
  9913. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9914. {
  9915. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9917. }
  9918. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9919. {
  9920. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9922. }
  9923. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9924. {
  9925. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9927. HeartBeatWaitTime = atoi(valuestr);
  9928. }
  9929. if(strcmp(keystr, "LightIntensity") == 0)
  9930. {
  9931. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9933. }
  9934. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9935. {
  9936. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9938. }
  9939. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9940. {
  9941. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9943. }
  9944. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9945. {
  9946. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9948. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9949. }
  9950. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9951. {
  9952. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9954. }
  9955. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9956. {
  9957. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9959. }
  9960. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9961. {
  9962. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9964. }
  9965. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9966. {
  9967. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9969. }
  9970. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9971. {
  9972. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9974. }
  9975. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9976. {
  9977. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9979. }
  9980. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9981. {
  9982. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9984. }
  9985. if(strcmp(keystr, "ResetRetries") == 0)
  9986. {
  9987. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9989. }
  9990. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9991. {
  9992. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9994. }
  9995. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9996. {
  9997. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9999. }
  10000. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10001. {
  10002. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10004. }
  10005. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10006. {
  10007. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10009. }
  10010. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10011. {
  10012. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10014. }
  10015. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10016. {
  10017. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10019. }
  10020. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10021. {
  10022. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10024. }
  10025. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10026. {
  10027. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10029. }
  10030. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10031. {
  10032. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10034. }
  10035. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10036. {
  10037. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10039. }
  10040. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10041. {
  10042. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10044. TransactionMessageAttemptsValue = atoi(valuestr);
  10045. }
  10046. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10047. {
  10048. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10050. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10051. }
  10052. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10053. {
  10054. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10056. }
  10057. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10058. {
  10059. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10061. }
  10062. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10063. {
  10064. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10066. }
  10067. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10068. {
  10069. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10071. }
  10072. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10073. {
  10074. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10076. }
  10077. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10078. {
  10079. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10081. }
  10082. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10083. {
  10084. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10086. }
  10087. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10088. {
  10089. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10091. }
  10092. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10093. {
  10094. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10096. }
  10097. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10098. {
  10099. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10101. }
  10102. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10103. {
  10104. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10106. }
  10107. }
  10108. fclose(fp);
  10109. }
  10110. return 0;
  10111. }
  10112. void StoreConfigurationTable(void)
  10113. {
  10114. FILE *outfile;
  10115. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10116. if(outfile == NULL)
  10117. {
  10118. DEBUG_INFO("Error opening file");
  10119. return ;
  10120. }
  10121. /*Core Profile*/
  10122. //AllowOfflineTxForUnknownId
  10123. /*
  10124. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10125. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10128. */
  10129. //DEBUG_INFO("data=%s\n",data);
  10130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10131. //AuthorizationCacheEnabled
  10132. /*
  10133. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10136. */
  10137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10138. //AuthorizeRemoteTxRequests
  10139. /*
  10140. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10143. */
  10144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10145. //BlinkRepeat
  10146. /*
  10147. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10150. */
  10151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10152. //ClockAlignedDataInterval
  10153. /*
  10154. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10157. */
  10158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10159. //ConnectionTimeOut
  10160. /*
  10161. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10164. */
  10165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10166. //GetConfigurationMaxKeys
  10167. /*
  10168. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10171. */
  10172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10173. // HeartbeatInterval
  10174. /*
  10175. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10178. */
  10179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10180. // LightIntensity
  10181. /*
  10182. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10185. */
  10186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10187. // LocalAuthorizeOffline
  10188. /*
  10189. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10192. */
  10193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10194. // LocalPreAuthorize
  10195. /*
  10196. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10199. */
  10200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10201. // MaxEnergyOnInvalidId
  10202. /*
  10203. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10206. */
  10207. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10209. // MeterValuesAlignedData
  10210. /*
  10211. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10214. */
  10215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10216. // MeterValuesAlignedDataMaxLength
  10217. /*
  10218. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10221. */
  10222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10223. // MeterValuesSampledData
  10224. /*
  10225. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10228. */
  10229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10230. // MeterValuesSampledDataMaxLength
  10231. /*
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10235. */
  10236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10237. // MeterValueSampleInterval
  10238. /*
  10239. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10242. */
  10243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10244. // MinimumStatusDuration
  10245. /*
  10246. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10249. */
  10250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10251. // NumberOfConnectors
  10252. /*
  10253. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10255. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10256. {
  10257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10258. }
  10259. else
  10260. {
  10261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10262. }
  10263. */
  10264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10265. // ResetRetries
  10266. /*
  10267. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10270. */
  10271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10272. // ConnectorPhaseRotation
  10273. /*
  10274. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10277. */
  10278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10279. // ConnectorPhaseRotationMaxLength
  10280. /*
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10284. */
  10285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10286. // StopTransactionOnEVSideDisconnect
  10287. /*
  10288. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10291. */
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10293. // StopTransactionOnInvalidId
  10294. /*
  10295. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10298. */
  10299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10300. // StopTxnAlignedData
  10301. /*
  10302. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10305. */
  10306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10307. // StopTxnAlignedDataMaxLength
  10308. /*
  10309. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10312. */
  10313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10314. // StopTxnSampledData
  10315. /*
  10316. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10319. */
  10320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10321. // StopTxnSampledDataMaxLength
  10322. /*
  10323. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10326. */
  10327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10328. // SupportedFeatureProfiles
  10329. /*
  10330. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10333. */
  10334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10335. // SupportedFeatureProfilesMaxLength
  10336. /*
  10337. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10340. */
  10341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10342. // TransactionMessageAttempts
  10343. /*
  10344. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10347. */
  10348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10349. // TransactionMessageRetryInterval
  10350. /*
  10351. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10354. */
  10355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10356. // UnlockConnectorOnEVSideDisconnect
  10357. /*
  10358. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10361. */
  10362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10363. // WebSocketPingInterval
  10364. /*
  10365. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10368. */
  10369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10370. //* Local Auth List Management Profile*/
  10371. //LocalAuthListEnabled
  10372. /*
  10373. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10376. */
  10377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10378. //LocalAuthListMaxLength
  10379. /*
  10380. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10383. */
  10384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10385. //SendLocalListMaxLength
  10386. /*
  10387. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10390. */
  10391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10392. //ReserveConnectorZeroSupported
  10393. /*
  10394. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10397. */
  10398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10399. //* Smart Charging Profile */
  10400. //ChargeProfileMaxStackLevel
  10401. /*
  10402. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10405. */
  10406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10407. // ChargingScheduleAllowedChargingRateUnit
  10408. /*
  10409. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10412. */
  10413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10414. // ChargingScheduleMaxPeriods
  10415. /*
  10416. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10419. */
  10420. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10421. // ConnectorSwitch3to1PhaseSupported
  10422. /*
  10423. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10426. */
  10427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10428. // MaxChargingProfilesInstalled
  10429. /*
  10430. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  10433. */
  10434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10435. fclose(outfile);
  10436. }
  10437. void getKeyValue(char *keyReq)
  10438. {
  10439. int isEmpty = FALSE;
  10440. int isKnowKey = FALSE;
  10441. //int unKnowIndex = 0;
  10442. DEBUG_INFO("getKeyValue \n");
  10443. DEBUG_INFO("keyReq=%s \n",keyReq);
  10444. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10445. isEmpty = TRUE;
  10446. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10447. {
  10448. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  10449. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10452. {
  10453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10454. }
  10455. else
  10456. {
  10457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10458. }
  10459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10460. isKnowKey = TRUE;
  10461. }
  10462. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10463. {
  10464. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10466. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10467. {
  10468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10469. }
  10470. else
  10471. {
  10472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10473. }
  10474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10475. isKnowKey = TRUE;
  10476. }
  10477. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10478. {
  10479. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10482. {
  10483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10484. }
  10485. else
  10486. {
  10487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10488. }
  10489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10490. isKnowKey = TRUE;
  10491. }
  10492. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10493. {
  10494. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10497. {
  10498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10499. }
  10500. else
  10501. {
  10502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10503. }
  10504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10505. isKnowKey = TRUE;
  10506. }
  10507. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10508. {
  10509. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10511. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10512. {
  10513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10514. }
  10515. else
  10516. {
  10517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10518. }
  10519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10520. isKnowKey = TRUE;
  10521. }
  10522. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10523. {
  10524. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10527. {
  10528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10529. }
  10530. else
  10531. {
  10532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10533. }
  10534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10535. isKnowKey = TRUE;
  10536. }
  10537. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10538. {
  10539. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10542. {
  10543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10544. }
  10545. else
  10546. {
  10547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10548. }
  10549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10550. isKnowKey = TRUE;
  10551. }
  10552. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10553. {
  10554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10557. {
  10558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10559. }
  10560. else
  10561. {
  10562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10563. }
  10564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10565. isKnowKey = TRUE;
  10566. }
  10567. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10568. {
  10569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10572. {
  10573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10574. }
  10575. else
  10576. {
  10577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10578. }
  10579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10580. isKnowKey = TRUE;
  10581. }
  10582. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10583. {
  10584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10587. {
  10588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10589. }
  10590. else
  10591. {
  10592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10593. }
  10594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10595. isKnowKey = TRUE;
  10596. }
  10597. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10598. {
  10599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10602. {
  10603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10604. }
  10605. else
  10606. {
  10607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10608. }
  10609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10610. isKnowKey = TRUE;
  10611. }
  10612. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10613. {
  10614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10617. {
  10618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10619. }
  10620. else
  10621. {
  10622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10623. }
  10624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10625. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10626. isKnowKey = TRUE;
  10627. }
  10628. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10629. {
  10630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10633. {
  10634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10635. }
  10636. else
  10637. {
  10638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10639. }
  10640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10641. isKnowKey = TRUE;
  10642. }
  10643. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10644. {
  10645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10648. {
  10649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10650. }
  10651. else
  10652. {
  10653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10654. }
  10655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10656. isKnowKey = TRUE;
  10657. }
  10658. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10659. {
  10660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10663. {
  10664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10665. }
  10666. else
  10667. {
  10668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10669. }
  10670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10671. isKnowKey = TRUE;
  10672. }
  10673. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10674. {
  10675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10678. {
  10679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10680. }
  10681. else
  10682. {
  10683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10684. }
  10685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10686. isKnowKey = TRUE;
  10687. }
  10688. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10689. {
  10690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10693. {
  10694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10695. }
  10696. else
  10697. {
  10698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10699. }
  10700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10701. isKnowKey = TRUE;
  10702. }
  10703. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10704. {
  10705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10708. {
  10709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10710. }
  10711. else
  10712. {
  10713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10714. }
  10715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10716. isKnowKey = TRUE;
  10717. }
  10718. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10719. {
  10720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10723. {
  10724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10725. }
  10726. else
  10727. {
  10728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10729. }
  10730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10731. isKnowKey = TRUE;
  10732. }
  10733. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10734. {
  10735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10738. {
  10739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10740. }
  10741. else
  10742. {
  10743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10744. }
  10745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10746. isKnowKey = TRUE;
  10747. }
  10748. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10749. {
  10750. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10753. {
  10754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10755. }
  10756. else
  10757. {
  10758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10759. }
  10760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10761. isKnowKey = TRUE;
  10762. }
  10763. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10764. {
  10765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10768. {
  10769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10770. }
  10771. else
  10772. {
  10773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10774. }
  10775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10776. isKnowKey = TRUE;
  10777. }
  10778. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10779. {
  10780. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10783. {
  10784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10785. }
  10786. else
  10787. {
  10788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10789. }
  10790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10791. isKnowKey = TRUE;
  10792. }
  10793. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10794. {
  10795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10798. {
  10799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10800. }
  10801. else
  10802. {
  10803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10804. }
  10805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10806. isKnowKey = TRUE;
  10807. }
  10808. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10809. {
  10810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10813. {
  10814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10815. }
  10816. else
  10817. {
  10818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10819. }
  10820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10821. isKnowKey = TRUE;
  10822. }
  10823. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10824. {
  10825. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10828. {
  10829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10830. }
  10831. else
  10832. {
  10833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10834. }
  10835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10836. isKnowKey = TRUE;
  10837. }
  10838. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10839. {
  10840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10843. {
  10844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10845. }
  10846. else
  10847. {
  10848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10849. }
  10850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10851. isKnowKey = TRUE;
  10852. }
  10853. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10854. {
  10855. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10858. {
  10859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10860. }
  10861. else
  10862. {
  10863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10864. }
  10865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10866. isKnowKey = TRUE;
  10867. }
  10868. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10869. {
  10870. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10873. {
  10874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10875. }
  10876. else
  10877. {
  10878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10879. }
  10880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10881. isKnowKey = TRUE;
  10882. }
  10883. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10884. {
  10885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10888. {
  10889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10890. }
  10891. else
  10892. {
  10893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10894. }
  10895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10896. isKnowKey = TRUE;
  10897. }
  10898. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10899. {
  10900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10903. {
  10904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10905. }
  10906. else
  10907. {
  10908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10909. }
  10910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10911. isKnowKey = TRUE;
  10912. }
  10913. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10914. {
  10915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10917. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10918. {
  10919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10920. }
  10921. else
  10922. {
  10923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10924. }
  10925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10926. isKnowKey = TRUE;
  10927. }
  10928. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10929. {
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10933. {
  10934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10935. }
  10936. else
  10937. {
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10939. }
  10940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10941. isKnowKey = TRUE;
  10942. }
  10943. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10944. {
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10948. {
  10949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10950. }
  10951. else
  10952. {
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10954. }
  10955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10956. isKnowKey = TRUE;
  10957. }
  10958. #if 0
  10959. //For OCTT Test Case
  10960. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10961. {
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10964. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10965. {
  10966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10967. }
  10968. else
  10969. {
  10970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10971. }
  10972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10973. isKnowKey = TRUE;
  10974. }
  10975. #endif
  10976. #if 1
  10977. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10978. {
  10979. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10981. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10982. {
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10984. }
  10985. else
  10986. {
  10987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10988. }
  10989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10990. isKnowKey = TRUE;
  10991. }
  10992. #endif
  10993. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10994. {
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10997. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10998. {
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11000. }
  11001. else
  11002. {
  11003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11004. }
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11006. isKnowKey = TRUE;
  11007. }
  11008. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11009. {
  11010. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11012. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11013. {
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11015. }
  11016. else
  11017. {
  11018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11019. }
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11021. isKnowKey = TRUE;
  11022. }
  11023. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11024. {
  11025. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11027. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11028. {
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11030. }
  11031. else
  11032. {
  11033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11034. }
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11036. isKnowKey = TRUE;
  11037. }
  11038. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11039. {
  11040. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11042. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11043. {
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11045. }
  11046. else
  11047. {
  11048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11049. }
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11051. isKnowKey = TRUE;
  11052. }
  11053. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11054. {
  11055. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11057. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11058. {
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11060. }
  11061. else
  11062. {
  11063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11064. }
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11066. isKnowKey = TRUE;
  11067. }
  11068. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11069. {
  11070. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11072. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11073. {
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11075. }
  11076. else
  11077. {
  11078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11079. }
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11081. isKnowKey = TRUE;
  11082. }
  11083. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11084. {
  11085. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11087. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11088. {
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11090. }
  11091. else
  11092. {
  11093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11094. }
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11096. isKnowKey = TRUE;
  11097. }
  11098. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11099. {
  11100. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11102. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11103. {
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11105. }
  11106. else
  11107. {
  11108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11109. }
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11111. isKnowKey = TRUE;
  11112. }
  11113. //=========================================================
  11114. if(!isEmpty && !isKnowKey)
  11115. {
  11116. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11117. strcpy(unknownkey[UnknownKeynum], keyReq);
  11118. UnknownKeynum = UnknownKeynum + 1;
  11119. }
  11120. }
  11121. void processUnkownKey(void)
  11122. {
  11123. DEBUG_INFO("processUnkownKey\n");
  11124. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11125. for(int index=0; index < UnknownKeynum; index++)
  11126. {
  11127. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11128. {
  11129. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11130. }
  11131. }
  11132. }
  11133. int setKeyValue(char *key, char *value)
  11134. {
  11135. int isSuccess = NotSupported;
  11136. int check_ascii=0;
  11137. char str[10]={0};
  11138. #ifdef Debug
  11139. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  11140. #endif
  11141. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11142. {
  11143. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11145. {
  11146. strcpy(str, (const char*)value);
  11147. for(int i = 0; str[i]; i++){
  11148. str[i] = tolower(str[i]);
  11149. }
  11150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11151. isSuccess = ConfigurationStatus_Accepted;
  11152. }
  11153. else
  11154. {
  11155. isSuccess = ConfigurationStatus_Rejected;
  11156. }
  11157. }
  11158. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11159. {
  11160. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11162. {
  11163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  11164. isSuccess = ConfigurationStatus_Accepted;
  11165. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  11166. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11167. }
  11168. else
  11169. {
  11170. isSuccess = ConfigurationStatus_Rejected;
  11171. }
  11172. }
  11173. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11174. {
  11175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11176. {
  11177. strcpy(str, (const char*)value);
  11178. for(int i = 0; str[i]; i++)
  11179. {
  11180. str[i] = tolower(str[i]);
  11181. }
  11182. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11184. isSuccess = ConfigurationStatus_Accepted;
  11185. }
  11186. else
  11187. {
  11188. isSuccess = ConfigurationStatus_Rejected;
  11189. }
  11190. }
  11191. if(strcmp(key, "BlinkRepeat") == 0)
  11192. {
  11193. //Charger.BlinkRepeat = Integer.parseInt(value);
  11194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11195. {
  11196. check_ascii = value[0];
  11197. if( (check_ascii < 48) || (check_ascii > 57) )
  11198. {
  11199. isSuccess = ConfigurationStatus_Rejected;
  11200. }
  11201. else
  11202. {
  11203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11204. isSuccess = ConfigurationStatus_Accepted;
  11205. }
  11206. }
  11207. else
  11208. {
  11209. isSuccess = ConfigurationStatus_Rejected;
  11210. }
  11211. }
  11212. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11213. {
  11214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11215. {
  11216. check_ascii = value[0];
  11217. if( (check_ascii < 48) || (check_ascii > 57) )
  11218. {
  11219. isSuccess = ConfigurationStatus_Rejected;
  11220. }
  11221. else
  11222. {
  11223. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11225. isSuccess = ConfigurationStatus_Accepted;
  11226. }
  11227. }
  11228. else
  11229. {
  11230. isSuccess = ConfigurationStatus_Rejected;
  11231. }
  11232. }
  11233. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11234. {
  11235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11236. {
  11237. check_ascii = value[0];
  11238. if( (check_ascii < 48) || (check_ascii > 57) )
  11239. {
  11240. isSuccess = ConfigurationStatus_Rejected;
  11241. }
  11242. else
  11243. {
  11244. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11246. isSuccess = ConfigurationStatus_Accepted;
  11247. }
  11248. }
  11249. else
  11250. {
  11251. isSuccess = ConfigurationStatus_Rejected;
  11252. }
  11253. }
  11254. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11255. {
  11256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11257. {
  11258. check_ascii = value[0];
  11259. if( (check_ascii < 48) || (check_ascii > 57) )
  11260. {
  11261. isSuccess = ConfigurationStatus_Rejected;
  11262. }
  11263. else
  11264. {
  11265. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11267. isSuccess = ConfigurationStatus_Accepted;
  11268. }
  11269. }
  11270. else
  11271. {
  11272. isSuccess = ConfigurationStatus_Rejected;
  11273. }
  11274. }
  11275. if(strcmp(key, "HeartbeatInterval") == 0)
  11276. {
  11277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11278. {
  11279. check_ascii = value[0];
  11280. if( (check_ascii < 48) || (check_ascii > 57) )
  11281. {
  11282. isSuccess = ConfigurationStatus_Rejected;
  11283. }
  11284. else
  11285. {
  11286. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11288. HeartBeatWaitTime = atoi(value);
  11289. isSuccess = ConfigurationStatus_Accepted;
  11290. }
  11291. }
  11292. else
  11293. {
  11294. isSuccess = ConfigurationStatus_Rejected;
  11295. }
  11296. }
  11297. if(strcmp(key, "LightIntensity") == 0)
  11298. {
  11299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11300. {
  11301. check_ascii = value[0];
  11302. if( (check_ascii < 48) || (check_ascii > 57) )
  11303. {
  11304. isSuccess = ConfigurationStatus_Rejected;
  11305. }
  11306. else
  11307. {
  11308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11309. isSuccess = ConfigurationStatus_Accepted;
  11310. }
  11311. }
  11312. else
  11313. {
  11314. isSuccess = ConfigurationStatus_Rejected;
  11315. }
  11316. }
  11317. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11318. {
  11319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11320. {
  11321. strcpy(str, (const char*)value);
  11322. for(int i = 0; str[i]; i++)
  11323. {
  11324. str[i] = tolower(str[i]);
  11325. }
  11326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11327. isSuccess = ConfigurationStatus_Accepted;
  11328. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11329. }
  11330. else
  11331. {
  11332. isSuccess = ConfigurationStatus_Rejected;
  11333. }
  11334. }
  11335. if(strcmp(key, "LocalPreAuthorize") == 0)
  11336. {
  11337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11338. {
  11339. strcpy(str, (const char*)value);
  11340. for(int i = 0; str[i]; i++)
  11341. {
  11342. str[i] = tolower(str[i]);
  11343. }
  11344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11345. isSuccess = ConfigurationStatus_Accepted;
  11346. }
  11347. else
  11348. {
  11349. isSuccess = ConfigurationStatus_Rejected;
  11350. }
  11351. }
  11352. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11353. {
  11354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11355. {
  11356. check_ascii = value[0];
  11357. if( (check_ascii < 48) || (check_ascii > 57) )
  11358. {
  11359. isSuccess = ConfigurationStatus_Rejected;
  11360. }
  11361. else
  11362. {
  11363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11364. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11365. isSuccess = ConfigurationStatus_Accepted;
  11366. }
  11367. }
  11368. else
  11369. {
  11370. isSuccess = ConfigurationStatus_Rejected;
  11371. }
  11372. }
  11373. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11374. {
  11375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11376. {
  11377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11378. isSuccess = ConfigurationStatus_Accepted;
  11379. }
  11380. else
  11381. {
  11382. isSuccess = ConfigurationStatus_Rejected;
  11383. }
  11384. }
  11385. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11386. {
  11387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11388. {
  11389. check_ascii = value[0];
  11390. if( (check_ascii < 48) || (check_ascii > 57) )
  11391. {
  11392. isSuccess = ConfigurationStatus_Rejected;
  11393. }
  11394. else
  11395. {
  11396. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11398. isSuccess = ConfigurationStatus_Accepted;
  11399. }
  11400. }
  11401. else
  11402. {
  11403. isSuccess = ConfigurationStatus_Rejected;
  11404. }
  11405. }
  11406. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11407. {
  11408. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11409. {
  11410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11411. isSuccess = ConfigurationStatus_Accepted;
  11412. }
  11413. else
  11414. {
  11415. isSuccess = ConfigurationStatus_Rejected;
  11416. }
  11417. }
  11418. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11419. {
  11420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11421. {
  11422. check_ascii = value[0];
  11423. if( (check_ascii < 48) || (check_ascii > 57) )
  11424. {
  11425. isSuccess = ConfigurationStatus_Rejected;
  11426. }
  11427. else
  11428. {
  11429. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11431. isSuccess = ConfigurationStatus_Accepted;
  11432. }
  11433. }
  11434. else
  11435. {
  11436. isSuccess = ConfigurationStatus_Rejected;
  11437. }
  11438. }
  11439. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11440. {
  11441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11442. {
  11443. check_ascii = value[0];
  11444. if( (check_ascii < 48) || (check_ascii > 57) )
  11445. {
  11446. isSuccess = ConfigurationStatus_Rejected;
  11447. }
  11448. else
  11449. {
  11450. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11452. isSuccess = ConfigurationStatus_Accepted;
  11453. }
  11454. }
  11455. else
  11456. {
  11457. isSuccess = ConfigurationStatus_Rejected;
  11458. }
  11459. }
  11460. if(strcmp(key, "MinimumStatusDuration") == 0)
  11461. {
  11462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11463. {
  11464. check_ascii = value[0];
  11465. if( (check_ascii < 48) || (check_ascii > 57) )
  11466. {
  11467. isSuccess = ConfigurationStatus_Rejected;
  11468. }
  11469. else
  11470. {
  11471. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11473. isSuccess = ConfigurationStatus_Accepted;
  11474. }
  11475. }
  11476. else
  11477. {
  11478. isSuccess = ConfigurationStatus_Rejected;
  11479. }
  11480. }
  11481. if(strcmp(key, "NumberOfConnectors") == 0)
  11482. {
  11483. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11484. {
  11485. check_ascii = value[0];
  11486. if( (check_ascii < 48) || (check_ascii > 57) )
  11487. {
  11488. isSuccess = ConfigurationStatus_Rejected;
  11489. }
  11490. else
  11491. {
  11492. //Charger.ResetRetries = Integer.parseInt(value);
  11493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11494. isSuccess = ConfigurationStatus_Accepted;
  11495. }
  11496. }
  11497. else
  11498. {
  11499. isSuccess = ConfigurationStatus_Rejected;
  11500. }
  11501. }
  11502. if(strcmp(key, "ResetRetries") == 0)
  11503. {
  11504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11505. {
  11506. check_ascii = value[0];
  11507. if( (check_ascii < 48) || (check_ascii > 57) )
  11508. {
  11509. isSuccess = ConfigurationStatus_Rejected;
  11510. }
  11511. else
  11512. {
  11513. //Charger.ResetRetries = Integer.parseInt(value);
  11514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11515. isSuccess = ConfigurationStatus_Accepted;
  11516. }
  11517. }
  11518. else
  11519. {
  11520. isSuccess = ConfigurationStatus_Rejected;
  11521. }
  11522. }
  11523. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11524. {
  11525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11526. {
  11527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  11528. isSuccess = ConfigurationStatus_Accepted;
  11529. }
  11530. else
  11531. {
  11532. isSuccess = ConfigurationStatus_Rejected;
  11533. }
  11534. }
  11535. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11536. {
  11537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11538. {
  11539. check_ascii = value[0];
  11540. if( (check_ascii < 48) || (check_ascii > 57) )
  11541. {
  11542. isSuccess = ConfigurationStatus_Rejected;
  11543. }
  11544. else
  11545. {
  11546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11547. isSuccess = ConfigurationStatus_Accepted;
  11548. }
  11549. }
  11550. else
  11551. {
  11552. isSuccess = ConfigurationStatus_Rejected;
  11553. }
  11554. }
  11555. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11556. {
  11557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11558. {
  11559. strcpy(str, (const char*)value);
  11560. for(int i = 0; str[i]; i++)
  11561. {
  11562. str[i] = tolower(str[i]);
  11563. }
  11564. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11566. isSuccess = ConfigurationStatus_Accepted;
  11567. }
  11568. else
  11569. {
  11570. isSuccess = ConfigurationStatus_Rejected;
  11571. }
  11572. }
  11573. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11574. {
  11575. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11576. {
  11577. strcpy(str, (const char*)value);
  11578. for(int i = 0; str[i]; i++)
  11579. {
  11580. str[i] = tolower(str[i]);
  11581. }
  11582. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11584. isSuccess = ConfigurationStatus_Accepted;
  11585. }
  11586. else
  11587. {
  11588. isSuccess = ConfigurationStatus_Rejected;
  11589. }
  11590. }
  11591. if(strcmp(key, "StopTxnAlignedData") == 0)
  11592. {
  11593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11594. {
  11595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11596. isSuccess = ConfigurationStatus_Accepted;
  11597. }
  11598. else
  11599. {
  11600. isSuccess = ConfigurationStatus_Rejected;
  11601. }
  11602. }
  11603. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11604. {
  11605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11606. {
  11607. check_ascii = value[0];
  11608. if( (check_ascii < 48) || (check_ascii > 57) )
  11609. {
  11610. isSuccess = ConfigurationStatus_Rejected;
  11611. }
  11612. else
  11613. {
  11614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11615. isSuccess = ConfigurationStatus_Accepted;
  11616. }
  11617. }
  11618. else
  11619. {
  11620. isSuccess = ConfigurationStatus_Rejected;
  11621. }
  11622. }
  11623. if(strcmp(key, "StopTxnSampledData") == 0)
  11624. {
  11625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11626. {
  11627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11628. isSuccess = ConfigurationStatus_Accepted;
  11629. }
  11630. else
  11631. {
  11632. isSuccess = ConfigurationStatus_Rejected;
  11633. }
  11634. }
  11635. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11636. {
  11637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11638. {
  11639. check_ascii = value[0];
  11640. if( (check_ascii < 48) || (check_ascii > 57) )
  11641. {
  11642. isSuccess = ConfigurationStatus_Rejected;
  11643. }
  11644. else
  11645. {
  11646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11647. isSuccess = ConfigurationStatus_Accepted;
  11648. }
  11649. }
  11650. else
  11651. {
  11652. isSuccess = ConfigurationStatus_Rejected;
  11653. }
  11654. }
  11655. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11656. {
  11657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11658. {
  11659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11660. isSuccess = ConfigurationStatus_Accepted;
  11661. }
  11662. else
  11663. {
  11664. isSuccess = ConfigurationStatus_Rejected;
  11665. }
  11666. }
  11667. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11668. {
  11669. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11670. {
  11671. check_ascii = value[0];
  11672. if( (check_ascii < 48) || (check_ascii > 57) )
  11673. {
  11674. isSuccess = ConfigurationStatus_Rejected;
  11675. }
  11676. else
  11677. {
  11678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11679. isSuccess = ConfigurationStatus_Accepted;
  11680. }
  11681. }
  11682. else
  11683. {
  11684. isSuccess = ConfigurationStatus_Rejected;
  11685. }
  11686. }
  11687. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11688. {
  11689. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11690. {
  11691. check_ascii = value[0];
  11692. if( (check_ascii < 48) || (check_ascii > 57) )
  11693. {
  11694. isSuccess = ConfigurationStatus_Rejected;
  11695. }
  11696. else
  11697. {
  11698. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11700. TransactionMessageAttemptsValue = atoi(value);
  11701. isSuccess = ConfigurationStatus_Accepted;
  11702. }
  11703. }
  11704. else
  11705. {
  11706. isSuccess = ConfigurationStatus_Rejected;
  11707. }
  11708. }
  11709. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11710. {
  11711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].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. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11722. TransactionMessageRetryIntervalValue = atoi(value);
  11723. isSuccess = ConfigurationStatus_Accepted;
  11724. }
  11725. }
  11726. else
  11727. {
  11728. isSuccess = ConfigurationStatus_Rejected;
  11729. }
  11730. }
  11731. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11732. {
  11733. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11734. {
  11735. strcpy(str, (const char*)value);
  11736. for(int i = 0; str[i]; i++)
  11737. {
  11738. str[i] = tolower(str[i]);
  11739. }
  11740. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11742. isSuccess = ConfigurationStatus_Accepted;
  11743. }
  11744. else
  11745. {
  11746. isSuccess = ConfigurationStatus_Rejected;
  11747. }
  11748. }
  11749. if(strcmp(key, "WebSocketPingInterval") == 0)
  11750. {
  11751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11752. {
  11753. check_ascii = value[0];
  11754. if( (check_ascii < 48) || (check_ascii > 57) )
  11755. {
  11756. isSuccess = ConfigurationStatus_Rejected;
  11757. }
  11758. else
  11759. {
  11760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11761. isSuccess = ConfigurationStatus_Accepted;
  11762. }
  11763. }
  11764. else
  11765. {
  11766. isSuccess = ConfigurationStatus_Rejected;
  11767. }
  11768. }
  11769. #if 0
  11770. //For OCPP Test Case
  11771. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11772. {
  11773. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11774. {
  11775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11776. isSuccess = ConfigurationStatus_Accepted;
  11777. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11778. }
  11779. else
  11780. {
  11781. isSuccess = ConfigurationStatus_Rejected;
  11782. }
  11783. }
  11784. #endif
  11785. #if 1
  11786. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11787. {
  11788. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11789. {
  11790. strcpy(str, (const char*)value);
  11791. for(int i = 0; str[i]; i++)
  11792. {
  11793. str[i] = tolower(str[i]);
  11794. }
  11795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11796. isSuccess = ConfigurationStatus_Accepted;
  11797. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11798. }
  11799. else
  11800. {
  11801. isSuccess = ConfigurationStatus_Rejected;
  11802. }
  11803. }
  11804. #endif
  11805. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11806. {
  11807. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11808. {
  11809. check_ascii = value[0];
  11810. if( (check_ascii < 48) || (check_ascii > 57) )
  11811. {
  11812. isSuccess = ConfigurationStatus_Rejected;
  11813. }
  11814. else
  11815. {
  11816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11817. isSuccess = ConfigurationStatus_Accepted;
  11818. }
  11819. }
  11820. else
  11821. {
  11822. isSuccess = ConfigurationStatus_Rejected;
  11823. }
  11824. }
  11825. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11826. {
  11827. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11828. {
  11829. check_ascii = value[0];
  11830. if( (check_ascii < 48) || (check_ascii > 57) )
  11831. {
  11832. isSuccess = ConfigurationStatus_Rejected;
  11833. }
  11834. else
  11835. {
  11836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11837. isSuccess = ConfigurationStatus_Accepted;
  11838. }
  11839. }
  11840. else
  11841. {
  11842. isSuccess = ConfigurationStatus_Rejected;
  11843. }
  11844. }
  11845. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11846. {
  11847. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11848. {
  11849. strcpy(str, (const char*)value);
  11850. for(int i = 0; str[i]; i++)
  11851. {
  11852. str[i] = tolower(str[i]);
  11853. }
  11854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11855. isSuccess = ConfigurationStatus_Accepted;
  11856. }
  11857. else
  11858. {
  11859. isSuccess = ConfigurationStatus_Rejected;
  11860. }
  11861. }
  11862. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11863. {
  11864. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11865. {
  11866. check_ascii = value[0];
  11867. if( (check_ascii < 48) || (check_ascii > 57) )
  11868. {
  11869. isSuccess = ConfigurationStatus_Rejected;
  11870. }
  11871. else
  11872. {
  11873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11874. isSuccess = ConfigurationStatus_Accepted;
  11875. }
  11876. }
  11877. else
  11878. {
  11879. isSuccess = ConfigurationStatus_Rejected;
  11880. }
  11881. }
  11882. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11883. {
  11884. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11885. {
  11886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11887. isSuccess = ConfigurationStatus_Accepted;
  11888. }
  11889. else
  11890. {
  11891. isSuccess = ConfigurationStatus_Rejected;
  11892. }
  11893. }
  11894. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11895. {
  11896. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11897. {
  11898. check_ascii = value[0];
  11899. if( (check_ascii < 48) || (check_ascii > 57) )
  11900. {
  11901. isSuccess = ConfigurationStatus_Rejected;
  11902. }
  11903. else
  11904. {
  11905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11906. isSuccess = ConfigurationStatus_Accepted;
  11907. }
  11908. }
  11909. else
  11910. {
  11911. isSuccess = ConfigurationStatus_Rejected;
  11912. }
  11913. }
  11914. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11915. {
  11916. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11917. {
  11918. strcpy(str, (const char*)value);
  11919. for(int i = 0; str[i]; i++)
  11920. {
  11921. str[i] = tolower(str[i]);
  11922. }
  11923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11924. isSuccess = ConfigurationStatus_Accepted;
  11925. }
  11926. else
  11927. {
  11928. isSuccess = ConfigurationStatus_Rejected;
  11929. }
  11930. }
  11931. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11932. {
  11933. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].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.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11943. isSuccess = ConfigurationStatus_Accepted;
  11944. }
  11945. }
  11946. else
  11947. {
  11948. isSuccess = ConfigurationStatus_Rejected;
  11949. }
  11950. }
  11951. return isSuccess;
  11952. }
  11953. int updateSetting(char *key, char *value)
  11954. {
  11955. mtrace();
  11956. int isSuccess = FALSE;
  11957. char string[1000]={0}, buffer[1000]={0};
  11958. char strtemp[50]={0};
  11959. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11960. int pos, c = 0;
  11961. char *loc;
  11962. int pos1=0;
  11963. FILE *f = fopen("/var/www/settings1", "r");
  11964. if(f == NULL)
  11965. {
  11966. #ifdef Debug
  11967. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11968. #endif
  11969. return isSuccess;
  11970. }
  11971. fseek(f, 0, SEEK_END);
  11972. long fsize = ftell(f);
  11973. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11974. fread(string, 1, fsize, f);
  11975. fclose(f);
  11976. string[fsize] = 0;
  11977. loc = strstr(string, key);
  11978. if(loc != NULL)
  11979. {
  11980. DEBUG_INFO("key exist!\n");
  11981. pos = loc - string-1;
  11982. f = fopen("/var/www/settings1", "w");
  11983. strncpy(buffer, string, pos);
  11984. fprintf(f, "%s", buffer);
  11985. memset(sstr ,0, sizeof(sstr) );
  11986. c = 0;
  11987. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11988. {
  11989. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11990. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11991. c++;
  11992. }
  11993. sstr[c] = '\0';
  11994. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11995. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11996. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11997. memset(buffer ,0, sizeof(buffer) );
  11998. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11999. //printf("buffer=%s",buffer);
  12000. fprintf(f, "%s", buffer);
  12001. fclose(f);
  12002. }
  12003. else
  12004. {
  12005. printf("key not exist!\n");
  12006. f = fopen("/var/www/settings1", "w+");
  12007. fputs(string, f);
  12008. fseek(f, -1, SEEK_CUR);
  12009. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12010. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12011. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12012. fclose(f);
  12013. }
  12014. isSuccess = TRUE;
  12015. return isSuccess;
  12016. }
  12017. int TransactionMessageAttemptsGet(void)
  12018. {
  12019. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12020. }
  12021. int FirstHeartBeatResponse(void)
  12022. {
  12023. return FirstHeartBeat;
  12024. }
  12025. int TransactionMessageRetryIntervalGet(void)
  12026. {
  12027. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12028. }
  12029. #define SA struct sockaddr
  12030. #define MAXBUF 1024
  12031. //static int m_socket_data;
  12032. //static int sockfd;
  12033. int ReadHttpStatus(int sock){
  12034. //char c;
  12035. char buff[1024]="",*ptr=buff+1;
  12036. int bytes_received, status;
  12037. DEBUG_INFO("Begin Response ..\n");
  12038. while((bytes_received = recv(sock, ptr, 1, 0))){
  12039. if(bytes_received==-1){
  12040. perror("ReadHttpStatus");
  12041. exit(1);
  12042. }
  12043. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12044. ptr++;
  12045. }
  12046. *ptr=0;
  12047. ptr=buff+1;
  12048. sscanf(ptr,"%*s %d ", &status);
  12049. DEBUG_INFO("%s\n",ptr);
  12050. DEBUG_INFO("status=%d\n",status);
  12051. DEBUG_INFO("End Response ..\n");
  12052. return (bytes_received>0)?status:0;
  12053. }
  12054. //the only filed that it parsed is 'Content-Length'
  12055. int ParseHeader(int sock){
  12056. //char c;
  12057. char buff[1024]="",*ptr=buff+4;
  12058. int bytes_received;
  12059. DEBUG_INFO("Begin HEADER ..\n");
  12060. while((bytes_received = recv(sock, ptr, 1, 0))){
  12061. if(bytes_received==-1){
  12062. perror("Parse Header");
  12063. exit(1);
  12064. }
  12065. if(
  12066. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12067. (ptr[-1]=='\r') && (*ptr=='\n' )
  12068. ) break;
  12069. ptr++;
  12070. }
  12071. *ptr=0;
  12072. ptr=buff+4;
  12073. //printf("%s",ptr);
  12074. if(bytes_received){
  12075. ptr=strstr(ptr,"Content-Length:");
  12076. if(ptr){
  12077. sscanf(ptr,"%*s %d",&bytes_received);
  12078. }else
  12079. bytes_received=-1; //unknown size
  12080. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12081. }
  12082. DEBUG_INFO("End HEADER ..\n");
  12083. return bytes_received ;
  12084. }
  12085. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12086. {
  12087. char rmFileCmd[100]={0};
  12088. char FilePath[100]={0};
  12089. char ftpbuf[200];
  12090. int systemresult;
  12091. //DEBUG_INFO("filename=%s\n",filename);
  12092. //DEBUG_INFO("url=%s\n",url);
  12093. sprintf(FilePath,"/mnt/%s",filename);
  12094. if((access(FilePath,F_OK))!=-1)
  12095. {
  12096. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12097. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12098. system(rmFileCmd);
  12099. }
  12100. memset(ftpbuf, 0, sizeof(ftpbuf));
  12101. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12102. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12103. systemresult = system(ftpbuf);
  12104. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12105. if(systemresult != 0)
  12106. {
  12107. DEBUG_INFO("http DownLoad error!\n");
  12108. return FALSE;
  12109. }
  12110. return TRUE;
  12111. }
  12112. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12113. {
  12114. char rmFileCmd[100]={0};
  12115. char FilePath[100]={0};
  12116. char ftpbuf[200];
  12117. int systemresult;
  12118. //char temp[100];
  12119. #if 0
  12120. struct hostent* server;
  12121. char *IPbuffer;
  12122. server = gethostbyname(location);
  12123. // To convert an Internet network
  12124. // address into ASCII string
  12125. IPbuffer = inet_ntoa(*((struct in_addr*)
  12126. server->h_addr_list[0]));
  12127. #endif
  12128. sprintf(FilePath,"/mnt/%s",filename);
  12129. if((access(FilePath,F_OK))!=-1)
  12130. {
  12131. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12132. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12133. system(rmFileCmd);
  12134. }
  12135. memset(ftpbuf, 0, sizeof(ftpbuf));
  12136. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12137. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12138. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12139. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12140. systemresult = system(ftpbuf);
  12141. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12142. if(systemresult != 0)
  12143. {
  12144. printf("wget error!\n");
  12145. return FALSE;
  12146. }
  12147. return TRUE;
  12148. }
  12149. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12150. {
  12151. char rmFileCmd[100]={0};
  12152. char FilePath[100]={0};
  12153. char ftpbuf[200];
  12154. char filenametemp[60]={0};
  12155. int systemresult;
  12156. //DEBUG_INFO("filename=%s\n",filename);
  12157. //DEBUG_INFO("url=%s\n",url);
  12158. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12159. if((access(FilePath,F_OK))!=-1)
  12160. {
  12161. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12162. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12163. system(rmFileCmd);
  12164. }
  12165. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12166. if(fp == NULL)
  12167. {
  12168. DEBUG_INFO("log is NULL\n");
  12169. return FALSE;
  12170. }
  12171. else
  12172. {
  12173. fprintf(fp, "%s\n", url);
  12174. sscanf(filename, "%*2[.]%s", filenametemp);
  12175. fprintf(fp, "%s\n", filenametemp);
  12176. fclose(fp);
  12177. }
  12178. memset(ftpbuf, 0, sizeof(ftpbuf));
  12179. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12180. systemresult = system(ftpbuf);
  12181. DEBUG_INFO("systemresult=%d\n",systemresult);
  12182. if(systemresult != 0)
  12183. {
  12184. DEBUG_INFO("http upload error!\n");
  12185. return FALSE;
  12186. }
  12187. return TRUE;
  12188. }
  12189. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12190. {
  12191. struct hostent* server;
  12192. char *IPbuffer;
  12193. char ftpbuf[200];
  12194. int systemresult;
  12195. // To retrieve host information
  12196. server = gethostbyname(location);
  12197. // To convert an Internet network
  12198. // address into ASCII string
  12199. IPbuffer = inet_ntoa(*((struct in_addr*)
  12200. server->h_addr_list[0]));
  12201. memset(ftpbuf, 0, sizeof(ftpbuf));
  12202. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12203. /* format : ftpput -u username -p passwd IP target source*/
  12204. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12205. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12206. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12207. systemresult = system(ftpbuf);
  12208. DEBUG_INFO("systemresult=%d\n",systemresult);
  12209. if(systemresult != 0)
  12210. {
  12211. DEBUG_INFO("ftpput error!\n");
  12212. return FALSE;
  12213. }
  12214. return TRUE;
  12215. }
  12216. int SettingChargingRecord(int target, int transactionId)
  12217. {
  12218. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12219. {
  12220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12221. {
  12222. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12223. {
  12224. addBuff(target, transactionId, 0);
  12225. return TRUE;
  12226. }
  12227. }
  12228. for (int index = 0; index < CCS_QUANTITY; index++)
  12229. {
  12230. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12231. {
  12232. addBuff(target, transactionId, 0);
  12233. return TRUE;
  12234. }
  12235. }
  12236. for (int index = 0; index < GB_QUANTITY; index++)
  12237. {
  12238. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12239. {
  12240. addBuff(target, transactionId, 0);
  12241. return TRUE;
  12242. }
  12243. }
  12244. }
  12245. else
  12246. {
  12247. for (int index = 0; index < AC_QUANTITY; index++)
  12248. {
  12249. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  12250. {
  12251. addBuff(target, transactionId, 0);
  12252. return TRUE;
  12253. }
  12254. }
  12255. }
  12256. return FALSE;
  12257. }
  12258. int addBuff(int gun_idx, int user_id, int cmd_sn)
  12259. {
  12260. int isSuccess = FALSE;
  12261. //char *query = NULL;
  12262. sqlite3_stmt *stmt;
  12263. int rc; // return code
  12264. char str[20];
  12265. sprintf(str,"%d",user_id);
  12266. 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 */
  12267. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  12268. rc = sqlite3_step(stmt); /* 3 */
  12269. if (rc != SQLITE_DONE) {
  12270. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  12271. goto out;
  12272. }
  12273. sqlite3_finalize(stmt);
  12274. // free(query);
  12275. out:
  12276. //----------------------
  12277. // close SQLite database
  12278. //----------------------
  12279. sqlite3_close(db);
  12280. printf("database closed.\n");
  12281. return isSuccess;
  12282. }
  12283. /**
  12284. * Place the contents of the specified file into a memory buffer
  12285. *
  12286. * @param[in] filename The path and name of the file to read
  12287. * @param[out] filebuffer A pointer to the contents in memory
  12288. * @return status 0 success, 1 on failure
  12289. */
  12290. int get_file_contents(const char* filename, char** outbuffer) {
  12291. FILE* file = NULL;
  12292. long filesize;
  12293. const int blocksize = 1;
  12294. size_t readsize;
  12295. char* filebuffer;
  12296. // Open the file
  12297. file = fopen(filename, "r");
  12298. if (NULL == file)
  12299. {
  12300. printf("'%s' not opened\n", filename);
  12301. exit(EXIT_FAILURE);
  12302. }
  12303. // Determine the file size
  12304. fseek(file, 0, SEEK_END);
  12305. filesize = ftell(file);
  12306. rewind (file);
  12307. // Allocate memory for the file contents
  12308. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12309. *outbuffer = filebuffer;
  12310. if (filebuffer == NULL)
  12311. {
  12312. fputs ("malloc out-of-memory", stderr);
  12313. exit(EXIT_FAILURE);
  12314. }
  12315. // Read in the file
  12316. readsize = fread(filebuffer, blocksize, filesize, file);
  12317. if (readsize != filesize)
  12318. {
  12319. fputs ("didn't read file completely",stderr);
  12320. exit(EXIT_FAILURE);
  12321. }
  12322. // Clean exit
  12323. fclose(file);
  12324. return EXIT_SUCCESS;
  12325. }
  12326. static int selectSqlCount = 0;
  12327. static int callback(void *data, int argc, char **argv, char **azColName){
  12328. int i;
  12329. printf("%s: ", (const char*)data);
  12330. selectSqlCount = argc;
  12331. for(i = 0; i<argc; i++){
  12332. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12333. }
  12334. printf("\n");
  12335. return 0;
  12336. }
  12337. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12338. //int i;
  12339. //printf("%s:\n", (const char*)data);
  12340. localversion = argv[5] ? atoi(argv[5]) : 0;
  12341. printf("localversion=%d\n", localversion);
  12342. return 0;
  12343. }
  12344. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12345. //int i;
  12346. //printf("%s:\n", (const char*)data);
  12347. //idTag
  12348. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12349. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12350. //parentIdTag
  12351. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12352. //expir_date
  12353. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12354. //status
  12355. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12356. //version
  12357. idTagQuery.listVersionInt = atoi(argv[5]);
  12358. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12359. return 0;
  12360. }
  12361. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  12362. int i;
  12363. //printf("%s:\n", (const char*)data);
  12364. #if 1
  12365. for(i=0; i<argc; i++){
  12366. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  12367. }
  12368. //printf("");
  12369. #endif
  12370. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12371. // printf("localversion=%d\n", localversion);
  12372. return 0;
  12373. }
  12374. /** sqlite3_exec的回调。
  12375. *
  12376. * 向控制台打印查询的结果。
  12377. *
  12378. * @param in data 传递给回调函数的数据。
  12379. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  12380. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  12381. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  12382. * @return 状态码。
  12383. */
  12384. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12385. {
  12386. for (int i = 0; i < n_columns; i++)
  12387. {
  12388. DEBUG_INFO("%s/t", col_values[i]);
  12389. }
  12390. DEBUG_INFO("/n");
  12391. return 0;
  12392. }
  12393. void OCPP_getListVerion()
  12394. {
  12395. int rc = 0;
  12396. // const char* data = "Callback function called";
  12397. char sql[100];
  12398. char zErrMsg[100];
  12399. memset(sql, 0, 100);
  12400. memset(zErrMsg, 0, 100);
  12401. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  12402. /* Execute SQL statement */
  12403. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12404. DEBUG_INFO("rc=%d\n",rc);
  12405. if( rc != SQLITE_OK ){
  12406. DEBUG_INFO("SQL error: %s", zErrMsg);
  12407. //sqlite3_free(zErrMsg);
  12408. }else{
  12409. DEBUG_INFO("Operation done successfully");
  12410. }
  12411. }
  12412. void OCPP_getIdTag(char idTag[])
  12413. {
  12414. int rc = 0;
  12415. // const char* data = "Callback function called";
  12416. char sql[100];
  12417. char zErrMsg[100];
  12418. memset(sql, 0, 100);
  12419. memset(zErrMsg, 0, 100);
  12420. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12421. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12422. DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12423. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12424. /* Execute SQL statement */
  12425. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12426. if( rc != SQLITE_OK ){
  12427. DEBUG_INFO("SQL error: %s", zErrMsg);
  12428. //sqlite3_free(zErrMsg);
  12429. }else{
  12430. printf("Operation done successfully");
  12431. }
  12432. //return ver;
  12433. }
  12434. void OCPP_get_TableAuthlocalAllData(void)
  12435. {
  12436. int rc = 0;
  12437. // const char* data = "Callback function called";
  12438. char sql[100];
  12439. char zErrMsg[100];
  12440. memset(sql, 0, 100);
  12441. memset(zErrMsg, 0, 100);
  12442. sprintf(sql,"select * from ocpp_auth_local ");
  12443. /* Execute SQL statement */
  12444. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12445. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  12446. if( rc != SQLITE_OK ){
  12447. DEBUG_INFO("SQL error: %s", zErrMsg);
  12448. //sqlite3_free(zErrMsg);
  12449. }else{
  12450. DEBUG_INFO("Operation done successfully");
  12451. }
  12452. //return ver;
  12453. }
  12454. int OCPP_cleanLocalList()
  12455. {
  12456. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12457. char *errMsg = 0;
  12458. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12459. if (SQLITE_OK != rc)
  12460. {
  12461. DEBUG_INFO("%s\n",errMsg);
  12462. return FALSE;
  12463. }
  12464. else
  12465. {
  12466. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  12467. }
  12468. return TRUE;
  12469. }
  12470. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12471. {
  12472. int isSuccess = FALSE;
  12473. int ret = 0;
  12474. //const char* data = "Callback function called";
  12475. char sql[300];
  12476. char zErrMsg[200];
  12477. memset(sql, 0, 300);
  12478. memset(zErrMsg, 0, 200);
  12479. 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);
  12480. //* Execute SQL statement */
  12481. //zErrMsg = 0;
  12482. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12483. if( ret != SQLITE_OK ){
  12484. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12485. // free(zErrMsg);
  12486. // free(sql);
  12487. return isSuccess;
  12488. }
  12489. DEBUG_INFO("successfully Insert records created\n");
  12490. isSuccess = TRUE;
  12491. return isSuccess;
  12492. }
  12493. void OCPP_deleteIdTag(char idTag[])
  12494. {
  12495. //int ver = 0;
  12496. //int isSuccess = FALSE;
  12497. int rc = 0;
  12498. char sql[100];
  12499. char zErrMsg[100];
  12500. memset(sql, 0, 100);
  12501. memset(zErrMsg, 0, 100);
  12502. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12503. //* Execute SQL statement */
  12504. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12505. if( rc != SQLITE_OK ){
  12506. DEBUG_INFO("SQL error: %s", zErrMsg);
  12507. //sqlite3_free(zErrMsg);
  12508. }else{
  12509. DEBUG_INFO("Operation done successfully");
  12510. }
  12511. }
  12512. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12513. {
  12514. int isSuccess = FALSE;
  12515. int ret = 0;
  12516. const char* data = "Callback function called";
  12517. char sql[200];
  12518. char zErrMsg[100];
  12519. memset(sql, 0, 200);
  12520. memset(zErrMsg, 0, 100);
  12521. //* selectFromTable */
  12522. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12523. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12524. //* Execute SQL statement */
  12525. selectSqlCount = 0;
  12526. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12527. if( ret != SQLITE_OK ){
  12528. printf("Error SQL: %s\n", zErrMsg);
  12529. }
  12530. printf("successfully select operation done\n");
  12531. memset(sql, 0, 200);
  12532. memset(zErrMsg, 0, 100);
  12533. if(selectSqlCount == 0)
  12534. {
  12535. //Insert
  12536. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12537. 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);
  12538. DEBUG_INFO("sql:%s\n", sql);
  12539. //* Execute SQL statement */
  12540. //zErrMsg = 0;
  12541. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12542. if( ret != SQLITE_OK ){
  12543. printf("SQL error: %s\n", zErrMsg);
  12544. return isSuccess;
  12545. }
  12546. DEBUG_INFO("successfully Insert records created\n");
  12547. isSuccess = TRUE;
  12548. }
  12549. else
  12550. {
  12551. //Update
  12552. //* Create merged SQL statement */
  12553. 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);
  12554. /* Execute SQL statement */
  12555. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12556. if( ret != SQLITE_OK ){
  12557. printf("SQL error: %s\n", zErrMsg);
  12558. //sqlite3_free(zErrMsg);
  12559. //sqlite3_free(sql);
  12560. return isSuccess;
  12561. }
  12562. DEBUG_INFO("Successfully operation done \n");
  12563. isSuccess = TRUE;
  12564. }
  12565. return isSuccess;
  12566. }
  12567. int GetOcppServerURL()
  12568. {
  12569. int result = FALSE;
  12570. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12571. memset(OcppHost, 0, sizeof(OcppHost));
  12572. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12573. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12574. {
  12575. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12576. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12577. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12578. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12579. result = TRUE;
  12580. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12581. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12582. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12583. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12584. goto End;
  12585. }
  12586. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12587. {
  12588. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12589. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12590. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12591. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12592. result = TRUE;
  12593. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12594. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12595. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12596. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12597. goto End;
  12598. }
  12599. else
  12600. {
  12601. strcpy(OcppHost,"");
  12602. }
  12603. End:
  12604. return result;
  12605. }
  12606. int GetOcppPath()
  12607. {
  12608. int result = FALSE;
  12609. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12610. {
  12611. if(OcppTempPath == NULL)
  12612. {
  12613. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12614. }
  12615. else
  12616. {
  12617. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12618. }
  12619. result = TRUE;
  12620. goto End;
  12621. }
  12622. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12623. {
  12624. if(OcppTempPath == NULL)
  12625. {
  12626. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12627. }
  12628. else
  12629. {
  12630. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12631. }
  12632. result = TRUE;
  12633. goto End;
  12634. }
  12635. else
  12636. {
  12637. strcpy(OcppPath,"");
  12638. }
  12639. End:
  12640. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12641. return result;
  12642. }
  12643. int GetOcppPort()
  12644. {
  12645. return OcppPort;
  12646. }
  12647. int GetOcppConnStatus(void)
  12648. {
  12649. return ShmOCPP16Data->OcppConnStatus;
  12650. }
  12651. void SetOcppConnStatus(uint8_t status)
  12652. {
  12653. ShmOCPP16Data->OcppConnStatus = status;
  12654. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12655. if(status == FALSE)
  12656. {
  12657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12658. {
  12659. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12660. }
  12661. else
  12662. {
  12663. SystemInitial = AC_QUANTITY;
  12664. }
  12665. }
  12666. }
  12667. int GetHeartBeatWithNOResponse(void)
  12668. {
  12669. return HeartBeatWithNOResponse;
  12670. }
  12671. void SetHeartBeatWithNOResponse(void)
  12672. {
  12673. HeartBeatWithNOResponse = 0;
  12674. }
  12675. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12676. /*
  12677. src 源字串的首地址(buf的地址)
  12678. separator 指定的分割字元
  12679. dest 接收子字串的陣列
  12680. num 分割後子字串的個數
  12681. */
  12682. char *pNext;
  12683. int count = 0;
  12684. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12685. return;
  12686. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12687. return;
  12688. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12689. while(pNext != NULL) {
  12690. *dest++ = pNext;
  12691. ++count;
  12692. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12693. }
  12694. *num = count;
  12695. }
  12696. int GetTransactionId(int gunindex, unsigned char idTag[])
  12697. {
  12698. char ch;
  12699. FILE *fptr1;
  12700. int temptransactionId;
  12701. char str[100]={0};
  12702. temptransactionId = 0;
  12703. /*------ Read the file ----------------*/
  12704. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12705. ch=fgetc(fptr1);
  12706. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12707. rewind(fptr1);
  12708. if(ch!=EOF)
  12709. {
  12710. // printf("%c",ch);
  12711. while (fgets(str, 100, fptr1) != NULL)
  12712. {
  12713. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12714. if(str[0]=='\0')
  12715. {
  12716. break;
  12717. }
  12718. char *revbuf[8] = {0}; //存放分割後的子字串
  12719. int num = 0;//分割後子字串的個數
  12720. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12721. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12722. {
  12723. temptransactionId = atoi(revbuf[2]);
  12724. break;
  12725. }
  12726. }
  12727. }
  12728. fclose(fptr1);
  12729. /*------- End of reading ---------------*/
  12730. return temptransactionId;
  12731. }
  12732. void SetTransactionIdZero(int transactionId)
  12733. {
  12734. //TransactionId[gunindex] = 0;
  12735. char ch;
  12736. FILE *fptr1, *fptr2;
  12737. int temptransactionId;
  12738. char str[100]={0}, temp[] = "/Storage/OCPP/temp.txt";
  12739. printf("\n\n Delete a specific line from a file :\n");
  12740. printf("-----------------------------------------\n");
  12741. //scanf("%s",fname);
  12742. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12743. if (!fptr1)
  12744. {
  12745. printf(" File not found or unable to open the input file!!\n");
  12746. return ;
  12747. }
  12748. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12749. if (!fptr2)
  12750. {
  12751. printf("Unable to open a temporary file to write!!\n");
  12752. fclose(fptr1);
  12753. return ;
  12754. }
  12755. ch=fgetc(fptr1);
  12756. //printf(" Now the content of the file %s is : \n",fname);
  12757. rewind(fptr1);
  12758. if(ch!=EOF)
  12759. {
  12760. // copy all contents to the temporary file except the specific line
  12761. while (fgets(str, 100, fptr1) != NULL)
  12762. {
  12763. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12764. if(str[0]=='\0')
  12765. {
  12766. break;
  12767. }
  12768. char *revbuf[8] = {0}; //存放分割後的子字串
  12769. int num = 0;//分割後子字串的個數
  12770. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12771. temptransactionId = atoi(revbuf[2]);
  12772. if(transactionId != temptransactionId)
  12773. {
  12774. fprintf(fptr2, "%s", str);
  12775. }
  12776. }
  12777. }
  12778. fclose(fptr1);
  12779. fclose(fptr2);
  12780. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12781. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12782. /*------ Read the file ----------------*/
  12783. }
  12784. int InternetDisconnect(void)
  12785. {
  12786. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12787. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12788. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12789. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12790. }
  12791. void GetChargingProfileRequest(int gunindex)
  12792. {
  12793. mtrace();
  12794. //int connectorIdInt, durationInt;
  12795. //char chargingRateUnitStr[4]={0};
  12796. int tempdurationInt = 0;
  12797. int tempchargingProfileId = 0;
  12798. int tempstackLevel = 0;
  12799. int temptransactionId = 0;
  12800. float tempminChargingRateFloat = 0.0;
  12801. char tempchargingProfilePurposeStr[24]={0};
  12802. char tempchargingProfileKindStr[12]={0};
  12803. char temprecurrencyKindStr[8]={0};
  12804. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12805. char tempvalidToStr[28]={0};
  12806. int tempStartPeriodInt = 0;
  12807. float tempLimitInt = 0.0;//0.1;
  12808. int tempNumberPhasesInt=0;
  12809. char fname[200];
  12810. //char comfirmstr[20];
  12811. float MinChargingRate =0.0;
  12812. double diff_t;
  12813. struct tm tp;
  12814. FILE *fptr1;//, *fptr2;
  12815. int c = 0;
  12816. char * pch;
  12817. char *loc;
  12818. char sstr[200]={ 0 };
  12819. int n_chargingProfile = 0;
  12820. int n_SchedulePeriods = 0;
  12821. char SchedulePeriodList[10][200]={0};
  12822. char sLineWord[1600]={0};
  12823. char word[1000]={0};
  12824. int confirmPeriods = 0;
  12825. struct StructProfile ChargePointMaxProfile;
  12826. struct StructProfile TxDefaultProfile;
  12827. struct StructProfile TxProfile;
  12828. struct StructProfile TxDefaultProfiletemp[2]={0};
  12829. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12830. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12831. struct StructChargingProfile TxProfile_TEMP={0};
  12832. int TxDefaultProfileFileIsNull=FALSE;
  12833. int ChargePointMaxProfileIsNull=FALSE;
  12834. int TxProfileIsNull=FALSE;
  12835. // int CompositeSceduleIndex = 0;
  12836. char ChargePointMaxProfileScheduleStr[30]={0};
  12837. char TxDefaultProfileScheduleStr[30]={0};
  12838. char TxProfileScheduleStr[30]={0};
  12839. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12840. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12841. memset(&TxProfile,0,sizeof(struct StructProfile));
  12842. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  12843. DEBUG_INFO("GetChargingProfileRequest\n");
  12844. //*****************************ChargePointMaxProfile******************************************/
  12845. strcpy(fname, ChargePointMaxProfile_JSON);
  12846. ChargePointMaxProfileIsNull=TRUE;
  12847. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12848. {
  12849. fptr1 = fopen(fname, "r");
  12850. int c;
  12851. c = fgetc(fptr1);
  12852. //DEBUG_INFO("c:%d\n",c);
  12853. rewind(fptr1);
  12854. if(c == EOF)
  12855. {
  12856. DEBUG_INFO("\n End of file reached.");
  12857. ChargePointMaxProfileIsNull=TRUE;
  12858. fclose(fptr1);
  12859. }
  12860. else
  12861. {
  12862. ChargePointMaxProfileIsNull=FALSE;
  12863. while(fscanf(fptr1, "%s", word) != EOF)
  12864. {
  12865. if(strcmp(word, "chargingProfileId") == 0)
  12866. {
  12867. n_chargingProfile = n_chargingProfile + 1;
  12868. }
  12869. }
  12870. rewind(fptr1);
  12871. //search Charging Profile Element
  12872. int i = 0;
  12873. int j = 0;
  12874. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12875. //***********chargingProfileId**************/
  12876. c = 0;
  12877. loc = strstr(sLineWord, "chargingProfileId");
  12878. //DEBUG_INFO("loc=%s\n",loc);
  12879. memset(sstr ,0, sizeof(sstr) );
  12880. if(loc != NULL)
  12881. {
  12882. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12883. {
  12884. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12885. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12886. c++;
  12887. }
  12888. sstr[c] = '\0';
  12889. tempchargingProfileId = atoi(sstr);
  12890. }
  12891. else
  12892. {
  12893. tempchargingProfileId = 0;
  12894. }
  12895. //***********stackLevel**************/
  12896. c = 0;
  12897. loc = strstr(sLineWord, "stackLevel");
  12898. //DEBUG_INFO("loc=%s\n",loc);
  12899. memset(sstr ,0, sizeof(sstr) );
  12900. if(loc != NULL)
  12901. {
  12902. while (loc[2+strlen("stackLevel")+c] != '\"')
  12903. {
  12904. sstr[c] = loc[2+strlen("stackLevel")+c];
  12905. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12906. c++;
  12907. }
  12908. sstr[c] = '\0';
  12909. tempstackLevel = atoi(sstr);
  12910. }
  12911. else
  12912. {
  12913. tempstackLevel = 0;
  12914. }
  12915. //***********chargingProfilePurpose **************/
  12916. c = 0;
  12917. loc = strstr(sLineWord, "chargingProfilePurpose");
  12918. //DEBUG_INFO("loc=%s\n",loc);
  12919. memset(sstr ,0, sizeof(sstr) );
  12920. if(loc != NULL)
  12921. {
  12922. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12923. {
  12924. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12925. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12926. c++;
  12927. }
  12928. sstr[c] = '\0';
  12929. strcpy(tempchargingProfilePurposeStr,sstr);
  12930. }
  12931. else
  12932. {
  12933. strcpy(tempchargingProfilePurposeStr,"");
  12934. }
  12935. //***********chargingProfileKind **************/
  12936. c = 0;
  12937. loc = strstr(sLineWord, "chargingProfileKind");
  12938. //DEBUG_INFO("loc=%s\n",loc);
  12939. memset(sstr ,0, sizeof(sstr) );
  12940. if(loc != NULL)
  12941. {
  12942. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12943. {
  12944. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12945. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12946. c++;
  12947. }
  12948. sstr[c] = '\0';
  12949. strcpy(tempchargingProfileKindStr,sstr);
  12950. }
  12951. else
  12952. {
  12953. strcpy(tempchargingProfileKindStr,"");
  12954. }
  12955. //***********recurrencyKind **************/
  12956. c = 0;
  12957. loc = strstr(sLineWord, "recurrencyKind");
  12958. //DEBUG_INFO("loc=%s\n",loc);
  12959. memset(sstr ,0, sizeof(sstr) );
  12960. if(loc != NULL)
  12961. {
  12962. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12963. {
  12964. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12965. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12966. c++;
  12967. }
  12968. sstr[c] = '\0';
  12969. strcpy(temprecurrencyKindStr,sstr);
  12970. }
  12971. else
  12972. {
  12973. strcpy(temprecurrencyKindStr,"");
  12974. }
  12975. //***********validFrom**************/
  12976. c = 0;
  12977. loc = strstr(sLineWord, "validFrom");
  12978. //DEBUG_INFO("loc=%s\n",loc);
  12979. memset(sstr ,0, sizeof(sstr) );
  12980. if(loc != NULL)
  12981. {
  12982. while (loc[3+strlen("validFrom")+c] != '\"')
  12983. {
  12984. sstr[c] = loc[3+strlen("validFrom")+c];
  12985. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12986. c++;
  12987. }
  12988. sstr[c] = '\0';
  12989. strcpy(tempvalidFromStr,sstr);
  12990. }
  12991. else
  12992. {
  12993. strcpy(tempvalidFromStr,"");
  12994. }
  12995. //***********validTo **************/
  12996. c = 0;
  12997. loc = strstr(sLineWord, "validTo");
  12998. //DEBUG_INFO("loc=%s\n",loc);
  12999. memset(sstr ,0, sizeof(sstr) );
  13000. if(loc != NULL)
  13001. {
  13002. while (loc[3+strlen("validTo")+c] != '\"')
  13003. {
  13004. sstr[c] = loc[3+strlen("validTo")+c];
  13005. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13006. c++;
  13007. }
  13008. sstr[c] = '\0';
  13009. strcpy(tempvalidToStr,sstr);
  13010. }
  13011. else
  13012. {
  13013. strcpy(tempvalidToStr,"");
  13014. }
  13015. //***********validFrom**************/
  13016. c = 0;
  13017. loc = strstr(sLineWord, "validFrom");
  13018. if(loc != NULL)
  13019. {
  13020. memset(sstr ,0, sizeof(sstr) );
  13021. while (loc[3+strlen("validFrom")+c] != '\"')
  13022. {
  13023. sstr[c] = loc[3+strlen("validFrom")+c];
  13024. c++;
  13025. }
  13026. sstr[c] = '\0';
  13027. strcpy(tempvalidFromStr,sstr);
  13028. }
  13029. else
  13030. {
  13031. strcpy(tempvalidFromStr,"");
  13032. }
  13033. //***********validTo **************/
  13034. c = 0;
  13035. loc = strstr(sLineWord, "validTo");
  13036. if(loc != NULL)
  13037. {
  13038. memset(sstr ,0, sizeof(sstr) );
  13039. while (loc[3+strlen("validTo")+c] != '\"')
  13040. {
  13041. sstr[c] = loc[3+strlen("validTo")+c];
  13042. c++;
  13043. }
  13044. sstr[c] = '\0';
  13045. strcpy(tempvalidToStr,sstr);
  13046. }
  13047. else
  13048. {
  13049. strcpy(tempvalidToStr,"");
  13050. }
  13051. //***********duration**************/
  13052. c = 0;
  13053. loc = strstr(sLineWord, "duration");
  13054. if(loc != NULL)
  13055. {
  13056. memset(sstr ,0, sizeof(sstr) );
  13057. while (loc[2+strlen("duration")+c] != ',')
  13058. {
  13059. sstr[c] = loc[2+strlen("duration")+c];
  13060. c++;
  13061. }
  13062. sstr[c] = '\0';
  13063. tempdurationInt = atoi(sstr);
  13064. }
  13065. else
  13066. {
  13067. tempdurationInt = 0;
  13068. }
  13069. //**********startSchedule**********/
  13070. c = 0;
  13071. loc = strstr(sLineWord, "startSchedule");
  13072. memset(sstr ,0, sizeof(sstr) );
  13073. while (loc[3+strlen("startSchedule")+c] != '\"')
  13074. {
  13075. sstr[c] = loc[3+strlen("startSchedule")+c];
  13076. c++;
  13077. }
  13078. sstr[c] = '\0';
  13079. strcpy(tempstartScheduleStr, sstr);
  13080. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  13081. //**********chargingRateUnit**********/
  13082. c = 0;
  13083. loc = strstr(sLineWord, "chargingRateUnit");
  13084. memset(sstr ,0, sizeof(sstr) );
  13085. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13086. {
  13087. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13088. c++;
  13089. }
  13090. sstr[c] = '\0';
  13091. strcpy(tempchargingRateUnitStr, sstr);
  13092. //**********minChargingRate*******/
  13093. c = 0;
  13094. loc = strstr(sLineWord, "minChargingRate");
  13095. if(loc != NULL)
  13096. {
  13097. memset(sstr ,0, sizeof(sstr) );
  13098. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13099. {
  13100. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13101. c++;
  13102. }
  13103. sstr[c] = '\0';
  13104. tempminChargingRateFloat = atof(sstr);
  13105. }
  13106. else
  13107. {
  13108. tempminChargingRateFloat = 0.0;
  13109. }
  13110. //
  13111. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13112. tp.tm_isdst = -1;
  13113. time_t utc = mktime(&tp);
  13114. time_t t = time(NULL);
  13115. diff_t = difftime(t, utc);
  13116. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13117. //parsing strings to words
  13118. i = 0;
  13119. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13120. loc = loc+3+strlen("chargingSchedulePeriod");
  13121. pch = strtok(loc ,"{");
  13122. while (pch != NULL)
  13123. {
  13124. strcpy(SchedulePeriodList[i], pch);
  13125. pch = strtok (NULL, "{");
  13126. i = i + 1;
  13127. }
  13128. n_SchedulePeriods = i;
  13129. for(int i=0;i<n_SchedulePeriods;i++)
  13130. {
  13131. //*************startPeriod****************/
  13132. c = 0;
  13133. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13134. memset(sstr ,0, sizeof(sstr) );
  13135. while (loc[strlen("startPeriod")+2+c] != ',')
  13136. {
  13137. sstr[c] = loc[strlen("startPeriod")+2+c];
  13138. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13139. c++;
  13140. }
  13141. sstr[c] = '\0';
  13142. tempStartPeriodInt = atoi(sstr);
  13143. //*************limit****************/
  13144. c = 0;
  13145. loc = strstr(SchedulePeriodList[i], "limit");
  13146. memset(sstr ,0, sizeof(sstr) );
  13147. while (loc[strlen("limit")+2+c] != ',')
  13148. {
  13149. sstr[c] = loc[strlen("limit")+2+c];
  13150. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13151. c++;
  13152. }
  13153. sstr[c] = '\0';
  13154. tempLimitInt = atof(sstr);
  13155. //*************numberPhases****************/
  13156. c = 0;
  13157. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13158. memset(sstr ,0, sizeof(sstr) );
  13159. while (loc[strlen("numberPhases")+2+c] != '}')
  13160. {
  13161. sstr[c] = loc[strlen("numberPhases")+2+c];
  13162. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13163. c++;
  13164. }
  13165. sstr[c] = '\0';
  13166. tempNumberPhasesInt = atoi(sstr);
  13167. if(j == 0)
  13168. {
  13169. ChargePointMaxProfile.Duration = tempdurationInt;
  13170. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  13171. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  13172. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13173. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13174. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13175. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  13176. ChargePointMaxProfile_TEMP.TransactionId = 0;
  13177. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13178. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13179. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13180. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13181. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13182. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13183. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13184. }
  13185. }
  13186. if(MinChargingRate < tempminChargingRateFloat)
  13187. {
  13188. MinChargingRate = tempminChargingRateFloat;
  13189. }
  13190. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13191. if(confirmPeriods < n_SchedulePeriods)
  13192. {
  13193. confirmPeriods = n_SchedulePeriods;
  13194. }
  13195. j = j + 1;
  13196. }
  13197. fclose(fptr1);
  13198. }
  13199. }// the end of access file ChargePointMaxProfile
  13200. //****************************TxDefaultProfile************************************************/
  13201. #if 0
  13202. switch(gunindex + 1)
  13203. {
  13204. case 0:
  13205. strcpy(fname, TxDefaultProfile_0_JSON );
  13206. break;
  13207. case 1:
  13208. strcpy(fname, TxDefaultProfile_1_JSON );
  13209. break;
  13210. case 2:
  13211. strcpy(fname, TxDefaultProfile_2_JSON );
  13212. break;
  13213. default:
  13214. strcpy(fname, TxDefaultProfile_1_JSON );
  13215. break;
  13216. }
  13217. #endif
  13218. memset(fname, 0, sizeof fname);
  13219. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  13220. TxDefaultProfileFileIsNull=TRUE;
  13221. if((access(fname,F_OK))!=-1)
  13222. {
  13223. fptr1 = fopen(fname, "r");
  13224. c = 0;
  13225. c = fgetc(fptr1);
  13226. //DEBUG_INFO("c:%d\n",c);
  13227. rewind(fptr1);
  13228. if(c == EOF)
  13229. {
  13230. DEBUG_INFO("\n End of file reached.");
  13231. TxDefaultProfileFileIsNull=TRUE;
  13232. fclose(fptr1);
  13233. }
  13234. else
  13235. {
  13236. TxDefaultProfileFileIsNull=FALSE;
  13237. while(fscanf(fptr1, "%s", word) != EOF)
  13238. {
  13239. if(strcmp(word, "chargingProfileId") == 0)
  13240. {
  13241. n_chargingProfile = n_chargingProfile + 1;
  13242. }
  13243. }
  13244. rewind(fptr1);
  13245. //search Charging Profile Element
  13246. int i = 0;
  13247. int j = 0;
  13248. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13249. #if 0
  13250. /***********connectorId****************/
  13251. c = 0;
  13252. loc = strstr(sLineWord, "connectorId");
  13253. memset(sstr ,0, sizeof(sstr) );
  13254. while (loc[strlen("connectorId")+2+c] != ',')
  13255. {
  13256. sstr[c] = loc[strlen("connectorId")+2+c];
  13257. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13258. c++;
  13259. }
  13260. sstr[c] = '\0';
  13261. tempconnectorIdInt = atoi(sstr);
  13262. #endif
  13263. //***********chargingProfileId**************/
  13264. c = 0;
  13265. loc = strstr(sLineWord, "chargingProfileId");
  13266. //DEBUG_INFO("loc=%s\n",loc);
  13267. memset(sstr ,0, sizeof(sstr) );
  13268. if(loc != NULL)
  13269. {
  13270. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13271. {
  13272. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13273. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13274. c++;
  13275. }
  13276. sstr[c] = '\0';
  13277. tempchargingProfileId = atoi(sstr);
  13278. }
  13279. else
  13280. {
  13281. tempchargingProfileId = 0;
  13282. }
  13283. //***********stackLevel**************/
  13284. c = 0;
  13285. loc = strstr(sLineWord, "stackLevel");
  13286. //DEBUG_INFO("loc=%s\n",loc);
  13287. memset(sstr ,0, sizeof(sstr) );
  13288. if(loc != NULL)
  13289. {
  13290. while (loc[2+strlen("stackLevel")+c] != '\"')
  13291. {
  13292. sstr[c] = loc[2+strlen("stackLevel")+c];
  13293. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13294. c++;
  13295. }
  13296. sstr[c] = '\0';
  13297. tempstackLevel = atoi(sstr);
  13298. }
  13299. else
  13300. {
  13301. tempstackLevel = 0;
  13302. }
  13303. //***********chargingProfilePurpose **************/
  13304. c = 0;
  13305. loc = strstr(sLineWord, "chargingProfilePurpose");
  13306. //DEBUG_INFO("loc=%s\n",loc);
  13307. memset(sstr ,0, sizeof(sstr) );
  13308. if(loc != NULL)
  13309. {
  13310. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13311. {
  13312. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13313. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13314. c++;
  13315. }
  13316. sstr[c] = '\0';
  13317. strcpy(tempchargingProfilePurposeStr,sstr);
  13318. }
  13319. else
  13320. {
  13321. strcpy(tempchargingProfilePurposeStr,"");
  13322. }
  13323. //***********chargingProfileKind **************/
  13324. c = 0;
  13325. loc = strstr(sLineWord, "chargingProfileKind");
  13326. //DEBUG_INFO("loc=%s\n",loc);
  13327. memset(sstr ,0, sizeof(sstr) );
  13328. if(loc != NULL)
  13329. {
  13330. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13331. {
  13332. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13333. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13334. c++;
  13335. }
  13336. sstr[c] = '\0';
  13337. strcpy(tempchargingProfileKindStr,sstr);
  13338. }
  13339. else
  13340. {
  13341. strcpy(tempchargingProfileKindStr,"");
  13342. }
  13343. //***********recurrencyKind **************/
  13344. c = 0;
  13345. loc = strstr(sLineWord, "recurrencyKind");
  13346. //DEBUG_INFO("loc=%s\n",loc);
  13347. memset(sstr ,0, sizeof(sstr) );
  13348. if(loc != NULL)
  13349. {
  13350. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13351. {
  13352. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13353. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13354. c++;
  13355. }
  13356. sstr[c] = '\0';
  13357. strcpy(temprecurrencyKindStr,sstr);
  13358. }
  13359. else
  13360. {
  13361. strcpy(temprecurrencyKindStr,"");
  13362. }
  13363. //***********validFrom**************/
  13364. c = 0;
  13365. loc = strstr(sLineWord, "validFrom");
  13366. if(loc != NULL)
  13367. {
  13368. memset(sstr ,0, sizeof(sstr) );
  13369. while (loc[3+strlen("validFrom")+c] != '\"')
  13370. {
  13371. sstr[c] = loc[3+strlen("validFrom")+c];
  13372. c++;
  13373. }
  13374. sstr[c] = '\0';
  13375. strcpy(tempvalidFromStr,sstr);
  13376. }
  13377. else
  13378. {
  13379. strcpy(tempvalidFromStr,"");
  13380. }
  13381. //***********validTo **************/
  13382. c = 0;
  13383. loc = strstr(sLineWord, "validTo");
  13384. if(loc != NULL)
  13385. {
  13386. memset(sstr ,0, sizeof(sstr) );
  13387. while (loc[3+strlen("validTo")+c] != '\"')
  13388. {
  13389. sstr[c] = loc[3+strlen("validTo")+c];
  13390. c++;
  13391. }
  13392. sstr[c] = '\0';
  13393. strcpy(tempvalidToStr,sstr);
  13394. }
  13395. else
  13396. {
  13397. strcpy(tempvalidToStr,"");
  13398. }
  13399. //***********duration**************/
  13400. c = 0;
  13401. loc = strstr(sLineWord, "duration");
  13402. if(loc != NULL)
  13403. {
  13404. memset(sstr ,0, sizeof(sstr) );
  13405. while (loc[2+strlen("duration")+c] != ',')
  13406. {
  13407. sstr[c] = loc[2+strlen("duration")+c];
  13408. c++;
  13409. }
  13410. sstr[c] = '\0';
  13411. tempdurationInt = atoi(sstr);
  13412. }
  13413. else
  13414. {
  13415. tempdurationInt = 0;
  13416. }
  13417. //**********startSchedule**********/
  13418. c = 0;
  13419. loc = strstr(sLineWord, "startSchedule");
  13420. memset(sstr ,0, sizeof(sstr) );
  13421. while (loc[3+strlen("startSchedule")+c] != '\"')
  13422. {
  13423. sstr[c] = loc[3+strlen("startSchedule")+c];
  13424. c++;
  13425. }
  13426. sstr[c] = '\0';
  13427. strcpy(tempstartScheduleStr, sstr);
  13428. strcpy(TxDefaultProfileScheduleStr, sstr);
  13429. //**********chargingRateUnit**********/
  13430. c = 0;
  13431. loc = strstr(sLineWord, "chargingRateUnit");
  13432. memset(sstr ,0, sizeof(sstr) );
  13433. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13434. {
  13435. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13436. c++;
  13437. }
  13438. sstr[c] = '\0';
  13439. strcpy(tempchargingRateUnitStr, sstr);
  13440. //**********minChargingRate*******/
  13441. c = 0;
  13442. loc = strstr(sLineWord, "minChargingRate");
  13443. if(loc != NULL)
  13444. {
  13445. memset(sstr ,0, sizeof(sstr) );
  13446. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13447. {
  13448. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13449. c++;
  13450. }
  13451. sstr[c] = '\0';
  13452. tempminChargingRateFloat = atof(sstr);
  13453. }
  13454. else
  13455. {
  13456. tempminChargingRateFloat = 0.0;
  13457. }
  13458. //
  13459. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13460. tp.tm_isdst = -1;
  13461. time_t utc = mktime(&tp);
  13462. time_t t = time(NULL);
  13463. diff_t = difftime(t, utc);
  13464. printf("diff between startScheduleStr and now =%f\n",diff_t);
  13465. //parsing strings to words
  13466. i = 0;
  13467. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13468. loc = loc+3+strlen("chargingSchedulePeriod");
  13469. pch = strtok(loc ,"{");
  13470. while (pch != NULL)
  13471. {
  13472. strcpy(SchedulePeriodList[i], pch);
  13473. pch = strtok (NULL, "{");
  13474. i = i + 1;
  13475. }
  13476. n_SchedulePeriods = i;
  13477. for(int i=0;i<n_SchedulePeriods;i++)
  13478. {
  13479. //*************startPeriod****************/
  13480. c = 0;
  13481. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13482. memset(sstr ,0, sizeof(sstr) );
  13483. while (loc[strlen("startPeriod")+2+c] != ',')
  13484. {
  13485. sstr[c] = loc[strlen("startPeriod")+2+c];
  13486. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13487. c++;
  13488. }
  13489. sstr[c] = '\0';
  13490. tempStartPeriodInt = atoi(sstr);
  13491. //*************limit****************/
  13492. c = 0;
  13493. loc = strstr(SchedulePeriodList[i], "limit");
  13494. memset(sstr ,0, sizeof(sstr) );
  13495. while (loc[strlen("limit")+2+c] != ',')
  13496. {
  13497. sstr[c] = loc[strlen("limit")+2+c];
  13498. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13499. c++;
  13500. }
  13501. sstr[c] = '\0';
  13502. tempLimitInt = atof(sstr);
  13503. //*************numberPhases****************/
  13504. c = 0;
  13505. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13506. memset(sstr ,0, sizeof(sstr) );
  13507. while (loc[strlen("numberPhases")+2+c] != '}')
  13508. {
  13509. sstr[c] = loc[strlen("numberPhases")+2+c];
  13510. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13511. c++;
  13512. }
  13513. sstr[c] = '\0';
  13514. tempNumberPhasesInt = atoi(sstr);
  13515. if(j == 0)
  13516. {
  13517. TxDefaultProfile.Duration = tempdurationInt;
  13518. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  13519. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  13520. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13521. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13522. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13523. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13524. TxDefaultProfile_TEMP.TransactionId = 0;
  13525. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13526. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13527. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13528. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13529. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13530. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13531. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13532. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13533. }
  13534. else
  13535. {
  13536. //other stack level charging Profile
  13537. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13538. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13539. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13540. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13541. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13542. }
  13543. }
  13544. if(MinChargingRate < tempminChargingRateFloat)
  13545. {
  13546. MinChargingRate = tempminChargingRateFloat;
  13547. }
  13548. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13549. if(confirmPeriods < n_SchedulePeriods)
  13550. confirmPeriods = n_SchedulePeriods;
  13551. j = j + 1;
  13552. }
  13553. fclose(fptr1);
  13554. //Stacking Charging Profiles
  13555. for(int l=0; l <(j-1) ;l++)
  13556. {
  13557. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13558. {
  13559. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13560. {
  13561. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13562. {
  13563. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13564. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13565. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13566. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13567. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13568. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13569. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13570. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13571. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13572. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13573. }
  13574. else
  13575. {
  13576. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13577. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13578. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13579. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13580. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13581. }
  13582. }
  13583. }
  13584. }
  13585. //end of Stacking Charging Profiles
  13586. }
  13587. }// the end of ACCESS TxDefaultProfile
  13588. //****************************TxProfile************************************************/
  13589. #if 0
  13590. switch(gunindex + 1)
  13591. {
  13592. case 0:
  13593. break;
  13594. case 1:
  13595. strcpy(fname, TxProfile_1_JSON );
  13596. break;
  13597. case 2:
  13598. strcpy(fname, TxProfile_2_JSON );
  13599. break;
  13600. default:
  13601. strcpy(fname, TxProfile_1_JSON );
  13602. break;
  13603. }
  13604. #endif
  13605. memset(fname, 0, sizeof fname);
  13606. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  13607. TxProfileIsNull=TRUE;
  13608. if((access(fname,F_OK))!=-1)
  13609. {
  13610. fptr1 = fopen(fname, "r");
  13611. c = 0;
  13612. c = fgetc(fptr1);
  13613. //DEBUG_INFO("c:%d\n",c);
  13614. rewind(fptr1);
  13615. if(c == EOF)
  13616. {
  13617. DEBUG_INFO("\n End of file reached.");
  13618. TxProfileIsNull=TRUE;
  13619. fclose(fptr1);
  13620. }
  13621. else
  13622. {
  13623. TxProfileIsNull=FALSE;
  13624. while(fscanf(fptr1, "%s", word) != EOF)
  13625. {
  13626. if(strcmp(word, "chargingProfileId") == 0)
  13627. {
  13628. n_chargingProfile = n_chargingProfile + 1;
  13629. }
  13630. }
  13631. rewind(fptr1);
  13632. //search Charging Profile Element
  13633. int i= 0;
  13634. int j= 0;
  13635. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13636. #if 0
  13637. /***********connectorId****************/
  13638. c = 0;
  13639. loc = strstr(sLineWord, "connectorId");
  13640. memset(sstr ,0, sizeof(sstr) );
  13641. while (loc[strlen("connectorId")+2+c] != ',')
  13642. {
  13643. sstr[c] = loc[strlen("connectorId")+2+c];
  13644. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13645. c++;
  13646. }
  13647. sstr[c] = '\0';
  13648. tempconnectorIdInt = atoi(sstr);
  13649. #endif
  13650. //***********chargingProfileId**************/
  13651. c = 0;
  13652. loc = strstr(sLineWord, "chargingProfileId");
  13653. memset(sstr ,0, sizeof(sstr) );
  13654. if(loc != NULL)
  13655. {
  13656. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13657. {
  13658. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13659. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13660. c++;
  13661. }
  13662. sstr[c] = '\0';
  13663. tempchargingProfileId = atoi(sstr);
  13664. }
  13665. else
  13666. {
  13667. tempchargingProfileId = 0;
  13668. }
  13669. //***********transactionId **************/
  13670. c = 0;
  13671. loc = strstr(sLineWord, "transactionId");
  13672. //DEBUG_INFO("loc=%s\n",loc);
  13673. memset(sstr ,0, sizeof(sstr) );
  13674. if(loc != NULL)
  13675. {
  13676. while (loc[2+strlen("transactionId")+c] != '\"')
  13677. {
  13678. sstr[c] = loc[2+strlen("transactionId")+c];
  13679. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13680. c++;
  13681. }
  13682. sstr[c] = '\0';
  13683. temptransactionId = atoi(sstr);
  13684. }
  13685. else
  13686. {
  13687. temptransactionId = 0;
  13688. }
  13689. //***********stackLevel**************/
  13690. c = 0;
  13691. loc = strstr(sLineWord, "stackLevel");
  13692. //DEBUG_INFO("loc=%s\n",loc);
  13693. memset(sstr ,0, sizeof(sstr) );
  13694. if(loc != NULL)
  13695. {
  13696. while (loc[2+strlen("stackLevel")+c] != '\"')
  13697. {
  13698. sstr[c] = loc[2+strlen("stackLevel")+c];
  13699. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13700. c++;
  13701. }
  13702. sstr[c] = '\0';
  13703. tempstackLevel = atoi(sstr);
  13704. }
  13705. else
  13706. {
  13707. tempstackLevel = 0;
  13708. }
  13709. //***********chargingProfilePurpose **************/
  13710. c = 0;
  13711. loc = strstr(sLineWord, "chargingProfilePurpose");
  13712. //DEBUG_INFO("loc=%s\n",loc);
  13713. memset(sstr ,0, sizeof(sstr) );
  13714. if(loc != NULL)
  13715. {
  13716. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13717. {
  13718. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13719. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13720. c++;
  13721. }
  13722. sstr[c] = '\0';
  13723. strcpy(tempchargingProfilePurposeStr,sstr);
  13724. }
  13725. else
  13726. {
  13727. strcpy(tempchargingProfilePurposeStr,"");
  13728. }
  13729. //***********chargingProfileKind **************/
  13730. c = 0;
  13731. loc = strstr(sLineWord, "chargingProfileKind");
  13732. //DEBUG_INFO("loc=%s\n",loc);
  13733. memset(sstr ,0, sizeof(sstr) );
  13734. if(loc != NULL)
  13735. {
  13736. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13737. {
  13738. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13739. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13740. c++;
  13741. }
  13742. sstr[c] = '\0';
  13743. strcpy(tempchargingProfileKindStr,sstr);
  13744. }
  13745. else
  13746. {
  13747. strcpy(tempchargingProfileKindStr,"");
  13748. }
  13749. //***********recurrencyKind **************/
  13750. c = 0;
  13751. loc = strstr(sLineWord, "recurrencyKind");
  13752. //DEBUG_INFO("loc=%s\n",loc);
  13753. memset(sstr ,0, sizeof(sstr) );
  13754. if(loc != NULL)
  13755. {
  13756. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13757. {
  13758. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13759. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13760. c++;
  13761. }
  13762. sstr[c] = '\0';
  13763. strcpy(temprecurrencyKindStr,sstr);
  13764. }
  13765. else
  13766. {
  13767. strcpy(temprecurrencyKindStr,"");
  13768. }
  13769. //***********validFrom**************/
  13770. c = 0;
  13771. loc = strstr(sLineWord, "validFrom");
  13772. if(loc != NULL)
  13773. {
  13774. memset(sstr ,0, sizeof(sstr) );
  13775. while (loc[3+strlen("validFrom")+c] != '\"')
  13776. {
  13777. sstr[c] = loc[3+strlen("validFrom")+c];
  13778. c++;
  13779. }
  13780. sstr[c] = '\0';
  13781. strcpy(tempvalidFromStr,sstr);
  13782. }
  13783. else
  13784. {
  13785. strcpy(tempvalidFromStr,"");
  13786. }
  13787. //***********validTo**************/
  13788. c = 0;
  13789. loc = strstr(sLineWord, "validTo");
  13790. if(loc != NULL)
  13791. {
  13792. memset(sstr ,0, sizeof(sstr) );
  13793. while (loc[3+strlen("validTo")+c] != '\"')
  13794. {
  13795. sstr[c] = loc[3+strlen("validTo")+c];
  13796. c++;
  13797. }
  13798. sstr[c] = '\0';
  13799. strcpy(tempvalidToStr,sstr);
  13800. }
  13801. else
  13802. {
  13803. strcpy(tempvalidToStr,"");
  13804. }
  13805. //***********duration**************/
  13806. c = 0;
  13807. loc = strstr(sLineWord, "duration");
  13808. //DEBUG_INFO("loc=%s\n",loc);
  13809. memset(sstr ,0, sizeof(sstr) );
  13810. if(loc != NULL)
  13811. {
  13812. while (loc[2+strlen("duration")+c] != '\"')
  13813. {
  13814. sstr[c] = loc[2+strlen("duration")+c];
  13815. c++;
  13816. }
  13817. sstr[c] = '\0';
  13818. tempdurationInt = atoi(sstr);
  13819. }
  13820. else
  13821. {
  13822. tempdurationInt = 0;
  13823. }
  13824. //**********startSchedule**********/
  13825. c = 0;
  13826. loc = strstr(sLineWord, "startSchedule");
  13827. memset(sstr ,0, sizeof(sstr) );
  13828. while (loc[3+strlen("startSchedule")+c] != '\"')
  13829. {
  13830. sstr[c] = loc[3+strlen("startSchedule")+c];
  13831. c++;
  13832. }
  13833. sstr[c] = '\0';
  13834. strcpy(tempstartScheduleStr, sstr);
  13835. strcpy(TxProfileScheduleStr, sstr);
  13836. //**********chargingRateUnit**********/
  13837. c = 0;
  13838. loc = strstr(sLineWord, "chargingRateUnit");
  13839. memset(sstr ,0, sizeof(sstr) );
  13840. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13841. {
  13842. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13843. c++;
  13844. }
  13845. sstr[c] = '\0';
  13846. strcpy(tempchargingRateUnitStr, sstr);
  13847. //**********minChargingRate*******/
  13848. c = 0;
  13849. loc = strstr(sLineWord, "minChargingRate");
  13850. if(loc != NULL)
  13851. {
  13852. memset(sstr ,0, sizeof(sstr) );
  13853. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13854. {
  13855. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13856. c++;
  13857. }
  13858. sstr[c] = '\0';
  13859. tempminChargingRateFloat = atof(sstr);
  13860. }
  13861. else
  13862. {
  13863. tempminChargingRateFloat = 0.0;
  13864. }
  13865. //
  13866. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13867. tp.tm_isdst = -1;
  13868. time_t utc = mktime(&tp);
  13869. time_t t = time(NULL);
  13870. diff_t = difftime(t, utc);
  13871. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13872. //parsing strings to words
  13873. i = 0;
  13874. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13875. loc = loc+3+strlen("chargingSchedulePeriod");
  13876. pch = strtok(loc ,"{");
  13877. while (pch != NULL)
  13878. {
  13879. strcpy(SchedulePeriodList[i], pch);
  13880. pch = strtok (NULL, "{");
  13881. i = i + 1;
  13882. }
  13883. n_SchedulePeriods = i;
  13884. for(int i=0;i<n_SchedulePeriods;i++)
  13885. {
  13886. //*************startPeriod****************/
  13887. c = 0;
  13888. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13889. memset(sstr ,0, sizeof(sstr) );
  13890. while (loc[strlen("startPeriod")+2+c] != ',')
  13891. {
  13892. sstr[c] = loc[strlen("startPeriod")+2+c];
  13893. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13894. c++;
  13895. }
  13896. sstr[c] = '\0';
  13897. tempStartPeriodInt = atoi(sstr);
  13898. //*************limit****************/
  13899. c = 0;
  13900. loc = strstr(SchedulePeriodList[i], "limit");
  13901. memset(sstr ,0, sizeof(sstr) );
  13902. while (loc[strlen("limit")+2+c] != ',')
  13903. {
  13904. sstr[c] = loc[strlen("limit")+2+c];
  13905. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13906. c++;
  13907. }
  13908. sstr[c] = '\0';
  13909. tempLimitInt = atof(sstr);
  13910. //*************numberPhases****************/
  13911. c = 0;
  13912. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13913. memset(sstr ,0, sizeof(sstr) );
  13914. while (loc[strlen("numberPhases")+2+c] != '}')
  13915. {
  13916. sstr[c] = loc[strlen("numberPhases")+2+c];
  13917. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13918. c++;
  13919. }
  13920. sstr[c] = '\0';
  13921. tempNumberPhasesInt = atoi(sstr);
  13922. //TxProfile.Duration = durationInt;
  13923. TxProfile.TotalPeriod = n_SchedulePeriods;
  13924. TxProfile.Period[i].Limit = tempLimitInt;
  13925. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13926. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13927. }
  13928. if(MinChargingRate < tempminChargingRateFloat)
  13929. {
  13930. MinChargingRate = tempminChargingRateFloat;
  13931. }
  13932. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13933. if(confirmPeriods < n_SchedulePeriods)
  13934. confirmPeriods = n_SchedulePeriods;
  13935. if(j == 0)
  13936. {
  13937. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13938. TxProfile_TEMP.StackLevel = tempstackLevel;
  13939. TxProfile_TEMP.TransactionId = 0;
  13940. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13941. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13942. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13943. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13944. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13945. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13946. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13947. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13948. }
  13949. }
  13950. fclose(fptr1);
  13951. }
  13952. }// the end of ACCESS TxProfile
  13953. //CompositeSchedule
  13954. int period=0;
  13955. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13956. {
  13957. //TxProfile
  13958. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13959. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13960. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13961. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13962. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13963. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13964. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13965. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13966. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13967. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13968. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13969. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13970. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13971. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13972. {
  13973. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13974. {
  13975. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13976. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13977. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13978. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13979. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13980. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13981. period = period + 1;
  13982. }
  13983. else
  13984. {
  13985. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13986. {
  13987. }
  13988. else
  13989. {
  13990. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13991. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13992. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13993. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13994. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13995. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13996. period = period + 1;
  13997. }
  13998. }
  13999. }
  14000. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14001. {
  14002. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  14003. {
  14004. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14005. {
  14006. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14007. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  14008. }
  14009. else
  14010. {
  14011. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14012. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  14013. }
  14014. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14015. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14016. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14017. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14018. period = period + 1;
  14019. }
  14020. }
  14021. }
  14022. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14023. {
  14024. //TxDefaultProfile
  14025. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14026. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14027. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14028. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14029. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  14030. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14031. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14032. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14033. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14034. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14035. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14036. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14037. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14038. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14039. {
  14040. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  14041. {
  14042. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14043. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14044. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14045. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14046. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14047. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14048. period = period + 1;
  14049. }
  14050. else
  14051. {
  14052. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14053. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14054. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14055. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  14056. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14057. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14058. period = period + 1;
  14059. }
  14060. }
  14061. }
  14062. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  14063. {
  14064. //TxDefaultProfile
  14065. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  14066. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  14067. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14068. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  14069. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  14070. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  14071. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14072. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  14073. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  14074. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  14075. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  14076. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  14077. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  14078. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  14079. {
  14080. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14081. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14082. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14083. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  14084. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  14085. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  14086. period = period + 1;
  14087. }
  14088. }
  14089. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  14090. {
  14091. //ChargePointMaxProfile
  14092. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  14093. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  14094. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  14095. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  14096. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  14097. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14098. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  14099. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  14100. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  14101. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  14102. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  14103. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  14104. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  14105. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  14106. {
  14107. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  14108. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  14109. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  14110. period = period + 1;
  14111. }
  14112. }
  14113. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  14114. {
  14115. //TxProfile
  14116. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14117. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14118. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14119. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14120. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14121. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14122. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14123. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14124. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14125. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14126. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14127. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14128. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14129. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14130. {
  14131. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  14132. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  14133. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  14134. }
  14135. }
  14136. confirmPeriods = period;
  14137. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  14138. 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,"
  14139. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  14140. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  14141. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  14142. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  14143. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  14144. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  14145. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  14146. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  14147. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  14148. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  14149. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  14150. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  14151. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  14152. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  14153. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  14154. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  14155. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  14156. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  14157. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  14158. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  14159. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  14160. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  14161. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  14162. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  14163. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  14164. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  14165. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  14166. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  14167. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  14168. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  14169. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  14170. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  14171. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  14172. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  14173. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  14174. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  14175. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  14176. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  14177. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  14178. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  14179. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  14180. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  14181. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  14182. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  14183. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  14184. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  14185. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  14186. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  14187. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  14188. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  14189. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  14190. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  14191. }
  14192. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14193. {
  14194. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14195. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14196. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14197. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14198. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14199. }
  14200. int GetWebSocketPingInterval(void)
  14201. {
  14202. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14203. }
  14204. void LWS_Send(char * str)
  14205. {
  14206. //=====================================================
  14207. // Check InternetConn 0: disconnected, 1: connected
  14208. //====================================================
  14209. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14210. {
  14211. DEBUG_INFO("\n offline now !!!\n");
  14212. return;
  14213. }
  14214. pthread_mutex_lock(&lock);
  14215. memset(SendBuffer,0,SendBufLen);
  14216. sprintf((char *)SendBuffer, "%s", str);
  14217. pthread_mutex_unlock(&lock);
  14218. lws_callback_on_writable(wsi_client);
  14219. lws_service(context, 10000);//timeout_ms
  14220. }