MessageHandler.c 574 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888
  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. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  60. struct StatusCodeData *ShmStatusCodeData;
  61. struct PsuData *ShmPsuData ;
  62. struct OCPP16Data *ShmOCPP16Data;
  63. // define Macro
  64. #define SystemLogMessage
  65. // OCPP Message Type
  66. #define MESSAGE_TYPE_CALL 2
  67. #define MESSAGE_TYPE_CALLRESULT 3
  68. #define MESSAGE_TYPE_CALLERROR 4
  69. //
  70. #define server_cycle_Status 120
  71. #define MACROSTR(k) #k
  72. //ConfigurationMaxKeys
  73. #define GetConfigurationMaxKeysNUM 43
  74. //char guid[37];
  75. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  76. char queuedata[2600]={0};
  77. //===============================
  78. // Configuration: unknownkey
  79. //===============================
  80. static char unknownkey[10][20]={0};
  81. static int UnknownKeynum = 0;
  82. //===============================
  83. // Gun Total Numbers
  84. //===============================
  85. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  86. static int gunTotalNumber=0;
  87. //===============================
  88. // Local List Version
  89. //===============================
  90. static int localversion=0;
  91. static char idTagAuthorization[32]={0};
  92. //===============================
  93. // OCPP Path
  94. //===============================
  95. extern char OcppPath[160];
  96. extern char OcppProtocol[10];
  97. extern char OcppHost[50];
  98. extern char OcppTempPath[50];
  99. int OcppPort=0;
  100. //===============================
  101. // OCPP sign variable
  102. //===============================
  103. int server_sign = FALSE;
  104. int server_pending = FALSE;
  105. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  106. int BootNotificationInterval = 0;
  107. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  108. //===============================
  109. // OCPP auth variable
  110. //===============================
  111. int authenrequest = FALSE;
  112. int authorizeRetryTimes = 0; //number of Retry times
  113. //===============================
  114. // OCPP StartTransaction transactionId variables
  115. //===============================
  116. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  117. //===============================
  118. // OCPP other variables
  119. //===============================
  120. int isUpdateRequest = FALSE;
  121. static int HeartBeatWaitTime = 10;
  122. static int FirstHeartBeat = 0;
  123. static int FirmwareStatusNotificationStatus = 3; // Idle
  124. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  125. static char CurrentChargingProfileScheduleStr[30]={0};
  126. //========================================
  127. // OCPP status/previous related variables
  128. //========================================
  129. static int GunStatusInterval = 10;
  130. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  131. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  132. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  133. static int GbPreviousSystemStatus[GB_QUANTITY];
  134. static int AcPreviousSystemStatus[AC_QUANTITY];
  135. int TransactionMessageAttemptsValue = 0;
  136. int TransactionMessageRetryIntervalValue = 0;
  137. static struct OCPPAuthLocalElemet
  138. {
  139. int listVersionInt;
  140. char idTagstr[20];
  141. char parentIdTag[20];
  142. char expiryDate[30];
  143. char idTagstatus[16];
  144. }idTagQuery;
  145. //=============================================
  146. // OCPP HeartBeat Response Not Receive Counts
  147. //============================================
  148. static int HeartBeatWithNOResponse = 0;
  149. static int HeartBeatCount = 0;
  150. extern struct lws *wsi_client;
  151. extern struct lws_context *context;
  152. extern unsigned char SendBuffer[4096];
  153. extern int SendBufLen;
  154. extern char *random_uuid( char buf[37] );
  155. extern void split(char **arr, char *str, const char *del);
  156. extern pthread_mutex_t mutex1;
  157. extern struct Charger_Info Charger;
  158. extern sqlite3 *db;
  159. int TransactionMessageAttemptsGet(void);
  160. int TransactionMessageRetryIntervalGet(void);
  161. int GetOcppConnStatus(void);
  162. void SetOcppConnStatus(uint8_t status);
  163. int updateSetting(char *key, char *value);
  164. int setKeyValue(char *key, char *value);
  165. void OCPP_get_TableAuthlocalAllData(void);
  166. void processUnkownKey(void);
  167. struct StructOCPPMeterValue
  168. {
  169. unsigned char TimeStamp[28];
  170. struct StructSampledValue SampledValue[10];
  171. };
  172. struct ClientTime
  173. {
  174. unsigned int Heartbeat;
  175. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  176. unsigned int StartTransaction;
  177. unsigned int StopTransaction;
  178. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  179. }clientTime;
  180. typedef union
  181. {
  182. //Operations Initiated by Central System
  183. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  184. struct
  185. {
  186. //CsMsgValue[0]
  187. unsigned char StatusNotificationReq :1; //bit 0,
  188. unsigned char StatusNotificationConf :1; //bit 0,
  189. unsigned char :6; //bit 2~7
  190. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  191. }CpinitiateMsg;
  192. CpinitiateMsg cpinitateMsg;
  193. //==========================================
  194. // Init all Enumeration & Mapping String
  195. //==========================================
  196. /*ChargePointErrorCode*/
  197. typedef enum {
  198. ConnectorLockFailure,
  199. EVCommunicationError,
  200. GroundFailure,
  201. HighTemperature,
  202. InternalError,
  203. LocalListConflict,
  204. NoError,
  205. OtherError,
  206. OverCurrentFailure,
  207. OverVoltage,
  208. PowerMeterFailure,
  209. PowerSwitchFailure,
  210. ReaderFailure,
  211. ResetFailure,
  212. UnderVoltage,
  213. WeakSignal
  214. } ChargePointErrorCode;
  215. #if 0
  216. static char *ChargePointErrorCodeStr[] = {
  217. MACROSTR(ConnectorLockFailure),
  218. MACROSTR(EVCommunicationError),
  219. MACROSTR(GroundFailure),
  220. MACROSTR(HighTemperature),
  221. MACROSTR(InternalError),
  222. MACROSTR(LocalListConflict),
  223. MACROSTR(NoError),
  224. MACROSTR(OtherError),
  225. MACROSTR(OverCurrentFailure),
  226. MACROSTR(OverVoltage),
  227. MACROSTR(PowerMeterFailure),
  228. MACROSTR(PowerSwitchFailure),
  229. MACROSTR(ReaderFailure),
  230. MACROSTR(ResetFailure),
  231. MACROSTR(UnderVoltage),
  232. MACROSTR(WeakSignal)
  233. };
  234. #endif
  235. /*ChargePointStatus*/
  236. typedef enum {
  237. Available =0,
  238. Preparing,
  239. Charging,
  240. SuspendedEVSE,
  241. SuspendedEV,
  242. Finishing,
  243. Reserved,
  244. Unavailable,
  245. Faulted
  246. } ChargePointStatus;
  247. static char * ChargePointStatusStr[] = {
  248. MACROSTR(Available),
  249. MACROSTR(Preparing),
  250. MACROSTR(Charging),
  251. MACROSTR(SuspendedEVSE),
  252. MACROSTR(SuspendedEV),
  253. MACROSTR(Finishing),
  254. MACROSTR(Reserved),
  255. MACROSTR(Unavailable),
  256. MACROSTR(Faulted)
  257. };
  258. /*AvailabilityType*/
  259. typedef enum {
  260. RegistrationStatus_Accepted,
  261. RegistrationStatus_Pending,
  262. RegistrationStatus_Rejected
  263. } RegistrationStatus;
  264. static char *RegistrationStatusStr[] = {
  265. MACROSTR(Accepted),
  266. MACROSTR(Pending),
  267. MACROSTR(Rejected)
  268. };
  269. /*AvailabilityType*/
  270. typedef enum {
  271. Inoperative,
  272. Operative
  273. } AvailabilityType;
  274. static char *AvailabilityTypeStr[] = {
  275. MACROSTR(Inoperative),
  276. MACROSTR(Operative)
  277. };
  278. /*AvailabilityStatus*/
  279. typedef enum {
  280. Accepted,
  281. Rejected,
  282. Scheduled
  283. } AvailabilityStatus;
  284. static char *AvailabilityStatusStr[] = {
  285. MACROSTR(Accepted),
  286. MACROSTR(Rejected),
  287. MACROSTR(Scheduled)
  288. };
  289. /*ConfigurationStatus*/
  290. typedef enum {
  291. ConfigurationStatus_Accepted,
  292. ConfigurationStatus_Rejected,
  293. RebootRequired,
  294. NotSupported
  295. } ConfigurationStatus;
  296. static char *ConfigurationStatusStr[] = {
  297. MACROSTR(Accepted),
  298. MACROSTR(Rejected),
  299. MACROSTR(RebootRequired),
  300. MACROSTR(NotSupported)
  301. };
  302. /*ClearCacheStatus*/
  303. typedef enum {
  304. ClearCacheStatus_Accepted,
  305. ClearCacheStatus_Rejected
  306. } ClearCacheStatus;
  307. static char *ClearCacheStatusStr[] = {
  308. MACROSTR(Accepted),
  309. MACROSTR(Rejected)
  310. };
  311. /*ChargingProfilePurposeType*/
  312. typedef enum {
  313. ChargePointMaxProfile,
  314. TxDefaultProfile,
  315. TxProfile
  316. } ChargingProfilePurposeType;
  317. static char *ChargingProfilePurposeTypeStr[] = {
  318. MACROSTR(ChargePointMaxProfile),
  319. MACROSTR(TxDefaultProfile),
  320. MACROSTR(TxProfile)
  321. };
  322. /*ChargingProfileStatus*/
  323. typedef enum {
  324. ChargingProfileStatus_Accepted,
  325. ChargingProfileStatus_Rejected,
  326. ChargingProfileStatus_NotSupported
  327. } ChargingProfileStatus;
  328. static char *ChargingProfileStatusStr[] = {
  329. MACROSTR(Accepted),
  330. MACROSTR(Rejected),
  331. MACROSTR(NotSupported)
  332. };
  333. /*ClearChargingProfileStatus*/
  334. typedef enum {
  335. ClearChargingProfileStatus_Accepted,
  336. ClearChargingProfileStatus_Unknown
  337. } ClearChargingProfileStatus;
  338. static char *ClearChargingProfileStatusStr[] = {
  339. MACROSTR(Accepted),
  340. MACROSTR(Unknown)
  341. };
  342. /*GetCompositeScheduleStatus*/
  343. typedef enum {
  344. GetCompositeScheduleStatus_Accepted,
  345. GetCompositeScheduleStatus_Rejected
  346. } GetCompositeScheduleStatus;
  347. static char *GetCompositeScheduleStatusStr[] = {
  348. MACROSTR(Accepted),
  349. MACROSTR(Rejected)
  350. };
  351. /*ChargingRateUnitType*/
  352. typedef enum {
  353. ChargingRateUnitType_W,
  354. ChargingRateUnitType_A
  355. } ChargingRateUnitType;
  356. /*AuthorizationStatus*/
  357. typedef enum {
  358. AuthorizationStatus_Accepted ,
  359. AuthorizationStatus_Blocked ,
  360. AuthorizationStatus_Expired ,
  361. AuthorizationStatus_Invalid ,
  362. AuthorizationStatus_ConcurrentTx
  363. } AuthorizationStatus;
  364. /*UpdateType*/
  365. typedef enum {
  366. Differential ,
  367. Full
  368. } UpdateType;
  369. static char *UpdateTypeStr[] = {
  370. MACROSTR(Differential),
  371. MACROSTR(Full)
  372. };
  373. /*UpdateStatus*/
  374. typedef enum {
  375. UpdateStatus_Accepted ,
  376. UpdateStatus_Failed ,
  377. UpdateStatus_NotSupported ,
  378. UpdateStatus_VersionMismatch
  379. } UpdateStatus;
  380. static char *UpdateStatusStr[] = {
  381. MACROSTR(Accepted),
  382. MACROSTR(Failed),
  383. MACROSTR(NotSupported),
  384. MACROSTR(VersionMismatch)
  385. };
  386. /*RemoteStartStopStatus*/
  387. typedef enum {
  388. RemoteStartStopStatus_Accepted,
  389. RemoteStartStopStatus_Rejected
  390. } RemoteStartStopStatus;
  391. static char *RemoteStartStopStatusStr[] = {
  392. MACROSTR(Accepted),
  393. MACROSTR(Rejected)
  394. };
  395. /*ReservationStatus*/
  396. typedef enum {
  397. ReservationStatus_Accepted,
  398. ReservationStatus_Faulted,
  399. ReservationStatus_Occupied,
  400. ReservationStatus_Rejected,
  401. ReservationStatus_Unavailable
  402. } ReservationStatus;
  403. static char *ReservationStatusStr[] = {
  404. MACROSTR(Accepted),
  405. MACROSTR(Faulted),
  406. MACROSTR(Occupied),
  407. MACROSTR(Rejected),
  408. MACROSTR(Unavailable)
  409. };
  410. /*ResetType*/
  411. typedef enum {
  412. Hard,
  413. Soft
  414. } ResetType;
  415. static char *ResetTypeStr[] = {
  416. MACROSTR(Hard),
  417. MACROSTR(Soft)
  418. };
  419. /*ResetStatus*/
  420. typedef enum {
  421. ResetStatus_Accepted,
  422. ResetStatus_Rejected
  423. } ResetStatus;
  424. static char *ResetStatusStr[] = {
  425. MACROSTR(Accepted),
  426. MACROSTR(Rejected)
  427. };
  428. /*DiagnosticsStatus*/
  429. typedef enum {
  430. DiagnosticsStatus_Idle,
  431. DiagnosticsStatus_Uploaded,
  432. DiagnosticsStatus_UploadFailed,
  433. DiagnosticsStatus_Uploading
  434. } DiagnosticsStatus;
  435. static char * DiagnosticsStatusStr[] = {
  436. MACROSTR(Idle),
  437. MACROSTR(Uploaded),
  438. MACROSTR(UploadFailed),
  439. MACROSTR(Uploading)
  440. };
  441. /*FirmwareStatus*/
  442. typedef enum {
  443. FirmwareStatus_Downloaded,
  444. FirmwareStatus_DownloadFailed,
  445. FirmwareStatus_Downloading,
  446. FirmwareStatus_Idle,
  447. FirmwareStatus_InstallationFailed,
  448. FirmwareStatus_Installing,
  449. FirmwareStatus_Installed
  450. } FirmwareStatus;
  451. static char * FirmwareStatusStr[] = {
  452. MACROSTR(Downloaded),
  453. MACROSTR(DownloadFailed),
  454. MACROSTR(Downloading),
  455. MACROSTR(Idle),
  456. MACROSTR(InstallationFailed),
  457. MACROSTR(Installing),
  458. MACROSTR(Installed)
  459. };
  460. /*MessageTrigger*/
  461. typedef enum {
  462. BootNotification,
  463. DiagnosticsStatusNotification,
  464. FirmwareStatusNotification,
  465. Heartbeat,
  466. MeterValues,
  467. StatusNotification
  468. } MessageTrigger;
  469. static char * MessageTriggerStr[] = {
  470. MACROSTR(BootNotification),
  471. MACROSTR(DiagnosticsStatusNotification),
  472. MACROSTR(FirmwareStatusNotification),
  473. MACROSTR(Heartbeat),
  474. MACROSTR(MeterValues),
  475. MACROSTR(StatusNotification)
  476. };
  477. /*TriggerMessageStatus*/
  478. typedef enum {
  479. TriggerMessageStatus_Accepted ,
  480. TriggerMessageStatus_Rejected ,
  481. TriggerMessageStatus_NotImplemented
  482. } TriggerMessageStatus;
  483. static char * TriggerMessageStatusStr[] = {
  484. MACROSTR(Accepted),
  485. MACROSTR(Rejected),
  486. MACROSTR(NotImplemented)
  487. };
  488. /*UnlockStatus*/
  489. typedef enum {
  490. Unlocked,
  491. UnlockFailed,
  492. UnlockStatus_NotSupported
  493. } UnlockStatus;
  494. static char * UnlockStatusStr[] = {
  495. MACROSTR(Unlocked),
  496. MACROSTR(UnlockFailed),
  497. MACROSTR(NotSupported)
  498. };
  499. /*StopTransactionReason*/
  500. typedef enum {
  501. EmergencyStop,
  502. EVDisconnected,
  503. HardReset,
  504. Local,
  505. Other,
  506. PowerLoss,
  507. Reboot,
  508. Remote,
  509. SoftReset,
  510. UnlockCommand,
  511. DeAuthorized
  512. } StopTransactionReason;
  513. #if 0
  514. static char * StopTransactionReasonStr[] = {
  515. MACROSTR(EmergencyStop),
  516. MACROSTR(EVDisconnected),
  517. MACROSTR(HardReset),
  518. MACROSTR(Local),
  519. MACROSTR(Other),
  520. MACROSTR(PowerLoss),
  521. MACROSTR(Reboot),
  522. MACROSTR(Remote),
  523. MACROSTR(SoftReset),
  524. MACROSTR(UnlockCommand),
  525. MACROSTR(DeAuthorized)
  526. };
  527. #endif
  528. /*CancelReservationStatus*/
  529. typedef enum {
  530. CancelReservationStatus_Accepted,
  531. CancelReservationStatus_Rejected
  532. } CancelReservationStatus;
  533. static char * CancelReservationStatusStr[] = {
  534. MACROSTR(Accepted),
  535. MACROSTR(Rejected)
  536. };
  537. /*ReadingContext*/
  538. typedef enum {
  539. ReadingContext_Interruption_Begin,
  540. ReadingContext_Interruption_End,
  541. ReadingContext_Other,
  542. ReadingContext_Sample_Clock,
  543. ReadingContext_Sample_Periodic ,
  544. ReadingContext_Transaction_Begin ,
  545. ReadingContext_Transaction_End,
  546. ReadingContext_Trigger
  547. } ReadingContext;
  548. static char * ReadingContextStr[] = {
  549. MACROSTR(Interruption.Begin),
  550. MACROSTR(Interruption.End),
  551. MACROSTR(Other),
  552. MACROSTR(Sample.Clock),
  553. MACROSTR(Sample.Periodic),
  554. MACROSTR(Transaction.Begin),
  555. MACROSTR(Transaction.End),
  556. MACROSTR(Trigger)
  557. };
  558. /*ValueFormat*/
  559. typedef enum {
  560. Raw,
  561. SignedData
  562. } ValueFormat;
  563. static char * ValueFormatStr[] = {
  564. MACROSTR(Raw),
  565. MACROSTR(SignedData)
  566. };
  567. /*Measurand*/
  568. typedef enum {
  569. Current_Export ,
  570. Current_Import,
  571. Current_Offered,
  572. Energy_Active_Export_Register,
  573. Energy_Active_Import_Register,
  574. Energy_Reactive_Export_Register,
  575. Energy_Reactive_Import_Register,
  576. Energy_Active_Export_Interval,
  577. Energy_Active_Import_Interval,
  578. Energy_Reactive_Export_Interval,
  579. Energy_Reactive_Import_Interval,
  580. Frequency,
  581. Power_Active_Export ,
  582. Power_Active_Import,
  583. Power_Factor,
  584. Power_Offered,
  585. Power_Reactive_Export,
  586. Power_Reactive_Import,
  587. RPM,
  588. SoC,
  589. Temperature ,
  590. Voltage
  591. } Measurand;
  592. static char * MeasurandStr[] = {
  593. MACROSTR(Current.Export),
  594. MACROSTR(Current.Import),
  595. MACROSTR(Current.Offered),
  596. MACROSTR(Energy.Active.Export.Register),
  597. MACROSTR(Energy.Active.Import.Register),
  598. MACROSTR(Energy.Reactive.Export.Register),
  599. MACROSTR(Energy.Reactive.Import.Register),
  600. MACROSTR(Energy.Active.Export.Interval),
  601. MACROSTR(Energy.Active.Import.Interval),
  602. MACROSTR(Energy.Reactive.Export.Interval),
  603. MACROSTR(Energy.Reactive.Import.Interval),
  604. MACROSTR(Frequency),
  605. MACROSTR(Power.Active.Export),
  606. MACROSTR(Power.Active.Import),
  607. MACROSTR(Power.Factor),
  608. MACROSTR(Power.Offered),
  609. MACROSTR(Power.Reactive.ExportMACROSTR),
  610. MACROSTR(Power.Reactive.Import),
  611. MACROSTR(RPM),
  612. MACROSTR(SoC),
  613. MACROSTR(Temperature),
  614. MACROSTR(Voltage)
  615. };
  616. /*Location*/
  617. typedef enum {
  618. Location_Body,
  619. Location_Cable,
  620. Location_EV,
  621. Location_Inlet ,
  622. Location_Outlet
  623. } Location;
  624. static char * LocationStr[] = {
  625. MACROSTR(Body),
  626. MACROSTR(Cable),
  627. MACROSTR(EV),
  628. MACROSTR(Inlet),
  629. MACROSTR(Outlet)
  630. };
  631. /*Phase*/
  632. typedef enum {
  633. L1,
  634. L2,
  635. L3,
  636. N,
  637. L1_N,
  638. L2_N,
  639. L3_N,
  640. L1_L2,
  641. L2_L3,
  642. L3_L1
  643. } Phase;
  644. static char * PhaseStr[] = {
  645. MACROSTR(L1),
  646. MACROSTR(L2),
  647. MACROSTR(L3),
  648. MACROSTR(N),
  649. MACROSTR(L1-N),
  650. MACROSTR(L2-N),
  651. MACROSTR(L3-N),
  652. MACROSTR(L1-L2),
  653. MACROSTR(L2-L3),
  654. MACROSTR(L3-L1)
  655. };
  656. /*UnitOfMeasure*/
  657. typedef enum {
  658. UnitOfMeasure_Wh,
  659. UnitOfMeasure_kWh ,
  660. UnitOfMeasure_varh ,
  661. UnitOfMeasure_kvarh ,
  662. UnitOfMeasure_W ,
  663. UnitOfMeasure_kW ,
  664. UnitOfMeasure_VA ,
  665. UnitOfMeasure_kVA ,
  666. UnitOfMeasure_var ,
  667. UnitOfMeasure_kvar ,
  668. UnitOfMeasure_A ,
  669. UnitOfMeasure_V ,
  670. UnitOfMeasure_Celsius ,
  671. UnitOfMeasure_Fahrenheit ,
  672. UnitOfMeasure_K ,
  673. UnitOfMeasure_Percent
  674. } UnitOfMeasure;
  675. static char * UnitOfMeasureStr[] = {
  676. MACROSTR(Wh),
  677. MACROSTR(kWh),
  678. MACROSTR(varh),
  679. MACROSTR(kvarh),
  680. MACROSTR(W),
  681. MACROSTR(kW),
  682. MACROSTR(VA),
  683. MACROSTR(kVA),
  684. MACROSTR(var),
  685. MACROSTR(kvar),
  686. MACROSTR(A),
  687. MACROSTR(V),
  688. MACROSTR(Celsius),
  689. MACROSTR(Fahrenheit),
  690. MACROSTR(K),
  691. MACROSTR(Percent)
  692. };
  693. #if 0
  694. /*Configuration enum*/
  695. enum CoreProfile {
  696. AllowOfflineTxForUnknownId=0,
  697. AuthorizationCacheEnabled,
  698. AuthorizeRemoteTxRequests,
  699. BlinkRepeat,
  700. ClockAlignedDataInterval,
  701. ConnectionTimeOut,
  702. GetConfigurationMaxKeys,
  703. HeartbeatInterval,
  704. LightIntensity,
  705. LocalAuthorizeOffline,
  706. LocalPreAuthorize,
  707. MaxEnergyOnInvalidId,
  708. MeterValuesAlignedData,
  709. MeterValuesAlignedDataMaxLength,
  710. MeterValuesSampledData,
  711. MeterValuesSampledDataMaxLength,
  712. MeterValueSampleInterval,
  713. MinimumStatusDuration,
  714. NumberOfConnectors,
  715. ResetRetries,
  716. ConnectorPhaseRotation,
  717. ConnectorPhaseRotationMaxLength,
  718. StopTransactionOnEVSideDisconnect,
  719. StopTransactionOnInvalidId,
  720. StopTxnAlignedData,
  721. StopTxnAlignedDataMaxLength,
  722. StopTxnSampledData,
  723. StopTxnSampledDataMaxLength,
  724. SupportedFeatureProfiles,
  725. SupportedFeatureProfilesMaxLength,
  726. TransactionMessageAttempts,
  727. TransactionMessageRetryInterval,
  728. UnlockConnectorOnEVSideDisconnect,
  729. WebSocketPingInterval,
  730. _CoreProfile_CNT
  731. };
  732. #endif
  733. enum LocalAuthListManagementProfile{
  734. LocalAuthListEnabled=0,
  735. LocalAuthListMaxLength,
  736. SendLocalListMaxLength,
  737. _LocalAuthListManagementProfile_CNT
  738. };
  739. enum ReservationProfile{
  740. ReserveConnectorZeroSupported
  741. };
  742. enum SmartChargingProfile{
  743. ChargeProfileMaxStackLevel,
  744. ChargingScheduleAllowedChargingRateUnit,
  745. ChargingScheduleMaxPeriods,
  746. ConnectorSwitch3to1PhaseSupported,
  747. MaxChargingProfilesInstalled
  748. };
  749. enum ChargerSystemStatus{
  750. ChargerSystemStatus_Booting,
  751. ChargerSystemStatus_Idle,
  752. ChargerSystemStatus_Authorizing,
  753. ChargerSystemStatus_Preparing,
  754. ChargerSystemStatus_Charging,
  755. ChargerSystemStatus_Terminating,
  756. ChargerSystemStatus_Alarm,
  757. ChargerSystemStatus_Fault
  758. };
  759. enum GetConfigurationKey {
  760. GetConfiguration_AllowOfflineTxForUnknownId=0,
  761. GetConfiguration_AuthorizationCacheEnabled,
  762. GetConfiguration_AuthorizeRemoteTxRequests,
  763. GetConfiguration_BlinkRepeat,
  764. GetConfiguration_ClockAlignedDataInterval,
  765. GetConfiguration_ConnectionTimeOut,
  766. GetConfiguration_GetConfigurationMaxKeys,
  767. GetConfiguration_HeartbeatInterval,
  768. GetConfiguration_LightIntensity,
  769. GetConfiguration_LocalAuthorizeOffline,
  770. GetConfiguration_LocalPreAuthorize,
  771. GetConfiguration_MaxEnergyOnInvalidId,
  772. GetConfiguration_MeterValuesAlignedData,
  773. GetConfiguration_MeterValuesAlignedDataMaxLength,
  774. GetConfiguration_MeterValuesSampledData,
  775. GetConfiguration_MeterValuesSampledDataMaxLength,
  776. GetConfiguration_MeterValueSampleInterval,
  777. GetConfiguration_MinimumStatusDuration,
  778. GetConfiguration_NumberOfConnectors,
  779. GetConfiguration_ResetRetries,
  780. GetConfiguration_ConnectorPhaseRotation,
  781. GetConfiguration_ConnectorPhaseRotationMaxLength,
  782. GetConfiguration_StopTransactionOnEVSideDisconnect,
  783. GetConfiguration_StopTransactionOnInvalidId,
  784. GetConfiguration_StopTxnAlignedData,
  785. GetConfiguration_StopTxnAlignedDataMaxLength,
  786. GetConfiguration_StopTxnSampledData,
  787. GetConfiguration_StopTxnSampledDataMaxLength,
  788. GetConfiguration_SupportedFeatureProfiles,
  789. GetConfiguration_SupportedFeatureProfilesMaxLength,
  790. GetConfiguration_TransactionMessageAttempts,
  791. GetConfiguration_TransactionMessageRetryInterval,
  792. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  793. GetConfiguration_WebSocketPingInterval,
  794. GetConfiguration_LocalAuthListEnabled,
  795. GetConfiguration_LocalAuthListMaxLength,
  796. GetConfiguration_SendLocalListMaxLength,
  797. GetConfiguration_ReserveConnectorZeroSupported,
  798. GetConfiguration_ChargeProfileMaxStackLevel,
  799. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  800. GetConfiguration_ChargingScheduleMaxPeriods,
  801. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  802. GetConfiguration_MaxChargingProfilesInstalled,
  803. };
  804. //GetConfiguration Array
  805. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  806. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  807. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  808. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  809. //==========================================
  810. // Init all share memory
  811. //==========================================
  812. int InitShareMemory()
  813. {
  814. int result = PASS;
  815. int MeterSMId;
  816. //creat ShmSysConfigAndInfo
  817. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  818. {
  819. #ifdef SystemLogMessage
  820. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  821. #endif
  822. result = FAIL;
  823. }
  824. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  825. {
  826. #ifdef SystemLogMessage
  827. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  828. #endif
  829. result = FAIL;
  830. }
  831. else
  832. {}
  833. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  834. {
  835. #ifdef SystemLogMessage
  836. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  837. #endif
  838. result = FAIL;
  839. }
  840. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  841. {
  842. #ifdef SystemLogMessage
  843. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  844. #endif
  845. result = FAIL;
  846. }
  847. else
  848. {}
  849. //creat ShmPsuData
  850. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  851. {
  852. #ifdef SystemLogMessage
  853. DEBUG_ERROR("shmget ShmPsuData NG\n");
  854. #endif
  855. result = FAIL;
  856. }
  857. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  858. {
  859. #ifdef SystemLogMessage
  860. DEBUG_ERROR("shmat ShmPsuData NG\n");
  861. #endif
  862. result = FAIL;
  863. }
  864. else
  865. {}
  866. //creat ShmOCPP16Data
  867. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  868. {
  869. #ifdef SystemLogMessage
  870. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  871. #endif
  872. result = FAIL;
  873. }
  874. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  875. {
  876. #ifdef SystemLogMessage
  877. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  878. #endif
  879. result = FAIL;
  880. }
  881. else
  882. {}
  883. /****************************** For Initial Settings************************************************/
  884. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  885. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  886. {
  887. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  888. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  889. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  890. }
  891. // Charger PRE_SYS_MODE
  892. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  893. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  894. clientTime.Heartbeat=time((time_t*)NULL);
  895. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  896. {
  897. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  898. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  899. }
  900. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  901. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  902. // allocate Configuration memory address
  903. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  904. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  905. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  906. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  908. {
  909. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  910. DEBUG_INFO("DC ...\n");
  911. }
  912. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  913. {
  914. SystemInitial = AC_QUANTITY;
  915. DEBUG_INFO("AC ...\n");
  916. }
  917. //Status Setting
  918. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  919. {
  920. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  921. }
  922. for (int index = 0; index < CCS_QUANTITY; index++)
  923. {
  924. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  925. }
  926. for (int index = 0; index < GB_QUANTITY; index++)
  927. {
  928. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  929. }
  930. for (int index = 0; index < AC_QUANTITY; index++)
  931. {
  932. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  933. }
  934. return result;
  935. }
  936. int ProcessShareMemory()
  937. {
  938. if(InitShareMemory() == FAIL)
  939. {
  940. #ifdef SystemLogMessage
  941. DEBUG_ERROR("InitShareMemory NG\n");
  942. #endif
  943. if(ShmStatusCodeData!=NULL)
  944. {
  945. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  946. }
  947. sleep(5);
  948. return FAIL;
  949. }
  950. return PASS;
  951. }
  952. //---------------------------------------------
  953. // new:
  954. // enum SYSTEM_STATUS
  955. // {
  956. // SYS_MODE_BOOTING = 0,
  957. // SYS_MODE_IDLE = 1,
  958. // SYS_MODE_AUTHORIZING = 2,
  959. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  960. // SYS_MODE_REASSIGN = 4,
  961. // SYS_MODE_PREPARING = 5,
  962. // SYS_MODE_PREPARE_FOR_EV = 6,
  963. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  964. // SYS_MODE_CHARGING = 8,
  965. // SYS_MODE_TERMINATING = 9,
  966. // SYS_MODE_COMPLETE = 10,
  967. // SYS_MODE_ALARM = 11,
  968. // SYS_MODE_FAULT = 12,
  969. // SYS_MODE_RESERVATION = 13,
  970. // SYS_MODE_BOOKING = 14,
  971. // SYS_MODE_MAINTAIN = 15,
  972. // SYS_MODE_DEBUG = 16,
  973. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  974. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  975. // SYS_MODE_UPDATE = 19
  976. // };
  977. //
  978. //
  979. //-----------------------------------------
  980. void CheckSystemValue(void)
  981. {
  982. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  983. int IdleModeCnt = 0;
  984. char filenmae[100]={0};
  985. char str[100]={0};
  986. //===============================
  987. // send Heartbeat
  988. //===============================
  989. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  990. {
  991. printf("Heartbeat !!!\n");
  992. //parameter for test
  993. sendHeartbeatRequest(0);
  994. //==============================================
  995. // Reset Waiting Time
  996. //==============================================
  997. clientTime.Heartbeat=time((time_t*)NULL);
  998. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  999. }
  1000. //==============================================
  1001. // Update firmware request
  1002. //==============================================
  1003. if(isUpdateRequest == TRUE )
  1004. {
  1005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1006. {
  1007. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1008. {
  1009. //check SystemStatus
  1010. /*************************DC*******************************/
  1011. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1012. {
  1013. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1014. {
  1015. IdleModeCnt = IdleModeCnt + 1;
  1016. }
  1017. }
  1018. for (int index = 0; index < CCS_QUANTITY; index++)
  1019. {
  1020. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1021. {
  1022. IdleModeCnt = IdleModeCnt + 1;
  1023. }
  1024. }
  1025. for (int index = 0; index < GB_QUANTITY; index++)
  1026. {
  1027. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1028. {
  1029. IdleModeCnt = IdleModeCnt + 1;
  1030. }
  1031. }
  1032. }
  1033. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1034. {
  1035. isUpdateRequest = FALSE;
  1036. }
  1037. }
  1038. else
  1039. {
  1040. /*************************AC*******************************/
  1041. for (int index = 0; index < AC_QUANTITY; index++)
  1042. {
  1043. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1044. {
  1045. IdleModeCnt = IdleModeCnt + 1;
  1046. }
  1047. }
  1048. if(IdleModeCnt == AC_QUANTITY)
  1049. {
  1050. isUpdateRequest = FALSE;
  1051. }
  1052. }
  1053. }
  1054. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1055. {
  1056. //===============================
  1057. // CSU Trigger Reset Conf
  1058. //===============================
  1059. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1060. {
  1061. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1062. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1063. {
  1064. server_sign = FALSE;
  1065. }
  1066. }
  1067. //===============================
  1068. // CSU Trigger Authorize Request
  1069. //===============================
  1070. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1071. {
  1072. //if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1073. //{
  1074. sendAuthorizeRequest(0);
  1075. authorizeRetryTimes = authorizeRetryTimes + 1;
  1076. // authenrequest = TRUE
  1077. if(authorizeRetryTimes < 3)
  1078. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1079. //}
  1080. }
  1081. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1082. {
  1083. authorizeRetryTimes = 0;
  1084. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1085. server_sign = FALSE;
  1086. }
  1087. 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))
  1088. {
  1089. sendAuthorizeRequest(0);
  1090. }
  1091. //===============================
  1092. // CSU Trigger Smart Charging Profilw
  1093. //===============================
  1094. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1095. {
  1096. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1097. GetChargingProfileRequest(gun_index);
  1098. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1099. }
  1100. //==============================================
  1101. // Charger start transaction
  1102. //==============================================
  1103. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1104. {
  1105. sendStartTransactionRequest(gun_index);
  1106. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1107. clientTime.StartTransaction = time((time_t*)NULL);
  1108. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1109. }
  1110. //==============================================
  1111. // Charger stop transaction
  1112. //==============================================
  1113. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1114. {
  1115. sendStopTransactionRequest(gun_index);
  1116. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1117. clientTime.StopTransaction = time((time_t*)NULL);
  1118. }
  1119. //==============================================
  1120. // Charger status report
  1121. //==============================================
  1122. /* Check Mode Change */
  1123. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1124. {
  1125. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1126. {
  1127. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1128. {
  1129. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1130. {
  1131. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1132. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1133. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1134. statusModeChage[gun_index] = TRUE;
  1135. }
  1136. }
  1137. }
  1138. for (int index = 0; index < CCS_QUANTITY; index++)
  1139. {
  1140. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1141. {
  1142. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1143. {
  1144. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1145. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1146. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1147. statusModeChage[gun_index] = TRUE;
  1148. }
  1149. }
  1150. }
  1151. for (int index = 0; index < GB_QUANTITY; index++)
  1152. {
  1153. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1154. {
  1155. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1156. {
  1157. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1158. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1159. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1160. statusModeChage[gun_index] = TRUE;
  1161. }
  1162. }
  1163. }
  1164. }
  1165. else //AC
  1166. {
  1167. for (int index = 0; index < AC_QUANTITY; index++)
  1168. {
  1169. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1170. {
  1171. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1172. {
  1173. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1174. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1175. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1176. statusModeChage[gun_index] = TRUE;
  1177. }
  1178. }
  1179. }// END OF FOR
  1180. }// END OF ELSE
  1181. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1182. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1183. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1184. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1185. {
  1186. if(SystemInitial != 0)
  1187. SystemInitial = SystemInitial -1;
  1188. sendStatusNotificationRequest(gun_index);
  1189. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1190. statusModeChage[gun_index] = FALSE;
  1191. }
  1192. //==============================================
  1193. // Meter report
  1194. //==============================================
  1195. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1196. {
  1197. //check Transaction active
  1198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1199. {
  1200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1201. {
  1202. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1203. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1204. {
  1205. meterValueSend[gun_index] =1;
  1206. }
  1207. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1208. {
  1209. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1210. if((access(filenmae,F_OK))!=-1)
  1211. {
  1212. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1213. sprintf(str,"rm -f %s",filenmae);
  1214. system(str);
  1215. }
  1216. }
  1217. }// End for CHAdeMO
  1218. for (int index = 0; index < CCS_QUANTITY; index++)
  1219. {
  1220. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1221. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1222. {
  1223. meterValueSend[gun_index] =1;
  1224. }
  1225. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1226. {
  1227. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1228. if((access(filenmae,F_OK))!=-1)
  1229. {
  1230. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1231. sprintf(str,"rm -f %s",filenmae);
  1232. system(str);
  1233. }
  1234. }
  1235. } // End for CCS
  1236. for (int index = 0; index < GB_QUANTITY; index++)
  1237. {
  1238. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1239. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1240. {
  1241. meterValueSend[gun_index] =1;
  1242. }
  1243. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1244. {
  1245. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1246. if((access(filenmae,F_OK))!=-1)
  1247. {
  1248. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1249. sprintf(str,"rm -f %s",filenmae);
  1250. system(str);
  1251. }
  1252. }
  1253. }// End for GB
  1254. }
  1255. else
  1256. {
  1257. for (int index = 0; index < AC_QUANTITY; index++)
  1258. {
  1259. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1260. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1261. {
  1262. meterValueSend[gun_index] =1;
  1263. }
  1264. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1265. {
  1266. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1267. if((access(filenmae,F_OK))!=-1)
  1268. {
  1269. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1270. sprintf(str,"rm -f %s",filenmae);
  1271. system(str);
  1272. }
  1273. }
  1274. }//End for AC
  1275. }//END OF ELSE
  1276. // sleep(1);
  1277. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1278. if(meterValueSend[gun_index] == 1)
  1279. sendMeterValuesRequest(gun_index);
  1280. }
  1281. //==============================================
  1282. // Check Connector reserved
  1283. //==============================================
  1284. //===============================
  1285. // Check if Reserve is expired
  1286. //===============================
  1287. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1288. {
  1289. double diff_t;
  1290. struct tm tp;
  1291. // current time
  1292. time_t t = time(NULL);
  1293. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1294. tp.tm_isdst = -1;
  1295. time_t utc = mktime(&tp);
  1296. diff_t = difftime(utc, t);
  1297. if(diff_t <= 0)
  1298. {
  1299. DEBUG_INFO("reserve expired !!! \n");
  1300. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1301. }
  1302. }//END OF Check if Reserve is expired
  1303. //==========================================
  1304. // csu trigger FirmwareStatusNotificationReq
  1305. //==========================================
  1306. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1307. {
  1308. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1309. }
  1310. //==========================================
  1311. // csu trigger CancelReservationConf
  1312. //==========================================
  1313. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1314. {
  1315. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1316. }
  1317. //==========================================
  1318. // csu trigger ChangeAvailabilityConf
  1319. //==========================================
  1320. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1321. {
  1322. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1323. }
  1324. //==========================================
  1325. // csu trigger UnlockConnectorConf
  1326. //==========================================
  1327. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1328. {
  1329. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1330. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1331. }
  1332. //==========================================
  1333. // csu trigger ReserveNowConf
  1334. //==========================================
  1335. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1336. {
  1337. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1338. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1339. }
  1340. //==========================================
  1341. // csu trigger DataTransferReq
  1342. //==========================================
  1343. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1344. {
  1345. sendDataTransferRequest(gun_index);
  1346. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1347. }
  1348. }
  1349. }
  1350. //==========================================
  1351. // send request routine
  1352. //==========================================
  1353. int sendAuthorizeRequest(int gun_index)
  1354. {
  1355. mtrace();
  1356. int result = FAIL;
  1357. char message[100]={0};
  1358. char guid[37];
  1359. char tempdata[65]={0};
  1360. DEBUG_INFO("sendAuthorizeRequest \n");
  1361. //Local Authorize
  1362. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))
  1363. {
  1364. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1365. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1366. {
  1367. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1368. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1369. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1370. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1371. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1372. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1373. authorizeRetryTimes = 0;
  1374. return result;
  1375. }
  1376. else
  1377. {
  1378. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1379. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1380. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1381. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1382. result = PASS;
  1383. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1384. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1385. authorizeRetryTimes = 0;
  1386. return result;
  1387. }
  1388. }
  1389. //initailize struct Authorize
  1390. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1391. //get data from shared memory
  1392. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1393. random_uuid(guid);
  1394. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1395. LWS_Send(message);
  1396. sprintf(tempdata, "Authorize,%d", gun_index);
  1397. if(hashmap_operation(0, guid, tempdata) == 1)
  1398. {
  1399. result = PASS;
  1400. DEBUG_ERROR("Authorize mapItem pass\n");
  1401. }
  1402. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1403. return result;
  1404. }
  1405. int sendBootNotificationRequest(void)
  1406. {
  1407. mtrace();
  1408. int result = FAIL;
  1409. char message[500]={0}, payload[700]={0};
  1410. char guid[37]={0};
  1411. char tempdata[65]={0};
  1412. int IsGunCharging = FALSE;
  1413. //check Transaction active
  1414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1415. {
  1416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1417. {
  1418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1419. {
  1420. IsGunCharging = TRUE;
  1421. }
  1422. }
  1423. for (int index = 0; index < CCS_QUANTITY; index++)
  1424. {
  1425. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1426. {
  1427. IsGunCharging = TRUE;
  1428. }
  1429. }
  1430. for (int index = 0; index < GB_QUANTITY; index++)
  1431. {
  1432. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1433. {
  1434. IsGunCharging = TRUE;
  1435. }
  1436. }
  1437. }
  1438. else
  1439. {
  1440. for (int index = 0; index < AC_QUANTITY; index++)
  1441. {
  1442. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1443. {
  1444. IsGunCharging = TRUE;
  1445. }
  1446. }
  1447. }
  1448. if(IsGunCharging == TRUE)
  1449. {
  1450. server_sign = TRUE;
  1451. return result;
  1452. }
  1453. // Fill BootNotification fields
  1454. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1455. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1456. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1457. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1458. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1459. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1460. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1461. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1462. ShmOCPP16Data->ChargeBoxId
  1463. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1464. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1465. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1466. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1467. ,ShmOCPP16Data->BootNotification.CpIccid
  1468. ,ShmOCPP16Data->BootNotification.CpImsi
  1469. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1470. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1471. random_uuid(guid);
  1472. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1473. LWS_Send(message);
  1474. sprintf(tempdata, "BootNotification,0");
  1475. 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*/)
  1476. {
  1477. result = PASS;
  1478. }
  1479. memset(queuedata, 0, sizeof(queuedata));
  1480. strcpy(queuedata,message);
  1481. HeartBeatCount = 0;
  1482. return result;
  1483. }
  1484. int sendDataTransferRequest(int gun_index)
  1485. {
  1486. mtrace();
  1487. char message[1000]={0};
  1488. char guid[37]={0};
  1489. char tempdata[65]={0};
  1490. int result = FAIL;
  1491. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1492. random_uuid(guid);
  1493. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1494. MESSAGE_TYPE_CALL,
  1495. guid,
  1496. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1497. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1498. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1499. LWS_Send(message);
  1500. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1501. 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*/)
  1502. {
  1503. result = PASS;
  1504. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1505. }
  1506. return result;
  1507. }
  1508. int sendDiagnosticsStatusNotificationRequest(char *status)
  1509. {
  1510. mtrace();
  1511. int result = FAIL;
  1512. char message[110]={0};
  1513. char guid[37]={0};
  1514. char tempdata[65]={0};
  1515. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1516. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1517. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1518. random_uuid(guid);
  1519. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1520. LWS_Send(message);
  1521. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1522. if(hashmap_operation(0, guid, tempdata) == 1)
  1523. {
  1524. result = PASS;
  1525. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1526. }
  1527. //#ifdef SystemLogMessage
  1528. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1529. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1530. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1531. //#endif
  1532. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1533. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1534. //record status
  1535. if(strcmp(status,"Idle")==0)
  1536. {
  1537. DiagnosticsStatusNotificationStatus = 0;
  1538. }
  1539. else if(strcmp(status,"Uploaded")==0)
  1540. {
  1541. DiagnosticsStatusNotificationStatus = 1;
  1542. }
  1543. else if(strcmp(status,"UploadFailed")==0)
  1544. {
  1545. DiagnosticsStatusNotificationStatus = 2;
  1546. }
  1547. else if(strcmp(status,"Uploading")==0)
  1548. {
  1549. DiagnosticsStatusNotificationStatus = 3;
  1550. }
  1551. return result;
  1552. }
  1553. int sendFirmwareStatusNotificationRequest(char *status)
  1554. {
  1555. mtrace();
  1556. int result = FAIL;
  1557. char message[110]={0};
  1558. char guid[37]={0};
  1559. char tempdata[65]={0};
  1560. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1561. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1562. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1563. random_uuid(guid);
  1564. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1565. LWS_Send(message);
  1566. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1567. 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*/)
  1568. {
  1569. result = PASS;
  1570. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1571. }
  1572. //#ifdef SystemLogMessage
  1573. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1574. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1575. //#endif
  1576. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1577. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1578. //record status
  1579. if(strcmp(status,"Downloaded")==0)
  1580. {
  1581. FirmwareStatusNotificationStatus = 0;
  1582. }
  1583. else if(strcmp(status,"DownloadFailed")==0)
  1584. {
  1585. FirmwareStatusNotificationStatus = 1;
  1586. }
  1587. else if(strcmp(status,"Downloading")==0)
  1588. {
  1589. FirmwareStatusNotificationStatus = 2;
  1590. }
  1591. else if(strcmp(status,"Idle")==0)
  1592. {
  1593. FirmwareStatusNotificationStatus = 3;
  1594. }
  1595. else if(strcmp(status,"InstallationFailed")==0)
  1596. {
  1597. FirmwareStatusNotificationStatus = 4;
  1598. }
  1599. else if(strcmp(status,"Installing")==0)
  1600. {
  1601. FirmwareStatusNotificationStatus = 5;
  1602. }
  1603. else if(strcmp(status,"Installed")==0)
  1604. {
  1605. FirmwareStatusNotificationStatus = 6;
  1606. }
  1607. return result;
  1608. }
  1609. int sendHeartbeatRequest(int gun_index)
  1610. {
  1611. mtrace();
  1612. int result = FAIL;
  1613. char message[80]={0};
  1614. char guid[37]={0};
  1615. char tempdata[65]={0};
  1616. random_uuid(guid);
  1617. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1618. , MESSAGE_TYPE_CALL
  1619. , guid );
  1620. LWS_Send(message);
  1621. sprintf(tempdata, "Heartbeat,%d", 0);
  1622. 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*/)
  1623. {
  1624. result = PASS;
  1625. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1626. }
  1627. return result;
  1628. }
  1629. int sendStartTransactionRequest(int gun_index)
  1630. {
  1631. mtrace();
  1632. int result = FAIL;
  1633. char message[250]={0};
  1634. char guid[37]={0};
  1635. struct timeval tmnow;
  1636. struct tm *tm;
  1637. char buf[28];//, usec_buf[6];
  1638. char tempdata[65]={0};
  1639. DEBUG_INFO("sendStartTransactionRequest...");
  1640. gettimeofday(&tmnow, NULL);
  1641. time_t t;
  1642. t = time(NULL);
  1643. /*UTC time and date*/
  1644. tm = gmtime(&t);
  1645. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1646. #if 0 // remove temporally
  1647. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1648. strcat(buf,".");
  1649. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1650. strcat(buf,usec_buf);
  1651. #endif
  1652. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1653. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1654. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1656. {
  1657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1658. {
  1659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1660. {
  1661. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1662. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1663. }
  1664. }
  1665. for (int index = 0; index < CCS_QUANTITY; index++)
  1666. {
  1667. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1668. {
  1669. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1670. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1671. }
  1672. }
  1673. for (int index = 0; index < GB_QUANTITY; index++)
  1674. {
  1675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1676. {
  1677. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1678. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1679. }
  1680. }
  1681. }
  1682. else
  1683. {
  1684. for (int index = 0; index < AC_QUANTITY; index++)
  1685. {
  1686. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1687. {
  1688. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1689. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1690. }
  1691. }
  1692. }//END OF ELSE
  1693. random_uuid(guid);
  1694. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1695. , MESSAGE_TYPE_CALL
  1696. , guid
  1697. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1698. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1699. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1700. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1701. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1702. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1703. 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*/)
  1704. {
  1705. result = PASS;
  1706. }
  1707. strcpy(queuedata, message);
  1708. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1709. LWS_Send(message);
  1710. #if 0
  1711. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1712. 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*/)
  1713. {
  1714. result = PASS;
  1715. }
  1716. strcpy(queuedata, message);
  1717. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1718. #endif
  1719. //#ifdef SystemLogMessage
  1720. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1721. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1722. //#endif
  1723. return result;
  1724. }
  1725. int sendStatusNotificationRequest(int gun_index)
  1726. {
  1727. mtrace();
  1728. int result = FAIL;
  1729. char message[600]={0};
  1730. char guid[37];
  1731. int currentStatus = 0;
  1732. struct timeval tmnow;
  1733. struct tm *tm;
  1734. char buf[28];//, usec_buf[6];
  1735. char tempdata[65]={0};
  1736. gettimeofday(&tmnow, NULL);
  1737. time_t t;
  1738. t = time(NULL);
  1739. /*UTC time and date*/
  1740. tm = gmtime(&t);
  1741. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1742. #if 0 // remove temporally
  1743. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1744. strcat(buf,".");
  1745. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1746. strcat(buf,usec_buf);
  1747. #endif
  1748. printf("%s",buf);
  1749. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1750. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1751. // it's option
  1752. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1753. /*
  1754. enum _SYSTEM_STATUS
  1755. {
  1756. S_BOOTING = 0,
  1757. S_IDLE, = 1
  1758. S_AUTHORIZING, =2
  1759. S_REASSIGN_CHECK, =3
  1760. S_REASSIGN, =4
  1761. S_PRECHARGE, =5
  1762. S_PREPARING_FOR_EV, =6
  1763. S_PREPARING_FOR_EVSE, =7
  1764. S_CHARGING, =8
  1765. S_TERMINATING, =9
  1766. S_COMPLETE, =10
  1767. S_ALARM, =11
  1768. S_FAULT =12
  1769. }
  1770. */
  1771. //check Transaction active
  1772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1773. {
  1774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1775. {
  1776. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1777. {
  1778. currentStatus = 0; //OCPP Status: Available
  1779. }
  1780. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1781. {
  1782. currentStatus = 1; //OCPP Status: Preparing
  1783. }
  1784. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1785. {
  1786. currentStatus = 2; //OCPP Status: Charging
  1787. }
  1788. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1789. {
  1790. currentStatus = 5; //OCPP Status: Finishing
  1791. }
  1792. 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
  1793. {
  1794. currentStatus = 4; //OCPP Status: SuspendedEV
  1795. }
  1796. 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
  1797. {
  1798. currentStatus = 7; //OCPP Status: Unavailable
  1799. }
  1800. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1801. {
  1802. currentStatus = 8; //OCPP Status: Faulted
  1803. }
  1804. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1805. {
  1806. currentStatus = 6; //OCPP Status: Reserved
  1807. }
  1808. }//end of for CHAdeMO_QUANTITY
  1809. for (int index = 0; index < CCS_QUANTITY; index++)
  1810. {
  1811. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1812. {
  1813. currentStatus = 0; //OCPP Status: Available
  1814. }
  1815. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1816. {
  1817. currentStatus = 1; //OCPP Status: Preparing
  1818. }
  1819. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1820. {
  1821. currentStatus = 2; //OCPP Status: Charging
  1822. }
  1823. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1824. {
  1825. currentStatus = 5; //OCPP Status: Finishing
  1826. }
  1827. 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
  1828. {
  1829. currentStatus = 4; //OCPP Status: SuspendedEV
  1830. }
  1831. 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
  1832. {
  1833. currentStatus = 7; //OCPP Status : Unavailable
  1834. }
  1835. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1836. {
  1837. currentStatus = 8; //OCPP Status: Faulted
  1838. }
  1839. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1840. {
  1841. currentStatus = 6; //OCPP Status: Reserved
  1842. }
  1843. }
  1844. for (int index = 0; index < GB_QUANTITY; index++)
  1845. {
  1846. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1847. {
  1848. currentStatus = 0; //OCPP Status: Available
  1849. }
  1850. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1851. {
  1852. currentStatus = 1; //OCPP Status: Preparing
  1853. }
  1854. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1855. {
  1856. currentStatus = 2; //OCPP Status: Charging
  1857. }
  1858. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1859. {
  1860. currentStatus = 5; //OCPP Status: Finishing
  1861. }
  1862. 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
  1863. {
  1864. currentStatus = 4; //OCPP Status: SuspendedEV
  1865. }
  1866. 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
  1867. {
  1868. currentStatus = 7; //OCPP Status: Unavailable
  1869. }
  1870. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1871. {
  1872. currentStatus = 8; //OCPP Status: Faulted
  1873. }
  1874. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1875. {
  1876. currentStatus = 6; //OCPP Status: Reserved
  1877. }
  1878. }
  1879. }
  1880. else
  1881. {
  1882. for (int index = 0; index < AC_QUANTITY; index++)
  1883. {
  1884. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1885. {
  1886. currentStatus = 0; //OCPP Status: Available
  1887. }
  1888. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1889. {
  1890. currentStatus = 1; //OCPP Status: Preparing
  1891. }
  1892. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1893. {
  1894. currentStatus = 2; //OCPP Status: Charging
  1895. }
  1896. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1897. {
  1898. currentStatus = 5; //OCPP Status: Finishing
  1899. }
  1900. 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
  1901. {
  1902. currentStatus = 4; //OCPP Status: SuspendedEV
  1903. }
  1904. 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
  1905. {
  1906. currentStatus = 7; //OCPP Status: Unavailable
  1907. }
  1908. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1909. {
  1910. currentStatus = 8; //OCPP Status: Faulted
  1911. }
  1912. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1913. {
  1914. currentStatus = 6; //OCPP Status: Reserved
  1915. }
  1916. }//end of for AC_QUANTITY
  1917. }//END OF ELSE
  1918. //it's option
  1919. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1920. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1921. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1922. random_uuid(guid);
  1923. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1924. , MESSAGE_TYPE_CALL
  1925. , guid
  1926. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1927. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1928. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1929. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1930. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1931. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1932. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1933. LWS_Send(message);
  1934. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1935. 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*/)
  1936. {
  1937. //DEBUG_ERROR("statusNotification mapitem pass");
  1938. result = PASS;
  1939. }
  1940. return result;
  1941. }
  1942. int sendStopTransactionRequest(int gun_index)
  1943. {
  1944. mtrace();
  1945. int result = FAIL;
  1946. //char message[1500]={0};
  1947. char guid[37]={0};
  1948. char tempdata[65]={0};
  1949. //int idx_sample=0;
  1950. DEBUG_ERROR("sendStopTransactionRequest \n");
  1951. memset(queuedata, 0, sizeof(queuedata));
  1952. //ENERGY_ACTIVE_IMPORT_REGISTER
  1953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1954. {
  1955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1956. {
  1957. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1958. {
  1959. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1960. }
  1961. }// END OF CHAdeMO_QUANTITY
  1962. for (int index = 0; index < CCS_QUANTITY; index++)
  1963. {
  1964. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1965. {
  1966. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1967. }
  1968. }// END OF CCS_QUANTITY
  1969. for (int index = 0; index < GB_QUANTITY; index++)
  1970. {
  1971. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1972. {
  1973. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1974. }
  1975. }// END OF GB_QUANTITY
  1976. }
  1977. else
  1978. {
  1979. for (int index = 0; index < AC_QUANTITY; index++)
  1980. {
  1981. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1982. {
  1983. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1984. }
  1985. }// END OF AC_QUANTITY
  1986. }//END OF ELSE
  1987. //Stop Transaction Time
  1988. struct timeval tmnow;
  1989. struct tm *tm;
  1990. char buf[28];//, usec_buf[6];
  1991. gettimeofday(&tmnow, NULL);
  1992. time_t t;
  1993. t = time(NULL);
  1994. /*UTC time and date*/
  1995. tm = gmtime(&t);
  1996. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  1998. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  1999. random_uuid(guid);
  2000. /***********************************transactionData******************************************************/
  2001. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2003. //=================================
  2004. // Transaction_Begin
  2005. //=================================
  2006. // Energy.Active.Export.Interval
  2007. //idx_sample=0;
  2008. 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
  2009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2011. 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*/]);
  2012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2013. {
  2014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2015. }
  2016. else
  2017. {
  2018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2019. }
  2020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2022. //=================================
  2023. // Transaction_End
  2024. //=================================
  2025. //Current.Export
  2026. //idx_sample=1;
  2027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2028. {
  2029. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2030. {
  2031. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2032. {
  2033. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2034. }
  2035. }
  2036. for (int index = 0; index < CCS_QUANTITY; index++)
  2037. {
  2038. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2039. {
  2040. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2041. }
  2042. }
  2043. for (int index = 0; index < GB_QUANTITY; index++)
  2044. {
  2045. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2046. {
  2047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2048. }
  2049. }
  2050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2051. }
  2052. else
  2053. {
  2054. for (int index = 0; index < AC_QUANTITY; index++)
  2055. {
  2056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2057. {
  2058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2059. }
  2060. }
  2061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2062. }// END FOR AC ELSE
  2063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2066. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2069. //Energy.Active.Export.Interval
  2070. //idx_sample=2;
  2071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2072. {
  2073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2074. {
  2075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2076. {
  2077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2078. }
  2079. }
  2080. for (int index = 0; index < CCS_QUANTITY; index++)
  2081. {
  2082. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2083. {
  2084. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2085. }
  2086. }
  2087. for (int index = 0; index < GB_QUANTITY; index++)
  2088. {
  2089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2090. {
  2091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2092. }
  2093. }
  2094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2095. }
  2096. else
  2097. {
  2098. for (int index = 0; index < AC_QUANTITY; index++)
  2099. {
  2100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2101. {
  2102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2103. }
  2104. }
  2105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2106. }// END FOR AC ELSE
  2107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2110. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2113. //Power.Active.Export
  2114. //idx_sample=3;
  2115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2116. {
  2117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2118. {
  2119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2120. {
  2121. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2122. }
  2123. }
  2124. for (int index = 0; index < CCS_QUANTITY; index++)
  2125. {
  2126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2127. {
  2128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2129. }
  2130. }
  2131. for (int index = 0; index < GB_QUANTITY; index++)
  2132. {
  2133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2134. {
  2135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2136. }
  2137. }
  2138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2139. }
  2140. else
  2141. {
  2142. for (int index = 0; index < AC_QUANTITY; index++)
  2143. {
  2144. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2145. {
  2146. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2147. }
  2148. }
  2149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2150. }// END FOR AC ELSE
  2151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2154. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2157. //Voltage
  2158. //idx_sample=4;
  2159. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2160. {
  2161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2162. {
  2163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2164. {
  2165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2166. }
  2167. }
  2168. for (int index = 0; index < CCS_QUANTITY; index++)
  2169. {
  2170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2171. {
  2172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2173. }
  2174. }
  2175. for (int index = 0; index < GB_QUANTITY; index++)
  2176. {
  2177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2178. {
  2179. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2180. }
  2181. }
  2182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2183. }
  2184. else
  2185. {
  2186. for (int index = 0; index < AC_QUANTITY; index++)
  2187. {
  2188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2189. {
  2190. 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
  2191. }
  2192. }
  2193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2194. }// END FOR AC ELSE
  2195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2198. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2201. //SoC
  2202. //idx_sample=5;
  2203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2204. {
  2205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2206. {
  2207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2208. {
  2209. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2210. }
  2211. }
  2212. for (int index = 0; index < CCS_QUANTITY; index++)
  2213. {
  2214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2215. {
  2216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2217. }
  2218. }
  2219. for (int index = 0; index < GB_QUANTITY; index++)
  2220. {
  2221. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2222. {
  2223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2224. }
  2225. }
  2226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2232. } // END FOR DC CASE
  2233. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2234. {
  2235. 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\" } ] } ] } ]"
  2236. ,MESSAGE_TYPE_CALL
  2237. ,guid
  2238. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2239. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2240. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2241. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2242. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2243. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2244. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2245. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2246. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2247. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2248. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2249. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2250. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2251. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2252. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2253. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2254. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2255. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2256. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2257. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2258. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2259. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2260. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2261. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2262. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2263. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2264. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2265. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2266. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2267. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2268. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2269. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2270. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2271. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2272. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2273. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2274. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2275. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2276. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2277. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2278. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2279. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2280. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2281. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2282. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2283. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2284. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2285. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2286. );
  2287. }
  2288. else
  2289. {
  2290. 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\" } ] } ] } ]"
  2291. ,MESSAGE_TYPE_CALL
  2292. ,guid
  2293. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2294. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2295. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2296. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2297. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2298. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2299. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2304. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2334. );
  2335. }
  2336. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2337. if(hashmap_operation(0, guid, tempdata) == 1)
  2338. {
  2339. result = PASS;
  2340. DEBUG_INFO("StopTransaction mapitem pass\n");
  2341. }
  2342. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2343. LWS_Send(queuedata);
  2344. #if 0
  2345. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2346. if(hashmap_operation(0, guid, tempdata) == 1)
  2347. {
  2348. result = PASS;
  2349. DEBUG_INFO("StopTransaction mapitem pass\n");
  2350. }
  2351. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2352. #endif
  2353. //for test
  2354. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2355. return result;
  2356. }
  2357. int sendMeterValuesRequest(int gun_index)
  2358. {
  2359. mtrace();
  2360. int result = FAIL;
  2361. // char message[1500]={0};
  2362. char guid[37]={0};
  2363. //int idx_sample=0;
  2364. //int length = 0;
  2365. char tempdata[65]={0};
  2366. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2367. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2368. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2369. {
  2370. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2371. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2372. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2373. return result;
  2374. }
  2375. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2376. {
  2377. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2378. }
  2379. memset(queuedata, 0, sizeof(queuedata));
  2380. //set value
  2381. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2382. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2383. random_uuid(guid);
  2384. //UTC Date time
  2385. struct timeval tmnow;
  2386. struct tm *tm;
  2387. char buf[28];//, usec_buf[6];
  2388. gettimeofday(&tmnow, NULL);
  2389. time_t t;
  2390. t = time(NULL);
  2391. /*UTC time and date*/
  2392. tm = gmtime(&t);
  2393. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2395. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2396. //idx_sample=0;
  2397. //********************************(1)Current.Export************************************************/
  2398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2399. {
  2400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2401. {
  2402. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2403. {
  2404. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2405. }
  2406. }
  2407. for (int index = 0; index < CCS_QUANTITY; index++)
  2408. {
  2409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2410. {
  2411. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2412. }
  2413. }
  2414. for (int index = 0; index < GB_QUANTITY; index++)
  2415. {
  2416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2417. {
  2418. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2419. }
  2420. }
  2421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2422. }
  2423. else
  2424. {
  2425. for (int index = 0; index < AC_QUANTITY; index++)
  2426. {
  2427. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2428. {
  2429. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2430. }
  2431. }
  2432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2433. }// END FOR AC ELSE
  2434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2437. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2438. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2440. //idx_sample=1;
  2441. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2443. {
  2444. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2445. {
  2446. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2447. {
  2448. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2449. }
  2450. }
  2451. for (int index = 0; index < CCS_QUANTITY; index++)
  2452. {
  2453. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2454. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2455. {
  2456. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2457. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2458. }
  2459. }
  2460. for (int index = 0; index < GB_QUANTITY; index++)
  2461. {
  2462. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2463. {
  2464. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2465. }
  2466. }
  2467. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2468. }
  2469. else
  2470. {
  2471. for (int index = 0; index < AC_QUANTITY; index++)
  2472. {
  2473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2474. {
  2475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2476. }
  2477. }
  2478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2479. }//END FOR AC ELSE
  2480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2483. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2486. //idx_sample=2;
  2487. //********************************(4)Power.Active.Export************************************************/
  2488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2489. {
  2490. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2491. {
  2492. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2493. {
  2494. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2495. }
  2496. }
  2497. for (int index = 0; index < CCS_QUANTITY; index++)
  2498. {
  2499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2500. {
  2501. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2502. }
  2503. }
  2504. for (int index = 0; index < GB_QUANTITY; index++)
  2505. {
  2506. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2507. {
  2508. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2509. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2510. }
  2511. }
  2512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2513. }
  2514. else
  2515. {
  2516. for (int index = 0; index < AC_QUANTITY; index++)
  2517. {
  2518. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2519. {
  2520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2521. }
  2522. }
  2523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2524. }// END FOR AC ELSE
  2525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2527. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2528. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2529. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2531. //idx_sample=3;
  2532. //***********************************************(5)VOLTAGE******************************************************/
  2533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2534. {
  2535. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2536. {
  2537. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2538. {
  2539. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2540. }
  2541. }
  2542. for (int index = 0; index < CCS_QUANTITY; index++)
  2543. {
  2544. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2545. {
  2546. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2547. }
  2548. }
  2549. for (int index = 0; index < GB_QUANTITY; index++)
  2550. {
  2551. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2552. {
  2553. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2554. }
  2555. }
  2556. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2557. }
  2558. else
  2559. {
  2560. for (int index = 0; index < AC_QUANTITY; index++)
  2561. {
  2562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2563. {
  2564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2565. }
  2566. }
  2567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2568. }//END FOR AC ELSE
  2569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2570. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2572. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2576. {
  2577. //idx_sample=4;
  2578. //sampledValue = NULL;
  2579. //***********************************************(6)SOC******************************************************/
  2580. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2581. {
  2582. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2583. {
  2584. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2585. }
  2586. }
  2587. for (int index = 0; index < CCS_QUANTITY; index++)
  2588. {
  2589. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2590. {
  2591. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2592. }
  2593. }
  2594. for (int index = 0; index < GB_QUANTITY; index++)
  2595. {
  2596. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2597. {
  2598. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2599. }
  2600. }
  2601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2606. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2607. }
  2608. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2609. {
  2610. 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\"}]}]}]"
  2611. ,MESSAGE_TYPE_CALL
  2612. ,guid
  2613. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2614. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2615. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2616. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2617. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2618. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2619. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2620. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2621. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2622. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2623. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2624. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2651. );
  2652. }
  2653. else
  2654. {
  2655. 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\"}]}]}]"
  2656. ,MESSAGE_TYPE_CALL
  2657. ,guid
  2658. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2659. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2660. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2662. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2663. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2664. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2689. );
  2690. }
  2691. // Put request guid to hash map
  2692. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2693. 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*/)
  2694. {
  2695. result = PASS;
  2696. DEBUG_INFO("MeterValues mapitem pass\n");
  2697. }
  2698. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2699. LWS_Send(queuedata);
  2700. #if 0
  2701. // Put request guid to hash map
  2702. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2703. 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*/)
  2704. {
  2705. result = PASS;
  2706. DEBUG_INFO("MeterValues mapitem pass\n");
  2707. }
  2708. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2709. #endif
  2710. return result;
  2711. }
  2712. //==========================================
  2713. // send confirm routine
  2714. //==========================================
  2715. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2716. {
  2717. mtrace();
  2718. int result = FAIL;
  2719. char message[100]={0};
  2720. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2721. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2722. LWS_Send(message);
  2723. result = TRUE;
  2724. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2725. return result;
  2726. }
  2727. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2728. {
  2729. mtrace();
  2730. int result = FAIL;
  2731. char message[100]={0};
  2732. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2733. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2734. LWS_Send(message);
  2735. result = TRUE;
  2736. return result;
  2737. }
  2738. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2739. {
  2740. mtrace();
  2741. int result = FAIL;
  2742. char message[100]={0};
  2743. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2744. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2745. LWS_Send(message);
  2746. result = TRUE;
  2747. return result;
  2748. }
  2749. int sendClearCacheConfirmation(char *uuid,char *payload)
  2750. {
  2751. mtrace();
  2752. int result = FAIL;
  2753. char message[500]={0};
  2754. // int count = 0;
  2755. // int gun_index = 0;
  2756. // char guid[37];
  2757. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2758. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2759. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2760. LWS_Send(message);
  2761. return result;
  2762. }
  2763. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2764. {
  2765. mtrace();
  2766. int result = FAIL;
  2767. char message[500]={0};
  2768. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2769. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2770. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2771. LWS_Send(message);
  2772. return result;
  2773. }
  2774. int sendDataTransferConfirmation(char *uuid,char *payload)
  2775. {
  2776. mtrace();
  2777. char statusStr[20]={0};
  2778. char dataStr[10]={0};
  2779. char sstr[20]={0};
  2780. int c = 0;
  2781. char *loc;
  2782. int result = FAIL;
  2783. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2784. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2785. /**********************status**************************/
  2786. loc = strstr(payload, "status");
  2787. memset(sstr ,0, sizeof(sstr) );
  2788. c = 0;
  2789. while (loc[3+strlen("status")+c] != '\"')
  2790. {
  2791. sstr[c] = loc[3+strlen("status")+c];
  2792. c++;
  2793. }
  2794. sstr[c] = '\0';
  2795. strcpy(statusStr, sstr);
  2796. /**********************data**************************/
  2797. loc = strstr(payload, "data");
  2798. memset(sstr ,0, sizeof(sstr) );
  2799. c = 0;
  2800. while (loc[3+strlen("data")+c] != '\"')
  2801. {
  2802. sstr[c] = loc[3+strlen("data")+c];
  2803. c++;
  2804. }
  2805. sstr[c] = '\0';
  2806. strcpy(dataStr, sstr);
  2807. return result;
  2808. }
  2809. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2810. {
  2811. mtrace();
  2812. int result = FAIL;
  2813. char message[1000]={0};
  2814. double diff_f = 0.0;
  2815. int diff_i = 0;
  2816. int diffSeconds = 0;
  2817. struct tm tp;
  2818. int TimeZero = FALSE;
  2819. int CompositeScheduleIndex = 0;
  2820. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2821. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2822. {
  2823. TimeZero = TRUE;
  2824. }
  2825. else
  2826. {
  2827. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2828. }
  2829. if(TimeZero == FALSE)
  2830. {
  2831. tp.tm_isdst = -1;
  2832. time_t utc = mktime(&tp);
  2833. time_t t = time(NULL);
  2834. diff_f = difftime(t, utc);
  2835. diff_i = (int)diff_f;
  2836. diffSeconds = diff_i % 86400;//86400 seconds/day
  2837. }
  2838. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2839. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2840. #if 0 //remove temporally
  2841. 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}"
  2842. ,MESSAGE_TYPE_CALLRESULT
  2843. ,uuid
  2844. ,payload
  2845. ,connectorIdInt
  2846. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2847. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2848. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2849. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2850. #endif
  2851. if(nPeriod == 0)
  2852. {
  2853. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2854. ,MESSAGE_TYPE_CALLRESULT
  2855. ,uuid
  2856. ,payload
  2857. ,connectorIdInt
  2858. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2859. }
  2860. else
  2861. {
  2862. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2863. ,MESSAGE_TYPE_CALLRESULT
  2864. ,uuid
  2865. ,payload
  2866. ,connectorIdInt
  2867. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2868. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2869. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2870. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2871. int len = nPeriod;
  2872. //Last Period StartPriod is less than diffSeconds
  2873. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2874. {
  2875. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2876. , 0
  2877. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2878. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2879. }
  2880. else
  2881. {
  2882. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2883. {
  2884. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2885. {
  2886. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2887. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2888. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2889. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2890. }
  2891. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2892. {
  2893. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2894. , (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*/))
  2895. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2896. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2897. }
  2898. }
  2899. }
  2900. sprintf(message + strlen(message), "]}}]");
  2901. }
  2902. LWS_Send(message);
  2903. result = TRUE;
  2904. return result;
  2905. }
  2906. int sendGetConfigurationConfirmation(char *uuid)
  2907. {
  2908. mtrace();
  2909. int result = FAIL;
  2910. int MaxKeySupported = 0;
  2911. int sentConfigurationNumber= 0;
  2912. int sentunConfigurationNumber= 0;
  2913. char message[4000]={0};
  2914. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2915. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2916. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2917. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  2918. ,MESSAGE_TYPE_CALLRESULT
  2919. ,uuid );
  2920. //configuration key
  2921. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2922. {
  2923. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2924. {
  2925. if (sentConfigurationNumber == 0)
  2926. {
  2927. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  2928. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2929. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2930. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2931. }
  2932. else
  2933. {
  2934. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2935. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2936. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2937. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2938. }
  2939. sentConfigurationNumber = sentConfigurationNumber + 1;
  2940. }
  2941. }
  2942. sprintf(message + strlen(message), "]");
  2943. if(UnknownKeynum != 0)
  2944. {
  2945. sprintf(message + strlen(message), ",\"unknownKey\":[");
  2946. //unkown key
  2947. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  2948. {
  2949. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  2950. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  2951. if(sentunConfigurationNumber == 0)
  2952. {
  2953. sprintf(message + strlen(message), "\"%s\""
  2954. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2955. }
  2956. else
  2957. {
  2958. sprintf(message + strlen(message), ",\"%s\""
  2959. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2960. }
  2961. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  2962. }
  2963. sprintf(message + strlen(message), "]");
  2964. }
  2965. sprintf(message + strlen(message), "} ]");
  2966. LWS_Send(message);
  2967. return result;
  2968. }
  2969. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  2970. {
  2971. mtrace();
  2972. int result = FAIL;
  2973. char message[400]={0};
  2974. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  2975. if(strcmp(payload,"")==0)
  2976. {
  2977. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  2978. }
  2979. else
  2980. {
  2981. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  2982. }
  2983. LWS_Send(message);
  2984. result = TRUE;
  2985. return result;
  2986. }
  2987. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  2988. {
  2989. mtrace();
  2990. int result = FAIL;
  2991. char message[80]={0};
  2992. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  2993. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  2994. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  2995. LWS_Send(message);
  2996. result = TRUE;
  2997. return result;
  2998. }
  2999. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3000. {
  3001. mtrace();
  3002. int result = FAIL;
  3003. char message[80]={0};
  3004. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3005. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3006. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3007. LWS_Send(message);
  3008. result = TRUE;
  3009. return result;
  3010. }
  3011. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3012. {
  3013. mtrace();
  3014. int result = FAIL;
  3015. char message[80]={0};
  3016. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3017. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3018. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3019. LWS_Send(message);
  3020. result = TRUE;
  3021. return result;
  3022. }
  3023. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3024. {
  3025. mtrace();
  3026. int result = FAIL;
  3027. char message[80]={0};
  3028. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3029. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3030. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3031. LWS_Send(message);
  3032. result = TRUE;
  3033. return result;
  3034. }
  3035. int sendResetConfirmation(char *uuid,char *payload)
  3036. {
  3037. mtrace();
  3038. int result = FAIL;
  3039. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3040. char message[80]={0};
  3041. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3042. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3043. LWS_Send(message);
  3044. result = TRUE;
  3045. return result;
  3046. }
  3047. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3048. {
  3049. mtrace();
  3050. int result = FAIL;
  3051. char message[500]={0};
  3052. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3053. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3054. LWS_Send(message);
  3055. result = TRUE;
  3056. return result;
  3057. }
  3058. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3059. {
  3060. mtrace();
  3061. int result = FAIL;
  3062. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3063. char message[80]={0};
  3064. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3065. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3066. LWS_Send(message);
  3067. result = TRUE;
  3068. return result;
  3069. }
  3070. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3071. {
  3072. mtrace();
  3073. int result = FAIL;
  3074. char message[80]={0};
  3075. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3076. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3077. LWS_Send(message);
  3078. result = TRUE;
  3079. return result;
  3080. }
  3081. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3082. {
  3083. mtrace();
  3084. int result = FAIL;
  3085. char message[80]={0};
  3086. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3087. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3088. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3089. LWS_Send(message);
  3090. result = TRUE;
  3091. return result;
  3092. }
  3093. int sendUpdateFirmwareConfirmation(char *uuid)
  3094. {
  3095. mtrace();
  3096. int result = FAIL;
  3097. char message[60]={0};
  3098. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3099. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3100. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3101. LWS_Send(message);
  3102. result = TRUE;
  3103. return result;
  3104. }
  3105. //==========================================
  3106. // send CallError routine
  3107. //==========================================
  3108. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3109. {
  3110. mtrace();
  3111. //int result = FAIL;
  3112. char message[220]={0};
  3113. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3114. #ifdef SystemLogMessage
  3115. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3116. uniqueId, action, errorCode, errorDescription);
  3117. #endif
  3118. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3119. LWS_Send(message);
  3120. //result = TRUE;
  3121. }
  3122. //==========================================
  3123. // Handle server request routine Start
  3124. //==========================================
  3125. #define GUN_NUM 1
  3126. int handleCancelReservationRequest(char *uuid, char *payload)
  3127. {
  3128. mtrace();
  3129. int result = FAIL;
  3130. int gunNO = 0;
  3131. int reservationIdInt =0;
  3132. char comfirmstr[20];
  3133. int c = 0;
  3134. char *loc;
  3135. char sstr[100]={0};
  3136. DEBUG_INFO("handle CancelReservationRequest\n");
  3137. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3138. c = 0;
  3139. loc = strstr(payload, "reservationId");
  3140. memset(sstr ,0, sizeof(sstr) );
  3141. while (loc[strlen("reservationId")+2+c] != '}')
  3142. {
  3143. sstr[c] = loc[strlen("reservationId")+2+c];
  3144. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3145. c++;
  3146. }
  3147. sstr[c] = '\0';
  3148. reservationIdInt = atoi(sstr);
  3149. memset(comfirmstr, 0, sizeof comfirmstr);
  3150. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3151. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3152. //check Transaction active
  3153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3154. {
  3155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3156. {
  3157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3158. {
  3159. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3160. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3161. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3162. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3163. goto end;
  3164. }
  3165. }
  3166. for (int index = 0; index < CCS_QUANTITY; index++)
  3167. {
  3168. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3169. {
  3170. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3171. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3172. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3173. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3174. goto end;
  3175. }
  3176. }
  3177. for (int index = 0; index < GB_QUANTITY; index++)
  3178. {
  3179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3180. {
  3181. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3182. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3183. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3184. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3185. goto end;
  3186. }
  3187. }
  3188. }
  3189. else
  3190. {
  3191. for (int index = 0; index < AC_QUANTITY; index++)
  3192. {
  3193. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3194. {
  3195. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3196. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3197. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3198. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3199. goto end;
  3200. }
  3201. }
  3202. }// END FOR AC ELSE
  3203. //The reservationId does NOT match the reservationId
  3204. sendCancelReservationConfirmation(uuid, comfirmstr);
  3205. end:
  3206. // Fill in ocpp packet uuid
  3207. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3208. return result;
  3209. }
  3210. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3211. {
  3212. mtrace();
  3213. int result = FAIL;
  3214. int gunIndex = 0;
  3215. char sstr[90]={0};
  3216. char typeStr[16]={0};
  3217. char comfirmstr[20];
  3218. int specificId = FALSE;
  3219. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3220. char *loc;
  3221. //int intervalInt = 0;
  3222. int c = 0;
  3223. /*** connectorId ****/
  3224. c = 0;
  3225. loc = strstr(payload, "connectorId");
  3226. memset(sstr ,0, sizeof(sstr) );
  3227. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3228. {
  3229. sstr[c] = loc[strlen("connectorId")+2+c];
  3230. c++;
  3231. }
  3232. sstr[c] = '\0';
  3233. gunIndex = atoi(sstr);
  3234. /***type ****/
  3235. loc = strstr(payload, "type");
  3236. memset(sstr ,0, sizeof(sstr) );
  3237. c = 0;
  3238. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3239. {
  3240. sstr[c] = loc[3+strlen("type")+c];
  3241. c++;
  3242. }
  3243. sstr[c] = '\0';
  3244. strcpy(typeStr, sstr);
  3245. if(gunIndex != 0)
  3246. {
  3247. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3248. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3249. }
  3250. else
  3251. {
  3252. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3253. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3254. }
  3255. memset(comfirmstr, 0, sizeof comfirmstr);
  3256. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3257. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3258. {
  3259. specificId = TRUE;
  3260. }
  3261. if(specificId == FALSE)
  3262. goto end;
  3263. if(gunIndex != 0)
  3264. {
  3265. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3266. }
  3267. else
  3268. {
  3269. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3270. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3271. }
  3272. /*
  3273. enum SYSTEM_STATUS
  3274. {
  3275. SYS_MODE_BOOTING = 0,
  3276. SYS_MODE_IDLE = 1,
  3277. SYS_MODE_AUTHORIZING = 2,
  3278. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3279. SYS_MODE_REASSIGN = 4,
  3280. SYS_MODE_PREPARING = 5,
  3281. SYS_MODE_PREPARE_FOR_EV = 6,
  3282. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3283. SYS_MODE_CHARGING = 8,
  3284. SYS_MODE_TERMINATING = 9,
  3285. SYS_MODE_COMPLETE = 10,
  3286. SYS_MODE_ALARM = 11,
  3287. SYS_MODE_FAULT = 12,
  3288. SYS_MODE_RESERVATION = 13,
  3289. SYS_MODE_BOOKING = 14,
  3290. SYS_MODE_MAINTAIN = 15,
  3291. SYS_MODE_DEBUG = 16,
  3292. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3293. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3294. SYS_MODE_UPDATE = 19
  3295. };
  3296. */
  3297. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3298. {
  3299. //check Transaction active
  3300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3301. {
  3302. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3303. {
  3304. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3305. {
  3306. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3307. {
  3308. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3309. }
  3310. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3311. {
  3312. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3313. }
  3314. else
  3315. {
  3316. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3317. }
  3318. goto end;
  3319. }
  3320. }//END FOR CHAdeMO_QUANTITY
  3321. for (int index = 0; index < CCS_QUANTITY; index++)
  3322. {
  3323. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3324. {
  3325. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3326. {
  3327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3328. }
  3329. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3330. {
  3331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3332. }
  3333. else
  3334. {
  3335. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3336. }
  3337. goto end;
  3338. }
  3339. }//END FOR CCS_QUANTITY
  3340. for (int index = 0; index < GB_QUANTITY; index++)
  3341. {
  3342. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3343. {
  3344. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3345. {
  3346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3347. }
  3348. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3349. {
  3350. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3351. }
  3352. else
  3353. {
  3354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3355. }
  3356. goto end;
  3357. }
  3358. }// END FOR GB_QUANTITY
  3359. }
  3360. else
  3361. {
  3362. for (int index = 0; index < AC_QUANTITY; index++)
  3363. {
  3364. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3365. {
  3366. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3367. {
  3368. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3369. }
  3370. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3371. {
  3372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3373. }
  3374. else
  3375. {
  3376. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3377. }
  3378. goto end;
  3379. }
  3380. }//END FOR AC_QUANTITY
  3381. }// END FOR AC ELSE
  3382. }//END FOR AvailabilityTypeStr[Inoperative]
  3383. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3384. {
  3385. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3386. //check Transaction active
  3387. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3388. {
  3389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3390. {
  3391. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3392. {
  3393. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3394. goto end;
  3395. }
  3396. }//END FOR CHAdeMO_QUANTITY
  3397. for (int index = 0; index < CCS_QUANTITY; index++)
  3398. {
  3399. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3400. {
  3401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3402. goto end;
  3403. }
  3404. }//END FOR CCS_QUANTITY
  3405. for (int index = 0; index < GB_QUANTITY; index++)
  3406. {
  3407. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3408. {
  3409. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3410. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3411. goto end;
  3412. }
  3413. }// END FOR GB_QUANTITY
  3414. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3415. }
  3416. else
  3417. {
  3418. for (int index = 0; index < AC_QUANTITY; index++)
  3419. {
  3420. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3421. {
  3422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3423. goto end;
  3424. }
  3425. }//END FOR CHAdeMO_QUANTITY
  3426. }//END FOR AC ELSE
  3427. }//END FOR AvailabilityTypeStr[Operative]
  3428. end:
  3429. if(gunIndex != 0)
  3430. {
  3431. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3432. }
  3433. else
  3434. {
  3435. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3436. }
  3437. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3438. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3439. return result;
  3440. }
  3441. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3442. {
  3443. mtrace();
  3444. int result = FAIL;
  3445. char sstr[100]={0};
  3446. char keystr[40]={0};
  3447. char valuestr[100]={0};
  3448. char *loc;
  3449. int c = 0;
  3450. char comfirmstr[20]={0};
  3451. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3452. /***key ****/
  3453. loc = strstr(payload, "key");
  3454. memset(sstr ,0, sizeof(sstr) );
  3455. c = 0;
  3456. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3457. {
  3458. sstr[c] = loc[3+strlen("key")+c];
  3459. c++;
  3460. }
  3461. sstr[c] = '\0';
  3462. strcpy(keystr, sstr);
  3463. //DEBUG_INFO( "keystr=%s\n",keystr);
  3464. /***value ****/
  3465. loc = strstr(payload, "value");
  3466. memset(sstr ,0, sizeof(sstr) );
  3467. c = 0;
  3468. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3469. {
  3470. sstr[c] = loc[3+strlen("value")+c];
  3471. c++;
  3472. }
  3473. sstr[c] = '\0';
  3474. strcpy(valuestr, sstr);
  3475. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3476. if((uuid==NULL) || (payload ==NULL) )
  3477. {
  3478. #ifdef Debug
  3479. DEBUG_INFO("payload is null\n");
  3480. #endif
  3481. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3482. }
  3483. else
  3484. {
  3485. int status = setKeyValue(keystr, valuestr);
  3486. switch(status)
  3487. {
  3488. case ConfigurationStatus_Accepted:
  3489. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3490. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3491. StoreConfigurationTable();
  3492. break;
  3493. case ConfigurationStatus_Rejected:
  3494. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3495. break;
  3496. case RebootRequired:
  3497. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3498. StoreConfigurationTable();
  3499. break;
  3500. case NotSupported:
  3501. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3502. break;
  3503. default:
  3504. break;
  3505. }
  3506. }
  3507. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3508. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3509. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3510. return result;
  3511. }
  3512. int handleClearCacheRequest(char *uuid, char *payload)
  3513. {
  3514. mtrace();
  3515. int result = FAIL;
  3516. char comfirmstr[20];
  3517. int fd;
  3518. char rmFileCmd[100]={0};
  3519. struct stat stats;
  3520. DEBUG_INFO("handle ClearCacheRequest\n");
  3521. stat("../Storage/OCPP", &stats);
  3522. // Check for directory existence
  3523. if (S_ISDIR(stats.st_mode) == 1)
  3524. {
  3525. //DEBUG_ERROR("\n OCPP directory exist \n");
  3526. }
  3527. else
  3528. {
  3529. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3530. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3531. system(rmFileCmd);
  3532. }
  3533. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3534. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3535. {
  3536. DEBUG_INFO("AuthorizationCache file exist.\n");
  3537. }
  3538. else
  3539. {
  3540. DEBUG_INFO("AuthorizationCache file not exist\n");
  3541. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3542. if(log == NULL)
  3543. {
  3544. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3545. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3546. goto end;
  3547. }
  3548. else
  3549. {
  3550. fclose(log);
  3551. }
  3552. }
  3553. fd = open(AuthorizationCache_JSON,O_RDWR);
  3554. if(fd < 0)
  3555. {
  3556. DEBUG_INFO("open AuthorizationCache file failed\n");
  3557. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3558. }
  3559. else
  3560. {
  3561. DEBUG_INFO("open AuthorizationCache file successful\n");
  3562. //* 清空? 件 */
  3563. ftruncate(fd,0);
  3564. //* ? 新设置? 件? 移??*/
  3565. lseek(fd,0,SEEK_SET);
  3566. close(fd);
  3567. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3568. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3569. }
  3570. end:
  3571. sendClearCacheConfirmation(uuid, comfirmstr);
  3572. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3573. return result;
  3574. }
  3575. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3576. {
  3577. mtrace();
  3578. int result = FAIL;
  3579. int resultRename;
  3580. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3581. char chargingProfilePurposeStr[26]={0};
  3582. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3583. char tempchargingProfilePurposeStr[26]={0};
  3584. char sstr[160]={0};//sstr[200]={ 0 };
  3585. char str[100]={0};
  3586. int c = 0;
  3587. //int i = 0;
  3588. //char * pch;
  3589. char *loc;
  3590. char fname[200];
  3591. char comfirmstr[20]={0};
  3592. char word[1000]={0};
  3593. int clearflag = FALSE;
  3594. int chargingProfileIdIsNULL = FALSE;
  3595. int connectorIsNULL = FALSE;
  3596. int chargingProfilePurposeIsNULL = FALSE;
  3597. int stackLevelIsNULL = FALSE;
  3598. int GotoEnd = FALSE;
  3599. FILE *fptr1, *fptr2;
  3600. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json";
  3601. int n_chargingProfile=0;
  3602. char sLineWord[1060]={0};
  3603. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3604. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3605. //***id ****/
  3606. c = 0;
  3607. loc = strstr(payload, "id");
  3608. memset(sstr ,0, sizeof(sstr) );
  3609. if(loc == NULL)
  3610. {
  3611. chargingProfileIdIsNULL = TRUE;
  3612. }
  3613. else
  3614. {
  3615. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3616. {
  3617. sstr[c] = loc[strlen("id")+2+c];
  3618. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3619. c++;
  3620. }
  3621. sstr[c] = '\0';
  3622. chargingProfileIdInt = atoi(sstr);
  3623. }
  3624. //***connectorId ****/
  3625. c=0;
  3626. loc = strstr(payload, "connectorId");
  3627. memset(sstr ,0, sizeof(sstr) );
  3628. if(loc == NULL)
  3629. {
  3630. connectorIsNULL = TRUE;
  3631. }
  3632. else
  3633. {
  3634. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3635. {
  3636. sstr[c] = loc[strlen("connectorId")+2+c];
  3637. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3638. c++;
  3639. }
  3640. sstr[c] = '\0';
  3641. connectorIdInt = atoi(sstr);
  3642. }
  3643. //***chargingProfilePurpose ****/
  3644. loc = strstr(payload, "chargingProfilePurpose");
  3645. memset(sstr ,0, sizeof(sstr) );
  3646. c = 0;
  3647. if(loc == NULL)
  3648. {
  3649. chargingProfilePurposeIsNULL = TRUE;
  3650. }
  3651. else
  3652. {
  3653. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3654. {
  3655. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3656. c++;
  3657. }
  3658. sstr[c] = '\0';
  3659. strcpy(chargingProfilePurposeStr, sstr);
  3660. }
  3661. //***stackLevel ****/
  3662. c=0;
  3663. loc = strstr(payload, "stackLevel");
  3664. memset(sstr ,0, sizeof(sstr) );
  3665. if(loc == NULL)
  3666. {
  3667. stackLevelIsNULL = TRUE;
  3668. }
  3669. else
  3670. {
  3671. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3672. {
  3673. sstr[c] = loc[strlen("stackLevel")+2+c];
  3674. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3675. c++;
  3676. }
  3677. sstr[c] = '\0';
  3678. stackLevelInt = atoi(sstr);
  3679. }
  3680. if(connectorIsNULL == FALSE)
  3681. {
  3682. switch(connectorIdInt)
  3683. {
  3684. case 0:
  3685. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3686. {
  3687. strcpy(fname, ChargePointMaxProfile_JSON);
  3688. }
  3689. else
  3690. {
  3691. strcpy(fname, TxDefaultProfile_0_JSON);
  3692. }
  3693. break;
  3694. case 1:
  3695. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3696. {
  3697. strcpy(fname, TxDefaultProfile_1_JSON);
  3698. }
  3699. // else
  3700. // {
  3701. // strcpy(fname, TxProfile_1_JSON);
  3702. // }
  3703. break;
  3704. case 2:
  3705. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3706. {
  3707. strcpy(fname, TxDefaultProfile_2_JSON);
  3708. }
  3709. // else
  3710. // {
  3711. // strcpy(fname, TxProfile_2_JSON);
  3712. // }
  3713. break;
  3714. default:
  3715. strcpy(fname, ChargePointMaxProfile_JSON );
  3716. break;
  3717. }
  3718. }
  3719. else
  3720. {
  3721. strcpy(fname, ChargePointMaxProfile_JSON );
  3722. }
  3723. fptr1 = fopen(fname, "r");
  3724. if (!fptr1)
  3725. {
  3726. //file not exist
  3727. DEBUG_INFO("Unable to open the input file!!\n");
  3728. fptr1 = fopen(fname, "w+");
  3729. }
  3730. fclose(fptr1);
  3731. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3732. {
  3733. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3734. goto end;
  3735. }
  3736. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3737. {
  3738. //clear file in C
  3739. sprintf(str,"rm -f %s",fname);
  3740. system(str);
  3741. // clear temp file
  3742. sprintf(str,"rm -f %s",temp);
  3743. system(str);
  3744. #if 0
  3745. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3746. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3747. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3748. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3749. fclose(fopen(TxProfile_1_JSON, "w"));
  3750. fclose(fopen(TxProfile_2_JSON, "w"));
  3751. #endif
  3752. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3753. goto end;
  3754. }
  3755. else
  3756. {
  3757. fptr1 = fopen(fname, "r");
  3758. fptr2 = fopen(temp, "w+");
  3759. while(fscanf(fptr1, "%s", word) != EOF)
  3760. {
  3761. //DEBUG_INFO("word=%s\n",word);
  3762. if(strcmp(word, "chargingProfileId") == 0)
  3763. {
  3764. n_chargingProfile = n_chargingProfile + 1;
  3765. DEBUG_INFO("chargingProfileId Found\n");
  3766. }
  3767. }
  3768. rewind(fptr1);
  3769. //search Charging Profile Element
  3770. //int i= 0;
  3771. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3772. {
  3773. //*************************tempconnectorIdInt*********************************/
  3774. loc = strstr(sLineWord, "connectorId");
  3775. c = 0;
  3776. memset(sstr ,0, sizeof(sstr) );
  3777. while (loc[strlen("connectorId")+2+c] != ',')
  3778. {
  3779. sstr[c] = loc[strlen("connectorId")+2+c];
  3780. c++;
  3781. }
  3782. sstr[c] = '\0';
  3783. tempconnectorIdInt = atoi(sstr);
  3784. //chargingProfileId
  3785. c = 0;
  3786. loc = strstr(sLineWord, "chargingProfileId");
  3787. memset(sstr ,0, sizeof(sstr) );
  3788. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3789. {
  3790. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3791. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3792. c++;
  3793. }
  3794. sstr[c] = '\0';
  3795. tempchargingProfileIdInt = atoi(sstr);
  3796. //stackLevel
  3797. c = 0;
  3798. loc = strstr(sLineWord, "stackLevel");
  3799. memset(sstr ,0, sizeof(sstr) );
  3800. while (loc[strlen("stackLevel")+2+c] != ',')
  3801. {
  3802. sstr[c] = loc[strlen("stackLevel")+2+c];
  3803. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3804. c++;
  3805. }
  3806. sstr[c] = '\0';
  3807. tempstackLevelInt = atoi(sstr);
  3808. c = 0;
  3809. loc = strstr(sLineWord, "chargingProfilePurpose");
  3810. memset(sstr ,0, sizeof(sstr) );
  3811. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3812. {
  3813. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3814. c++;
  3815. }
  3816. sstr[c] = '\0';
  3817. strcpy(tempchargingProfilePurposeStr, sstr);
  3818. if(chargingProfileIdIsNULL == FALSE)
  3819. {
  3820. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3821. {
  3822. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3823. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3824. clearflag = TRUE;
  3825. continue;
  3826. }
  3827. else
  3828. {
  3829. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3830. //json_object_array_add(newHeatMap, jsonitem);
  3831. fprintf(fptr2, sLineWord);//writing data into file
  3832. }
  3833. }
  3834. else
  3835. {
  3836. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3837. {
  3838. if(stackLevelIsNULL == TRUE)//((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3839. {
  3840. fclose(fptr1);
  3841. fclose(fptr2);
  3842. sprintf(str,"rm -f %s",fname);
  3843. system(str);
  3844. // clear temp file
  3845. sprintf(str,"rm -f %s",temp);
  3846. system(str);
  3847. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3848. clearflag = TRUE;
  3849. GotoEnd = TRUE;
  3850. break;
  3851. }
  3852. else if((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt))
  3853. {
  3854. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3855. clearflag = TRUE;
  3856. continue;
  3857. }
  3858. }
  3859. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3860. {
  3861. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3862. {
  3863. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3864. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3865. {
  3866. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3867. clearflag = TRUE;
  3868. continue;
  3869. }
  3870. }
  3871. }
  3872. else
  3873. {
  3874. //json_object_array_add(newHeatMap, jsonitem);
  3875. fprintf(fptr2, sLineWord);//writing data into file
  3876. }
  3877. }
  3878. memset(sLineWord, 0, sizeof sLineWord);
  3879. }
  3880. if((clearflag == FALSE) && (GotoEnd == TRUE))
  3881. {
  3882. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3883. sprintf(str,"rm -f %s",temp);
  3884. system(str);
  3885. goto end;
  3886. }
  3887. else
  3888. {
  3889. goto end;
  3890. }
  3891. fclose(fptr1);
  3892. fclose(fptr2);
  3893. sprintf(str,"rm -f %s",fname);
  3894. system(str);
  3895. resultRename = rename(temp, fname);
  3896. if(resultRename == 0)
  3897. {
  3898. DEBUG_INFO("File ChargingProfile renamed successfully");
  3899. }
  3900. else
  3901. {
  3902. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  3903. }
  3904. }
  3905. end:
  3906. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3907. return result;
  3908. }
  3909. int handleDataTransferRequest(char *uuid, char *payload)
  3910. {
  3911. mtrace();
  3912. int result = FAIL;
  3913. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  3914. char tempvendorId[255]={0};
  3915. char tempmessageId[50]={0};
  3916. char tempdata[50]={0};
  3917. char sstr[160]={0};//sstr[200]={ 0 };
  3918. char message[80]={0};
  3919. int c = 0;
  3920. char *loc;
  3921. DEBUG_INFO("handle DataTransferRequest\n");
  3922. if((uuid != NULL) && (payload != NULL))
  3923. {
  3924. //===============================
  3925. // vendorId
  3926. //===============================
  3927. c = 0;
  3928. loc = strstr(payload, "vendorId");
  3929. while (loc[strlen("vendorId")+3+c] != '\"')
  3930. {
  3931. sstr[c] = loc[strlen("vendorId")+3+c];
  3932. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3933. c++;
  3934. }
  3935. sstr[c] = '\0';
  3936. strcpy(tempvendorId,sstr);
  3937. //===============================
  3938. // messageId
  3939. //===============================
  3940. memset(sstr ,0, sizeof(sstr) );
  3941. c = 0;
  3942. loc = strstr(payload, "messageId");
  3943. while (loc[strlen("messageId")+3+c] != '\"')
  3944. {
  3945. sstr[c] = loc[strlen("messageId")+3+c];
  3946. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3947. c++;
  3948. }
  3949. sstr[c] = '\0';
  3950. strcpy(tempmessageId,sstr);
  3951. //===============================
  3952. // data
  3953. //===============================
  3954. memset(sstr ,0, sizeof(sstr) );
  3955. c = 0;
  3956. loc = strstr(payload, "data");
  3957. printf("loc=%s\n",loc);
  3958. while (loc[strlen("data")+3+c] != '\"')
  3959. {
  3960. sstr[c] = loc[strlen("data")+3+c];
  3961. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3962. c++;
  3963. }
  3964. sstr[c] = '\0';
  3965. strcpy(tempdata,sstr);
  3966. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  3967. }
  3968. else
  3969. {
  3970. char guid[37]={0};
  3971. random_uuid(guid);
  3972. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  3973. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  3974. }
  3975. LWS_Send(message);
  3976. return result;
  3977. }
  3978. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  3979. {
  3980. mtrace();
  3981. int result = FAIL;
  3982. int connectorIdInt, durationInt;
  3983. char chargingRateUnitStr[4]={0};
  3984. //int tempconnectorIdInt,
  3985. int tempdurationInt;
  3986. float tempminChargingRateFloat = 0.0;
  3987. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  3988. int tempStartPeriodInt=0;
  3989. float tempLimitInt=0.0;//0.1;
  3990. int tempNumberPhasesInt=0;
  3991. char fname[200];
  3992. char comfirmstr[20];
  3993. //float totallimit =0.0;
  3994. float MinChargingRate =0.0;
  3995. //double diff_t;
  3996. //struct tm tp;
  3997. FILE *fptr1;
  3998. int c = 0;
  3999. //int i = 0;
  4000. char * pch;
  4001. char *loc;
  4002. char sstr[200]={ 0 };
  4003. int n_chargingProfile = 0;
  4004. int n_SchedulePeriods = 0;
  4005. char SchedulePeriodList[10][200]={0};
  4006. char sLineWord[800]={0};
  4007. //int n_periods = 0;
  4008. char word[1000]={0};
  4009. int confirmPeriods = 0;
  4010. struct StructProfile ChargePointMaxProfile;
  4011. struct StructProfile TxDefaultProfile;
  4012. struct StructProfile TxProfile;
  4013. struct StructProfile TxDefaultProfiletemp[2]={0};
  4014. int TxDefaultProfileFileIsNull=FALSE;
  4015. int ChargePointMaxProfileIsNull=FALSE;
  4016. int TxProfileIsNull=FALSE;
  4017. int CompositeSceduleIndex = 0;
  4018. char ChargePointMaxProfileScheduleStr[30]={0};
  4019. char TxDefaultProfileScheduleStr[30]={0};
  4020. char TxProfileScheduleStr[30]={0};
  4021. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4022. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4023. memset(&TxProfile,0,sizeof(struct StructProfile));
  4024. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4025. c=0;
  4026. loc = strstr(payload, "connectorId");
  4027. memset(sstr ,0, sizeof(sstr) );
  4028. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4029. {
  4030. sstr[c] = loc[strlen("connectorId")+2+c];
  4031. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4032. c++;
  4033. }
  4034. sstr[c] = '\0';
  4035. connectorIdInt = atoi(sstr);
  4036. c=0;
  4037. loc = strstr(payload, "duration");
  4038. memset(sstr ,0, sizeof(sstr) );
  4039. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4040. {
  4041. sstr[c] = loc[strlen("duration")+2+c];
  4042. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4043. c++;
  4044. }
  4045. sstr[c] = '\0';
  4046. durationInt = atoi(sstr);
  4047. c = 0;
  4048. loc = strstr(payload, "chargingRateUnit");
  4049. memset(sstr ,0, sizeof(sstr) );
  4050. if(loc == NULL)
  4051. {
  4052. }
  4053. else
  4054. {
  4055. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4056. {
  4057. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4058. c++;
  4059. }
  4060. sstr[c] = '\0';
  4061. strcpy(chargingRateUnitStr, sstr);
  4062. }
  4063. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4064. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4065. if(connectorIdInt==0) // connectorId is 0
  4066. {
  4067. //******************************ChargePointMaxProfile*****************************************************/
  4068. strcpy(fname, ChargePointMaxProfile_JSON );
  4069. char word[30]={0};
  4070. char sLineWord[1060]={0};
  4071. int n_chargingProfile=0;
  4072. ChargePointMaxProfileIsNull=TRUE;
  4073. if((access(fname,F_OK))!=-1)
  4074. {
  4075. fptr1 = fopen(fname, "r");
  4076. int c;
  4077. c = fgetc(fptr1);
  4078. //DEBUG_INFO("c:%d\n",c);
  4079. rewind(fptr1);
  4080. if(c == EOF)
  4081. {
  4082. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4083. ChargePointMaxProfileIsNull=TRUE;
  4084. fclose(fptr1);
  4085. }
  4086. else
  4087. {
  4088. ChargePointMaxProfileIsNull=FALSE;
  4089. while(fscanf(fptr1, "%s", word) != EOF)
  4090. {
  4091. if(strcmp(word, "chargingProfileId") == 0)
  4092. {
  4093. n_chargingProfile = n_chargingProfile + 1;
  4094. printf("Found\n");
  4095. }
  4096. }
  4097. rewind(fptr1);
  4098. //search Charging Profile Element
  4099. int i= 0;
  4100. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4101. #if 0
  4102. /***********connectorId****************/
  4103. c = 0;
  4104. loc = strstr(sLineWord, "connectorId");
  4105. // printf("loc=%s\n",loc);
  4106. memset(sstr ,0, sizeof(sstr) );
  4107. while (loc[strlen("connectorId")+2+c] != ',')
  4108. {
  4109. sstr[c] = loc[strlen("connectorId")+2+c];
  4110. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4111. c++;
  4112. }
  4113. sstr[c] = '\0';
  4114. tempconnectorIdInt = atoi(sstr);
  4115. #endif
  4116. //***********validFrom**************/
  4117. c = 0;
  4118. loc = strstr(sLineWord, "validFrom");
  4119. //DEBUG_INFO("loc=%s\n",loc);
  4120. memset(sstr ,0, sizeof(sstr) );
  4121. if(loc != NULL)
  4122. {
  4123. while (loc[3+strlen("validFrom")+c] != '\"')
  4124. {
  4125. sstr[c] = loc[3+strlen("validFrom")+c];
  4126. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4127. c++;
  4128. }
  4129. sstr[c] = '\0';
  4130. DEBUG_INFO("validFrom=%s\n",sstr);
  4131. strcpy(tempvalidFromStr,sstr);
  4132. }
  4133. else
  4134. {
  4135. strcpy(tempvalidFromStr,"");
  4136. }
  4137. //**********startSchedule**********/
  4138. c = 0;
  4139. loc = strstr(sLineWord, "startSchedule");
  4140. //DEBUG_INFO("loc=%s\n",loc);
  4141. memset(sstr ,0, sizeof(sstr) );
  4142. while (loc[3+strlen("startSchedule")+c] != '\"')
  4143. {
  4144. sstr[c] = loc[3+strlen("startSchedule")+c];
  4145. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4146. c++;
  4147. }
  4148. sstr[c] = '\0';
  4149. strcpy(tempstartScheduleStr, sstr);
  4150. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4151. //**********chargingRateUnit**********/
  4152. c = 0;
  4153. loc = strstr(sLineWord, "chargingRateUnit");
  4154. memset(sstr ,0, sizeof(sstr) );
  4155. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4156. {
  4157. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4158. c++;
  4159. }
  4160. sstr[c] = '\0';
  4161. strcpy(tempchargingRateUnitStr, sstr);
  4162. //**********minChargingRate*******/
  4163. c = 0;
  4164. loc = strstr(sLineWord, "minChargingRate");
  4165. //printf("loc=%s\n",loc);
  4166. if(loc != NULL)
  4167. {
  4168. memset(sstr ,0, sizeof(sstr) );
  4169. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4170. {
  4171. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4172. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4173. c++;
  4174. }
  4175. sstr[c] = '\0';
  4176. tempminChargingRateFloat = atof(sstr);
  4177. }
  4178. else
  4179. {
  4180. tempminChargingRateFloat = 0.0;
  4181. }
  4182. //
  4183. #if 0
  4184. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4185. tp.tm_isdst = -1;
  4186. time_t utc = mktime(&tp);
  4187. // current time
  4188. time_t t = time(NULL);
  4189. #endif
  4190. //diff_t = difftime(t, utc);
  4191. //parsing strings to words
  4192. i = 0;
  4193. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4194. loc = loc+3+strlen("chargingSchedulePeriod");
  4195. pch = strtok(loc ,"{");
  4196. while (pch != NULL)
  4197. {
  4198. strcpy(SchedulePeriodList[i], pch);
  4199. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4200. //printf ("%s\n",pch);
  4201. pch = strtok (NULL, "{");
  4202. i = i + 1;
  4203. }
  4204. n_SchedulePeriods = i;
  4205. for(int i=0;i<n_SchedulePeriods;i++)
  4206. {
  4207. //*************startPeriod****************/
  4208. c = 0;
  4209. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4210. memset(sstr ,0, sizeof(sstr) );
  4211. while (loc[strlen("startPeriod")+2+c] != ',')
  4212. {
  4213. sstr[c] = loc[strlen("startPeriod")+2+c];
  4214. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4215. c++;
  4216. }
  4217. sstr[c] = '\0';
  4218. tempStartPeriodInt = atoi(sstr);
  4219. //*************limit****************/
  4220. c = 0;
  4221. loc = strstr(SchedulePeriodList[i], "limit");
  4222. memset(sstr ,0, sizeof(sstr) );
  4223. while (loc[strlen("limit")+2+c] != ',')
  4224. {
  4225. sstr[c] = loc[strlen("limit")+2+c];
  4226. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4227. c++;
  4228. }
  4229. sstr[c] = '\0';
  4230. tempLimitInt = atof(sstr);
  4231. //*************numberPhases****************/
  4232. c = 0;
  4233. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4234. memset(sstr ,0, sizeof(sstr) );
  4235. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4236. {
  4237. sstr[c] = loc[strlen("numberPhases")+2+c];
  4238. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4239. c++;
  4240. }
  4241. sstr[c] = '\0';
  4242. tempNumberPhasesInt = atoi(sstr);
  4243. ChargePointMaxProfile.Duration = durationInt;
  4244. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4245. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4246. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4247. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4248. }
  4249. if(MinChargingRate < tempminChargingRateFloat)
  4250. MinChargingRate = tempminChargingRateFloat;
  4251. }
  4252. }// End of file ChargingProfile
  4253. } //THE END OF ACCESS ChargePointMaxProfile
  4254. //******************************TxDefaultProfile***********************************************/
  4255. strcpy(fname, TxDefaultProfile_0_JSON);
  4256. memset(word, 0, 30);
  4257. memset(sLineWord, 0, 1060);
  4258. //char word[30]={0};
  4259. //char sLineWord[1060]={0};
  4260. n_chargingProfile=0;
  4261. TxDefaultProfileFileIsNull=TRUE;
  4262. if((access(fname,F_OK))!=-1)
  4263. {
  4264. fptr1 = fopen(fname, "r");
  4265. c = 0;
  4266. c = fgetc(fptr1);
  4267. //DEBUG_INFO("c:%d\n",c);
  4268. rewind(fptr1);
  4269. if(c == EOF)
  4270. {
  4271. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4272. TxDefaultProfileFileIsNull=TRUE;
  4273. fclose(fptr1);
  4274. }
  4275. else
  4276. {
  4277. TxDefaultProfileFileIsNull=FALSE;
  4278. while(fscanf(fptr1, "%s", word) != EOF)
  4279. {
  4280. if(strcmp(word, "chargingProfileId") == 0)
  4281. {
  4282. n_chargingProfile = n_chargingProfile + 1;
  4283. printf("Found\n");
  4284. }
  4285. }
  4286. rewind(fptr1);
  4287. //search Charging Profile Element
  4288. int i= 0;
  4289. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4290. #if 0
  4291. /***********connectorId****************/
  4292. c = 0;
  4293. loc = strstr(sLineWord, "connectorId");
  4294. // printf("loc=%s\n",loc);
  4295. memset(sstr ,0, sizeof(sstr) );
  4296. while (loc[strlen("connectorId")+2+c] != ',')
  4297. {
  4298. sstr[c] = loc[strlen("connectorId")+2+c];
  4299. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4300. c++;
  4301. }
  4302. sstr[c] = '\0';
  4303. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4304. tempconnectorIdInt = atoi(sstr);
  4305. #endif
  4306. //***********validFrom**************/
  4307. c = 0;
  4308. loc = strstr(sLineWord, "validFrom");
  4309. //DEBUG_INFO("loc=%s\n",loc);
  4310. memset(sstr ,0, sizeof(sstr) );
  4311. if(loc != NULL)
  4312. {
  4313. while (loc[3+strlen("validFrom")+c] != '\"')
  4314. {
  4315. sstr[c] = loc[3+strlen("validFrom")+c];
  4316. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4317. c++;
  4318. }
  4319. sstr[c] = '\0';
  4320. DEBUG_INFO("validFrom=%s\n",sstr);
  4321. strcpy(tempvalidFromStr,sstr);
  4322. }
  4323. else
  4324. {
  4325. strcpy(tempvalidFromStr,"");
  4326. }
  4327. //**********startSchedule**********/
  4328. c = 0;
  4329. loc = strstr(sLineWord, "startSchedule");
  4330. //DEBUG_INFO("loc=%s\n",loc);
  4331. memset(sstr ,0, sizeof(sstr) );
  4332. while (loc[3+strlen("startSchedule")+c] != '\"')
  4333. {
  4334. sstr[c] = loc[3+strlen("startSchedule")+c];
  4335. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4336. c++;
  4337. }
  4338. sstr[c] = '\0';
  4339. strcpy(tempstartScheduleStr, sstr);
  4340. strcpy(TxDefaultProfileScheduleStr, sstr);
  4341. DEBUG_INFO(" debug 3-1\n");
  4342. //**********chargingRateUnit**********/
  4343. c = 0;
  4344. loc = strstr(sLineWord, "chargingRateUnit");
  4345. memset(sstr ,0, sizeof(sstr) );
  4346. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4347. {
  4348. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4349. c++;
  4350. }
  4351. sstr[c] = '\0';
  4352. strcpy(tempchargingRateUnitStr, sstr);
  4353. //**********minChargingRate*******/
  4354. c = 0;
  4355. loc = strstr(sLineWord, "minChargingRate");
  4356. //printf("loc=%s\n",loc);
  4357. if(loc != NULL)
  4358. {
  4359. memset(sstr ,0, sizeof(sstr) );
  4360. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4361. {
  4362. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4363. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4364. c++;
  4365. }
  4366. sstr[c] = '\0';
  4367. tempminChargingRateFloat = atof(sstr);
  4368. }
  4369. else
  4370. {
  4371. tempminChargingRateFloat = 0.0;
  4372. }
  4373. #if 0
  4374. //
  4375. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4376. tp.tm_isdst = -1;
  4377. time_t utc = mktime(&tp);
  4378. // current time
  4379. time_t t = time(NULL);
  4380. //diff_t = difftime(t, utc);
  4381. #endif
  4382. //parsing strings to words
  4383. i = 0;
  4384. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4385. loc = loc+3+strlen("chargingSchedulePeriod");
  4386. pch = strtok(loc ,"{");
  4387. while (pch != NULL)
  4388. {
  4389. strcpy(SchedulePeriodList[i], pch);
  4390. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4391. //printf ("%s\n",pch);
  4392. pch = strtok (NULL, "{");
  4393. i = i + 1;
  4394. }
  4395. n_SchedulePeriods = i;
  4396. for(int i=0;i<n_SchedulePeriods;i++)
  4397. {
  4398. //*************startPeriod****************/
  4399. c = 0;
  4400. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4401. memset(sstr ,0, sizeof(sstr) );
  4402. while (loc[strlen("startPeriod")+2+c] != ',')
  4403. {
  4404. sstr[c] = loc[strlen("startPeriod")+2+c];
  4405. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4406. c++;
  4407. }
  4408. sstr[c] = '\0';
  4409. tempStartPeriodInt = atoi(sstr);
  4410. //*************limit****************/
  4411. c = 0;
  4412. loc = strstr(SchedulePeriodList[i], "limit");
  4413. memset(sstr ,0, sizeof(sstr) );
  4414. while (loc[strlen("limit")+2+c] != ',')
  4415. {
  4416. sstr[c] = loc[strlen("limit")+2+c];
  4417. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4418. c++;
  4419. }
  4420. sstr[c] = '\0';
  4421. tempLimitInt = atof(sstr);
  4422. //*************numberPhases****************/
  4423. c = 0;
  4424. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4425. memset(sstr ,0, sizeof(sstr) );
  4426. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4427. {
  4428. sstr[c] = loc[strlen("numberPhases")+2+c];
  4429. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4430. c++;
  4431. }
  4432. sstr[c] = '\0';
  4433. tempNumberPhasesInt = atoi(sstr);
  4434. TxDefaultProfile.Duration = durationInt;
  4435. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4436. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4437. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4438. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4439. }
  4440. if(MinChargingRate < tempminChargingRateFloat)
  4441. MinChargingRate = tempminChargingRateFloat;
  4442. }
  4443. }
  4444. }// the end of ACCESS TxDefaultProfile
  4445. // Composite Schedule
  4446. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4447. {
  4448. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4449. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4450. {
  4451. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4452. {
  4453. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4454. }
  4455. else
  4456. {
  4457. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4458. }
  4459. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4460. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4461. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4462. }
  4463. }
  4464. //* Define temporary variables */
  4465. struct tm *gtime;
  4466. time_t now;
  4467. char buf[28];
  4468. /* Read the current system time */
  4469. time(&now);
  4470. /* Convert the system time to GMT (now UTC) */
  4471. gtime = gmtime(&now);
  4472. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4473. // make .conf
  4474. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4475. //MaxChargingProfilesInstalled is 10
  4476. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4477. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4478. //nPeriod = 1;
  4479. if(chargingRateUnitStr[0] != 0)
  4480. {
  4481. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4482. }
  4483. else
  4484. {
  4485. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4486. }
  4487. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4488. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4489. confirmPeriods = 1;
  4490. }
  4491. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4492. {
  4493. //*****************************ChargePointMaxProfile******************************************/
  4494. strcpy(fname, ChargePointMaxProfile_JSON);
  4495. ChargePointMaxProfileIsNull=TRUE;
  4496. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4497. {
  4498. fptr1 = fopen(fname, "r");
  4499. int c;
  4500. c = fgetc(fptr1);
  4501. //DEBUG_INFO("c:%d\n",c);
  4502. rewind(fptr1);
  4503. if(c == EOF)
  4504. {
  4505. DEBUG_INFO("\n End of file reached.");
  4506. ChargePointMaxProfileIsNull=TRUE;
  4507. fclose(fptr1);
  4508. }
  4509. else
  4510. {
  4511. ChargePointMaxProfileIsNull=FALSE;
  4512. while(fscanf(fptr1, "%s", word) != EOF)
  4513. {
  4514. if(strcmp(word, "chargingProfileId") == 0)
  4515. {
  4516. n_chargingProfile = n_chargingProfile + 1;
  4517. }
  4518. }
  4519. rewind(fptr1);
  4520. //search Charging Profile Element
  4521. int i = 0;
  4522. int j = 0;
  4523. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4524. #if 0
  4525. /***********connectorId****************/
  4526. c = 0;
  4527. loc = strstr(sLineWord, "connectorId");
  4528. memset(sstr ,0, sizeof(sstr) );
  4529. while (loc[strlen("connectorId")+2+c] != ',')
  4530. {
  4531. sstr[c] = loc[strlen("connectorId")+2+c];
  4532. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4533. c++;
  4534. }
  4535. sstr[c] = '\0';
  4536. tempconnectorIdInt = atoi(sstr);
  4537. #endif
  4538. //***********validFrom**************/
  4539. c = 0;
  4540. loc = strstr(sLineWord, "validFrom");
  4541. if(loc != NULL)
  4542. {
  4543. memset(sstr ,0, sizeof(sstr) );
  4544. while (loc[3+strlen("validFrom")+c] != '\"')
  4545. {
  4546. sstr[c] = loc[3+strlen("validFrom")+c];
  4547. c++;
  4548. }
  4549. sstr[c] = '\0';
  4550. strcpy(tempvalidFromStr,sstr);
  4551. }
  4552. else
  4553. {
  4554. strcpy(tempvalidFromStr,"");
  4555. }
  4556. //***********validFrom**************/
  4557. c = 0;
  4558. loc = strstr(sLineWord, "duration");
  4559. if(loc != NULL)
  4560. {
  4561. memset(sstr ,0, sizeof(sstr) );
  4562. while (loc[2+strlen("duration")+c] != ',')
  4563. {
  4564. sstr[c] = loc[2+strlen("duration")+c];
  4565. c++;
  4566. }
  4567. sstr[c] = '\0';
  4568. tempdurationInt = atoi(sstr);
  4569. }
  4570. else
  4571. {
  4572. tempdurationInt = 0;
  4573. }
  4574. //**********startSchedule**********/
  4575. c = 0;
  4576. loc = strstr(sLineWord, "startSchedule");
  4577. memset(sstr ,0, sizeof(sstr) );
  4578. while (loc[3+strlen("startSchedule")+c] != '\"')
  4579. {
  4580. sstr[c] = loc[3+strlen("startSchedule")+c];
  4581. c++;
  4582. }
  4583. sstr[c] = '\0';
  4584. strcpy(tempstartScheduleStr, sstr);
  4585. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4586. //**********chargingRateUnit**********/
  4587. c = 0;
  4588. loc = strstr(sLineWord, "chargingRateUnit");
  4589. memset(sstr ,0, sizeof(sstr) );
  4590. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4591. {
  4592. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4593. c++;
  4594. }
  4595. sstr[c] = '\0';
  4596. strcpy(tempchargingRateUnitStr, sstr);
  4597. //**********minChargingRate*******/
  4598. c = 0;
  4599. loc = strstr(sLineWord, "minChargingRate");
  4600. if(loc != NULL)
  4601. {
  4602. memset(sstr ,0, sizeof(sstr) );
  4603. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4604. {
  4605. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4606. c++;
  4607. }
  4608. sstr[c] = '\0';
  4609. tempminChargingRateFloat = atof(sstr);
  4610. }
  4611. else
  4612. {
  4613. tempminChargingRateFloat = 0.0;
  4614. }
  4615. #if 0
  4616. //
  4617. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4618. tp.tm_isdst = -1;
  4619. time_t utc = mktime(&tp);
  4620. time_t t = time(NULL);
  4621. //diff_t = difftime(t, utc);
  4622. #endif
  4623. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4624. //DEBUG_INFO(" debug 5 -1\n");
  4625. //parsing strings to words
  4626. i = 0;
  4627. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4628. loc = loc+3+strlen("chargingSchedulePeriod");
  4629. pch = strtok(loc ,"{");
  4630. while (pch != NULL)
  4631. {
  4632. strcpy(SchedulePeriodList[i], pch);
  4633. pch = strtok (NULL, "{");
  4634. i = i + 1;
  4635. }
  4636. n_SchedulePeriods = i;
  4637. for(int i=0;i<n_SchedulePeriods;i++)
  4638. {
  4639. //*************startPeriod****************/
  4640. c = 0;
  4641. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4642. memset(sstr ,0, sizeof(sstr) );
  4643. while (loc[strlen("startPeriod")+2+c] != ',')
  4644. {
  4645. sstr[c] = loc[strlen("startPeriod")+2+c];
  4646. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4647. c++;
  4648. }
  4649. sstr[c] = '\0';
  4650. tempStartPeriodInt = atoi(sstr);
  4651. //*************limit****************/
  4652. c = 0;
  4653. loc = strstr(SchedulePeriodList[i], "limit");
  4654. memset(sstr ,0, sizeof(sstr) );
  4655. while (loc[strlen("limit")+2+c] != ',')
  4656. {
  4657. sstr[c] = loc[strlen("limit")+2+c];
  4658. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4659. c++;
  4660. }
  4661. sstr[c] = '\0';
  4662. tempLimitInt = atof(sstr);
  4663. //*************numberPhases****************/
  4664. c = 0;
  4665. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4666. memset(sstr ,0, sizeof(sstr) );
  4667. while (loc[strlen("numberPhases")+2+c] != '}')
  4668. {
  4669. sstr[c] = loc[strlen("numberPhases")+2+c];
  4670. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4671. c++;
  4672. }
  4673. sstr[c] = '\0';
  4674. tempNumberPhasesInt = atoi(sstr);
  4675. if(j == 0)
  4676. {
  4677. ChargePointMaxProfile.Duration = tempdurationInt;
  4678. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4679. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4680. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4681. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4682. }
  4683. }
  4684. if(MinChargingRate < tempminChargingRateFloat)
  4685. {
  4686. MinChargingRate = tempminChargingRateFloat;
  4687. }
  4688. if(confirmPeriods < n_SchedulePeriods)
  4689. {
  4690. confirmPeriods = n_SchedulePeriods;
  4691. }
  4692. j = j + 1;
  4693. }
  4694. fclose(fptr1);
  4695. }
  4696. }// the end of access file ChargePointMaxProfile
  4697. //****************************TxDefaultProfile************************************************/
  4698. switch(connectorIdInt)
  4699. {
  4700. case 0:
  4701. break;
  4702. case 1:
  4703. strcpy(fname, TxDefaultProfile_1_JSON );
  4704. break;
  4705. case 2:
  4706. strcpy(fname, TxDefaultProfile_2_JSON );
  4707. break;
  4708. default:
  4709. strcpy(fname, TxDefaultProfile_1_JSON );
  4710. break;
  4711. }
  4712. TxDefaultProfileFileIsNull=TRUE;
  4713. if((access(fname,F_OK))!=-1)
  4714. {
  4715. fptr1 = fopen(fname, "r");
  4716. c = 0;
  4717. c = fgetc(fptr1);
  4718. //DEBUG_INFO("c:%d\n",c);
  4719. rewind(fptr1);
  4720. if(c == EOF)
  4721. {
  4722. DEBUG_INFO("\n End of file reached.");
  4723. TxDefaultProfileFileIsNull=TRUE;
  4724. fclose(fptr1);
  4725. }
  4726. else
  4727. {
  4728. TxDefaultProfileFileIsNull=FALSE;
  4729. while(fscanf(fptr1, "%s", word) != EOF)
  4730. {
  4731. if(strcmp(word, "chargingProfileId") == 0)
  4732. {
  4733. n_chargingProfile = n_chargingProfile + 1;
  4734. }
  4735. }
  4736. rewind(fptr1);
  4737. //search Charging Profile Element
  4738. int i = 0;
  4739. int j = 0;
  4740. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4741. //DEBUG_INFO(" 1-1\n");
  4742. #if 0
  4743. /***********connectorId****************/
  4744. c = 0;
  4745. loc = strstr(sLineWord, "connectorId");
  4746. memset(sstr ,0, sizeof(sstr) );
  4747. while (loc[strlen("connectorId")+2+c] != ',')
  4748. {
  4749. sstr[c] = loc[strlen("connectorId")+2+c];
  4750. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4751. c++;
  4752. }
  4753. sstr[c] = '\0';
  4754. tempconnectorIdInt = atoi(sstr);
  4755. #endif
  4756. //***********validFrom**************/
  4757. c = 0;
  4758. loc = strstr(sLineWord, "validFrom");
  4759. if(loc != NULL)
  4760. {
  4761. memset(sstr ,0, sizeof(sstr) );
  4762. while (loc[3+strlen("validFrom")+c] != '\"')
  4763. {
  4764. sstr[c] = loc[3+strlen("validFrom")+c];
  4765. c++;
  4766. }
  4767. sstr[c] = '\0';
  4768. strcpy(tempvalidFromStr,sstr);
  4769. }
  4770. else
  4771. {
  4772. strcpy(tempvalidFromStr,"");
  4773. }
  4774. //***********validFrom**************/
  4775. c = 0;
  4776. loc = strstr(sLineWord, "duration");
  4777. if(loc != NULL)
  4778. {
  4779. memset(sstr ,0, sizeof(sstr) );
  4780. while (loc[2+strlen("duration")+c] != ',')
  4781. {
  4782. sstr[c] = loc[2+strlen("duration")+c];
  4783. c++;
  4784. }
  4785. sstr[c] = '\0';
  4786. tempdurationInt = atoi(sstr);
  4787. }
  4788. else
  4789. {
  4790. tempdurationInt = 0;
  4791. }
  4792. //**********startSchedule**********/
  4793. c = 0;
  4794. loc = strstr(sLineWord, "startSchedule");
  4795. memset(sstr ,0, sizeof(sstr) );
  4796. while (loc[3+strlen("startSchedule")+c] != '\"')
  4797. {
  4798. sstr[c] = loc[3+strlen("startSchedule")+c];
  4799. c++;
  4800. }
  4801. sstr[c] = '\0';
  4802. strcpy(tempstartScheduleStr, sstr);
  4803. strcpy(TxDefaultProfileScheduleStr, sstr);
  4804. //**********chargingRateUnit**********/
  4805. c = 0;
  4806. loc = strstr(sLineWord, "chargingRateUnit");
  4807. memset(sstr ,0, sizeof(sstr) );
  4808. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4809. {
  4810. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4811. c++;
  4812. }
  4813. sstr[c] = '\0';
  4814. strcpy(tempchargingRateUnitStr, sstr);
  4815. //**********minChargingRate*******/
  4816. c = 0;
  4817. loc = strstr(sLineWord, "minChargingRate");
  4818. if(loc != NULL)
  4819. {
  4820. memset(sstr ,0, sizeof(sstr) );
  4821. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4822. {
  4823. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4824. c++;
  4825. }
  4826. sstr[c] = '\0';
  4827. tempminChargingRateFloat = atof(sstr);
  4828. }
  4829. else
  4830. {
  4831. tempminChargingRateFloat = 0.0;
  4832. }
  4833. #if 0
  4834. //
  4835. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4836. tp.tm_isdst = -1;
  4837. time_t utc = mktime(&tp);
  4838. time_t t = time(NULL);
  4839. //diff_t = difftime(t, utc);
  4840. #endif
  4841. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4842. //parsing strings to words
  4843. i = 0;
  4844. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4845. loc = loc+3+strlen("chargingSchedulePeriod");
  4846. pch = strtok(loc ,"{");
  4847. while (pch != NULL)
  4848. {
  4849. strcpy(SchedulePeriodList[i], pch);
  4850. pch = strtok (NULL, "{");
  4851. i = i + 1;
  4852. }
  4853. n_SchedulePeriods = i;
  4854. for(int i=0;i<n_SchedulePeriods;i++)
  4855. {
  4856. //*************startPeriod****************/
  4857. c = 0;
  4858. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4859. memset(sstr ,0, sizeof(sstr) );
  4860. while (loc[strlen("startPeriod")+2+c] != ',')
  4861. {
  4862. sstr[c] = loc[strlen("startPeriod")+2+c];
  4863. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4864. c++;
  4865. }
  4866. sstr[c] = '\0';
  4867. tempStartPeriodInt = atoi(sstr);
  4868. //*************limit****************/
  4869. c = 0;
  4870. loc = strstr(SchedulePeriodList[i], "limit");
  4871. memset(sstr ,0, sizeof(sstr) );
  4872. while (loc[strlen("limit")+2+c] != ',')
  4873. {
  4874. sstr[c] = loc[strlen("limit")+2+c];
  4875. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4876. c++;
  4877. }
  4878. sstr[c] = '\0';
  4879. tempLimitInt = atof(sstr);
  4880. //*************numberPhases****************/
  4881. c = 0;
  4882. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4883. memset(sstr ,0, sizeof(sstr) );
  4884. while (loc[strlen("numberPhases")+2+c] != '}')
  4885. {
  4886. sstr[c] = loc[strlen("numberPhases")+2+c];
  4887. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4888. c++;
  4889. }
  4890. sstr[c] = '\0';
  4891. tempNumberPhasesInt = atoi(sstr);
  4892. if(j == 0)
  4893. {
  4894. TxDefaultProfile.Duration = tempdurationInt;
  4895. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4896. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4897. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4898. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4899. }
  4900. else
  4901. {
  4902. //other stack level charging Profile
  4903. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  4904. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  4905. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  4906. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  4907. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  4908. }
  4909. }
  4910. if(MinChargingRate < tempminChargingRateFloat)
  4911. MinChargingRate = tempminChargingRateFloat;
  4912. if(confirmPeriods < n_SchedulePeriods)
  4913. confirmPeriods = n_SchedulePeriods;
  4914. j = j + 1;
  4915. //DEBUG_INFO(" 1-2\n");
  4916. }
  4917. fclose(fptr1);
  4918. //Stacking Charging Profiles
  4919. for(int l=0; l <(j-1) ;l++)
  4920. {
  4921. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  4922. {
  4923. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  4924. {
  4925. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  4926. {
  4927. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  4928. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  4929. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  4930. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4931. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4932. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4933. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4934. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4935. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4936. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4937. }
  4938. else
  4939. {
  4940. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4941. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4942. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4943. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4944. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4945. }
  4946. }
  4947. }
  4948. }
  4949. //end of Stacking Charging Profiles
  4950. }
  4951. }// the end of ACCESS TxDefaultProfile
  4952. //****************************TxProfile************************************************/
  4953. switch(connectorIdInt)
  4954. {
  4955. case 0:
  4956. break;
  4957. case 1:
  4958. strcpy(fname, TxProfile_1_JSON );
  4959. break;
  4960. case 2:
  4961. strcpy(fname, TxProfile_2_JSON );
  4962. break;
  4963. default:
  4964. strcpy(fname, TxProfile_1_JSON );
  4965. break;
  4966. }
  4967. TxProfileIsNull=TRUE;
  4968. if((access(fname,F_OK))!=-1)
  4969. {
  4970. fptr1 = fopen(fname, "r");
  4971. c = 0;
  4972. c = fgetc(fptr1);
  4973. //DEBUG_INFO("c:%d\n",c);
  4974. rewind(fptr1);
  4975. if(c == EOF)
  4976. {
  4977. DEBUG_INFO("\n End of file reached.");
  4978. TxProfileIsNull=TRUE;
  4979. fclose(fptr1);
  4980. }
  4981. else
  4982. {
  4983. TxProfileIsNull=FALSE;
  4984. while(fscanf(fptr1, "%s", word) != EOF)
  4985. {
  4986. if(strcmp(word, "chargingProfileId") == 0)
  4987. {
  4988. n_chargingProfile = n_chargingProfile + 1;
  4989. }
  4990. }
  4991. rewind(fptr1);
  4992. //search Charging Profile Element
  4993. int i= 0;
  4994. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4995. #if 0
  4996. /***********connectorId****************/
  4997. c = 0;
  4998. loc = strstr(sLineWord, "connectorId");
  4999. memset(sstr ,0, sizeof(sstr) );
  5000. while (loc[strlen("connectorId")+2+c] != ',')
  5001. {
  5002. sstr[c] = loc[strlen("connectorId")+2+c];
  5003. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5004. c++;
  5005. }
  5006. sstr[c] = '\0';
  5007. tempconnectorIdInt = atoi(sstr);
  5008. #endif
  5009. //***********validFrom**************/
  5010. c = 0;
  5011. loc = strstr(sLineWord, "validFrom");
  5012. if(loc != NULL)
  5013. {
  5014. memset(sstr ,0, sizeof(sstr) );
  5015. while (loc[3+strlen("validFrom")+c] != '\"')
  5016. {
  5017. sstr[c] = loc[3+strlen("validFrom")+c];
  5018. c++;
  5019. }
  5020. sstr[c] = '\0';
  5021. strcpy(tempvalidFromStr,sstr);
  5022. }
  5023. else
  5024. {
  5025. strcpy(tempvalidFromStr,"");
  5026. }
  5027. //**********startSchedule**********/
  5028. c = 0;
  5029. loc = strstr(sLineWord, "startSchedule");
  5030. memset(sstr ,0, sizeof(sstr) );
  5031. while (loc[3+strlen("startSchedule")+c] != '\"')
  5032. {
  5033. sstr[c] = loc[3+strlen("startSchedule")+c];
  5034. c++;
  5035. }
  5036. sstr[c] = '\0';
  5037. strcpy(tempstartScheduleStr, sstr);
  5038. strcpy(TxProfileScheduleStr, sstr);
  5039. //**********chargingRateUnit**********/
  5040. c = 0;
  5041. loc = strstr(sLineWord, "chargingRateUnit");
  5042. memset(sstr ,0, sizeof(sstr) );
  5043. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5044. {
  5045. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5046. c++;
  5047. }
  5048. sstr[c] = '\0';
  5049. strcpy(tempchargingRateUnitStr, sstr);
  5050. //**********minChargingRate*******/
  5051. c = 0;
  5052. loc = strstr(sLineWord, "minChargingRate");
  5053. if(loc != NULL)
  5054. {
  5055. memset(sstr ,0, sizeof(sstr) );
  5056. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5057. {
  5058. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5059. c++;
  5060. }
  5061. sstr[c] = '\0';
  5062. tempminChargingRateFloat = atof(sstr);
  5063. }
  5064. else
  5065. {
  5066. tempminChargingRateFloat = 0.0;
  5067. }
  5068. #if 0
  5069. //
  5070. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5071. tp.tm_isdst = -1;
  5072. time_t utc = mktime(&tp);
  5073. time_t t = time(NULL);
  5074. //diff_t = difftime(t, utc);
  5075. #endif
  5076. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5077. //parsing strings to words
  5078. i = 0;
  5079. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5080. loc = loc+3+strlen("chargingSchedulePeriod");
  5081. pch = strtok(loc ,"{");
  5082. while (pch != NULL)
  5083. {
  5084. strcpy(SchedulePeriodList[i], pch);
  5085. pch = strtok (NULL, "{");
  5086. i = i + 1;
  5087. }
  5088. n_SchedulePeriods = i;
  5089. for(int i=0;i<n_SchedulePeriods;i++)
  5090. {
  5091. //*************startPeriod****************/
  5092. c = 0;
  5093. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5094. memset(sstr ,0, sizeof(sstr) );
  5095. while (loc[strlen("startPeriod")+2+c] != ',')
  5096. {
  5097. sstr[c] = loc[strlen("startPeriod")+2+c];
  5098. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5099. c++;
  5100. }
  5101. sstr[c] = '\0';
  5102. tempStartPeriodInt = atoi(sstr);
  5103. //*************limit****************/
  5104. c = 0;
  5105. loc = strstr(SchedulePeriodList[i], "limit");
  5106. memset(sstr ,0, sizeof(sstr) );
  5107. while (loc[strlen("limit")+2+c] != ',')
  5108. {
  5109. sstr[c] = loc[strlen("limit")+2+c];
  5110. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5111. c++;
  5112. }
  5113. sstr[c] = '\0';
  5114. tempLimitInt = atof(sstr);
  5115. //*************numberPhases****************/
  5116. c = 0;
  5117. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5118. memset(sstr ,0, sizeof(sstr) );
  5119. while (loc[strlen("numberPhases")+2+c] != '}')
  5120. {
  5121. sstr[c] = loc[strlen("numberPhases")+2+c];
  5122. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5123. c++;
  5124. }
  5125. sstr[c] = '\0';
  5126. tempNumberPhasesInt = atoi(sstr);
  5127. TxProfile.Duration = durationInt;
  5128. TxProfile.TotalPeriod = n_SchedulePeriods;
  5129. TxProfile.Period[i].Limit = tempLimitInt;
  5130. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5131. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5132. }
  5133. if(MinChargingRate < tempminChargingRateFloat)
  5134. MinChargingRate = tempminChargingRateFloat;
  5135. if(confirmPeriods < n_SchedulePeriods)
  5136. confirmPeriods = n_SchedulePeriods;
  5137. }
  5138. fclose(fptr1);
  5139. }
  5140. }// the end of ACCESS TxProfile
  5141. //CompositeSchedule
  5142. int period=0;
  5143. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5144. {
  5145. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5146. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5147. {
  5148. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5149. {
  5150. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5151. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5152. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5153. period = period + 1;
  5154. }
  5155. else
  5156. {
  5157. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5158. {
  5159. }
  5160. else
  5161. {
  5162. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5163. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5164. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5165. period = period + 1;
  5166. }
  5167. }
  5168. }
  5169. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5170. {
  5171. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5172. {
  5173. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5174. {
  5175. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5176. }
  5177. else
  5178. {
  5179. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5180. }
  5181. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5182. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5183. period = period + 1;
  5184. }
  5185. }
  5186. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5187. {
  5188. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5189. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5190. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5191. period = period + 1;
  5192. }
  5193. }
  5194. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5195. {
  5196. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5197. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5198. {
  5199. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5200. {
  5201. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5202. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5203. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5204. period = period + 1;
  5205. }
  5206. else
  5207. {
  5208. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5209. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5210. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5211. period = period + 1;
  5212. }
  5213. }
  5214. }
  5215. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5216. {
  5217. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5218. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5219. {
  5220. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5221. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5222. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5223. period = period + 1;
  5224. }
  5225. }
  5226. confirmPeriods = period;
  5227. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5228. //* Define temporary variables */
  5229. struct tm *gtime;
  5230. time_t now;
  5231. char buf[28];
  5232. //* Read the current system time */
  5233. time(&now);
  5234. //* Convert the system time to GMT (now UTC) */
  5235. gtime = gmtime(&now);
  5236. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5237. // make .conf
  5238. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5239. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5240. //DEBUG_INFO(" debug 11\n");
  5241. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5242. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5243. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5244. }
  5245. else
  5246. {
  5247. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5248. }
  5249. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5250. return result;
  5251. }
  5252. int handleGetConfigurationRequest(char *uuid, char *payload)
  5253. {
  5254. mtrace();
  5255. int result = FAIL;
  5256. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5257. //struct json_object *jsonitem;
  5258. int MaxKeySupported = 0;
  5259. int n_keys = 0;
  5260. char requestKey[43][50]={0};
  5261. char search[]="[";
  5262. char sstr[500]={ 0 };
  5263. //int pos;
  5264. int l, c = 0;
  5265. int i = 0;
  5266. char *delim = "\",\"";
  5267. char * pch;
  5268. char *loc = strstr(payload, search);
  5269. //********************* Parsing String ***********************************/
  5270. if(loc == NULL) {
  5271. DEBUG_INFO("no key match in Configuration \n");
  5272. }
  5273. else {
  5274. //pos = loc - payload;
  5275. l = strlen(loc)-4;
  5276. while (c < l)
  5277. {
  5278. sstr[c] = loc[c+2];
  5279. c++;
  5280. }
  5281. sstr[c] = '\0';
  5282. //parsing strings to words
  5283. pch = strtok(sstr,delim);
  5284. if(pch == NULL)
  5285. {
  5286. strcpy(requestKey[0], sstr);
  5287. }
  5288. else
  5289. {
  5290. while (pch != NULL)
  5291. {
  5292. strcpy(requestKey[i], pch);
  5293. pch = strtok (NULL, delim);
  5294. i = i + 1;
  5295. }
  5296. n_keys = i;
  5297. }
  5298. }
  5299. UnknownKeynum = 0;
  5300. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5301. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5302. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5303. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5304. if(n_keys != 0)
  5305. {
  5306. for(int i=0;i<n_keys;i++)
  5307. {
  5308. getKeyValue(requestKey[i]);
  5309. //json_object_put(jsonitem);
  5310. }
  5311. }
  5312. else
  5313. {
  5314. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5315. getKeyValue("");
  5316. }
  5317. processUnkownKey();
  5318. sendGetConfigurationConfirmation(uuid);
  5319. return result;
  5320. }
  5321. static char fnamePlusPath[100]={0};
  5322. static char fnamePWithNoPath[60]={0};
  5323. void checkUploadLog(void)
  5324. {
  5325. FILE *fp;
  5326. /* Open the command for reading. */
  5327. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5328. if (fp == NULL) {
  5329. printf("Failed to run command\n" );
  5330. exit(1);
  5331. }
  5332. int ftppathlen = 0;
  5333. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5334. int i = 0;
  5335. /* Read the output a line at a time - output it. */
  5336. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5337. if(i==0)
  5338. {
  5339. ftppathlen = strlen(fnamePlusPath);
  5340. printf("%s\n", fnamePlusPath);
  5341. fnamePlusPath[ftppathlen]='\0';
  5342. break;
  5343. }
  5344. i= i+1;
  5345. }
  5346. /* close */
  5347. pclose(fp);
  5348. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5349. {
  5350. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5351. {
  5352. fnamePlusPath[k]='\0';
  5353. }
  5354. }
  5355. i=1;
  5356. //char fname[60]={0};
  5357. while(i < ftppathlen)
  5358. {
  5359. int len=ftppathlen-i;
  5360. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5361. {
  5362. printf("compare '/' all right\n");
  5363. break;
  5364. }
  5365. i=i+1;
  5366. }
  5367. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5368. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5369. fnamePWithNoPath[i+1] = '\0';
  5370. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5371. {
  5372. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5373. {
  5374. fnamePWithNoPath[j]='\0';
  5375. }
  5376. }
  5377. FILE* fp1 = fopen(fnamePlusPath, "r");
  5378. if (fp1)
  5379. {
  5380. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5381. // file exists
  5382. fclose(fp1);
  5383. }
  5384. else
  5385. {
  5386. // file doesn't exist
  5387. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5388. }
  5389. }
  5390. static char GetDiagnosticspayloadData[300]={0};
  5391. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5392. {
  5393. mtrace();
  5394. int result = FAIL;
  5395. pthread_t t; // pthread 變數
  5396. system("exec /root/logPackTools 'log' 6");
  5397. #if 0
  5398. //char buffer [128];
  5399. time (&rawtime);
  5400. //printf("%ld\n", rawtime);
  5401. timeinfo = localtime (&rawtime);
  5402. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5403. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5404. if((access(fnamePlusPath,F_OK))!=-1)
  5405. {
  5406. DEBUG_INFO("fnamePlusPath exist.\n");
  5407. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5408. }
  5409. else
  5410. {
  5411. DEBUG_INFO("fnamePlusPath not exist!\n");
  5412. }
  5413. #endif
  5414. checkUploadLog();
  5415. memset(GetDiagnosticspayloadData, 0, 300);
  5416. strcpy(GetDiagnosticspayloadData, payload);
  5417. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5418. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5419. return result;
  5420. }
  5421. void* GetDiagnosticsProcess(void* data)
  5422. {
  5423. pthread_detach(pthread_self());
  5424. mtrace();
  5425. int retriesInt=0, retryIntervalInt=0;
  5426. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5427. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5428. 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};
  5429. int port=0;
  5430. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5431. int c = 0;
  5432. char *loc;
  5433. int isSuccess = FALSE;
  5434. char ftpbuf[200]={0};
  5435. //char temp[100]={0};
  5436. char * pch;
  5437. // [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"}]
  5438. char str[300]={ 0 };
  5439. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5440. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5441. DEBUG_INFO("GetDiagnosticsProcess\n");
  5442. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5443. //****************location*******************/
  5444. c = 0;
  5445. memset(sstr ,0, sizeof(sstr) );
  5446. loc = strstr(str, "location");
  5447. while (loc[3+strlen("location")+c] != '\"')
  5448. {
  5449. sstr[c] = loc[3+strlen("location")+c];
  5450. c++;
  5451. }
  5452. sstr[c] = '\0';
  5453. strcpy(locationstr,sstr);
  5454. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5455. if(strcmp(locationstr,"")==0)
  5456. {
  5457. DEBUG_INFO("location is <Empty>!\n");
  5458. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5459. goto end;
  5460. }
  5461. //****************retries*******************/
  5462. c = 0;
  5463. loc = strstr(str, "retries");
  5464. if(loc == NULL)
  5465. {
  5466. retriesIsNULL = TRUE;
  5467. }
  5468. else
  5469. {
  5470. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5471. {
  5472. sstr[c] = loc[strlen("retries")+2+c];
  5473. c++;
  5474. }
  5475. sstr[c] = '\0';
  5476. retriesInt = atoi(sstr);
  5477. }
  5478. if(retriesIsNULL == TRUE)
  5479. {
  5480. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5481. }
  5482. //****************retryInterval*******************/
  5483. c = 0;
  5484. loc = strstr(str, "retryInterval");
  5485. if(loc == NULL)
  5486. {
  5487. retryIntervalIsNULL = TRUE;
  5488. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5489. }
  5490. else
  5491. {
  5492. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5493. {
  5494. sstr[c] = loc[strlen("retryInterval")+2+c];
  5495. c++;
  5496. }
  5497. sstr[c] = '\0';
  5498. retryIntervalInt = atoi(sstr);
  5499. }
  5500. //****************startTime*******************/
  5501. c = 0;
  5502. memset(sstr ,0, sizeof(sstr) );
  5503. loc = strstr(str, "startTime");
  5504. if(loc == NULL)
  5505. {
  5506. startTimeIsNULL = TRUE;
  5507. }
  5508. else
  5509. {
  5510. while (loc[3+strlen("startTime")+c] != '\"')
  5511. {
  5512. sstr[c] = loc[3+strlen("startTime")+c];
  5513. c++;
  5514. }
  5515. sstr[c] = '\0';
  5516. strcpy(startTimestr,sstr);
  5517. }
  5518. //****************stopTime*******************/
  5519. c = 0;
  5520. memset(sstr ,0, sizeof(sstr) );
  5521. loc = strstr(str, "stopTime");
  5522. if(loc == NULL)
  5523. {
  5524. stopTimeIsNULL = TRUE;
  5525. }
  5526. else
  5527. {
  5528. while (loc[3+strlen("stopTime")+c] != '\"')
  5529. {
  5530. sstr[c] = loc[3+strlen("stopTime")+c];
  5531. c++;
  5532. }
  5533. sstr[c] = '\0';
  5534. strcpy(stopTimestr,sstr);
  5535. }
  5536. memset(protocol, 0, sizeof(protocol));
  5537. memset(user, 0, sizeof(user) );
  5538. memset(password, 0, sizeof(password));
  5539. memset(host, 0, sizeof(host));
  5540. memset(path, 0, sizeof(path));
  5541. memset(ftppath, 0, sizeof(ftppath));
  5542. memset(host1, 0, sizeof(host1));
  5543. memset(path1, 0, sizeof(path1));
  5544. /*location: ftp://user:password@host:port/path*/
  5545. #if 0
  5546. time_t rawtime;
  5547. struct tm * timeinfo;
  5548. //char buffer [128];
  5549. time (&rawtime);
  5550. //printf("%ld\n", rawtime);
  5551. timeinfo = localtime (&rawtime);
  5552. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5553. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5554. #endif
  5555. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5556. if((access(fnamePlusPath,F_OK))!=-1)
  5557. {
  5558. DEBUG_INFO("fnamePlusPath exist.\n");
  5559. }
  5560. else
  5561. {
  5562. DEBUG_INFO("fnamePlusPath not exist!\n");
  5563. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5564. goto end;
  5565. }
  5566. pch=strchr(locationstr,'@');
  5567. if(pch==NULL)
  5568. {
  5569. sscanf(locationstr,
  5570. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5571. protocol, host, &port, path);
  5572. strcpy(user,"anonymous");
  5573. strcpy(password,"");
  5574. }
  5575. else
  5576. {
  5577. //DEBUG_INFO("pch=%s\n", pch);
  5578. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5579. protocol, user, password, host, &port, path);
  5580. }
  5581. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5582. {
  5583. DEBUG_INFO("protocol is not ftp/http ! \n");
  5584. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5585. goto end;
  5586. }
  5587. if(strncmp(locationstr,"http", 4) == 0)
  5588. {
  5589. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  5590. sprintf(ftppath,"/%s", path);
  5591. do{
  5592. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5593. sleep(retryIntervalInt);
  5594. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5595. if(!isSuccess)
  5596. {
  5597. DEBUG_INFO("Diagnostics fail.\n");
  5598. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5599. }
  5600. else
  5601. {
  5602. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5603. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5604. }
  5605. }
  5606. else
  5607. {
  5608. sscanf(host,"%[^/]%s",host1, path1);
  5609. sprintf(ftppath,"%s", path1);
  5610. int ftppathlen=strlen(ftppath);
  5611. int i=1;
  5612. char filenametemp[50];
  5613. while(i < ftppathlen)
  5614. {
  5615. int len=ftppathlen-i;
  5616. if(ftppath[len]== 47) // '/' ascll code: 47
  5617. {
  5618. DEBUG_INFO("find '/' all right\n");
  5619. break;
  5620. }
  5621. i=i+1;
  5622. }
  5623. memset(filenametemp, 0, sizeof(filenametemp));
  5624. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5625. filenametemp[i+1] = 0;
  5626. memset(ftpbuf, 0, sizeof(ftpbuf));
  5627. if(port == 0)
  5628. port = 21;
  5629. do{
  5630. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  5631. sleep(retryIntervalInt);
  5632. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5633. if(!isSuccess)
  5634. {
  5635. DEBUG_INFO("Diagnostics fail.\n");
  5636. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5637. }
  5638. else
  5639. {
  5640. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5641. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5642. }
  5643. }
  5644. end:
  5645. DiagnosticsStatusNotificationStatus = 0; //Idle
  5646. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5647. }
  5648. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5649. {
  5650. mtrace();
  5651. int result = FAIL;
  5652. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5653. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5654. {
  5655. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5656. localversion = -1;
  5657. }
  5658. else
  5659. {
  5660. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5661. OCPP_getListVerion();
  5662. }
  5663. //from db.OCPP_getListVerion
  5664. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5665. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5666. sendGetLocalListVersionConfirmation(uuid,"");
  5667. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5668. return result;
  5669. }
  5670. int handleRemoteStartRequest(char *uuid, char *payload)
  5671. {
  5672. mtrace();
  5673. int result = FAIL;
  5674. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5675. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5676. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5677. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5678. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5679. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5680. int chargingSchedulePeriodCount = 0;
  5681. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5682. int c = 0;
  5683. char *loc;
  5684. char comfirmstr[20]={0};
  5685. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5686. if(server_pending == TRUE)
  5687. {
  5688. return 0;
  5689. }
  5690. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5691. //**********connectorId****************/
  5692. c = 0;
  5693. memset(sstr ,0, sizeof(sstr) );
  5694. loc = strstr(payload, "connectorId");
  5695. if(loc == NULL)
  5696. {
  5697. connectorIdIsNULL = TRUE;
  5698. }
  5699. else
  5700. {
  5701. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5702. {
  5703. sstr[c] = loc[strlen("connectorId")+2+c];
  5704. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5705. c++;
  5706. }
  5707. sstr[c] = '\0';
  5708. connectorIdInt = atoi(sstr);
  5709. }
  5710. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  5711. {
  5712. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5713. goto end;
  5714. }
  5715. //****************idTag*******************/
  5716. c = 0;
  5717. memset(sstr ,0, sizeof(sstr) );
  5718. loc = strstr(payload, "idTag");
  5719. while (loc[3+strlen("idTag")+c] != '\"')
  5720. {
  5721. sstr[c] = loc[3+strlen("idTag")+c];
  5722. c++;
  5723. }
  5724. sstr[c] = '\0';
  5725. strcpy(idTagstr,sstr);
  5726. //****************chargingProfile*******************/
  5727. c = 0;
  5728. memset(sstr ,0, sizeof(sstr) );
  5729. loc = strstr(payload, "chargingProfile");
  5730. if(loc == NULL)
  5731. {
  5732. chargingProfileIsNULL = TRUE;
  5733. }
  5734. else
  5735. {
  5736. //****************chargingProfileId*******************/
  5737. c=0;
  5738. loc = strstr(payload, "chargingProfileId");
  5739. memset(sstr ,0, sizeof(sstr) );
  5740. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5741. {
  5742. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5743. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5744. c++;
  5745. }
  5746. sstr[c] = '\0';
  5747. chargingProfileIdInt = atoi(sstr);
  5748. //****************transactionId*******************/
  5749. loc = strstr(payload, "transactionId");
  5750. if(loc == NULL)
  5751. {
  5752. transactionIdIsNULL = TRUE;
  5753. }
  5754. else
  5755. {
  5756. c=0;
  5757. memset(sstr ,0, sizeof(sstr) );
  5758. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5759. {
  5760. sstr[c] = loc[strlen("transactionId")+2+c];
  5761. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5762. c++;
  5763. }
  5764. sstr[c] = '\0';
  5765. transactionIdInt = atoi(sstr);
  5766. }
  5767. //****************stackLevel*******************/
  5768. c=0;
  5769. loc = strstr(payload, "stackLevel");
  5770. memset(sstr ,0, sizeof(sstr) );
  5771. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5772. {
  5773. sstr[c] = loc[strlen("stackLevel")+2+c];
  5774. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5775. c++;
  5776. }
  5777. sstr[c] = '\0';
  5778. stackLevelInt = atoi(sstr);
  5779. //****************chargingProfilePurpose*******************/
  5780. c = 0;
  5781. memset(sstr ,0, sizeof(sstr) );
  5782. loc = strstr(payload, "chargingProfilePurpose");
  5783. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5784. {
  5785. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5786. c++;
  5787. }
  5788. sstr[c] = '\0';
  5789. strcpy(chargingProfilePurposestr,sstr);
  5790. //****************chargingProfileKind*******************/
  5791. c = 0;
  5792. memset(sstr ,0, sizeof(sstr) );
  5793. loc = strstr(payload, "chargingProfileKind");
  5794. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5795. {
  5796. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5797. c++;
  5798. }
  5799. sstr[c] = '\0';
  5800. strcpy(chargingProfileKindstr,sstr);
  5801. //****************recurrencyKind*******************/
  5802. loc = strstr(payload, "recurrencyKind");
  5803. if(loc == NULL)
  5804. {
  5805. recurrencyKindIsNULL = TRUE;
  5806. }
  5807. else
  5808. {
  5809. c = 0;
  5810. memset(sstr ,0, sizeof(sstr) );
  5811. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5812. {
  5813. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5814. c++;
  5815. }
  5816. sstr[c] = '\0';
  5817. strcpy(recurrencyKindstr,sstr);
  5818. }
  5819. //****************validFrom*******************/
  5820. loc = strstr(payload, "validFrom");
  5821. if(loc == NULL)
  5822. {
  5823. validFromIsNULL = TRUE;
  5824. }
  5825. else
  5826. {
  5827. c = 0;
  5828. memset(sstr ,0, sizeof(sstr) );
  5829. while (loc[3+strlen("validFrom")+c] != '\"')
  5830. {
  5831. sstr[c] = loc[3+strlen("validFrom")+c];
  5832. c++;
  5833. }
  5834. sstr[c] = '\0';
  5835. strcpy(validFromstr,sstr);
  5836. }
  5837. //****************validTo*******************/
  5838. loc = strstr(payload, "validTo");
  5839. if(loc == NULL)
  5840. {
  5841. validToIsNULL = TRUE;
  5842. }
  5843. else
  5844. {
  5845. c = 0;
  5846. memset(sstr ,0, sizeof(sstr) );
  5847. while (loc[3+strlen("validTo")+c] != '\"')
  5848. {
  5849. sstr[c] = loc[3+strlen("validTo")+c];
  5850. c++;
  5851. }
  5852. sstr[c] = '\0';
  5853. strcpy(validTostr,sstr);
  5854. }
  5855. //****************chargingSchedule*******************/
  5856. loc = strstr(payload, "chargingSchedule");
  5857. if(loc != NULL)
  5858. {
  5859. //****************duration*******************/
  5860. loc = strstr(payload, "duration");
  5861. if(loc == NULL)
  5862. {
  5863. durationIsNULL = TRUE;
  5864. }
  5865. else
  5866. {
  5867. c=0;
  5868. memset(sstr ,0, sizeof(sstr) );
  5869. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5870. {
  5871. sstr[c] = loc[strlen("duration")+2+c];
  5872. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5873. c++;
  5874. }
  5875. sstr[c] = '\0';
  5876. durationInt = atoi(sstr);
  5877. }
  5878. //****************startSchedule******************/
  5879. loc = strstr(payload, "startSchedule");
  5880. if(loc == NULL)
  5881. {
  5882. startScheduleIsNULL = TRUE;
  5883. }
  5884. else
  5885. {
  5886. c = 0;
  5887. memset(sstr ,0, sizeof(sstr) );
  5888. while (loc[3+strlen("startSchedule")+c] != '\"')
  5889. {
  5890. sstr[c] = loc[3+strlen("startSchedule")+c];
  5891. c++;
  5892. }
  5893. sstr[c] = '\0';
  5894. strcpy(startSchedulestr,sstr);
  5895. }
  5896. //****************chargingRateUnit*******************/
  5897. c = 0;
  5898. memset(sstr ,0, sizeof(sstr) );
  5899. loc = strstr(payload, "chargingRateUnit");
  5900. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5901. {
  5902. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5903. c++;
  5904. }
  5905. sstr[c] = '\0';
  5906. strcpy(chargingRateUnitstr,sstr);
  5907. //****************minChargingRate*******************/
  5908. loc = strstr(payload, "minChargingRate");
  5909. if(loc == NULL)
  5910. {
  5911. minChargingRateIsNULL = TRUE;
  5912. }
  5913. else
  5914. {
  5915. c=0;
  5916. memset(sstr ,0, sizeof(sstr) );
  5917. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5918. {
  5919. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5920. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5921. c++;
  5922. }
  5923. sstr[c] = '\0';
  5924. minChargingRateflaot = atof(sstr);
  5925. }
  5926. //****************chargingSchedulePeriod count*******************/
  5927. int what_len = strlen("startPeriod");
  5928. char *where = payload;
  5929. while ((where = strstr(where, "startPeriod"))) {
  5930. where += what_len;
  5931. chargingSchedulePeriodCount++;
  5932. }
  5933. where = payload;
  5934. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5935. {
  5936. //****************startPeriod*******************/
  5937. c=0;
  5938. loc = strstr(where, "startPeriod");
  5939. memset(sstr ,0, sizeof(sstr) );
  5940. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5941. {
  5942. sstr[c] = loc[strlen("startPeriod")+2+c];
  5943. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5944. c++;
  5945. }
  5946. sstr[c] = '\0';
  5947. startPeriodInt[periodNums] = atoi(sstr);
  5948. //****************limit*******************/
  5949. c=0;
  5950. loc = strstr(where, "limit");
  5951. memset(sstr ,0, sizeof(sstr) );
  5952. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5953. {
  5954. sstr[c] = loc[strlen("limit")+2+c];
  5955. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5956. c++;
  5957. }
  5958. sstr[c] = '\0';
  5959. limitflaot[periodNums] = atof(sstr);
  5960. //****************numberPhases*******************/
  5961. loc = strstr(where, "numberPhases");
  5962. if(loc == NULL)
  5963. {
  5964. numberPhasesIsNULL = TRUE;
  5965. }
  5966. else
  5967. {
  5968. c=0;
  5969. memset(sstr ,0, sizeof(sstr) );
  5970. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  5971. {
  5972. sstr[c] = loc[strlen("numberPhases")+2+c];
  5973. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5974. c++;
  5975. }
  5976. sstr[c] = '\0';
  5977. numberPhasesInt[periodNums] = atoi(sstr);
  5978. }
  5979. where = loc;
  5980. }
  5981. }
  5982. }
  5983. /*
  5984. enum _SYSTEM_STATUS
  5985. {
  5986. S_BOOTING = 0,
  5987. S_IDLE, = 1
  5988. S_AUTHORIZING, =2
  5989. S_REASSIGN_CHECK, =3
  5990. S_REASSIGN, =4
  5991. S_PRECHARGE, =5
  5992. S_PREPARING_FOR_EV, =6
  5993. S_PREPARING_FOR_EVSE, =7
  5994. S_CHARGING, =8
  5995. S_TERMINATING, =9
  5996. S_COMPLETE, =10
  5997. S_ALARM, =11
  5998. S_FAULT =12
  5999. }
  6000. */
  6001. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6002. {
  6003. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6004. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6005. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6006. //check Transaction active
  6007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6008. {
  6009. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6010. {
  6011. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6012. {
  6013. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6014. {
  6015. //Reserved
  6016. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6017. }
  6018. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6019. {
  6020. //Reserved
  6021. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6022. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6023. goto end;
  6024. }
  6025. else
  6026. {
  6027. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6028. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6029. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6030. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6031. {
  6032. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6033. goto end;
  6034. }
  6035. }//END FOR ELSE
  6036. }
  6037. }// END FOR CHAdeMO_QUANTITY
  6038. for (int index = 0; index < CCS_QUANTITY; index++)
  6039. {
  6040. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6041. {
  6042. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6043. {
  6044. //Reserved
  6045. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6046. }
  6047. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6048. {
  6049. //Reserved
  6050. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6051. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6052. goto end;
  6053. }
  6054. else
  6055. {
  6056. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6057. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6058. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6059. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6060. {
  6061. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6062. goto end;
  6063. }
  6064. }// END FOR ELSE
  6065. }
  6066. }// END FOR CCS_QUANTITY
  6067. for (int index = 0; index < GB_QUANTITY; index++)
  6068. {
  6069. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6070. {
  6071. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6072. {
  6073. //Reserved
  6074. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6075. }
  6076. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6077. {
  6078. //Reserved
  6079. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6080. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6081. goto end;
  6082. }
  6083. else
  6084. {
  6085. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6086. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6087. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6088. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6089. {
  6090. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6091. goto end;
  6092. }
  6093. }// END FOR ELSE
  6094. }
  6095. } // END FOR GB_QUANTITY
  6096. }
  6097. else
  6098. {
  6099. for (int index = 0; index < AC_QUANTITY; index++)
  6100. {
  6101. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6102. {
  6103. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6104. {
  6105. //Reserved
  6106. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6107. }
  6108. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6109. {
  6110. //Reserved
  6111. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6112. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6113. goto end;
  6114. }
  6115. else
  6116. {
  6117. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6118. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6119. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6120. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6121. {
  6122. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6123. goto end;
  6124. }
  6125. }//END FOR ELSE
  6126. }
  6127. }// END FOR AC_QUANTITY
  6128. }
  6129. if(chargingProfileIsNULL == FALSE)
  6130. {
  6131. //ChargingProfile
  6132. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6133. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6134. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6135. if(recurrencyKindIsNULL == FALSE) //OPTION
  6136. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6137. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6138. if(transactionIdIsNULL == FALSE) // OPTION
  6139. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6140. if(validFromIsNULL == FALSE) // OPTION
  6141. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6142. if(validToIsNULL == FALSE) //OPTION
  6143. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6144. //ChargingSchedule
  6145. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6146. if(durationIsNULL == FALSE) //OPTION
  6147. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6148. if(minChargingRateIsNULL == FALSE) //OPTION
  6149. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6150. if(startScheduleIsNULL == FALSE) //OPTION
  6151. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6152. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6153. {
  6154. //ChargingSchedulePeriod
  6155. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6156. if(numberPhasesIsNULL == FALSE)
  6157. {
  6158. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6159. }
  6160. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6161. }
  6162. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6163. {
  6164. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6165. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6166. //memset idTag
  6167. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6168. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6169. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6170. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6171. }
  6172. else
  6173. {
  6174. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6175. }
  6176. }
  6177. else
  6178. {
  6179. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6180. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6181. //memset idTag
  6182. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6183. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6184. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6185. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6186. }
  6187. }
  6188. else
  6189. {
  6190. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6191. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6192. }
  6193. end:
  6194. if(connectorIdIsNULL == FALSE)
  6195. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6196. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6197. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6198. //OCPP send RemoteStartConfirmation by first.
  6199. sendRemoteStartConfirmation(uuid, comfirmstr);
  6200. return result;
  6201. }
  6202. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6203. {
  6204. mtrace();
  6205. int result = FAIL;
  6206. int match = FALSE;
  6207. int GunNO = 0;
  6208. int transactionIdInt=0;
  6209. int transactionIdIsNULL= FALSE;
  6210. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6211. int c = 0;
  6212. char *loc;
  6213. char comfirmstr[20];
  6214. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6215. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6216. if(server_pending == TRUE)
  6217. {
  6218. return 0;
  6219. }
  6220. c=0;
  6221. loc = strstr(payload, "transactionId");
  6222. if(loc == NULL)
  6223. {
  6224. transactionIdIsNULL= TRUE;
  6225. }
  6226. else
  6227. {
  6228. memset(sstr ,0, sizeof(sstr) );
  6229. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6230. {
  6231. sstr[c] = loc[strlen("transactionId")+2+c];
  6232. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6233. c++;
  6234. }
  6235. sstr[c] = '\0';
  6236. transactionIdInt = atoi(sstr);
  6237. }
  6238. if(transactionIdIsNULL == FALSE)
  6239. {
  6240. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6241. {
  6242. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6243. {
  6244. //check Transaction active
  6245. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6246. {
  6247. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6248. {
  6249. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6250. {
  6251. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6252. {
  6253. match = TRUE;
  6254. GunNO = gun_index;
  6255. }
  6256. }
  6257. }// END FOR CHAdeMO_QUANTITY
  6258. for (int index = 0; index < CCS_QUANTITY; index++)
  6259. {
  6260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6261. {
  6262. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6263. {
  6264. match = TRUE;
  6265. GunNO = gun_index;
  6266. }
  6267. }
  6268. }// END FOR CCS_QUANTITY
  6269. for (int index = 0; index < GB_QUANTITY; index++)
  6270. {
  6271. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6272. {
  6273. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6274. {
  6275. match = TRUE;
  6276. GunNO = gun_index;
  6277. }
  6278. }
  6279. }// END FOR GB_QUANTITY
  6280. }
  6281. else
  6282. {
  6283. for (int index = 0; index < AC_QUANTITY; index++)
  6284. {
  6285. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6286. {
  6287. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6288. {
  6289. match = TRUE;
  6290. GunNO = gun_index;
  6291. }
  6292. }
  6293. }// END FOR CHAdeMO_QUANTITY
  6294. }// END FOR AC ELSE
  6295. }// CHECK IF ResponseTransactionId == transactionIdInt
  6296. }//END FOR
  6297. if( match == TRUE)
  6298. {
  6299. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6300. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6301. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6302. }
  6303. else
  6304. {
  6305. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6306. }
  6307. }
  6308. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6309. return result;
  6310. }
  6311. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6312. {
  6313. mtrace();
  6314. int result = FAIL;
  6315. int connectorIdInt=0, reservationIdInt=0;
  6316. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6317. char comfirmstr[20]={0};
  6318. char sstr[180]={ 0 };
  6319. int c = 0;
  6320. char *loc;
  6321. //char *ptr;
  6322. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6323. //***(1)connectorId ****/
  6324. c=0;
  6325. loc = strstr(payload, "connectorId");
  6326. memset(sstr ,0, sizeof(sstr) );
  6327. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6328. {
  6329. sstr[c] = loc[strlen("connectorId")+2+c];
  6330. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6331. c++;
  6332. }
  6333. sstr[c] = '\0';
  6334. connectorIdInt = atoi(sstr);
  6335. //***(2)expiryDate ****/
  6336. loc = strstr(payload, "expiryDate");
  6337. memset(sstr ,0, sizeof(sstr) );
  6338. c = 0;
  6339. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6340. {
  6341. sstr[c] = loc[3+strlen("expiryDate")+c];
  6342. c++;
  6343. }
  6344. sstr[c] = '\0';
  6345. strcpy(expiryDatestr, sstr);
  6346. //***(3)idTag ****/
  6347. loc = strstr(payload, "idTag");
  6348. memset(sstr ,0, sizeof(sstr) );
  6349. c = 0;
  6350. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6351. {
  6352. sstr[c] = loc[3+strlen("idTag")+c];
  6353. c++;
  6354. }
  6355. sstr[c] = '\0';
  6356. strcpy(idTagstr, sstr);
  6357. //***(4)parentIdTag ****/
  6358. loc = strstr(payload, "parentIdTag");
  6359. memset(sstr ,0, sizeof(sstr) );
  6360. c = 0;
  6361. if(loc == NULL)
  6362. {
  6363. strcpy(parentIdTagstr, "");
  6364. }
  6365. else
  6366. {
  6367. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6368. {
  6369. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6370. c++;
  6371. }
  6372. sstr[c] = '\0';
  6373. strcpy(parentIdTagstr, sstr);
  6374. }
  6375. //***(5)reservationId ****/
  6376. c=0;
  6377. loc = strstr(payload, "reservationId");
  6378. memset(sstr ,0, sizeof(sstr) );
  6379. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6380. {
  6381. sstr[c] = loc[strlen("reservationId")+2+c];
  6382. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6383. c++;
  6384. }
  6385. sstr[c] = '\0';
  6386. reservationIdInt = atoi(sstr);
  6387. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6388. /*
  6389. enum SYSTEM_STATUS
  6390. {
  6391. SYS_MODE_BOOTING = 0,
  6392. SYS_MODE_IDLE = 1,
  6393. SYS_MODE_AUTHORIZING = 2,
  6394. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6395. SYS_MODE_REASSIGN = 4,
  6396. SYS_MODE_PREPARING = 5,
  6397. SYS_MODE_PREPARE_FOR_EV = 6,
  6398. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6399. SYS_MODE_CHARGING = 8,
  6400. SYS_MODE_TERMINATING = 9,
  6401. SYS_MODE_COMPLETE = 10,
  6402. SYS_MODE_ALARM = 11,
  6403. SYS_MODE_FAULT = 12,
  6404. SYS_MODE_RESERVATION = 13,
  6405. SYS_MODE_BOOKING = 14,
  6406. SYS_MODE_MAINTAIN = 15,
  6407. SYS_MODE_DEBUG = 16,
  6408. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6409. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6410. SYS_MODE_UPDATE = 19
  6411. };
  6412. */
  6413. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6414. {
  6415. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6416. goto end;
  6417. }
  6418. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6419. {
  6420. //check Transaction active
  6421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6422. {
  6423. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6424. {
  6425. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6426. {
  6427. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6428. {
  6429. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6430. {
  6431. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6432. {
  6433. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6434. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6435. }
  6436. 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'))
  6437. {
  6438. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6439. }
  6440. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6441. {
  6442. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6443. }
  6444. else
  6445. {
  6446. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6447. }
  6448. }
  6449. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6450. {
  6451. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6452. }
  6453. }
  6454. else
  6455. {
  6456. //replace reservation
  6457. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6458. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6459. }
  6460. }
  6461. } // END FOR CHAdeMO_QUANTITY
  6462. for (int index = 0; index < CCS_QUANTITY; index++)
  6463. {
  6464. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6465. {
  6466. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6467. {
  6468. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6469. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6470. {
  6471. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6472. {
  6473. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6475. }
  6476. 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'))
  6477. {
  6478. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6479. }
  6480. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6481. {
  6482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6483. }
  6484. else
  6485. {
  6486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6487. }
  6488. }
  6489. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6490. {
  6491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6492. }
  6493. }
  6494. else
  6495. {
  6496. //replace reservation
  6497. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6499. }
  6500. }
  6501. } // END FOR CCS_QUANTITY
  6502. for (int index = 0; index < GB_QUANTITY; index++)
  6503. {
  6504. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6505. {
  6506. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6507. {
  6508. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6509. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6510. {
  6511. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6512. {
  6513. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6514. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6515. }
  6516. 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'))
  6517. {
  6518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6519. }
  6520. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6521. {
  6522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6523. }
  6524. else
  6525. {
  6526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6527. }
  6528. }
  6529. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6530. {
  6531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6532. }
  6533. }
  6534. else
  6535. {
  6536. //replace reservation
  6537. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6539. }
  6540. }
  6541. }// END FOR GB_QUANTITY
  6542. }
  6543. else
  6544. {
  6545. for (int index = 0; index < AC_QUANTITY; index++)
  6546. {
  6547. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6548. {
  6549. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6550. {
  6551. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6552. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6553. {
  6554. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6555. {
  6556. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6557. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6558. }
  6559. 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'))
  6560. {
  6561. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6562. }
  6563. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6564. {
  6565. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6566. }
  6567. else
  6568. {
  6569. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6570. }
  6571. }
  6572. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6573. {
  6574. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6575. }
  6576. }
  6577. else
  6578. {
  6579. //replace reservation
  6580. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6582. }
  6583. }
  6584. } // END FOR AC_QUANTITY
  6585. }//END FOR AC ELSE
  6586. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6587. }
  6588. else if(connectorIdInt == 0)
  6589. {
  6590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6591. {
  6592. //check Transaction active
  6593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6594. {
  6595. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6596. {
  6597. 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'))
  6598. {
  6599. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6600. goto end;
  6601. }
  6602. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6603. {
  6604. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6605. goto end;
  6606. }
  6607. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6608. {
  6609. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6610. goto end;
  6611. }
  6612. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6613. {
  6614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6615. goto end;
  6616. }
  6617. }
  6618. }// END FOR CHAdeMO_QUANTITY
  6619. for (int index = 0; index < CCS_QUANTITY; index++)
  6620. {
  6621. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6622. {
  6623. 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'))
  6624. {
  6625. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6626. }
  6627. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6628. {
  6629. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6630. }
  6631. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6632. {
  6633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6634. }
  6635. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6636. {
  6637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6638. }
  6639. }
  6640. } // END FOR CCS_QUANTITY
  6641. for (int index = 0; index < GB_QUANTITY; index++)
  6642. {
  6643. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6644. {
  6645. 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'))
  6646. {
  6647. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6648. }
  6649. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6650. {
  6651. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6652. }
  6653. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6654. {
  6655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6656. }
  6657. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6658. {
  6659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6660. }
  6661. }
  6662. } // END FOR GB_QUANTITY
  6663. }
  6664. else
  6665. {
  6666. for (int index = 0; index < AC_QUANTITY; index++)
  6667. {
  6668. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6669. {
  6670. 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'))
  6671. {
  6672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6673. goto end;
  6674. }
  6675. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6676. {
  6677. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6678. goto end;
  6679. }
  6680. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6681. {
  6682. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6683. goto end;
  6684. }
  6685. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6686. {
  6687. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6688. goto end;
  6689. }
  6690. }
  6691. }// END FOR AC_QUANTITY
  6692. }
  6693. //The connectorId is 0
  6694. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6696. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6697. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6698. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6699. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6700. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6701. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6702. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6703. result = TRUE;
  6704. return result;
  6705. }
  6706. else
  6707. {
  6708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6709. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6710. }
  6711. if(strcmp(comfirmstr,"Accepted") == 0)
  6712. {
  6713. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6714. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6715. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6716. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6717. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6718. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6719. result = TRUE;
  6720. return result;
  6721. }
  6722. end:
  6723. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6724. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6725. return result;
  6726. }
  6727. int handleResetRequest(char *uuid, char *payload)
  6728. {
  6729. mtrace();
  6730. int result = FAIL;
  6731. char sstr[10]={0};
  6732. char typestr[10]={0};
  6733. char comfirmstr[20]={0};
  6734. int c = 0;
  6735. char *loc;
  6736. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6737. DEBUG_INFO("handleResetRequest ...\n");
  6738. loc = strstr(payload, "type");
  6739. memset(sstr ,0, sizeof(sstr) );
  6740. c = 0;
  6741. while (loc[3+strlen("type")+c] != '\"')
  6742. {
  6743. sstr[c] = loc[3+strlen("type")+c];
  6744. c++;
  6745. }
  6746. sstr[c] = '\0';
  6747. strcpy(typestr,sstr);
  6748. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6749. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6750. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6751. {
  6752. //check Transaction active
  6753. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6754. {
  6755. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6756. {
  6757. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6758. {
  6759. //0: unplug, 1: Plug-in
  6760. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6761. }
  6762. }
  6763. for (int index = 0; index < CCS_QUANTITY; index++)
  6764. {
  6765. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6766. {
  6767. //0: unplug, 1: Plug-in
  6768. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6769. }
  6770. }
  6771. for (int index = 0; index < GB_QUANTITY; index++)
  6772. {
  6773. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6774. {
  6775. //0: unplug, 1: Plug-in
  6776. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6777. }
  6778. }
  6779. }
  6780. else
  6781. {
  6782. for (int index = 0; index < AC_QUANTITY; index++)
  6783. {
  6784. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6785. {
  6786. //0: unplug, 1: Plug-in
  6787. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6788. }
  6789. }
  6790. }// END FOR AC ELSE
  6791. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6792. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6793. result = TRUE;
  6794. return result;
  6795. }
  6796. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6797. {
  6798. //check Transaction active
  6799. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6800. {
  6801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6802. {
  6803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6804. {
  6805. //0: unplug, 1: Plug-in
  6806. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6807. }
  6808. }
  6809. for (int index = 0; index < CCS_QUANTITY; index++)
  6810. {
  6811. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6812. {
  6813. //0: unplug, 1: Plug-in
  6814. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6815. }
  6816. }
  6817. for (int index = 0; index < GB_QUANTITY; index++)
  6818. {
  6819. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6820. {
  6821. //0: unplug, 1: Plug-in
  6822. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6823. }
  6824. }
  6825. }
  6826. else
  6827. {
  6828. for (int index = 0; index < AC_QUANTITY; index++)
  6829. {
  6830. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6831. {
  6832. //0: unplug, 1: Plug-in
  6833. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6834. }
  6835. }
  6836. }// END FOR AC ELSE
  6837. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6838. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6839. result = TRUE;
  6840. return result;
  6841. }
  6842. else
  6843. {
  6844. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6845. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6846. goto errorend;
  6847. }
  6848. errorend:
  6849. sendResetConfirmation(uuid, comfirmstr);
  6850. return result;
  6851. }
  6852. int handleSendLocalListRequest(char *uuid, char *payload)
  6853. {
  6854. mtrace();
  6855. int result = FAIL;
  6856. int listVersionInt;
  6857. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6858. char listsearch[]="listVersion";
  6859. char updateTypesearch[]="updateType";
  6860. char localAuthorizationListsearch[]="localAuthorizationList";
  6861. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6862. char CardList[500][160]={0};
  6863. char updateTypestr[15]={0};
  6864. char idTagstr[20]={0};
  6865. char parentIdTag[20]={0};
  6866. char expiryDate[30]={0};
  6867. char idTagstatus[16]={0};
  6868. int c = 0;
  6869. int i = 0;
  6870. char *delim1 = "}";
  6871. char * pch;
  6872. char *loc;
  6873. //char *ptr;
  6874. char comfirmstr[20];
  6875. //int n_localAuthorizations = 0;
  6876. int checkState_Faulted = FALSE;
  6877. DEBUG_INFO("handleSendLocalListRequest\n");
  6878. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6879. {
  6880. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6881. goto end;
  6882. }
  6883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6884. {
  6885. //check Charge Point state
  6886. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6887. {
  6888. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6889. {
  6890. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6891. }
  6892. }
  6893. for (int index = 0; index < CCS_QUANTITY; index++)
  6894. {
  6895. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6896. {
  6897. checkState_Faulted = TRUE; //OCPP Status
  6898. }
  6899. }
  6900. for (int index = 0; index < GB_QUANTITY; index++)
  6901. {
  6902. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6903. {
  6904. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6905. }
  6906. }
  6907. }
  6908. else
  6909. {
  6910. //check Charge Point state
  6911. for (int index = 0; index < AC_QUANTITY; index++)
  6912. {
  6913. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6914. {
  6915. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6916. }
  6917. }
  6918. }// END FOR AC ELSE
  6919. if(checkState_Faulted == TRUE)
  6920. {
  6921. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6922. goto end;
  6923. }
  6924. //listVersion
  6925. c = 0;
  6926. loc = strstr(payload, listsearch);
  6927. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  6928. {
  6929. sstr[c] = loc[strlen("listVersion")+2+c];
  6930. c++;
  6931. }
  6932. sstr[c] = '\0';
  6933. listVersionInt = atoi(sstr);
  6934. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6935. //updateType
  6936. loc = strstr(payload, updateTypesearch);
  6937. c = 0;
  6938. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6939. {
  6940. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6941. c++;
  6942. }
  6943. sstr[c] = '\0';
  6944. strcpy(updateTypestr, sstr);
  6945. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6946. //localAuthorizationList
  6947. memset(sstr ,0, sizeof(sstr) );
  6948. loc = strstr(payload, localAuthorizationListsearch);
  6949. if(loc != NULL) // localAuthorizationList is not NULL
  6950. {
  6951. //Check UpdateType
  6952. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6953. {
  6954. //Local list full update
  6955. printf("Local list full update.\n");
  6956. OCPP_cleanLocalList();
  6957. }
  6958. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6959. {
  6960. //Local list different update
  6961. printf("Local list different update.\n");
  6962. OCPP_getListVerion();
  6963. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6964. {
  6965. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6966. goto end;
  6967. }
  6968. }
  6969. else
  6970. {
  6971. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6972. goto end;
  6973. }
  6974. c = 0;
  6975. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6976. {
  6977. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6978. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6979. c++;
  6980. }
  6981. sstr[c] = '\0';
  6982. //DEBUG_INFO("sstr=%s\n", sstr);
  6983. //parsing strings to words
  6984. i = 0;
  6985. pch = strtok(sstr,delim1);
  6986. while (pch != NULL)
  6987. {
  6988. strcpy(CardList[i], pch);
  6989. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  6990. pch = strtok (NULL, delim1);
  6991. i = i + 1;
  6992. }
  6993. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  6994. //local Authorizations List Numbers
  6995. //n_localAuthorizations = i;
  6996. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6997. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  6998. c= 0;
  6999. while(c < i)
  7000. {
  7001. //Search "IdToken"
  7002. memset(sstr ,0, sizeof(sstr) );
  7003. loc = strstr(CardList[c], "idTag");
  7004. int j = 0;
  7005. while (loc[3+strlen("idTag")+j] != '\"')
  7006. {
  7007. sstr[j] = loc[3+strlen("idTag")+j];
  7008. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7009. j++;
  7010. }
  7011. sstr[j] = '\0';
  7012. strcpy(idTagstr, sstr);
  7013. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7014. //Search "expiryDate"
  7015. memset(sstr ,0, sizeof(sstr) );
  7016. loc = strstr(CardList[c], "expiryDate");
  7017. j = 0;
  7018. if(loc != NULL)
  7019. {
  7020. while (loc[3+strlen("expiryDate")+j] != '\"')
  7021. {
  7022. sstr[j] = loc[3+strlen("expiryDate")+j];
  7023. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7024. j++;
  7025. }
  7026. sstr[j] = '\0';
  7027. strcpy(expiryDate, sstr);
  7028. }
  7029. else
  7030. {
  7031. strcpy(expiryDate, "");
  7032. }
  7033. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7034. //Search "parentIdTag"
  7035. memset(sstr ,0, sizeof(sstr) );
  7036. loc = strstr(CardList[c], "parentIdTag");
  7037. j = 0;
  7038. if(loc != NULL)
  7039. {
  7040. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7041. {
  7042. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7043. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7044. j++;
  7045. }
  7046. sstr[j] = '\0';
  7047. strcpy(parentIdTag, sstr);
  7048. }
  7049. else
  7050. {
  7051. strcpy(parentIdTag, "");
  7052. }
  7053. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7054. //Search "status"
  7055. memset(sstr ,0, sizeof(sstr) );
  7056. loc = strstr(CardList[c], "status");
  7057. j = 0;
  7058. while (loc[3+strlen("status")+j] != '\"')
  7059. {
  7060. sstr[j] = loc[3+strlen("status")+j];
  7061. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7062. j++;
  7063. }
  7064. sstr[j] = '\0';
  7065. strcpy(idTagstatus, sstr);
  7066. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7067. OCPP_getIdTag(idTagstr);
  7068. //OCPP_getIdTag("test"); For Test
  7069. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7070. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7071. {
  7072. //Local list full update
  7073. DEBUG_INFO("Local list full update.\n");
  7074. // update list
  7075. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7076. OCPP_get_TableAuthlocalAllData();
  7077. }
  7078. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7079. {
  7080. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7081. {
  7082. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7083. }
  7084. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7085. {
  7086. OCPP_deleteIdTag(idTagstr);
  7087. }
  7088. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7089. {
  7090. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7091. }
  7092. }
  7093. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7094. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7095. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7096. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7097. c++;
  7098. }
  7099. }
  7100. else
  7101. {
  7102. //Check UpdateType
  7103. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7104. {
  7105. //Local list full update
  7106. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7107. OCPP_cleanLocalList();
  7108. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7109. goto end;
  7110. }
  7111. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7112. {
  7113. //Local list different update
  7114. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7115. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7116. goto end;
  7117. }
  7118. }
  7119. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7120. end:
  7121. sendSendLocalListConfirmation(uuid, comfirmstr);
  7122. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7123. return result;
  7124. }
  7125. #define MAX 200
  7126. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7127. {
  7128. mtrace();
  7129. int result = FAIL;
  7130. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7131. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7132. char chargingProfilePurposeStr[30]={0};
  7133. char chargingProfileKindStr[16]={0};
  7134. char recurrencyKindStr[10]={0};
  7135. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7136. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7137. int chargingSchedulePeriodCount = 0;
  7138. //int updateflag = FALSE;
  7139. char comfirmstr[20]={0};
  7140. int meet= FALSE;
  7141. char sstr[10]={0};
  7142. int c = 0;
  7143. char *loc;
  7144. FILE *fptr1;//, *fptr2;
  7145. //int lno=0;//, linectr = 0;
  7146. //int modifyflag = FALSE;
  7147. char filename[MAX]={0};
  7148. char tempfile[] = "/Storage/OCPP/temp.json";
  7149. //int resultRename=0;
  7150. char rmFileCmd[50]={0};
  7151. char tempchargingProfilePurposeStr[30]={0};
  7152. //[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}}}]
  7153. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7154. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7155. //*********************connectorId***************************/
  7156. loc = strstr(payload, "connectorId");
  7157. c = 0;
  7158. memset(sstr ,0, sizeof(sstr) );
  7159. while (loc[strlen("connectorId")+2+c] != ',')
  7160. {
  7161. sstr[c] = loc[strlen("connectorId")+2+c];
  7162. c++;
  7163. }
  7164. sstr[c] = '\0';
  7165. connectorIdInt = atoi(sstr);
  7166. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7167. {
  7168. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7169. }
  7170. else
  7171. {
  7172. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7173. }
  7174. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7175. //*********************chargingProfileId***************************/
  7176. loc = strstr(payload, "chargingProfileId");
  7177. c = 0;
  7178. memset(sstr ,0, sizeof(sstr) );
  7179. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7180. {
  7181. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7182. c++;
  7183. }
  7184. sstr[c] = '\0';
  7185. chargingProfileIdInt = atoi(sstr);
  7186. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7187. {
  7188. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7189. }
  7190. else
  7191. {
  7192. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7193. }
  7194. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7195. //*********************transactionId***************************/
  7196. loc = strstr(payload, "transactionId");
  7197. if(loc != NULL)
  7198. {
  7199. c = 0;
  7200. memset(sstr ,0, sizeof(sstr) );
  7201. while (loc[strlen("transactionId")+2+c] != ',')
  7202. {
  7203. sstr[c] = loc[strlen("transactionId")+2+c];
  7204. c++;
  7205. }
  7206. sstr[c] = '\0';
  7207. transactionIdInt = atoi(sstr);
  7208. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7209. {
  7210. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7211. }
  7212. else
  7213. {
  7214. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7215. }
  7216. }
  7217. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7218. //*********************stackLevel***************************/
  7219. loc = strstr(payload, "stackLevel");
  7220. c = 0;
  7221. memset(sstr ,0, sizeof(sstr) );
  7222. while (loc[strlen("stackLevel")+2+c] != ',')
  7223. {
  7224. sstr[c] = loc[strlen("stackLevel")+2+c];
  7225. c++;
  7226. }
  7227. sstr[c] = '\0';
  7228. stackLevelInt = atoi(sstr);
  7229. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7230. {
  7231. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7232. }
  7233. else
  7234. {
  7235. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7236. }
  7237. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7238. //*********************chargingProfilePurpose***************************/
  7239. loc = strstr(payload, "chargingProfilePurpose");
  7240. c = 0;
  7241. memset(sstr ,0, sizeof(sstr) );
  7242. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7243. {
  7244. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7245. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7246. c++;
  7247. }
  7248. sstr[c] = '\0';
  7249. strcpy(chargingProfilePurposeStr,sstr);
  7250. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7251. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7252. {
  7253. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7254. }
  7255. else
  7256. {
  7257. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7258. }
  7259. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7260. //*********************chargingProfileKind***************************/
  7261. loc = strstr(payload, "chargingProfileKind");
  7262. c = 0;
  7263. memset(sstr ,0, sizeof(sstr) );
  7264. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7265. {
  7266. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7267. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7268. c++;
  7269. }
  7270. sstr[c] = '\0';
  7271. strcpy(chargingProfileKindStr,sstr);
  7272. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7273. {
  7274. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7275. }
  7276. else
  7277. {
  7278. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7279. }
  7280. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7281. //*********************recurrencyKind***************************/
  7282. loc = strstr(payload, "recurrencyKind");
  7283. if(loc != NULL)
  7284. {
  7285. c = 0;
  7286. memset(sstr ,0, sizeof(sstr) );
  7287. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7288. {
  7289. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7290. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7291. c++;
  7292. }
  7293. sstr[c] = '\0';
  7294. strcpy(recurrencyKindStr,sstr);
  7295. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7296. {
  7297. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7298. }
  7299. else
  7300. {
  7301. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7302. }
  7303. }
  7304. else
  7305. {
  7306. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7307. {
  7308. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7309. }
  7310. else
  7311. {
  7312. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7313. }
  7314. }
  7315. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7316. //*********************validFrom***************************/
  7317. loc = strstr(payload, "validFrom");
  7318. if(loc != NULL)
  7319. {
  7320. c = 0;
  7321. memset(sstr ,0, sizeof(sstr) );
  7322. while (loc[3+strlen("validFrom")+c] != '\"')
  7323. {
  7324. sstr[c] = loc[3+strlen("validFrom")+c];
  7325. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7326. c++;
  7327. }
  7328. sstr[c] = '\0';
  7329. strcpy(validFromStr,sstr);
  7330. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7331. {
  7332. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7333. }
  7334. else
  7335. {
  7336. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7337. }
  7338. }
  7339. else
  7340. {
  7341. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7342. {
  7343. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7344. }
  7345. else
  7346. {
  7347. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7348. }
  7349. }
  7350. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7351. //*********************validTo***************************/
  7352. loc = strstr(payload, "validTo");
  7353. if(loc != NULL)
  7354. {
  7355. c = 0;
  7356. memset(sstr ,0, sizeof(sstr) );
  7357. while (loc[3+strlen("validTo")+c] != '\"')
  7358. {
  7359. sstr[c] = loc[3+strlen("validTo")+c];
  7360. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7361. c++;
  7362. }
  7363. sstr[c] = '\0';
  7364. strcpy(validToStr,sstr);
  7365. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7366. {
  7367. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7368. }
  7369. else
  7370. {
  7371. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7372. }
  7373. }
  7374. else
  7375. {
  7376. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7377. {
  7378. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7379. }
  7380. else
  7381. {
  7382. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7383. }
  7384. }
  7385. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7386. //*********************duration***************************/
  7387. loc = strstr(payload, "duration");
  7388. if(loc != NULL)
  7389. {
  7390. c = 0;
  7391. memset(sstr ,0, sizeof(sstr) );
  7392. while (loc[strlen("duration")+2+c] != ',')
  7393. {
  7394. sstr[c] = loc[strlen("duration")+2+c];
  7395. c++;
  7396. }
  7397. sstr[c] = '\0';
  7398. durationInt = atoi(sstr);
  7399. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7400. {
  7401. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7402. }
  7403. else
  7404. {
  7405. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7406. }
  7407. }
  7408. else
  7409. {
  7410. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7411. {
  7412. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7413. }
  7414. else
  7415. {
  7416. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7417. }
  7418. }
  7419. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7420. //*********************startSchedule***************************/
  7421. loc = strstr(payload, "startSchedule");
  7422. if(loc != NULL)
  7423. {
  7424. c = 0;
  7425. memset(sstr ,0, sizeof(sstr) );
  7426. while (loc[3+strlen("startSchedule")+c] != '\"')
  7427. {
  7428. sstr[c] = loc[3+strlen("startSchedule")+c];
  7429. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7430. c++;
  7431. }
  7432. sstr[c] = '\0';
  7433. strcpy(startScheduleStr,sstr);
  7434. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7435. {
  7436. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7437. }
  7438. else
  7439. {
  7440. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7441. }
  7442. }
  7443. else
  7444. {
  7445. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7446. {
  7447. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7448. }
  7449. else
  7450. {
  7451. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7452. }
  7453. }
  7454. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7455. //*********************chargingRateUnit***************************/
  7456. loc = strstr(payload, "chargingRateUnit");
  7457. if(loc != NULL)
  7458. {
  7459. c = 0;
  7460. memset(sstr ,0, sizeof(sstr) );
  7461. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7462. {
  7463. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7464. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7465. c++;
  7466. }
  7467. sstr[c] = '\0';
  7468. strcpy(chargingRateUnitStr,sstr);
  7469. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7470. {
  7471. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7472. }
  7473. else
  7474. {
  7475. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7476. }
  7477. }
  7478. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7479. //****************chargingSchedulePeriod count start*******************/
  7480. int what_len = strlen("startPeriod");
  7481. char tempChargingProfile[1000]={0};
  7482. strcpy(tempChargingProfile,(const char*)payload);
  7483. char *where = tempChargingProfile;
  7484. if (what_len)
  7485. {
  7486. while ((where = strstr(where, "startPeriod"))) {
  7487. where += what_len;
  7488. chargingSchedulePeriodCount++;
  7489. }
  7490. }
  7491. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7492. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7493. //where = payload;
  7494. int templength = 0;
  7495. //int searchstart = 0;
  7496. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7497. {
  7498. //****************startPeriod*******************/
  7499. c=0;
  7500. loc = strstr(tempChargingProfile + templength, "startPeriod");
  7501. memset(sstr ,0, sizeof(sstr) );
  7502. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7503. {
  7504. sstr[c] = loc[strlen("startPeriod")+2+c];
  7505. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7506. c++;
  7507. }
  7508. sstr[c] = '\0';
  7509. startPeriodInt[periodNums] = atoi(sstr);
  7510. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7511. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7512. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7513. {
  7514. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7515. }
  7516. else
  7517. {
  7518. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7519. }
  7520. templength = strlen("startPeriod")+2+c;
  7521. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7522. //****************limit*******************/
  7523. c=0;
  7524. loc = strstr(tempChargingProfile + templength, "limit");
  7525. memset(sstr ,0, sizeof(sstr) );
  7526. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7527. {
  7528. sstr[c] = loc[strlen("limit")+2+c];
  7529. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7530. c++;
  7531. }
  7532. sstr[c] = '\0';
  7533. limitflaot[periodNums] = atof(sstr);
  7534. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7535. {
  7536. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7537. }
  7538. else
  7539. {
  7540. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7541. }
  7542. templength = templength + strlen("limit")+2+c;
  7543. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7544. //****************numberPhases*******************/
  7545. loc = strstr(tempChargingProfile + templength, "numberPhases");
  7546. if(loc != NULL)
  7547. {
  7548. c=0;
  7549. memset(sstr ,0, sizeof(sstr) );
  7550. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7551. {
  7552. sstr[c] = loc[strlen("numberPhases")+2+c];
  7553. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7554. c++;
  7555. }
  7556. sstr[c] = '\0';
  7557. numberPhasesInt[periodNums] = atoi(sstr);
  7558. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7559. {
  7560. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7561. }
  7562. else
  7563. {
  7564. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7565. }
  7566. templength = templength + strlen("numberPhases")+2+c;
  7567. }
  7568. //where = loc;
  7569. }
  7570. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7571. //****************chargingSchedulePeriod count end*******************/
  7572. //*********************minChargingRate***************************/
  7573. loc = strstr(payload, "minChargingRate");
  7574. if(loc != NULL)
  7575. {
  7576. c = 0;
  7577. memset(sstr ,0, sizeof(sstr) );
  7578. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7579. {
  7580. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7581. c++;
  7582. }
  7583. sstr[c] = '\0';
  7584. minChargingRateFloat = atof(sstr);
  7585. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7586. {
  7587. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7588. }
  7589. else
  7590. {
  7591. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7592. }
  7593. }
  7594. else
  7595. {
  7596. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7597. {
  7598. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7599. }
  7600. else
  7601. {
  7602. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7603. }
  7604. }
  7605. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7606. {
  7607. //printf("set chargingProfile 1-2\n");
  7608. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7609. if(connectorIdInt != 0)
  7610. {
  7611. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7612. goto end;
  7613. }
  7614. strcpy(filename, ChargePointMaxProfile_JSON );
  7615. fptr1 = fopen(filename, "r");
  7616. if (!fptr1)
  7617. {
  7618. //file not exist
  7619. DEBUG_INFO("Unable to open the input file!!\n");
  7620. fptr1 = fopen(filename, "w+");
  7621. }
  7622. fclose(fptr1);
  7623. }
  7624. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7625. {
  7626. //printf("set chargingProfile 1-3\n");
  7627. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7628. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7629. {
  7630. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7631. goto end;
  7632. }
  7633. switch(connectorIdInt)
  7634. {
  7635. case 0:
  7636. strcpy(filename, TxDefaultProfile_0_JSON );
  7637. break;
  7638. case 1:
  7639. strcpy(filename, TxDefaultProfile_1_JSON );
  7640. break;
  7641. case 2:
  7642. strcpy(filename, TxDefaultProfile_2_JSON );
  7643. break;
  7644. default:
  7645. strcpy(filename, TxDefaultProfile_0_JSON );
  7646. break;
  7647. }
  7648. fptr1 = fopen(filename, "r");
  7649. if (!fptr1)
  7650. {
  7651. //file not exist
  7652. //DEBUG_INFO("Unable to open the input file!!\n");
  7653. fptr1 = fopen(filename, "w+");
  7654. }
  7655. fclose(fptr1);
  7656. }
  7657. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7658. {
  7659. //printf("set chargingProfile 1-4\n");
  7660. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7661. //check Transaction active
  7662. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7663. {
  7664. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7665. {
  7666. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7667. {
  7668. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7669. {
  7670. meet = TRUE;
  7671. break;
  7672. }
  7673. }
  7674. }
  7675. }
  7676. for (int index = 0; index < CCS_QUANTITY; index++)
  7677. {
  7678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7679. {
  7680. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7681. {
  7682. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7683. {
  7684. meet = TRUE;
  7685. break;
  7686. }
  7687. }
  7688. }
  7689. }
  7690. for (int index = 0; index < GB_QUANTITY; index++)
  7691. {
  7692. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7693. {
  7694. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7695. {
  7696. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7697. {
  7698. meet = TRUE;
  7699. break;
  7700. }
  7701. }
  7702. }
  7703. }
  7704. if(meet == FALSE)
  7705. {
  7706. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7707. goto end;
  7708. }
  7709. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7710. {
  7711. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7712. goto end;
  7713. }
  7714. switch(connectorIdInt)
  7715. {
  7716. case 0:
  7717. break;
  7718. case 1:
  7719. strcpy(filename, TxProfile_1_JSON);
  7720. break;
  7721. case 2:
  7722. strcpy(filename, TxProfile_2_JSON);
  7723. break;
  7724. default:
  7725. strcpy(filename, TxProfile_1_JSON);
  7726. break;
  7727. }
  7728. fptr1 = fopen(filename, "r");
  7729. if (!fptr1)
  7730. {
  7731. //file not exist
  7732. DEBUG_INFO("Unable to open the input file!!\n");
  7733. fptr1 = fopen(filename, "w+");
  7734. }
  7735. fclose(fptr1);
  7736. }
  7737. //**********************************Write to File********************************************************/
  7738. FILE *infile;
  7739. FILE *outfile;
  7740. // open file for writing
  7741. infile = fopen (filename, "r");
  7742. outfile = fopen (tempfile, "w");
  7743. int d =0;
  7744. d = fgetc(infile);
  7745. //DEBUG_INFO("d:%d\n",d);
  7746. rewind(infile);
  7747. //*检测到文件结束标识返回1,否则返回0。*/
  7748. if(d == EOF)
  7749. {
  7750. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7751. fprintf(outfile,"%s\n",payload);
  7752. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7753. fclose(infile);
  7754. fclose(outfile);
  7755. sprintf(rmFileCmd,"rm -f %s",filename);
  7756. system(rmFileCmd);
  7757. rename(tempfile, filename);
  7758. #if 0
  7759. resultRename = rename(tempfile, filename);
  7760. if(resultRename == 0)
  7761. {
  7762. DEBUG_INFO("File chargingProfile renamed successfully");
  7763. }
  7764. else
  7765. {
  7766. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7767. }
  7768. #endif
  7769. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7770. //system(rmFileCmd);
  7771. }
  7772. else
  7773. {
  7774. char buf[1000]={0};
  7775. int ChargingProfileAdded = FALSE;
  7776. while (fgets(buf, sizeof(buf), infile) != NULL)
  7777. {
  7778. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7779. //*************************tempconnectorIdInt*********************************/
  7780. loc = strstr(buf, "connectorId");
  7781. c = 0;
  7782. memset(sstr ,0, sizeof(sstr) );
  7783. while (loc[strlen("connectorId")+2+c] != ',')
  7784. {
  7785. sstr[c] = loc[strlen("connectorId")+2+c];
  7786. c++;
  7787. }
  7788. sstr[c] = '\0';
  7789. tempconnectorIdInt = atoi(sstr);
  7790. //*************************tempchargingProfileIdInt*********************************/
  7791. loc = strstr(buf, "chargingProfileId");
  7792. c = 0;
  7793. memset(sstr ,0, sizeof(sstr) );
  7794. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7795. {
  7796. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7797. c++;
  7798. }
  7799. sstr[c] = '\0';
  7800. tempchargingProfileIdInt = atoi(sstr);
  7801. //*************************tempstackLevelInt*********************************/
  7802. loc = strstr(buf, "stackLevel");
  7803. c = 0;
  7804. memset(sstr ,0, sizeof(sstr) );
  7805. while (loc[strlen("stackLevel")+2+c] != ',')
  7806. {
  7807. sstr[c] = loc[strlen("stackLevel")+2+c];
  7808. c++;
  7809. }
  7810. sstr[c] = '\0';
  7811. tempstackLevelInt = atoi(sstr);
  7812. //*************************tempchargingProfilePurposeStr*********************************/
  7813. loc = strstr(payload, "chargingProfilePurpose");
  7814. c = 0;
  7815. memset(sstr ,0, sizeof(sstr) );
  7816. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7817. {
  7818. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7819. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7820. c++;
  7821. }
  7822. sstr[c] = '\0';
  7823. strcpy(tempchargingProfilePurposeStr,sstr);
  7824. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7825. {
  7826. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7827. {
  7828. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7829. if(ChargingProfileAdded == FALSE)
  7830. {
  7831. fprintf(outfile,"%s\n",payload);
  7832. ChargingProfileAdded = TRUE;
  7833. }
  7834. }
  7835. else
  7836. {
  7837. if(tempstackLevelInt < stackLevelInt)
  7838. {
  7839. if(ChargingProfileAdded == FALSE)
  7840. {
  7841. fprintf(outfile,"%s\n",payload);
  7842. ChargingProfileAdded = TRUE;
  7843. fprintf(outfile,"%s\n",buf);
  7844. }
  7845. else
  7846. {
  7847. fprintf(outfile,"%s\n",buf);
  7848. }
  7849. }
  7850. else
  7851. {
  7852. if(ChargingProfileAdded == FALSE)
  7853. {
  7854. fprintf(outfile,"%s\n",buf);
  7855. fprintf(outfile,"%s\n",payload);
  7856. ChargingProfileAdded = TRUE;
  7857. }
  7858. else
  7859. {
  7860. fprintf(outfile,"%s\n",buf);
  7861. }
  7862. }
  7863. }
  7864. }
  7865. else
  7866. {
  7867. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7868. {
  7869. if(ChargingProfileAdded == FALSE)
  7870. {
  7871. fprintf(outfile,"%s\n",payload);
  7872. ChargingProfileAdded = TRUE;
  7873. fprintf(outfile,"%s\n",buf);
  7874. }
  7875. else
  7876. {
  7877. fprintf(outfile,"%s\n",buf);
  7878. }
  7879. }
  7880. else if(tempstackLevelInt < stackLevelInt)
  7881. {
  7882. if(ChargingProfileAdded == FALSE)
  7883. {
  7884. fprintf(outfile,"%s\n",payload);
  7885. ChargingProfileAdded = TRUE;
  7886. fprintf(outfile,"%s\n",buf);
  7887. }
  7888. else
  7889. {
  7890. fprintf(outfile,"%s\n",buf);
  7891. }
  7892. }
  7893. else
  7894. {
  7895. if(ChargingProfileAdded == FALSE)
  7896. {
  7897. fprintf(outfile,"%s\n",buf);
  7898. fprintf(outfile,"%s\n",payload);
  7899. ChargingProfileAdded = TRUE;
  7900. }
  7901. else
  7902. {
  7903. fprintf(outfile,"%s\n",buf);
  7904. }
  7905. }
  7906. }
  7907. } // end of while loop
  7908. fclose(infile);
  7909. fclose(outfile);
  7910. sprintf(rmFileCmd,"rm -f %s",filename);
  7911. system(rmFileCmd);
  7912. rename(tempfile, filename);
  7913. #if 0
  7914. resultRename = rename(tempfile, filename);
  7915. if(resultRename == 0)
  7916. {
  7917. DEBUG_INFO("File chargingProfile renamed successfully");
  7918. }
  7919. else
  7920. {
  7921. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7922. }
  7923. #endif
  7924. result = TRUE;
  7925. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7926. }
  7927. end:
  7928. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7929. return result;
  7930. return result;
  7931. }
  7932. int handleTriggerMessageRequest(char *uuid, char *payload)
  7933. {
  7934. mtrace();
  7935. int result = FAIL;
  7936. int connectorIdIsNULL = FALSE;
  7937. int connectorIdInt =0;
  7938. char sstr[40]={0};
  7939. char requestedMessagestr[40]={0};
  7940. char comfirmstr[20]={0};
  7941. int c = 0;
  7942. char *loc;
  7943. DEBUG_INFO("handleTriggerMessageRequest\n");
  7944. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7945. c = 0;
  7946. loc = strstr(payload, "requestedMessage");
  7947. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7948. {
  7949. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7950. c++;
  7951. }
  7952. sstr[c] = '\0';
  7953. strcpy(requestedMessagestr, sstr);
  7954. c = 0;
  7955. loc = strstr(payload, "connectorId");
  7956. if(loc == NULL)
  7957. {
  7958. connectorIdIsNULL = TRUE;
  7959. }
  7960. else
  7961. {
  7962. memset(sstr ,0, sizeof(sstr) );
  7963. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7964. {
  7965. sstr[c] = loc[strlen("connectorId")+2+c];
  7966. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7967. c++;
  7968. }
  7969. sstr[c] = '\0';
  7970. connectorIdInt = atoi(sstr);
  7971. }
  7972. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7973. {
  7974. //connectorIdInt = json_object_get_int(connectorId);
  7975. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7976. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7977. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7978. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7979. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7980. }
  7981. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7982. {
  7983. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7984. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7985. return TRUE;
  7986. }
  7987. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7988. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7989. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7990. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7991. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7992. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7993. {
  7994. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7995. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7996. return TRUE;
  7997. }
  7998. else
  7999. {
  8000. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8001. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8002. }
  8003. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8004. {
  8005. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8006. {
  8007. FirmwareStatusNotificationStatus = 3;
  8008. }
  8009. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8010. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8011. }
  8012. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8013. {
  8014. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8015. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8016. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8017. }
  8018. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8019. {
  8020. sendBootNotificationRequest();
  8021. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8022. }
  8023. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8024. {
  8025. sendHeartbeatRequest(connectorIdInt);
  8026. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8027. }
  8028. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8029. {
  8030. if(connectorIdIsNULL == FALSE)
  8031. {
  8032. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8033. {
  8034. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8035. sendMeterValuesRequest(connectorIdInt -1);
  8036. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8037. }
  8038. }
  8039. else
  8040. {
  8041. for(int idx=0;idx< gunTotalNumber;idx++)
  8042. {
  8043. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8044. sendMeterValuesRequest(idx);
  8045. }
  8046. }
  8047. }
  8048. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8049. {
  8050. if(connectorIdIsNULL == FALSE)
  8051. {
  8052. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8053. {
  8054. sendStatusNotificationRequest(connectorIdInt -1);
  8055. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8056. }
  8057. }
  8058. else
  8059. {
  8060. for(int idx=0;idx< gunTotalNumber;idx++)
  8061. sendStatusNotificationRequest(idx);
  8062. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8063. }
  8064. }
  8065. return result;
  8066. }
  8067. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8068. {
  8069. mtrace();
  8070. int result = FAIL;
  8071. char sstr[6]={0};
  8072. int connectorIdInt =0;
  8073. char comfirmstr[20]={0};
  8074. int c = 0;
  8075. char *loc;
  8076. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8077. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8078. c = 0;
  8079. loc = strstr(payload, "connectorId");
  8080. memset(sstr ,0, sizeof(sstr) );
  8081. while (loc[strlen("connectorId")+2+c] != '}')
  8082. {
  8083. sstr[c] = loc[strlen("connectorId")+2+c];
  8084. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8085. c++;
  8086. }
  8087. sstr[c] = '\0';
  8088. connectorIdInt = atoi(sstr);
  8089. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8090. if(gunTotalNumber == 0)
  8091. {
  8092. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8093. goto end;
  8094. }
  8095. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8096. {
  8097. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8098. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8099. goto end;
  8100. }
  8101. else
  8102. {
  8103. //check Transaction active
  8104. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8105. {
  8106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8107. {
  8108. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8109. {
  8110. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8111. }
  8112. }
  8113. for (int index = 0; index < CCS_QUANTITY; index++)
  8114. {
  8115. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8116. {
  8117. //stop Transaction
  8118. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8119. }
  8120. }
  8121. for (int index = 0; index < GB_QUANTITY; index++)
  8122. {
  8123. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8124. {
  8125. //stop Transaction
  8126. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8127. }
  8128. }
  8129. }
  8130. else
  8131. {
  8132. for (int index = 0; index < AC_QUANTITY; index++)
  8133. {
  8134. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8135. {
  8136. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8137. }
  8138. }
  8139. }// END FOR AC ELSE
  8140. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8141. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8142. result = TRUE;
  8143. return result;
  8144. }
  8145. end:
  8146. //json_object_put(obj); --- remove temporally
  8147. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8148. return result;
  8149. }
  8150. static char UpdateFirmwarepayloadData[300]={0};
  8151. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8152. {
  8153. mtrace();
  8154. int result = FAIL;
  8155. pthread_t t;
  8156. sendUpdateFirmwareConfirmation(uuid);
  8157. memset(UpdateFirmwarepayloadData, 0, 300);
  8158. strcpy(UpdateFirmwarepayloadData, payload);
  8159. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8160. ////pthread_join(t, NULL); //
  8161. //pthread_detach(t);
  8162. //sendUpdateFirmwareConfirmation(uuid);
  8163. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8164. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8165. return result;
  8166. }
  8167. void *UpdateFirmwareProcess(void *data)
  8168. {
  8169. pthread_detach(pthread_self());
  8170. mtrace();
  8171. int retriesInt =0, retryIntervalInt=0;
  8172. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8173. int port=0;
  8174. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8175. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8176. //char comfirmstr[20];
  8177. int isSuccess = 0;
  8178. char ftpbuf[200];
  8179. char temp[100];
  8180. char * pch;
  8181. int retriesISNULL=FALSE;
  8182. int retryInterval=FALSE;
  8183. int c = 0;
  8184. //int i = 0;
  8185. char *loc;
  8186. char sstr[300]={ 0 };
  8187. char str[300]={ 0 };
  8188. //char *str = (char*) data; // ? ?輸入資 ?
  8189. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8190. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8191. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8192. //***************location **************/
  8193. loc = strstr(str, "location");
  8194. memset(sstr ,0, sizeof(sstr) );
  8195. c = 0;
  8196. while (loc[3+strlen("location")+c] != '\"')
  8197. {
  8198. sstr[c] = loc[3+strlen("location")+c];
  8199. c++;
  8200. }
  8201. sstr[c] = '\0';
  8202. strcpy(locationstr, sstr);
  8203. //***************retries**************/
  8204. c = 0;
  8205. loc = strstr(str, "retries");
  8206. if(loc == NULL)
  8207. {
  8208. retriesISNULL=TRUE;
  8209. }
  8210. else
  8211. {
  8212. memset(sstr ,0, sizeof(sstr) );
  8213. while (loc[strlen("retries")+2+c] != ',')
  8214. {
  8215. sstr[c] = loc[strlen("retries")+2+c];
  8216. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8217. c++;
  8218. }
  8219. sstr[c] = '\0';
  8220. }
  8221. if(retriesISNULL == FALSE)
  8222. {
  8223. retriesInt = atoi(sstr);
  8224. }
  8225. //***************retrieveDate **************/
  8226. loc = strstr(str, "retrieveDate");
  8227. memset(sstr ,0, sizeof(sstr) );
  8228. c = 0;
  8229. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8230. {
  8231. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8232. c++;
  8233. }
  8234. sstr[c] = '\0';
  8235. strcpy(retrieveDatestr, sstr);
  8236. //***************retryInterval **************/
  8237. c = 0;
  8238. loc = strstr(str, "retryInterval");
  8239. memset(sstr ,0, sizeof(sstr) );
  8240. if(loc == NULL)
  8241. {
  8242. retryInterval=TRUE;
  8243. }
  8244. else
  8245. {
  8246. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8247. {
  8248. sstr[c] = loc[strlen("retryInterval")+2+c];
  8249. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8250. c++;
  8251. }
  8252. sstr[c] = '\0';
  8253. }
  8254. if(retryInterval==FALSE)
  8255. {
  8256. retryIntervalInt = atoi(sstr);
  8257. }
  8258. memset(ftppath, 0, sizeof(ftppath));
  8259. memset(path, 0, sizeof(path));
  8260. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8261. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8262. if(strncmp(locationstr,"http", 4) == 0)
  8263. {
  8264. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8265. protocol, host, path);
  8266. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8267. // protocol, user, password, host, path);
  8268. sprintf(ftppath,"/%s", path);
  8269. //DEBUG_INFO("protocol =%s\n",protocol);
  8270. //DEBUG_INFO("host =%s\n",host);
  8271. //DEBUG_INFO("path =%s\n",path);
  8272. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8273. int ftppathlen=strlen(ftppath);
  8274. int i=1;
  8275. char filenametemp[50];
  8276. while(i < ftppathlen)
  8277. {
  8278. int len=ftppathlen-i;
  8279. if(ftppath[len]== 47) // '/' ascll code: 47
  8280. {
  8281. DEBUG_INFO("compare '/' all right\n");
  8282. break;
  8283. }
  8284. i=i+1;
  8285. }
  8286. memset(filenametemp, 0, sizeof(filenametemp));
  8287. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8288. filenametemp[i+1] = 0;
  8289. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8290. do{
  8291. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8292. sleep(retryIntervalInt);
  8293. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8294. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8295. if(!isSuccess)
  8296. {
  8297. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8298. }
  8299. else
  8300. {
  8301. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8302. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8303. isUpdateRequest = TRUE;
  8304. }
  8305. }
  8306. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8307. {
  8308. memset(ftpbuf, 0, sizeof(ftpbuf));
  8309. memset(temp, 0, sizeof(temp));
  8310. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8311. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8312. int ftppathlen=strlen(ftpbuf);
  8313. int i=1;
  8314. char filenametemp[50];
  8315. while(i < ftppathlen)
  8316. {
  8317. int len=ftppathlen-i;
  8318. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8319. {
  8320. DEBUG_INFO(" compare '/' all right\n");
  8321. break;
  8322. }
  8323. i=i+1;
  8324. }
  8325. memset(filenametemp, 0, sizeof(filenametemp));
  8326. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8327. filenametemp[i+1] = 0;
  8328. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8329. pch=strchr(temp,'@');
  8330. if(pch==NULL)
  8331. {
  8332. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8333. protocol, host, &port, path);
  8334. strcpy(user,"anonymous");
  8335. strcpy(password,"");
  8336. }
  8337. else
  8338. {
  8339. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8340. protocol, user, password, host, &port, path);
  8341. }
  8342. sscanf(host,"%[^/]%s",host1, path1);
  8343. sprintf(ftppath,"%s", path1);
  8344. //DEBUG_INFO("protocol =%s\n",protocol);
  8345. //DEBUG_INFO("user =%s\n",user);
  8346. //DEBUG_INFO("password =%s\n",password);
  8347. //DEBUG_INFO("host1 =%s\n",host1);
  8348. //DEBUG_INFO("port =%d\n",port);
  8349. //DEBUG_INFO("path1 =%s\n",path1);
  8350. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8351. //ftpFile(host, user, password, port, ftppath, fname);
  8352. //download firmware pthred
  8353. if(port == 0)
  8354. {
  8355. port = 21;
  8356. }
  8357. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8358. do{
  8359. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8360. sleep(retryIntervalInt);
  8361. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8362. if(!isSuccess)
  8363. {
  8364. //BulldogUtil.sleepMs(interval*1000);
  8365. DEBUG_INFO("Update firmware request and download file fail.\n");
  8366. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8367. }
  8368. else
  8369. {
  8370. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8371. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8372. isUpdateRequest = TRUE;
  8373. }
  8374. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8375. }
  8376. else
  8377. {
  8378. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8379. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8380. }
  8381. pthread_exit(NULL);
  8382. }
  8383. //==========================================
  8384. // Handle server response routine
  8385. //==========================================
  8386. void handleAuthorizeResponse(char *payload, int gun_index)
  8387. {
  8388. mtrace();
  8389. char expiryDatestr[30]={0};
  8390. char parentIdTagstr[20]={0};
  8391. char statusstr[20]={0};
  8392. char expiryDatestrtemp[30]={0};
  8393. char parentIdTagstrtemp[20]={0};
  8394. char IdTagstrtemp[20]={0};
  8395. char statusstrtemp[20]={0};
  8396. int expiryDateISNULL=FALSE;
  8397. int parentIdTagISNULL=FALSE;
  8398. char sstr[160]={ 0 };
  8399. char* filename = AuthorizationCache_JSON;
  8400. char tempfile[] = "/Storage/OCPP/temp.json";
  8401. int c = 0;
  8402. char *loc;
  8403. int resultRename=0;
  8404. int responseIdTagInfoAsZero= 0;
  8405. char rmFileCmd[50]={0};
  8406. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8407. //***********expiryDate*************/
  8408. loc = strstr(payload, "expiryDate");
  8409. memset(sstr ,0, sizeof(sstr) );
  8410. c = 0;
  8411. if(loc == NULL)
  8412. {
  8413. expiryDateISNULL = TRUE;
  8414. }
  8415. else
  8416. {
  8417. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8418. {
  8419. sstr[c] = loc[3+strlen("expiryDate")+c];
  8420. c++;
  8421. }
  8422. sstr[c] = '\0';
  8423. strcpy(expiryDatestr, sstr);
  8424. }
  8425. //***********parentIdTag*************/
  8426. loc = strstr(payload, "parentIdTag");
  8427. memset(sstr ,0, sizeof(sstr) );
  8428. c = 0;
  8429. if(loc == NULL)
  8430. {
  8431. parentIdTagISNULL = TRUE;
  8432. }
  8433. else
  8434. {
  8435. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8436. {
  8437. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8438. c++;
  8439. }
  8440. sstr[c] = '\0';
  8441. strcpy(parentIdTagstr, sstr);
  8442. }
  8443. //***********status*************/
  8444. loc = strstr(payload, "status");
  8445. memset(sstr ,0, sizeof(sstr) );
  8446. c = 0;
  8447. while (loc[3+strlen("status")+c] != '\"')
  8448. {
  8449. sstr[c] = loc[3+strlen("status")+c];
  8450. c++;
  8451. }
  8452. sstr[c] = '\0';
  8453. strcpy(statusstr, sstr);
  8454. if(expiryDateISNULL == FALSE)
  8455. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8456. if(parentIdTagISNULL == FALSE)
  8457. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8458. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8459. //Update idTag information to authorization cache if supproted
  8460. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8461. {
  8462. if((access(filename,F_OK))!=-1)
  8463. {
  8464. printf("AuthorizationCache exist.\n");
  8465. }
  8466. else
  8467. {
  8468. printf("AuthorizationCache not exist\n");
  8469. FILE *log = fopen(filename, "w+");
  8470. if(log == NULL)
  8471. {
  8472. printf("log is NULL\n");
  8473. goto out;
  8474. }
  8475. else
  8476. {
  8477. fclose(log);
  8478. }
  8479. }
  8480. FILE *infile;
  8481. FILE *outfile;
  8482. // open file for writing
  8483. infile = fopen (filename, "r");
  8484. outfile = fopen (tempfile, "w");
  8485. //*检测到文件结束标识返回1,否则返回0。*/
  8486. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8487. int c;
  8488. c = fgetc(infile);
  8489. //DEBUG_INFO("c:%d\n",c);
  8490. rewind(infile);
  8491. if(c == EOF)
  8492. {
  8493. DEBUG_INFO("Orignal File is NULL\n");
  8494. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8495. {
  8496. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8497. }
  8498. else
  8499. {
  8500. strcpy(expiryDatestrtemp, "");
  8501. }
  8502. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8503. {
  8504. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8505. }
  8506. else
  8507. {
  8508. //write Authorize IdTag
  8509. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8510. }
  8511. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8512. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8513. fclose(infile);
  8514. fclose(outfile);
  8515. sprintf(rmFileCmd,"rm -f %s",filename);
  8516. system(rmFileCmd);
  8517. resultRename = rename(tempfile, filename);
  8518. if(resultRename == 0)
  8519. {
  8520. printf("File renamed successfully");
  8521. }
  8522. else
  8523. {
  8524. printf("Error: unable to rename the file");
  8525. }
  8526. }
  8527. else
  8528. {
  8529. char buf[160]={0};
  8530. while (fgets(buf, sizeof(buf), infile) != NULL)
  8531. {
  8532. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8533. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8534. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8535. memset(statusstr, 0, sizeof(statusstrtemp));
  8536. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8537. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8538. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8539. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8540. //------------------IdTag-----------------------
  8541. loc = strstr(buf, "idTag");
  8542. memset(sstr ,0, sizeof(sstr) );
  8543. c = 0;
  8544. while (loc[3+strlen("idTag")+c] != '\"')
  8545. {
  8546. sstr[c] = loc[3+strlen("idTag")+c];
  8547. c++;
  8548. }
  8549. sstr[c] = '\0';
  8550. strcpy(IdTagstrtemp,sstr);
  8551. //*********************expiryDate***************/
  8552. loc = strstr(buf, "expiryDate");
  8553. memset(sstr ,0, sizeof(sstr) );
  8554. c = 0;
  8555. while (loc[3+strlen("expiryDate")+c] != '\"')
  8556. {
  8557. sstr[c] = loc[3+strlen("expiryDate")+c];
  8558. c++;
  8559. }
  8560. sstr[c] = '\0';
  8561. strcpy(expiryDatestr,sstr);
  8562. //*********************parentIdTag***************/
  8563. loc = strstr(buf, "parentIdTag");
  8564. memset(sstr ,0, sizeof(sstr) );
  8565. c = 0;
  8566. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8567. {
  8568. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8569. c++;
  8570. }
  8571. sstr[c] = '\0';
  8572. strcpy(parentIdTagstr,sstr);
  8573. //*********************status***************/
  8574. loc = strstr(buf, "status");
  8575. memset(sstr ,0, sizeof(sstr) );
  8576. c = 0;
  8577. while (loc[3+strlen("status")+c] != '\"')
  8578. {
  8579. sstr[c] = loc[3+strlen("status")+c];
  8580. c++;
  8581. }
  8582. sstr[c] = '\0';
  8583. strcpy(statusstr,sstr);
  8584. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8585. {
  8586. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8587. responseIdTagInfoAsZero = 1;
  8588. }
  8589. else
  8590. {
  8591. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8592. }
  8593. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8594. {
  8595. //modify item
  8596. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8597. {
  8598. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8599. }
  8600. else
  8601. {
  8602. strcpy(expiryDatestrtemp, "");
  8603. }
  8604. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8605. {
  8606. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8607. }
  8608. else
  8609. {
  8610. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8611. }
  8612. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8613. }
  8614. else
  8615. {
  8616. //wrie original item
  8617. strcpy(expiryDatestrtemp, expiryDatestr);
  8618. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8619. strcpy(statusstrtemp, statusstr);
  8620. }
  8621. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8622. }
  8623. fclose(infile);
  8624. fclose(outfile);
  8625. sprintf(rmFileCmd,"rm -f %s",filename);
  8626. system(rmFileCmd);
  8627. resultRename = rename(tempfile, filename);
  8628. if(resultRename == 0)
  8629. {
  8630. DEBUG_INFO("File renamed successfully");
  8631. }
  8632. else
  8633. {
  8634. DEBUG_INFO("Error: unable to rename the file");
  8635. }
  8636. }
  8637. }
  8638. out:
  8639. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8640. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8641. authorizeRetryTimes = 0;
  8642. }
  8643. void handleBootNotificationResponse(char *payload, int gun_index)
  8644. {
  8645. mtrace();
  8646. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8647. char statusStr[12]={0};
  8648. char currentTimeStr[30]={0};
  8649. char *loc;
  8650. int intervalInt = 0;
  8651. int c = 0;
  8652. //double diff_t;
  8653. struct tm tp;
  8654. char buf[28]={0};
  8655. char timebuf[50]={0};
  8656. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8657. //*** interval ****/
  8658. c = 0;
  8659. loc = strstr(payload, "interval");
  8660. //printf("loc=%s\n",loc);
  8661. memset(sstr ,0, sizeof(sstr) );
  8662. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8663. {
  8664. sstr[c] = loc[strlen("interval")+2+c];
  8665. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8666. c++;
  8667. }
  8668. sstr[c] = '\0';
  8669. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8670. intervalInt = atoi(sstr);
  8671. //***status ****/
  8672. loc = strstr(payload, "status");
  8673. memset(sstr ,0, sizeof(sstr) );
  8674. c = 0;
  8675. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8676. {
  8677. sstr[c] = loc[3+strlen("status")+c];
  8678. c++;
  8679. }
  8680. sstr[c] = '\0';
  8681. strcpy(statusStr, sstr);
  8682. //***currentTime ****/
  8683. loc = strstr(payload, "currentTime");
  8684. //printf("loc=%s\n",loc);
  8685. memset(sstr ,0, sizeof(sstr) );
  8686. c = 0;
  8687. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8688. {
  8689. sstr[c] = loc[3+strlen("currentTime")+c];
  8690. c++;
  8691. }
  8692. sstr[c] = '\0';
  8693. strcpy(currentTimeStr, sstr);
  8694. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8695. HeartBeatWaitTime = BootNotificationInterval;
  8696. clientTime.Heartbeat=time((time_t*)NULL);
  8697. //write back to ShmOCPP16Data->BootNotification
  8698. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8699. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8700. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8701. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8702. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8703. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8704. {
  8705. server_sign = TRUE;
  8706. server_pending =FALSE;
  8707. }
  8708. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8709. {
  8710. server_pending = TRUE;
  8711. }
  8712. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8713. tp.tm_isdst = -1;
  8714. //time_t utc = mktime(&tp);
  8715. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8716. memset(timebuf, 0, sizeof timebuf);
  8717. sprintf(timebuf,"date -s '%s'",buf);
  8718. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8719. system(timebuf);
  8720. //==============================================
  8721. // RTC sync
  8722. //==============================================
  8723. system("/sbin/hwclock -w --systohc");
  8724. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8725. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8726. }
  8727. void handleDataTransferResponse(char *payload, int gun_index)
  8728. {
  8729. char sstr[160]={0};//sstr[200]={ 0 };
  8730. int c = 0;
  8731. char *loc;
  8732. DEBUG_INFO("handleDataTransferResponse ...\n");
  8733. loc = strstr(payload, "status");
  8734. printf("loc=%s\n",loc);
  8735. c = 0;
  8736. while (loc[3+strlen("status")+c] != '\"')
  8737. {
  8738. sstr[c] = loc[3+strlen("status")+c];
  8739. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8740. c++;
  8741. }
  8742. sstr[c] = '\0';
  8743. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8744. }
  8745. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8746. {
  8747. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8748. //struct json_object *obj;
  8749. // obj = json_tokener_parse(payload);
  8750. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8751. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8752. //No fields are defined.
  8753. }
  8754. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8755. {
  8756. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8757. //struct json_object *obj;
  8758. // obj = json_tokener_parse(payload);
  8759. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8760. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8761. //No fields are defined.
  8762. }
  8763. void handleHeartbeatResponse(char *payload, int gun_index)
  8764. {
  8765. mtrace();
  8766. //double diff_t;
  8767. struct tm tp;
  8768. char buf[28]={0};
  8769. char timebuf[50]={0};
  8770. char sstr[30]={ 0 };
  8771. int c = 0;
  8772. char *loc;
  8773. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8774. if((HeartBeatCount%360) == 0)
  8775. {
  8776. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8777. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8778. }
  8779. HeartBeatCount = HeartBeatCount + 1;
  8780. c = 0;
  8781. loc = strstr(payload, "currentTime");
  8782. memset(sstr ,0, sizeof(sstr) );
  8783. while (loc[3+strlen("currentTime")+c] != '\"')
  8784. {
  8785. sstr[c] = loc[3+strlen("currentTime")+c];
  8786. c++;
  8787. }
  8788. sstr[c] = '\0';
  8789. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8790. // #ifdef SystemLogMessage
  8791. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8792. // #endif
  8793. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8794. tp.tm_isdst = -1;
  8795. //time_t utc = mktime(&tp);
  8796. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8797. memset(timebuf, 0, sizeof timebuf);
  8798. sprintf(timebuf,"date -s '%s'",buf);
  8799. system(timebuf);
  8800. //==============================================
  8801. // RTC sync
  8802. //==============================================
  8803. system("/sbin/hwclock -w --systohc");
  8804. if(FirstHeartBeat == 0)
  8805. {
  8806. FirstHeartBeat = 1;
  8807. }
  8808. HeartBeatWithNOResponse = 0;
  8809. }
  8810. void handleMeterValuesResponse(char *payload, int gun_index)
  8811. {
  8812. mtrace();
  8813. //struct json_object *obj;
  8814. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8815. //No fields are defined.
  8816. }
  8817. void handleStartTransactionResponse(char *payload, int gun_index)
  8818. {
  8819. mtrace();
  8820. char sstr[28]={ 0 };
  8821. int c = 0;
  8822. char *loc;
  8823. int transactionIdInt = 0;
  8824. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8825. DEBUG_INFO("handleStartTransactionResponse\n");
  8826. //****************expiryDate********************/
  8827. loc = strstr(payload, "expiryDate");
  8828. if(loc == NULL)
  8829. {
  8830. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8831. }
  8832. else
  8833. {
  8834. c = 0;
  8835. memset(sstr ,0, sizeof(sstr) );
  8836. while (loc[3+strlen("expiryDate")+c] != '\"')
  8837. {
  8838. sstr[c] = loc[3+strlen("expiryDate")+c];
  8839. c++;
  8840. }
  8841. sstr[c] = '\0';
  8842. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8843. }
  8844. //****************parentIdTag********************/
  8845. loc = strstr(payload, "parentIdTag");
  8846. if(loc == NULL)
  8847. {
  8848. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8849. }
  8850. else
  8851. {
  8852. c = 0;
  8853. memset(sstr ,0, sizeof(sstr) );
  8854. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8855. {
  8856. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8857. c++;
  8858. }
  8859. sstr[c] = '\0';
  8860. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8861. }
  8862. //****************status********************/
  8863. loc = strstr(payload, "status");
  8864. if(loc == NULL)
  8865. {
  8866. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8867. }
  8868. else
  8869. {
  8870. c = 0;
  8871. memset(sstr ,0, sizeof(sstr) );
  8872. while (loc[3+strlen("status")+c] != '\"')
  8873. {
  8874. sstr[c] = loc[3+strlen("status")+c];
  8875. c++;
  8876. }
  8877. sstr[c] = '\0';
  8878. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8879. }
  8880. //****************transactionId********************/
  8881. c=0;
  8882. loc = strstr(payload, "transactionId");
  8883. memset(sstr ,0, sizeof(sstr) );
  8884. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8885. {
  8886. sstr[c] = loc[strlen("transactionId")+2+c];
  8887. c++;
  8888. }
  8889. sstr[c] = '\0';
  8890. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8891. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8892. TransactionId[gun_index] = transactionIdInt;
  8893. DEBUG_INFO("gun_index: %d\n", gun_index);
  8894. DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  8895. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8896. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8897. #ifdef SystemLogMessage
  8898. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8899. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8900. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8901. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8902. #endif
  8903. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8904. {
  8905. //add Charging Record
  8906. SettingChargingRecord(gun_index, transactionIdInt);
  8907. }
  8908. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8909. }
  8910. void handleStatusNotificationResponse(char *payload, int gun_index)
  8911. {
  8912. mtrace();
  8913. printf("handleStatusNotificationResponse\n");
  8914. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8915. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8916. }
  8917. void handleStopTransactionnResponse(char *payload, int gun_index)
  8918. {
  8919. mtrace();
  8920. char sstr[30]={ 0 };
  8921. int c = 0;
  8922. char *loc;
  8923. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8924. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8925. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8926. loc = strstr(payload, "idTagInfo");
  8927. //***********************idTagInfo************************/
  8928. if(loc != NULL)
  8929. {
  8930. //***********************expiryDate************************/
  8931. loc = strstr(payload, "expiryDate");
  8932. if(loc != NULL)
  8933. {
  8934. memset(sstr ,0, sizeof(sstr) );
  8935. c = 0;
  8936. while (loc[3+strlen("expiryDate")+c] != '\"')
  8937. {
  8938. sstr[c] = loc[3+strlen("expiryDate")+c];
  8939. c++;
  8940. }
  8941. sstr[c] = '\0';
  8942. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8943. }
  8944. //***********************parentIdTag************************/
  8945. loc = strstr(payload, "parentIdTag");
  8946. if(loc != NULL)
  8947. {
  8948. memset(sstr ,0, sizeof(sstr) );
  8949. c = 0;
  8950. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8951. {
  8952. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8953. c++;
  8954. }
  8955. sstr[c] = '\0';
  8956. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8957. }
  8958. //***********************status************************/
  8959. loc = strstr(payload, "status");
  8960. memset(sstr ,0, sizeof(sstr) );
  8961. c = 0;
  8962. while (loc[3+strlen("status")+c] != '\"')
  8963. {
  8964. sstr[c] = loc[3+strlen("status")+c];
  8965. c++;
  8966. }
  8967. sstr[c] = '\0';
  8968. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8969. }
  8970. #ifdef SystemLogMessage
  8971. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8972. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8973. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8974. #endif
  8975. }
  8976. //==========================================
  8977. // Handle Error routine
  8978. //==========================================
  8979. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8980. {
  8981. mtrace();
  8982. #ifdef SystemLogMessage
  8983. DEBUG_INFO("errorCode: %s\n", errorCode);
  8984. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8985. DEBUG_INFO("errorDetails: %s\n", payload);
  8986. #endif
  8987. }
  8988. //===============================================
  8989. // Common routine
  8990. //===============================================
  8991. int initialConfigurationTable(void)
  8992. {
  8993. FILE *fp;
  8994. FILE *outfile;
  8995. char str[200]={0};
  8996. char sstr[100]={0};
  8997. int c = 0;
  8998. char *loc;
  8999. printf("initialConfigurationTable \n");
  9000. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9001. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9002. {
  9003. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9004. if(outfile == NULL) {
  9005. DEBUG_INFO("Error opening file");
  9006. return FALSE;
  9007. }
  9008. /*Core Profile*/
  9009. //AllowOfflineTxForUnknownId
  9010. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9011. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  9015. //AuthorizationCacheEnabled
  9016. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9020. //AuthorizeRemoteTxRequests
  9021. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "TRUE");
  9025. //BlinkRepeat
  9026. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9030. //ClockAlignedDataInterval
  9031. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9035. //ConnectionTimeOut
  9036. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9040. //GetConfigurationMaxKeys
  9041. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9045. // HeartbeatInterval
  9046. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9050. // LightIntensity
  9051. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9055. // LocalAuthorizeOffline
  9056. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9060. // LocalPreAuthorize
  9061. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9065. // MaxEnergyOnInvalidId
  9066. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9069. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9071. // MeterValuesAlignedData
  9072. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9076. // MeterValuesAlignedDataMaxLength
  9077. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9081. // MeterValuesSampledData
  9082. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9086. // MeterValuesSampledDataMaxLength
  9087. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9091. // MeterValueSampleInterval
  9092. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9096. // MinimumStatusDuration
  9097. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9101. // NumberOfConnectors
  9102. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9104. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9105. {
  9106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9107. }
  9108. else
  9109. {
  9110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9111. }
  9112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9113. // ResetRetries
  9114. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9118. // ConnectorPhaseRotation
  9119. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9123. // ConnectorPhaseRotationMaxLength
  9124. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9128. // StopTransactionOnEVSideDisconnect
  9129. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9133. // StopTransactionOnInvalidId
  9134. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9138. // StopTxnAlignedData
  9139. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9143. // StopTxnAlignedDataMaxLength
  9144. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9148. // StopTxnSampledData
  9149. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9153. // StopTxnSampledDataMaxLength
  9154. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9156. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9157. {
  9158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9159. }
  9160. else
  9161. {
  9162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9163. }
  9164. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9166. // SupportedFeatureProfiles
  9167. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9171. // SupportedFeatureProfilesMaxLength
  9172. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9176. // TransactionMessageAttempts
  9177. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9180. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9182. // TransactionMessageRetryInterval
  9183. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9186. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9188. // UnlockConnectorOnEVSideDisconnect
  9189. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9193. // WebSocketPingInterval
  9194. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9198. //* Local Auth List Management Profile*/
  9199. #if 0
  9200. //For OCTT Test Case
  9201. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9204. #endif
  9205. #if 1
  9206. //LocalAuthListEnabled
  9207. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9211. #endif
  9212. //LocalAuthListMaxLength
  9213. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9217. //SendLocalListMaxLength
  9218. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9222. //ReserveConnectorZeroSupported
  9223. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9227. //* Smart Charging Profile */
  9228. //ChargeProfileMaxStackLevel
  9229. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9233. // ChargingScheduleAllowedChargingRateUnit
  9234. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9238. // ChargingScheduleMaxPeriods
  9239. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9243. // ConnectorSwitch3to1PhaseSupported
  9244. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9248. // MaxChargingProfilesInstalled
  9249. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9253. fclose(outfile);
  9254. }
  9255. else
  9256. {
  9257. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9258. char keystr[60]={0};
  9259. char readonlystr[10]={0};
  9260. char valuestr[100]={0};
  9261. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9262. if(fp == NULL) {
  9263. DEBUG_INFO("Error opening file");
  9264. return FALSE;
  9265. }
  9266. while( fgets (str, sizeof(str), fp)!=NULL )
  9267. {
  9268. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9269. //*************************key*********************************/
  9270. loc = strstr(str, "key");
  9271. c = 0;
  9272. memset(sstr ,0, sizeof(sstr) );
  9273. while (loc[strlen("key")+3+c] != '\"')
  9274. {
  9275. sstr[c] = loc[strlen("key")+3+c];
  9276. c++;
  9277. }
  9278. sstr[c] = '\0';
  9279. strcpy(keystr,sstr);
  9280. //*************************readonly*********************************/
  9281. loc = strstr(str, "readonly");
  9282. c = 0;
  9283. memset(sstr ,0, sizeof(sstr) );
  9284. while (loc[strlen("readonly")+2+c] != ',')
  9285. {
  9286. sstr[c] = loc[strlen("readonly")+2+c];
  9287. c++;
  9288. }
  9289. sstr[c] = '\0';
  9290. strcpy(readonlystr,sstr);
  9291. //*************************value*********************************/
  9292. loc = strstr(str, "value");
  9293. c = 0;
  9294. memset(sstr ,0, sizeof(sstr) );
  9295. while (loc[strlen("value")+3+c] != '\"')
  9296. {
  9297. sstr[c] = loc[strlen("value")+3+c];
  9298. c++;
  9299. }
  9300. sstr[c] = '\0';
  9301. strcpy(valuestr,sstr);
  9302. // DEBUG_INFO("keystr=%s\n",keystr);
  9303. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9304. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9305. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9306. {
  9307. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9308. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9310. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9311. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9312. }
  9313. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9314. {
  9315. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9316. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9318. }
  9319. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9320. {
  9321. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9323. }
  9324. if(strcmp(keystr, "BlinkRepeat") == 0)
  9325. {
  9326. //Charger.BlinkRepeat = Integer.parseInt(value);
  9327. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9329. }
  9330. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9331. {
  9332. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9334. }
  9335. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9336. {
  9337. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9339. }
  9340. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9341. {
  9342. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9344. }
  9345. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9346. {
  9347. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9349. HeartBeatWaitTime = atoi(valuestr);
  9350. }
  9351. if(strcmp(keystr, "LightIntensity") == 0)
  9352. {
  9353. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9355. }
  9356. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9357. {
  9358. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9360. }
  9361. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9362. {
  9363. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9365. }
  9366. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9367. {
  9368. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9370. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9371. }
  9372. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9373. {
  9374. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9376. }
  9377. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9378. {
  9379. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9380. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9381. }
  9382. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9383. {
  9384. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9386. }
  9387. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9388. {
  9389. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9391. }
  9392. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9393. {
  9394. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9396. }
  9397. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9398. {
  9399. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9401. }
  9402. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9403. {
  9404. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9406. }
  9407. if(strcmp(keystr, "ResetRetries") == 0)
  9408. {
  9409. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9411. }
  9412. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9413. {
  9414. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9416. }
  9417. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9418. {
  9419. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9421. }
  9422. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  9423. {
  9424. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  9426. }
  9427. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  9428. {
  9429. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  9431. }
  9432. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  9433. {
  9434. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  9436. }
  9437. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  9438. {
  9439. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9441. }
  9442. if(strcmp(keystr, "StopTxnSampledData") == 0)
  9443. {
  9444. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  9446. }
  9447. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  9448. {
  9449. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9451. }
  9452. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  9453. {
  9454. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  9456. }
  9457. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  9458. {
  9459. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  9461. }
  9462. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  9463. {
  9464. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  9466. TransactionMessageAttemptsValue = atoi(valuestr);
  9467. }
  9468. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  9469. {
  9470. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  9472. TransactionMessageRetryIntervalValue = atoi(valuestr);
  9473. }
  9474. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  9475. {
  9476. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  9478. }
  9479. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  9480. {
  9481. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  9483. }
  9484. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  9485. {
  9486. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  9488. }
  9489. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  9490. {
  9491. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  9493. }
  9494. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  9495. {
  9496. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  9498. }
  9499. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  9500. {
  9501. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  9503. }
  9504. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  9505. {
  9506. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  9508. }
  9509. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  9510. {
  9511. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  9513. }
  9514. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  9515. {
  9516. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  9518. }
  9519. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  9520. {
  9521. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  9523. }
  9524. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  9525. {
  9526. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  9528. }
  9529. }
  9530. fclose(fp);
  9531. }
  9532. return 0;
  9533. }
  9534. void StoreConfigurationTable(void)
  9535. {
  9536. FILE *outfile;
  9537. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9538. if(outfile == NULL)
  9539. {
  9540. DEBUG_INFO("Error opening file");
  9541. return ;
  9542. }
  9543. /*Core Profile*/
  9544. //AllowOfflineTxForUnknownId
  9545. /*
  9546. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9547. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9550. */
  9551. //DEBUG_INFO("data=%s\n",data);
  9552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9553. //AuthorizationCacheEnabled
  9554. /*
  9555. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9558. */
  9559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9560. //AuthorizeRemoteTxRequests
  9561. /*
  9562. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9565. */
  9566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9567. //BlinkRepeat
  9568. /*
  9569. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9572. */
  9573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9574. //ClockAlignedDataInterval
  9575. /*
  9576. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9579. */
  9580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9581. //ConnectionTimeOut
  9582. /*
  9583. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9586. */
  9587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9588. //GetConfigurationMaxKeys
  9589. /*
  9590. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9593. */
  9594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9595. // HeartbeatInterval
  9596. /*
  9597. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9600. */
  9601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9602. // LightIntensity
  9603. /*
  9604. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9607. */
  9608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9609. // LocalAuthorizeOffline
  9610. /*
  9611. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9614. */
  9615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9616. // LocalPreAuthorize
  9617. /*
  9618. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9621. */
  9622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9623. // MaxEnergyOnInvalidId
  9624. /*
  9625. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9628. */
  9629. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9631. // MeterValuesAlignedData
  9632. /*
  9633. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9636. */
  9637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9638. // MeterValuesAlignedDataMaxLength
  9639. /*
  9640. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9643. */
  9644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9645. // MeterValuesSampledData
  9646. /*
  9647. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9650. */
  9651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9652. // MeterValuesSampledDataMaxLength
  9653. /*
  9654. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9657. */
  9658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9659. // MeterValueSampleInterval
  9660. /*
  9661. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9664. */
  9665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9666. // MinimumStatusDuration
  9667. /*
  9668. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9671. */
  9672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9673. // NumberOfConnectors
  9674. /*
  9675. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9677. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9678. {
  9679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9680. }
  9681. else
  9682. {
  9683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9684. }
  9685. */
  9686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9687. // ResetRetries
  9688. /*
  9689. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9692. */
  9693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9694. // ConnectorPhaseRotation
  9695. /*
  9696. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9699. */
  9700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9701. // ConnectorPhaseRotationMaxLength
  9702. /*
  9703. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9706. */
  9707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9708. // StopTransactionOnEVSideDisconnect
  9709. /*
  9710. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9713. */
  9714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9715. // StopTransactionOnInvalidId
  9716. /*
  9717. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9720. */
  9721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9722. // StopTxnAlignedData
  9723. /*
  9724. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9727. */
  9728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9729. // StopTxnAlignedDataMaxLength
  9730. /*
  9731. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9734. */
  9735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9736. // StopTxnSampledData
  9737. /*
  9738. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9741. */
  9742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9743. // StopTxnSampledDataMaxLength
  9744. /*
  9745. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9748. */
  9749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9750. // SupportedFeatureProfiles
  9751. /*
  9752. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9755. */
  9756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  9757. // SupportedFeatureProfilesMaxLength
  9758. /*
  9759. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9762. */
  9763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  9764. // TransactionMessageAttempts
  9765. /*
  9766. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9769. */
  9770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9771. // TransactionMessageRetryInterval
  9772. /*
  9773. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9776. */
  9777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9778. // UnlockConnectorOnEVSideDisconnect
  9779. /*
  9780. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9783. */
  9784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  9785. // WebSocketPingInterval
  9786. /*
  9787. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9790. */
  9791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  9792. //* Local Auth List Management Profile*/
  9793. //LocalAuthListEnabled
  9794. /*
  9795. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9798. */
  9799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9800. //LocalAuthListMaxLength
  9801. /*
  9802. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9805. */
  9806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  9807. //SendLocalListMaxLength
  9808. /*
  9809. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9812. */
  9813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  9814. //ReserveConnectorZeroSupported
  9815. /*
  9816. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9819. */
  9820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9821. //* Smart Charging Profile */
  9822. //ChargeProfileMaxStackLevel
  9823. /*
  9824. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9827. */
  9828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9829. // ChargingScheduleAllowedChargingRateUnit
  9830. /*
  9831. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9834. */
  9835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9836. // ChargingScheduleMaxPeriods
  9837. /*
  9838. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9841. */
  9842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9843. // ConnectorSwitch3to1PhaseSupported
  9844. /*
  9845. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9848. */
  9849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9850. // MaxChargingProfilesInstalled
  9851. /*
  9852. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9855. */
  9856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9857. fclose(outfile);
  9858. }
  9859. void getKeyValue(char *keyReq)
  9860. {
  9861. int isEmpty = FALSE;
  9862. int isKnowKey = FALSE;
  9863. //int unKnowIndex = 0;
  9864. DEBUG_INFO("getKeyValue \n");
  9865. DEBUG_INFO("keyReq=%s \n",keyReq);
  9866. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9867. isEmpty = TRUE;
  9868. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9869. {
  9870. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  9871. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9874. {
  9875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9876. }
  9877. else
  9878. {
  9879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9880. }
  9881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9882. isKnowKey = TRUE;
  9883. }
  9884. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9885. {
  9886. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9889. {
  9890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9891. }
  9892. else
  9893. {
  9894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9895. }
  9896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9897. isKnowKey = TRUE;
  9898. }
  9899. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9900. {
  9901. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9904. {
  9905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9906. }
  9907. else
  9908. {
  9909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9910. }
  9911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9912. isKnowKey = TRUE;
  9913. }
  9914. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9915. {
  9916. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9919. {
  9920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9921. }
  9922. else
  9923. {
  9924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9925. }
  9926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9927. isKnowKey = TRUE;
  9928. }
  9929. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9930. {
  9931. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9934. {
  9935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9936. }
  9937. else
  9938. {
  9939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9940. }
  9941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9942. isKnowKey = TRUE;
  9943. }
  9944. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9945. {
  9946. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9949. {
  9950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9951. }
  9952. else
  9953. {
  9954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9955. }
  9956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9957. isKnowKey = TRUE;
  9958. }
  9959. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9960. {
  9961. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9964. {
  9965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9966. }
  9967. else
  9968. {
  9969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9970. }
  9971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9972. isKnowKey = TRUE;
  9973. }
  9974. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9975. {
  9976. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9979. {
  9980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9981. }
  9982. else
  9983. {
  9984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9985. }
  9986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9987. isKnowKey = TRUE;
  9988. }
  9989. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9990. {
  9991. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9994. {
  9995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9996. }
  9997. else
  9998. {
  9999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10000. }
  10001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10002. isKnowKey = TRUE;
  10003. }
  10004. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10005. {
  10006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10009. {
  10010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10011. }
  10012. else
  10013. {
  10014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10015. }
  10016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10017. isKnowKey = TRUE;
  10018. }
  10019. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10020. {
  10021. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10024. {
  10025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10026. }
  10027. else
  10028. {
  10029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10030. }
  10031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10032. isKnowKey = TRUE;
  10033. }
  10034. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10035. {
  10036. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10038. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10039. {
  10040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10041. }
  10042. else
  10043. {
  10044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10045. }
  10046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10047. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10048. isKnowKey = TRUE;
  10049. }
  10050. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10051. {
  10052. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10055. {
  10056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10057. }
  10058. else
  10059. {
  10060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10061. }
  10062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10063. isKnowKey = TRUE;
  10064. }
  10065. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10066. {
  10067. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10070. {
  10071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10072. }
  10073. else
  10074. {
  10075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10076. }
  10077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10078. isKnowKey = TRUE;
  10079. }
  10080. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10081. {
  10082. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10085. {
  10086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10087. }
  10088. else
  10089. {
  10090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10091. }
  10092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10093. isKnowKey = TRUE;
  10094. }
  10095. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10096. {
  10097. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10099. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10100. {
  10101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10102. }
  10103. else
  10104. {
  10105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10106. }
  10107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10108. isKnowKey = TRUE;
  10109. }
  10110. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10111. {
  10112. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10115. {
  10116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10117. }
  10118. else
  10119. {
  10120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10121. }
  10122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10123. isKnowKey = TRUE;
  10124. }
  10125. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10126. {
  10127. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10129. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10130. {
  10131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10132. }
  10133. else
  10134. {
  10135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10136. }
  10137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10138. isKnowKey = TRUE;
  10139. }
  10140. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10141. {
  10142. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10145. {
  10146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10147. }
  10148. else
  10149. {
  10150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10151. }
  10152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10153. isKnowKey = TRUE;
  10154. }
  10155. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10156. {
  10157. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10160. {
  10161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10162. }
  10163. else
  10164. {
  10165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10166. }
  10167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10168. isKnowKey = TRUE;
  10169. }
  10170. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10171. {
  10172. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10174. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10175. {
  10176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10177. }
  10178. else
  10179. {
  10180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10181. }
  10182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10183. isKnowKey = TRUE;
  10184. }
  10185. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10186. {
  10187. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10190. {
  10191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10192. }
  10193. else
  10194. {
  10195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10196. }
  10197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10198. isKnowKey = TRUE;
  10199. }
  10200. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10201. {
  10202. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10204. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10205. {
  10206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10207. }
  10208. else
  10209. {
  10210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10211. }
  10212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10213. isKnowKey = TRUE;
  10214. }
  10215. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10216. {
  10217. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10219. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10220. {
  10221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10222. }
  10223. else
  10224. {
  10225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10226. }
  10227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10228. isKnowKey = TRUE;
  10229. }
  10230. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10231. {
  10232. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10234. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10235. {
  10236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10237. }
  10238. else
  10239. {
  10240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10241. }
  10242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10243. isKnowKey = TRUE;
  10244. }
  10245. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10246. {
  10247. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10250. {
  10251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10252. }
  10253. else
  10254. {
  10255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10256. }
  10257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10258. isKnowKey = TRUE;
  10259. }
  10260. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10261. {
  10262. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10264. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10265. {
  10266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10267. }
  10268. else
  10269. {
  10270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10271. }
  10272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10273. isKnowKey = TRUE;
  10274. }
  10275. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10276. {
  10277. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10280. {
  10281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10282. }
  10283. else
  10284. {
  10285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10286. }
  10287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10288. isKnowKey = TRUE;
  10289. }
  10290. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10291. {
  10292. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10295. {
  10296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10297. }
  10298. else
  10299. {
  10300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10301. }
  10302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10303. isKnowKey = TRUE;
  10304. }
  10305. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10306. {
  10307. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10309. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10310. {
  10311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10312. }
  10313. else
  10314. {
  10315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10316. }
  10317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10318. isKnowKey = TRUE;
  10319. }
  10320. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10321. {
  10322. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10324. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10325. {
  10326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10327. }
  10328. else
  10329. {
  10330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10331. }
  10332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10333. isKnowKey = TRUE;
  10334. }
  10335. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10336. {
  10337. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10340. {
  10341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10342. }
  10343. else
  10344. {
  10345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10346. }
  10347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10348. isKnowKey = TRUE;
  10349. }
  10350. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10351. {
  10352. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10355. {
  10356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10357. }
  10358. else
  10359. {
  10360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10361. }
  10362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10363. isKnowKey = TRUE;
  10364. }
  10365. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10366. {
  10367. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10369. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10370. {
  10371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10372. }
  10373. else
  10374. {
  10375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10376. }
  10377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10378. isKnowKey = TRUE;
  10379. }
  10380. #if 0
  10381. //For OCTT Test Case
  10382. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10383. {
  10384. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10386. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10387. {
  10388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10389. }
  10390. else
  10391. {
  10392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10393. }
  10394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10395. isKnowKey = TRUE;
  10396. }
  10397. #endif
  10398. #if 1
  10399. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10400. {
  10401. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10403. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10404. {
  10405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10406. }
  10407. else
  10408. {
  10409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10410. }
  10411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10412. isKnowKey = TRUE;
  10413. }
  10414. #endif
  10415. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10416. {
  10417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10419. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10420. {
  10421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10422. }
  10423. else
  10424. {
  10425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10426. }
  10427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  10428. isKnowKey = TRUE;
  10429. }
  10430. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  10431. {
  10432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  10433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  10434. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  10435. {
  10436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10437. }
  10438. else
  10439. {
  10440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10441. }
  10442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  10443. isKnowKey = TRUE;
  10444. }
  10445. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  10446. {
  10447. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  10448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  10449. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  10450. {
  10451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  10452. }
  10453. else
  10454. {
  10455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  10456. }
  10457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10458. isKnowKey = TRUE;
  10459. }
  10460. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  10461. {
  10462. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  10463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  10464. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  10465. {
  10466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  10467. }
  10468. else
  10469. {
  10470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  10471. }
  10472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10473. isKnowKey = TRUE;
  10474. }
  10475. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  10476. {
  10477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  10478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  10479. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  10480. {
  10481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  10482. }
  10483. else
  10484. {
  10485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  10486. }
  10487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10488. isKnowKey = TRUE;
  10489. }
  10490. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  10491. {
  10492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  10493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  10494. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  10495. {
  10496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  10497. }
  10498. else
  10499. {
  10500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  10501. }
  10502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10503. isKnowKey = TRUE;
  10504. }
  10505. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  10506. {
  10507. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  10508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  10509. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  10510. {
  10511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  10512. }
  10513. else
  10514. {
  10515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  10516. }
  10517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10518. isKnowKey = TRUE;
  10519. }
  10520. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  10521. {
  10522. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  10523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  10524. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  10525. {
  10526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  10527. }
  10528. else
  10529. {
  10530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  10531. }
  10532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10533. isKnowKey = TRUE;
  10534. }
  10535. //=========================================================
  10536. if(!isEmpty && !isKnowKey)
  10537. {
  10538. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  10539. strcpy(unknownkey[UnknownKeynum], keyReq);
  10540. UnknownKeynum = UnknownKeynum + 1;
  10541. }
  10542. }
  10543. void processUnkownKey(void)
  10544. {
  10545. DEBUG_INFO("processUnkownKey\n");
  10546. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  10547. for(int index=0; index < UnknownKeynum; index++)
  10548. {
  10549. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  10550. {
  10551. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  10552. }
  10553. }
  10554. }
  10555. int setKeyValue(char *key, char *value)
  10556. {
  10557. int isSuccess = NotSupported;
  10558. int check_ascii=0;
  10559. char str[10]={0};
  10560. #ifdef Debug
  10561. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  10562. #endif
  10563. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  10564. {
  10565. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10566. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10567. {
  10568. strcpy(str, (const char*)value);
  10569. for(int i = 0; str[i]; i++){
  10570. str[i] = tolower(str[i]);
  10571. }
  10572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10573. isSuccess = ConfigurationStatus_Accepted;
  10574. }
  10575. else
  10576. {
  10577. isSuccess = ConfigurationStatus_Rejected;
  10578. }
  10579. }
  10580. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  10581. {
  10582. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10584. {
  10585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  10586. isSuccess = ConfigurationStatus_Accepted;
  10587. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  10588. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  10589. }
  10590. else
  10591. {
  10592. isSuccess = ConfigurationStatus_Rejected;
  10593. }
  10594. }
  10595. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  10596. {
  10597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10598. {
  10599. strcpy(str, (const char*)value);
  10600. for(int i = 0; str[i]; i++)
  10601. {
  10602. str[i] = tolower(str[i]);
  10603. }
  10604. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  10605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10606. isSuccess = ConfigurationStatus_Accepted;
  10607. }
  10608. else
  10609. {
  10610. isSuccess = ConfigurationStatus_Rejected;
  10611. }
  10612. }
  10613. if(strcmp(key, "BlinkRepeat") == 0)
  10614. {
  10615. //Charger.BlinkRepeat = Integer.parseInt(value);
  10616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10617. {
  10618. check_ascii = value[0];
  10619. if( (check_ascii < 48) || (check_ascii > 57) )
  10620. {
  10621. isSuccess = ConfigurationStatus_Rejected;
  10622. }
  10623. else
  10624. {
  10625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  10626. isSuccess = ConfigurationStatus_Accepted;
  10627. }
  10628. }
  10629. else
  10630. {
  10631. isSuccess = ConfigurationStatus_Rejected;
  10632. }
  10633. }
  10634. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  10635. {
  10636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10637. {
  10638. check_ascii = value[0];
  10639. if( (check_ascii < 48) || (check_ascii > 57) )
  10640. {
  10641. isSuccess = ConfigurationStatus_Rejected;
  10642. }
  10643. else
  10644. {
  10645. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  10646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  10647. isSuccess = ConfigurationStatus_Accepted;
  10648. }
  10649. }
  10650. else
  10651. {
  10652. isSuccess = ConfigurationStatus_Rejected;
  10653. }
  10654. }
  10655. if(strcmp(key, "ConnectionTimeOut") == 0 )
  10656. {
  10657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10658. {
  10659. check_ascii = value[0];
  10660. if( (check_ascii < 48) || (check_ascii > 57) )
  10661. {
  10662. isSuccess = ConfigurationStatus_Rejected;
  10663. }
  10664. else
  10665. {
  10666. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  10667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  10668. isSuccess = ConfigurationStatus_Accepted;
  10669. }
  10670. }
  10671. else
  10672. {
  10673. isSuccess = ConfigurationStatus_Rejected;
  10674. }
  10675. }
  10676. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  10677. {
  10678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10679. {
  10680. check_ascii = value[0];
  10681. if( (check_ascii < 48) || (check_ascii > 57) )
  10682. {
  10683. isSuccess = ConfigurationStatus_Rejected;
  10684. }
  10685. else
  10686. {
  10687. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  10689. isSuccess = ConfigurationStatus_Accepted;
  10690. }
  10691. }
  10692. else
  10693. {
  10694. isSuccess = ConfigurationStatus_Rejected;
  10695. }
  10696. }
  10697. if(strcmp(key, "HeartbeatInterval") == 0)
  10698. {
  10699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10700. {
  10701. check_ascii = value[0];
  10702. if( (check_ascii < 48) || (check_ascii > 57) )
  10703. {
  10704. isSuccess = ConfigurationStatus_Rejected;
  10705. }
  10706. else
  10707. {
  10708. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  10710. HeartBeatWaitTime = atoi(value);
  10711. isSuccess = ConfigurationStatus_Accepted;
  10712. }
  10713. }
  10714. else
  10715. {
  10716. isSuccess = ConfigurationStatus_Rejected;
  10717. }
  10718. }
  10719. if(strcmp(key, "LightIntensity") == 0)
  10720. {
  10721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10722. {
  10723. check_ascii = value[0];
  10724. if( (check_ascii < 48) || (check_ascii > 57) )
  10725. {
  10726. isSuccess = ConfigurationStatus_Rejected;
  10727. }
  10728. else
  10729. {
  10730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10731. isSuccess = ConfigurationStatus_Accepted;
  10732. }
  10733. }
  10734. else
  10735. {
  10736. isSuccess = ConfigurationStatus_Rejected;
  10737. }
  10738. }
  10739. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10740. {
  10741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10742. {
  10743. strcpy(str, (const char*)value);
  10744. for(int i = 0; str[i]; i++)
  10745. {
  10746. str[i] = tolower(str[i]);
  10747. }
  10748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10749. isSuccess = ConfigurationStatus_Accepted;
  10750. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10751. }
  10752. else
  10753. {
  10754. isSuccess = ConfigurationStatus_Rejected;
  10755. }
  10756. }
  10757. if(strcmp(key, "LocalPreAuthorize") == 0)
  10758. {
  10759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10760. {
  10761. strcpy(str, (const char*)value);
  10762. for(int i = 0; str[i]; i++)
  10763. {
  10764. str[i] = tolower(str[i]);
  10765. }
  10766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10767. isSuccess = ConfigurationStatus_Accepted;
  10768. }
  10769. else
  10770. {
  10771. isSuccess = ConfigurationStatus_Rejected;
  10772. }
  10773. }
  10774. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10775. {
  10776. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10777. {
  10778. check_ascii = value[0];
  10779. if( (check_ascii < 48) || (check_ascii > 57) )
  10780. {
  10781. isSuccess = ConfigurationStatus_Rejected;
  10782. }
  10783. else
  10784. {
  10785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10786. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  10787. isSuccess = ConfigurationStatus_Accepted;
  10788. }
  10789. }
  10790. else
  10791. {
  10792. isSuccess = ConfigurationStatus_Rejected;
  10793. }
  10794. }
  10795. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10796. {
  10797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10798. {
  10799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10800. isSuccess = ConfigurationStatus_Accepted;
  10801. }
  10802. else
  10803. {
  10804. isSuccess = ConfigurationStatus_Rejected;
  10805. }
  10806. }
  10807. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  10808. {
  10809. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10810. {
  10811. check_ascii = value[0];
  10812. if( (check_ascii < 48) || (check_ascii > 57) )
  10813. {
  10814. isSuccess = ConfigurationStatus_Rejected;
  10815. }
  10816. else
  10817. {
  10818. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  10820. isSuccess = ConfigurationStatus_Accepted;
  10821. }
  10822. }
  10823. else
  10824. {
  10825. isSuccess = ConfigurationStatus_Rejected;
  10826. }
  10827. }
  10828. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10829. {
  10830. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10831. {
  10832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10833. isSuccess = ConfigurationStatus_Accepted;
  10834. }
  10835. else
  10836. {
  10837. isSuccess = ConfigurationStatus_Rejected;
  10838. }
  10839. }
  10840. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  10841. {
  10842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10843. {
  10844. check_ascii = value[0];
  10845. if( (check_ascii < 48) || (check_ascii > 57) )
  10846. {
  10847. isSuccess = ConfigurationStatus_Rejected;
  10848. }
  10849. else
  10850. {
  10851. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  10853. isSuccess = ConfigurationStatus_Accepted;
  10854. }
  10855. }
  10856. else
  10857. {
  10858. isSuccess = ConfigurationStatus_Rejected;
  10859. }
  10860. }
  10861. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10862. {
  10863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10864. {
  10865. check_ascii = value[0];
  10866. if( (check_ascii < 48) || (check_ascii > 57) )
  10867. {
  10868. isSuccess = ConfigurationStatus_Rejected;
  10869. }
  10870. else
  10871. {
  10872. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10874. isSuccess = ConfigurationStatus_Accepted;
  10875. }
  10876. }
  10877. else
  10878. {
  10879. isSuccess = ConfigurationStatus_Rejected;
  10880. }
  10881. }
  10882. if(strcmp(key, "MinimumStatusDuration") == 0)
  10883. {
  10884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10885. {
  10886. check_ascii = value[0];
  10887. if( (check_ascii < 48) || (check_ascii > 57) )
  10888. {
  10889. isSuccess = ConfigurationStatus_Rejected;
  10890. }
  10891. else
  10892. {
  10893. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10895. isSuccess = ConfigurationStatus_Accepted;
  10896. }
  10897. }
  10898. else
  10899. {
  10900. isSuccess = ConfigurationStatus_Rejected;
  10901. }
  10902. }
  10903. if(strcmp(key, "NumberOfConnectors") == 0)
  10904. {
  10905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10906. {
  10907. check_ascii = value[0];
  10908. if( (check_ascii < 48) || (check_ascii > 57) )
  10909. {
  10910. isSuccess = ConfigurationStatus_Rejected;
  10911. }
  10912. else
  10913. {
  10914. //Charger.ResetRetries = Integer.parseInt(value);
  10915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  10916. isSuccess = ConfigurationStatus_Accepted;
  10917. }
  10918. }
  10919. else
  10920. {
  10921. isSuccess = ConfigurationStatus_Rejected;
  10922. }
  10923. }
  10924. if(strcmp(key, "ResetRetries") == 0)
  10925. {
  10926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10927. {
  10928. check_ascii = value[0];
  10929. if( (check_ascii < 48) || (check_ascii > 57) )
  10930. {
  10931. isSuccess = ConfigurationStatus_Rejected;
  10932. }
  10933. else
  10934. {
  10935. //Charger.ResetRetries = Integer.parseInt(value);
  10936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10937. isSuccess = ConfigurationStatus_Accepted;
  10938. }
  10939. }
  10940. else
  10941. {
  10942. isSuccess = ConfigurationStatus_Rejected;
  10943. }
  10944. }
  10945. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10946. {
  10947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10948. {
  10949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10950. isSuccess = ConfigurationStatus_Accepted;
  10951. }
  10952. else
  10953. {
  10954. isSuccess = ConfigurationStatus_Rejected;
  10955. }
  10956. }
  10957. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  10958. {
  10959. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10960. {
  10961. check_ascii = value[0];
  10962. if( (check_ascii < 48) || (check_ascii > 57) )
  10963. {
  10964. isSuccess = ConfigurationStatus_Rejected;
  10965. }
  10966. else
  10967. {
  10968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  10969. isSuccess = ConfigurationStatus_Accepted;
  10970. }
  10971. }
  10972. else
  10973. {
  10974. isSuccess = ConfigurationStatus_Rejected;
  10975. }
  10976. }
  10977. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10978. {
  10979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10980. {
  10981. strcpy(str, (const char*)value);
  10982. for(int i = 0; str[i]; i++)
  10983. {
  10984. str[i] = tolower(str[i]);
  10985. }
  10986. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10988. isSuccess = ConfigurationStatus_Accepted;
  10989. }
  10990. else
  10991. {
  10992. isSuccess = ConfigurationStatus_Rejected;
  10993. }
  10994. }
  10995. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10996. {
  10997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10998. {
  10999. strcpy(str, (const char*)value);
  11000. for(int i = 0; str[i]; i++)
  11001. {
  11002. str[i] = tolower(str[i]);
  11003. }
  11004. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11006. isSuccess = ConfigurationStatus_Accepted;
  11007. }
  11008. else
  11009. {
  11010. isSuccess = ConfigurationStatus_Rejected;
  11011. }
  11012. }
  11013. if(strcmp(key, "StopTxnAlignedData") == 0)
  11014. {
  11015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11016. {
  11017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11018. isSuccess = ConfigurationStatus_Accepted;
  11019. }
  11020. else
  11021. {
  11022. isSuccess = ConfigurationStatus_Rejected;
  11023. }
  11024. }
  11025. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11026. {
  11027. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11028. {
  11029. check_ascii = value[0];
  11030. if( (check_ascii < 48) || (check_ascii > 57) )
  11031. {
  11032. isSuccess = ConfigurationStatus_Rejected;
  11033. }
  11034. else
  11035. {
  11036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11037. isSuccess = ConfigurationStatus_Accepted;
  11038. }
  11039. }
  11040. else
  11041. {
  11042. isSuccess = ConfigurationStatus_Rejected;
  11043. }
  11044. }
  11045. if(strcmp(key, "StopTxnSampledData") == 0)
  11046. {
  11047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11048. {
  11049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11050. isSuccess = ConfigurationStatus_Accepted;
  11051. }
  11052. else
  11053. {
  11054. isSuccess = ConfigurationStatus_Rejected;
  11055. }
  11056. }
  11057. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11058. {
  11059. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11060. {
  11061. check_ascii = value[0];
  11062. if( (check_ascii < 48) || (check_ascii > 57) )
  11063. {
  11064. isSuccess = ConfigurationStatus_Rejected;
  11065. }
  11066. else
  11067. {
  11068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11069. isSuccess = ConfigurationStatus_Accepted;
  11070. }
  11071. }
  11072. else
  11073. {
  11074. isSuccess = ConfigurationStatus_Rejected;
  11075. }
  11076. }
  11077. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11078. {
  11079. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11080. {
  11081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11082. isSuccess = ConfigurationStatus_Accepted;
  11083. }
  11084. else
  11085. {
  11086. isSuccess = ConfigurationStatus_Rejected;
  11087. }
  11088. }
  11089. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11090. {
  11091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11092. {
  11093. check_ascii = value[0];
  11094. if( (check_ascii < 48) || (check_ascii > 57) )
  11095. {
  11096. isSuccess = ConfigurationStatus_Rejected;
  11097. }
  11098. else
  11099. {
  11100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11101. isSuccess = ConfigurationStatus_Accepted;
  11102. }
  11103. }
  11104. else
  11105. {
  11106. isSuccess = ConfigurationStatus_Rejected;
  11107. }
  11108. }
  11109. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11110. {
  11111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11112. {
  11113. check_ascii = value[0];
  11114. if( (check_ascii < 48) || (check_ascii > 57) )
  11115. {
  11116. isSuccess = ConfigurationStatus_Rejected;
  11117. }
  11118. else
  11119. {
  11120. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11122. TransactionMessageAttemptsValue = atoi(value);
  11123. isSuccess = ConfigurationStatus_Accepted;
  11124. }
  11125. }
  11126. else
  11127. {
  11128. isSuccess = ConfigurationStatus_Rejected;
  11129. }
  11130. }
  11131. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11132. {
  11133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11134. {
  11135. check_ascii = value[0];
  11136. if( (check_ascii < 48) || (check_ascii > 57) )
  11137. {
  11138. isSuccess = ConfigurationStatus_Rejected;
  11139. }
  11140. else
  11141. {
  11142. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11144. TransactionMessageRetryIntervalValue = atoi(value);
  11145. isSuccess = ConfigurationStatus_Accepted;
  11146. }
  11147. }
  11148. else
  11149. {
  11150. isSuccess = ConfigurationStatus_Rejected;
  11151. }
  11152. }
  11153. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11154. {
  11155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11156. {
  11157. strcpy(str, (const char*)value);
  11158. for(int i = 0; str[i]; i++)
  11159. {
  11160. str[i] = tolower(str[i]);
  11161. }
  11162. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11164. isSuccess = ConfigurationStatus_Accepted;
  11165. }
  11166. else
  11167. {
  11168. isSuccess = ConfigurationStatus_Rejected;
  11169. }
  11170. }
  11171. if(strcmp(key, "WebSocketPingInterval") == 0)
  11172. {
  11173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11174. {
  11175. check_ascii = value[0];
  11176. if( (check_ascii < 48) || (check_ascii > 57) )
  11177. {
  11178. isSuccess = ConfigurationStatus_Rejected;
  11179. }
  11180. else
  11181. {
  11182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11183. isSuccess = ConfigurationStatus_Accepted;
  11184. }
  11185. }
  11186. else
  11187. {
  11188. isSuccess = ConfigurationStatus_Rejected;
  11189. }
  11190. }
  11191. #if 0
  11192. //For OCPP Test Case
  11193. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11194. {
  11195. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11196. {
  11197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11198. isSuccess = ConfigurationStatus_Accepted;
  11199. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11200. }
  11201. else
  11202. {
  11203. isSuccess = ConfigurationStatus_Rejected;
  11204. }
  11205. }
  11206. #endif
  11207. #if 1
  11208. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11209. {
  11210. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11211. {
  11212. strcpy(str, (const char*)value);
  11213. for(int i = 0; str[i]; i++)
  11214. {
  11215. str[i] = tolower(str[i]);
  11216. }
  11217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11218. isSuccess = ConfigurationStatus_Accepted;
  11219. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11220. }
  11221. else
  11222. {
  11223. isSuccess = ConfigurationStatus_Rejected;
  11224. }
  11225. }
  11226. #endif
  11227. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11228. {
  11229. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11230. {
  11231. check_ascii = value[0];
  11232. if( (check_ascii < 48) || (check_ascii > 57) )
  11233. {
  11234. isSuccess = ConfigurationStatus_Rejected;
  11235. }
  11236. else
  11237. {
  11238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11239. isSuccess = ConfigurationStatus_Accepted;
  11240. }
  11241. }
  11242. else
  11243. {
  11244. isSuccess = ConfigurationStatus_Rejected;
  11245. }
  11246. }
  11247. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11248. {
  11249. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11250. {
  11251. check_ascii = value[0];
  11252. if( (check_ascii < 48) || (check_ascii > 57) )
  11253. {
  11254. isSuccess = ConfigurationStatus_Rejected;
  11255. }
  11256. else
  11257. {
  11258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11259. isSuccess = ConfigurationStatus_Accepted;
  11260. }
  11261. }
  11262. else
  11263. {
  11264. isSuccess = ConfigurationStatus_Rejected;
  11265. }
  11266. }
  11267. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11268. {
  11269. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11270. {
  11271. strcpy(str, (const char*)value);
  11272. for(int i = 0; str[i]; i++)
  11273. {
  11274. str[i] = tolower(str[i]);
  11275. }
  11276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11277. isSuccess = ConfigurationStatus_Accepted;
  11278. }
  11279. else
  11280. {
  11281. isSuccess = ConfigurationStatus_Rejected;
  11282. }
  11283. }
  11284. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11285. {
  11286. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11287. {
  11288. check_ascii = value[0];
  11289. if( (check_ascii < 48) || (check_ascii > 57) )
  11290. {
  11291. isSuccess = ConfigurationStatus_Rejected;
  11292. }
  11293. else
  11294. {
  11295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11296. isSuccess = ConfigurationStatus_Accepted;
  11297. }
  11298. }
  11299. else
  11300. {
  11301. isSuccess = ConfigurationStatus_Rejected;
  11302. }
  11303. }
  11304. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11305. {
  11306. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11307. {
  11308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11309. isSuccess = ConfigurationStatus_Accepted;
  11310. }
  11311. else
  11312. {
  11313. isSuccess = ConfigurationStatus_Rejected;
  11314. }
  11315. }
  11316. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11317. {
  11318. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11319. {
  11320. check_ascii = value[0];
  11321. if( (check_ascii < 48) || (check_ascii > 57) )
  11322. {
  11323. isSuccess = ConfigurationStatus_Rejected;
  11324. }
  11325. else
  11326. {
  11327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11328. isSuccess = ConfigurationStatus_Accepted;
  11329. }
  11330. }
  11331. else
  11332. {
  11333. isSuccess = ConfigurationStatus_Rejected;
  11334. }
  11335. }
  11336. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11337. {
  11338. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11339. {
  11340. strcpy(str, (const char*)value);
  11341. for(int i = 0; str[i]; i++)
  11342. {
  11343. str[i] = tolower(str[i]);
  11344. }
  11345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11346. isSuccess = ConfigurationStatus_Accepted;
  11347. }
  11348. else
  11349. {
  11350. isSuccess = ConfigurationStatus_Rejected;
  11351. }
  11352. }
  11353. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11354. {
  11355. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11356. {
  11357. check_ascii = value[0];
  11358. if( (check_ascii < 48) || (check_ascii > 57) )
  11359. {
  11360. isSuccess = ConfigurationStatus_Rejected;
  11361. }
  11362. else
  11363. {
  11364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11365. isSuccess = ConfigurationStatus_Accepted;
  11366. }
  11367. }
  11368. else
  11369. {
  11370. isSuccess = ConfigurationStatus_Rejected;
  11371. }
  11372. }
  11373. return isSuccess;
  11374. }
  11375. int updateSetting(char *key, char *value)
  11376. {
  11377. mtrace();
  11378. int isSuccess = FALSE;
  11379. char string[1000]={0}, buffer[1000]={0};
  11380. char strtemp[50]={0};
  11381. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11382. int pos, c = 0;
  11383. char *loc;
  11384. int pos1=0;
  11385. FILE *f = fopen("/var/www/settings1", "r");
  11386. if(f == NULL)
  11387. {
  11388. #ifdef Debug
  11389. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11390. #endif
  11391. return isSuccess;
  11392. }
  11393. fseek(f, 0, SEEK_END);
  11394. long fsize = ftell(f);
  11395. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11396. fread(string, 1, fsize, f);
  11397. fclose(f);
  11398. string[fsize] = 0;
  11399. loc = strstr(string, key);
  11400. if(loc != NULL)
  11401. {
  11402. DEBUG_INFO("key exist!\n");
  11403. pos = loc - string-1;
  11404. f = fopen("/var/www/settings1", "w");
  11405. strncpy(buffer, string, pos);
  11406. fprintf(f, "%s", buffer);
  11407. memset(sstr ,0, sizeof(sstr) );
  11408. c = 0;
  11409. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11410. {
  11411. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11412. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11413. c++;
  11414. }
  11415. sstr[c] = '\0';
  11416. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11417. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11418. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11419. memset(buffer ,0, sizeof(buffer) );
  11420. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11421. //printf("buffer=%s",buffer);
  11422. fprintf(f, "%s", buffer);
  11423. fclose(f);
  11424. }
  11425. else
  11426. {
  11427. printf("key not exist!\n");
  11428. f = fopen("/var/www/settings1", "w+");
  11429. fputs(string, f);
  11430. fseek(f, -1, SEEK_CUR);
  11431. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  11432. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  11433. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  11434. fclose(f);
  11435. }
  11436. isSuccess = TRUE;
  11437. return isSuccess;
  11438. }
  11439. int TransactionMessageAttemptsGet(void)
  11440. {
  11441. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11442. }
  11443. int FirstHeartBeatResponse(void)
  11444. {
  11445. return FirstHeartBeat;
  11446. }
  11447. int TransactionMessageRetryIntervalGet(void)
  11448. {
  11449. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11450. }
  11451. #define SA struct sockaddr
  11452. #define MAXBUF 1024
  11453. //static int m_socket_data;
  11454. //static int sockfd;
  11455. int ReadHttpStatus(int sock){
  11456. //char c;
  11457. char buff[1024]="",*ptr=buff+1;
  11458. int bytes_received, status;
  11459. DEBUG_INFO("Begin Response ..\n");
  11460. while((bytes_received = recv(sock, ptr, 1, 0))){
  11461. if(bytes_received==-1){
  11462. perror("ReadHttpStatus");
  11463. exit(1);
  11464. }
  11465. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  11466. ptr++;
  11467. }
  11468. *ptr=0;
  11469. ptr=buff+1;
  11470. sscanf(ptr,"%*s %d ", &status);
  11471. DEBUG_INFO("%s\n",ptr);
  11472. DEBUG_INFO("status=%d\n",status);
  11473. DEBUG_INFO("End Response ..\n");
  11474. return (bytes_received>0)?status:0;
  11475. }
  11476. //the only filed that it parsed is 'Content-Length'
  11477. int ParseHeader(int sock){
  11478. //char c;
  11479. char buff[1024]="",*ptr=buff+4;
  11480. int bytes_received;
  11481. DEBUG_INFO("Begin HEADER ..\n");
  11482. while((bytes_received = recv(sock, ptr, 1, 0))){
  11483. if(bytes_received==-1){
  11484. perror("Parse Header");
  11485. exit(1);
  11486. }
  11487. if(
  11488. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  11489. (ptr[-1]=='\r') && (*ptr=='\n' )
  11490. ) break;
  11491. ptr++;
  11492. }
  11493. *ptr=0;
  11494. ptr=buff+4;
  11495. //printf("%s",ptr);
  11496. if(bytes_received){
  11497. ptr=strstr(ptr,"Content-Length:");
  11498. if(ptr){
  11499. sscanf(ptr,"%*s %d",&bytes_received);
  11500. }else
  11501. bytes_received=-1; //unknown size
  11502. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  11503. }
  11504. DEBUG_INFO("End HEADER ..\n");
  11505. return bytes_received ;
  11506. }
  11507. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  11508. {
  11509. char rmFileCmd[100]={0};
  11510. char FilePath[100]={0};
  11511. char ftpbuf[200];
  11512. int systemresult;
  11513. //DEBUG_INFO("filename=%s\n",filename);
  11514. //DEBUG_INFO("url=%s\n",url);
  11515. sprintf(FilePath,"../mnt/%s",filename);
  11516. if((access(FilePath,F_OK))!=-1)
  11517. {
  11518. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11519. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11520. system(rmFileCmd);
  11521. }
  11522. memset(ftpbuf, 0, sizeof(ftpbuf));
  11523. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11524. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11525. systemresult = system(ftpbuf);
  11526. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11527. if(systemresult != 0)
  11528. {
  11529. DEBUG_INFO("http DownLoad error!\n");
  11530. return FALSE;
  11531. }
  11532. return TRUE;
  11533. }
  11534. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  11535. {
  11536. char rmFileCmd[100]={0};
  11537. char FilePath[100]={0};
  11538. char ftpbuf[200];
  11539. int systemresult;
  11540. //char temp[100];
  11541. #if 0
  11542. struct hostent* server;
  11543. char *IPbuffer;
  11544. server = gethostbyname(location);
  11545. // To convert an Internet network
  11546. // address into ASCII string
  11547. IPbuffer = inet_ntoa(*((struct in_addr*)
  11548. server->h_addr_list[0]));
  11549. #endif
  11550. sprintf(FilePath,"../mnt/%s",filename);
  11551. if((access(FilePath,F_OK))!=-1)
  11552. {
  11553. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11554. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11555. system(rmFileCmd);
  11556. }
  11557. memset(ftpbuf, 0, sizeof(ftpbuf));
  11558. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11559. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  11560. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11561. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11562. systemresult = system(ftpbuf);
  11563. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11564. if(systemresult != 0)
  11565. {
  11566. printf("wget error!\n");
  11567. return FALSE;
  11568. }
  11569. return TRUE;
  11570. }
  11571. int httpUploadFile(char *location, char *path, char *filename,char *url)
  11572. {
  11573. char rmFileCmd[100]={0};
  11574. char FilePath[100]={0};
  11575. char ftpbuf[200];
  11576. char filenametemp[60]={0};
  11577. int systemresult;
  11578. //DEBUG_INFO("filename=%s\n",filename);
  11579. //DEBUG_INFO("url=%s\n",url);
  11580. sprintf(FilePath,"%s","../mnt/upload_file.txt");
  11581. if((access(FilePath,F_OK))!=-1)
  11582. {
  11583. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11584. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11585. system(rmFileCmd);
  11586. }
  11587. FILE *fp = fopen("../mnt/upload_file.txt", "w+");
  11588. if(fp == NULL)
  11589. {
  11590. DEBUG_INFO("log is NULL\n");
  11591. return FALSE;
  11592. }
  11593. else
  11594. {
  11595. fprintf(fp, "%s\n", url);
  11596. sscanf(filename, "%*2[.]%s", filenametemp);
  11597. fprintf(fp, "%s\n", filenametemp);
  11598. fclose(fp);
  11599. }
  11600. memset(ftpbuf, 0, sizeof(ftpbuf));
  11601. sprintf(ftpbuf, "%s","../bin/php-cgi /var/www/ocpp_upload.php");
  11602. systemresult = system(ftpbuf);
  11603. DEBUG_INFO("systemresult=%d\n",systemresult);
  11604. if(systemresult != 0)
  11605. {
  11606. DEBUG_INFO("http upload error!\n");
  11607. return FALSE;
  11608. }
  11609. return TRUE;
  11610. }
  11611. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  11612. {
  11613. struct hostent* server;
  11614. char *IPbuffer;
  11615. char ftpbuf[200];
  11616. int systemresult;
  11617. // To retrieve host information
  11618. server = gethostbyname(location);
  11619. // To convert an Internet network
  11620. // address into ASCII string
  11621. IPbuffer = inet_ntoa(*((struct in_addr*)
  11622. server->h_addr_list[0]));
  11623. memset(ftpbuf, 0, sizeof(ftpbuf));
  11624. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  11625. /* format : ftpput -u username -p passwd IP target source*/
  11626. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  11627. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11628. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11629. systemresult = system(ftpbuf);
  11630. DEBUG_INFO("systemresult=%d\n",systemresult);
  11631. if(systemresult != 0)
  11632. {
  11633. DEBUG_INFO("ftpput error!\n");
  11634. return FALSE;
  11635. }
  11636. return TRUE;
  11637. }
  11638. int SettingChargingRecord(int target, int transactionId)
  11639. {
  11640. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11641. {
  11642. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11643. {
  11644. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11645. {
  11646. addBuff(target, transactionId, 0);
  11647. return TRUE;
  11648. }
  11649. }
  11650. for (int index = 0; index < CCS_QUANTITY; index++)
  11651. {
  11652. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11653. {
  11654. addBuff(target, transactionId, 0);
  11655. return TRUE;
  11656. }
  11657. }
  11658. for (int index = 0; index < GB_QUANTITY; index++)
  11659. {
  11660. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11661. {
  11662. addBuff(target, transactionId, 0);
  11663. return TRUE;
  11664. }
  11665. }
  11666. }
  11667. else
  11668. {
  11669. for (int index = 0; index < AC_QUANTITY; index++)
  11670. {
  11671. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11672. {
  11673. addBuff(target, transactionId, 0);
  11674. return TRUE;
  11675. }
  11676. }
  11677. }
  11678. return FALSE;
  11679. }
  11680. int addBuff(int gun_idx, int user_id, int cmd_sn)
  11681. {
  11682. int isSuccess = FALSE;
  11683. //char *query = NULL;
  11684. sqlite3_stmt *stmt;
  11685. int rc; // return code
  11686. char str[20];
  11687. sprintf(str,"%d",user_id);
  11688. 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 */
  11689. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  11690. rc = sqlite3_step(stmt); /* 3 */
  11691. if (rc != SQLITE_DONE) {
  11692. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  11693. goto out;
  11694. }
  11695. sqlite3_finalize(stmt);
  11696. // free(query);
  11697. out:
  11698. //----------------------
  11699. // close SQLite database
  11700. //----------------------
  11701. sqlite3_close(db);
  11702. printf("database closed.\n");
  11703. return isSuccess;
  11704. }
  11705. /**
  11706. * Place the contents of the specified file into a memory buffer
  11707. *
  11708. * @param[in] filename The path and name of the file to read
  11709. * @param[out] filebuffer A pointer to the contents in memory
  11710. * @return status 0 success, 1 on failure
  11711. */
  11712. int get_file_contents(const char* filename, char** outbuffer) {
  11713. FILE* file = NULL;
  11714. long filesize;
  11715. const int blocksize = 1;
  11716. size_t readsize;
  11717. char* filebuffer;
  11718. // Open the file
  11719. file = fopen(filename, "r");
  11720. if (NULL == file)
  11721. {
  11722. printf("'%s' not opened\n", filename);
  11723. exit(EXIT_FAILURE);
  11724. }
  11725. // Determine the file size
  11726. fseek(file, 0, SEEK_END);
  11727. filesize = ftell(file);
  11728. rewind (file);
  11729. // Allocate memory for the file contents
  11730. filebuffer = (char*) malloc(sizeof(char) * filesize);
  11731. *outbuffer = filebuffer;
  11732. if (filebuffer == NULL)
  11733. {
  11734. fputs ("malloc out-of-memory", stderr);
  11735. exit(EXIT_FAILURE);
  11736. }
  11737. // Read in the file
  11738. readsize = fread(filebuffer, blocksize, filesize, file);
  11739. if (readsize != filesize)
  11740. {
  11741. fputs ("didn't read file completely",stderr);
  11742. exit(EXIT_FAILURE);
  11743. }
  11744. // Clean exit
  11745. fclose(file);
  11746. return EXIT_SUCCESS;
  11747. }
  11748. static int selectSqlCount = 0;
  11749. static int callback(void *data, int argc, char **argv, char **azColName){
  11750. int i;
  11751. printf("%s: ", (const char*)data);
  11752. selectSqlCount = argc;
  11753. for(i = 0; i<argc; i++){
  11754. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  11755. }
  11756. printf("\n");
  11757. return 0;
  11758. }
  11759. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  11760. //int i;
  11761. //printf("%s:\n", (const char*)data);
  11762. localversion = argv[5] ? atoi(argv[5]) : 0;
  11763. printf("localversion=%d\n", localversion);
  11764. return 0;
  11765. }
  11766. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  11767. //int i;
  11768. //printf("%s:\n", (const char*)data);
  11769. //idTag
  11770. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  11771. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  11772. //parentIdTag
  11773. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  11774. //expir_date
  11775. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  11776. //status
  11777. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  11778. //version
  11779. idTagQuery.listVersionInt = atoi(argv[5]);
  11780. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  11781. return 0;
  11782. }
  11783. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  11784. int i;
  11785. //printf("%s:\n", (const char*)data);
  11786. #if 1
  11787. for(i=0; i<argc; i++){
  11788. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  11789. }
  11790. //printf("");
  11791. #endif
  11792. // localversion = argv[5] ? atoi(argv[5]) : 0;
  11793. // printf("localversion=%d\n", localversion);
  11794. return 0;
  11795. }
  11796. /** sqlite3_exec的回调。
  11797. *
  11798. * 向控制台打印查询的结果。
  11799. *
  11800. * @param in data 传递给回调函数的数据。
  11801. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  11802. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  11803. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  11804. * @return 状态码。
  11805. */
  11806. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  11807. {
  11808. for (int i = 0; i < n_columns; i++)
  11809. {
  11810. DEBUG_INFO("%s/t", col_values[i]);
  11811. }
  11812. DEBUG_INFO("/n");
  11813. return 0;
  11814. }
  11815. void OCPP_getListVerion()
  11816. {
  11817. int rc = 0;
  11818. // const char* data = "Callback function called";
  11819. char sql[100];
  11820. char zErrMsg[100];
  11821. memset(sql, 0, 100);
  11822. memset(zErrMsg, 0, 100);
  11823. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  11824. /* Execute SQL statement */
  11825. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  11826. DEBUG_INFO("rc=%d\n",rc);
  11827. if( rc != SQLITE_OK ){
  11828. DEBUG_INFO("SQL error: %s", zErrMsg);
  11829. //sqlite3_free(zErrMsg);
  11830. }else{
  11831. DEBUG_INFO("Operation done successfully");
  11832. }
  11833. }
  11834. void OCPP_getIdTag(char *idTag)
  11835. {
  11836. int rc = 0;
  11837. // const char* data = "Callback function called";
  11838. char sql[100];
  11839. char zErrMsg[100];
  11840. memset(sql, 0, 100);
  11841. memset(zErrMsg, 0, 100);
  11842. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  11843. memset(&idTagQuery, 0, sizeof(idTagQuery));
  11844. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11845. /* Execute SQL statement */
  11846. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  11847. if( rc != SQLITE_OK ){
  11848. DEBUG_INFO("SQL error: %s", zErrMsg);
  11849. //sqlite3_free(zErrMsg);
  11850. }else{
  11851. printf("Operation done successfully");
  11852. }
  11853. //return ver;
  11854. }
  11855. void OCPP_get_TableAuthlocalAllData(void)
  11856. {
  11857. int rc = 0;
  11858. // const char* data = "Callback function called";
  11859. char sql[100];
  11860. char zErrMsg[100];
  11861. memset(sql, 0, 100);
  11862. memset(zErrMsg, 0, 100);
  11863. sprintf(sql,"select * from ocpp_auth_local ");
  11864. /* Execute SQL statement */
  11865. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  11866. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  11867. if( rc != SQLITE_OK ){
  11868. DEBUG_INFO("SQL error: %s", zErrMsg);
  11869. //sqlite3_free(zErrMsg);
  11870. }else{
  11871. DEBUG_INFO("Operation done successfully");
  11872. }
  11873. //return ver;
  11874. }
  11875. int OCPP_cleanLocalList()
  11876. {
  11877. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  11878. char *errMsg = 0;
  11879. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  11880. if (SQLITE_OK != rc)
  11881. {
  11882. DEBUG_INFO("%s\n",errMsg);
  11883. return FALSE;
  11884. }
  11885. else
  11886. {
  11887. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  11888. }
  11889. return TRUE;
  11890. }
  11891. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11892. {
  11893. int isSuccess = FALSE;
  11894. int ret = 0;
  11895. //const char* data = "Callback function called";
  11896. char sql[200];
  11897. char zErrMsg[100];
  11898. memset(sql, 0, 200);
  11899. memset(zErrMsg, 0, 100);
  11900. 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);
  11901. //* Execute SQL statement */
  11902. //zErrMsg = 0;
  11903. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  11904. if( ret != SQLITE_OK ){
  11905. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  11906. // free(zErrMsg);
  11907. // free(sql);
  11908. return isSuccess;
  11909. }
  11910. DEBUG_INFO("successfully Insert records created\n");
  11911. isSuccess = TRUE;
  11912. return isSuccess;
  11913. }
  11914. void OCPP_deleteIdTag(char *idTag)
  11915. {
  11916. //int ver = 0;
  11917. //int isSuccess = FALSE;
  11918. int rc = 0;
  11919. char sql[100];
  11920. char zErrMsg[100];
  11921. memset(sql, 0, 100);
  11922. memset(zErrMsg, 0, 100);
  11923. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  11924. //* Execute SQL statement */
  11925. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  11926. if( rc != SQLITE_OK ){
  11927. DEBUG_INFO("SQL error: %s", zErrMsg);
  11928. //sqlite3_free(zErrMsg);
  11929. }else{
  11930. DEBUG_INFO("Operation done successfully");
  11931. }
  11932. }
  11933. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11934. {
  11935. int isSuccess = FALSE;
  11936. int ret = 0;
  11937. const char* data = "Callback function called";
  11938. char sql[200];
  11939. char zErrMsg[100];
  11940. memset(sql, 0, 200);
  11941. memset(zErrMsg, 0, 100);
  11942. //* selectFromTable */
  11943. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  11944. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11945. //* Execute SQL statement */
  11946. selectSqlCount = 0;
  11947. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11948. if( ret != SQLITE_OK ){
  11949. printf("Error SQL: %s\n", zErrMsg);
  11950. }
  11951. printf("successfully select operation done\n");
  11952. memset(sql, 0, 200);
  11953. memset(zErrMsg, 0, 100);
  11954. if(selectSqlCount == 0)
  11955. {
  11956. //Insert
  11957. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  11958. 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);
  11959. DEBUG_INFO("sql:%s\n", sql);
  11960. //* Execute SQL statement */
  11961. //zErrMsg = 0;
  11962. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  11963. if( ret != SQLITE_OK ){
  11964. printf("SQL error: %s\n", zErrMsg);
  11965. return isSuccess;
  11966. }
  11967. DEBUG_INFO("successfully Insert records created\n");
  11968. isSuccess = TRUE;
  11969. }
  11970. else
  11971. {
  11972. //Update
  11973. //* Create merged SQL statement */
  11974. 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);
  11975. /* Execute SQL statement */
  11976. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11977. if( ret != SQLITE_OK ){
  11978. printf("SQL error: %s\n", zErrMsg);
  11979. //sqlite3_free(zErrMsg);
  11980. //sqlite3_free(sql);
  11981. return isSuccess;
  11982. }
  11983. DEBUG_INFO("Successfully operation done \n");
  11984. isSuccess = TRUE;
  11985. }
  11986. return isSuccess;
  11987. }
  11988. int GetOcppServerURL()
  11989. {
  11990. int result = FALSE;
  11991. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  11992. memset(OcppHost, 0, sizeof(OcppHost));
  11993. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  11994. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  11995. {
  11996. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  11997. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  11998. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11999. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12000. result = TRUE;
  12001. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12002. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12003. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12004. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12005. goto End;
  12006. }
  12007. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12008. {
  12009. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12010. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12011. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12012. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12013. result = TRUE;
  12014. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12015. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12016. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12017. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12018. goto End;
  12019. }
  12020. else
  12021. {
  12022. strcpy(OcppHost,"");
  12023. }
  12024. End:
  12025. return result;
  12026. }
  12027. int GetOcppPath()
  12028. {
  12029. int result = FALSE;
  12030. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12031. {
  12032. if(OcppTempPath == NULL)
  12033. {
  12034. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12035. }
  12036. else
  12037. {
  12038. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12039. }
  12040. result = TRUE;
  12041. goto End;
  12042. }
  12043. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12044. {
  12045. if(OcppTempPath == NULL)
  12046. {
  12047. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12048. }
  12049. else
  12050. {
  12051. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12052. }
  12053. result = TRUE;
  12054. goto End;
  12055. }
  12056. else
  12057. {
  12058. strcpy(OcppPath,"");
  12059. }
  12060. End:
  12061. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12062. return result;
  12063. }
  12064. int GetOcppPort()
  12065. {
  12066. return OcppPort;
  12067. }
  12068. int GetOcppConnStatus(void)
  12069. {
  12070. return ShmOCPP16Data->OcppConnStatus;
  12071. }
  12072. void SetOcppConnStatus(uint8_t status)
  12073. {
  12074. ShmOCPP16Data->OcppConnStatus = status;
  12075. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12076. if(status == FALSE)
  12077. {
  12078. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12079. {
  12080. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12081. }
  12082. else
  12083. {
  12084. SystemInitial = AC_QUANTITY;
  12085. }
  12086. }
  12087. }
  12088. int GetHeartBeatWithNOResponse(void)
  12089. {
  12090. return HeartBeatWithNOResponse;
  12091. }
  12092. void SetHeartBeatWithNOResponse(void)
  12093. {
  12094. HeartBeatWithNOResponse = 0;
  12095. }
  12096. int GetTransactionId(int gunindex)
  12097. {
  12098. return TransactionId[gunindex];
  12099. }
  12100. void SetTransactionIdZero(int gunindex)
  12101. {
  12102. TransactionId[gunindex] = 0;
  12103. }
  12104. int InternetDisconnect(void)
  12105. {
  12106. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12107. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12108. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12109. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12110. }
  12111. void GetChargingProfileRequest(int gunindex)
  12112. {
  12113. mtrace();
  12114. //int connectorIdInt, durationInt;
  12115. //char chargingRateUnitStr[4]={0};
  12116. int tempdurationInt = 0;
  12117. int tempchargingProfileId = 0;
  12118. int tempstackLevel = 0;
  12119. int temptransactionId = 0;
  12120. float tempminChargingRateFloat = 0.0;
  12121. char tempchargingProfilePurposeStr[24]={0};
  12122. char tempchargingProfileKindStr[12]={0};
  12123. char temprecurrencyKindStr[8]={0};
  12124. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12125. char tempvalidToStr[28]={0};
  12126. int tempStartPeriodInt = 0;
  12127. float tempLimitInt = 0.0;//0.1;
  12128. int tempNumberPhasesInt=0;
  12129. char fname[200];
  12130. //char comfirmstr[20];
  12131. float MinChargingRate =0.0;
  12132. double diff_t;
  12133. struct tm tp;
  12134. FILE *fptr1;//, *fptr2;
  12135. int c = 0;
  12136. char * pch;
  12137. char *loc;
  12138. char sstr[200]={ 0 };
  12139. int n_chargingProfile = 0;
  12140. int n_SchedulePeriods = 0;
  12141. char SchedulePeriodList[10][200]={0};
  12142. char sLineWord[800]={0};
  12143. char word[1000]={0};
  12144. int confirmPeriods = 0;
  12145. struct StructProfile ChargePointMaxProfile;
  12146. struct StructProfile TxDefaultProfile;
  12147. struct StructProfile TxProfile;
  12148. struct StructProfile TxDefaultProfiletemp[2]={0};
  12149. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12150. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12151. struct StructChargingProfile TxProfile_TEMP={0};
  12152. int TxDefaultProfileFileIsNull=FALSE;
  12153. int ChargePointMaxProfileIsNull=FALSE;
  12154. int TxProfileIsNull=FALSE;
  12155. // int CompositeSceduleIndex = 0;
  12156. char ChargePointMaxProfileScheduleStr[30]={0};
  12157. char TxDefaultProfileScheduleStr[30]={0};
  12158. char TxProfileScheduleStr[30]={0};
  12159. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12160. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12161. memset(&TxProfile,0,sizeof(struct StructProfile));
  12162. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  12163. DEBUG_INFO("GetChargingProfileRequest\n");
  12164. //*****************************ChargePointMaxProfile******************************************/
  12165. strcpy(fname, ChargePointMaxProfile_JSON);
  12166. ChargePointMaxProfileIsNull=TRUE;
  12167. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12168. {
  12169. fptr1 = fopen(fname, "r");
  12170. int c;
  12171. c = fgetc(fptr1);
  12172. //DEBUG_INFO("c:%d\n",c);
  12173. rewind(fptr1);
  12174. if(c == EOF)
  12175. {
  12176. DEBUG_INFO("\n End of file reached.");
  12177. ChargePointMaxProfileIsNull=TRUE;
  12178. fclose(fptr1);
  12179. }
  12180. else
  12181. {
  12182. ChargePointMaxProfileIsNull=FALSE;
  12183. while(fscanf(fptr1, "%s", word) != EOF)
  12184. {
  12185. if(strcmp(word, "chargingProfileId") == 0)
  12186. {
  12187. n_chargingProfile = n_chargingProfile + 1;
  12188. }
  12189. }
  12190. rewind(fptr1);
  12191. //search Charging Profile Element
  12192. int i = 0;
  12193. int j = 0;
  12194. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12195. //***********chargingProfileId**************/
  12196. c = 0;
  12197. loc = strstr(sLineWord, "chargingProfileId");
  12198. //DEBUG_INFO("loc=%s\n",loc);
  12199. memset(sstr ,0, sizeof(sstr) );
  12200. if(loc != NULL)
  12201. {
  12202. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12203. {
  12204. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12205. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12206. c++;
  12207. }
  12208. sstr[c] = '\0';
  12209. tempchargingProfileId = atoi(sstr);
  12210. }
  12211. else
  12212. {
  12213. tempchargingProfileId = 0;
  12214. }
  12215. //***********stackLevel**************/
  12216. c = 0;
  12217. loc = strstr(sLineWord, "stackLevel");
  12218. //DEBUG_INFO("loc=%s\n",loc);
  12219. memset(sstr ,0, sizeof(sstr) );
  12220. if(loc != NULL)
  12221. {
  12222. while (loc[2+strlen("stackLevel")+c] != '\"')
  12223. {
  12224. sstr[c] = loc[2+strlen("stackLevel")+c];
  12225. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12226. c++;
  12227. }
  12228. sstr[c] = '\0';
  12229. tempstackLevel = atoi(sstr);
  12230. }
  12231. else
  12232. {
  12233. tempstackLevel = 0;
  12234. }
  12235. //***********chargingProfilePurpose **************/
  12236. c = 0;
  12237. loc = strstr(sLineWord, "chargingProfilePurpose");
  12238. //DEBUG_INFO("loc=%s\n",loc);
  12239. memset(sstr ,0, sizeof(sstr) );
  12240. if(loc != NULL)
  12241. {
  12242. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12243. {
  12244. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12245. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12246. c++;
  12247. }
  12248. sstr[c] = '\0';
  12249. strcpy(tempchargingProfilePurposeStr,sstr);
  12250. }
  12251. else
  12252. {
  12253. strcpy(tempchargingProfilePurposeStr,"");
  12254. }
  12255. //***********chargingProfileKind **************/
  12256. c = 0;
  12257. loc = strstr(sLineWord, "chargingProfileKind");
  12258. //DEBUG_INFO("loc=%s\n",loc);
  12259. memset(sstr ,0, sizeof(sstr) );
  12260. if(loc != NULL)
  12261. {
  12262. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12263. {
  12264. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12265. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12266. c++;
  12267. }
  12268. sstr[c] = '\0';
  12269. strcpy(tempchargingProfileKindStr,sstr);
  12270. }
  12271. else
  12272. {
  12273. strcpy(tempchargingProfileKindStr,"");
  12274. }
  12275. //***********recurrencyKind **************/
  12276. c = 0;
  12277. loc = strstr(sLineWord, "recurrencyKind");
  12278. //DEBUG_INFO("loc=%s\n",loc);
  12279. memset(sstr ,0, sizeof(sstr) );
  12280. if(loc != NULL)
  12281. {
  12282. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12283. {
  12284. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12285. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12286. c++;
  12287. }
  12288. sstr[c] = '\0';
  12289. strcpy(temprecurrencyKindStr,sstr);
  12290. }
  12291. else
  12292. {
  12293. strcpy(temprecurrencyKindStr,"");
  12294. }
  12295. //***********validFrom**************/
  12296. c = 0;
  12297. loc = strstr(sLineWord, "validFrom");
  12298. //DEBUG_INFO("loc=%s\n",loc);
  12299. memset(sstr ,0, sizeof(sstr) );
  12300. if(loc != NULL)
  12301. {
  12302. while (loc[3+strlen("validFrom")+c] != '\"')
  12303. {
  12304. sstr[c] = loc[3+strlen("validFrom")+c];
  12305. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12306. c++;
  12307. }
  12308. sstr[c] = '\0';
  12309. strcpy(tempvalidFromStr,sstr);
  12310. }
  12311. else
  12312. {
  12313. strcpy(tempvalidFromStr,"");
  12314. }
  12315. //***********validTo **************/
  12316. c = 0;
  12317. loc = strstr(sLineWord, "validTo");
  12318. //DEBUG_INFO("loc=%s\n",loc);
  12319. memset(sstr ,0, sizeof(sstr) );
  12320. if(loc != NULL)
  12321. {
  12322. while (loc[3+strlen("validTo")+c] != '\"')
  12323. {
  12324. sstr[c] = loc[3+strlen("validTo")+c];
  12325. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12326. c++;
  12327. }
  12328. sstr[c] = '\0';
  12329. strcpy(tempvalidToStr,sstr);
  12330. }
  12331. else
  12332. {
  12333. strcpy(tempvalidToStr,"");
  12334. }
  12335. //***********validFrom**************/
  12336. c = 0;
  12337. loc = strstr(sLineWord, "validFrom");
  12338. if(loc != NULL)
  12339. {
  12340. memset(sstr ,0, sizeof(sstr) );
  12341. while (loc[3+strlen("validFrom")+c] != '\"')
  12342. {
  12343. sstr[c] = loc[3+strlen("validFrom")+c];
  12344. c++;
  12345. }
  12346. sstr[c] = '\0';
  12347. strcpy(tempvalidFromStr,sstr);
  12348. }
  12349. else
  12350. {
  12351. strcpy(tempvalidFromStr,"");
  12352. }
  12353. //***********validTo **************/
  12354. c = 0;
  12355. loc = strstr(sLineWord, "validTo");
  12356. if(loc != NULL)
  12357. {
  12358. memset(sstr ,0, sizeof(sstr) );
  12359. while (loc[3+strlen("validTo")+c] != '\"')
  12360. {
  12361. sstr[c] = loc[3+strlen("validTo")+c];
  12362. c++;
  12363. }
  12364. sstr[c] = '\0';
  12365. strcpy(tempvalidToStr,sstr);
  12366. }
  12367. else
  12368. {
  12369. strcpy(tempvalidToStr,"");
  12370. }
  12371. //***********duration**************/
  12372. c = 0;
  12373. loc = strstr(sLineWord, "duration");
  12374. if(loc != NULL)
  12375. {
  12376. memset(sstr ,0, sizeof(sstr) );
  12377. while (loc[2+strlen("duration")+c] != ',')
  12378. {
  12379. sstr[c] = loc[2+strlen("duration")+c];
  12380. c++;
  12381. }
  12382. sstr[c] = '\0';
  12383. tempdurationInt = atoi(sstr);
  12384. }
  12385. else
  12386. {
  12387. tempdurationInt = 0;
  12388. }
  12389. //**********startSchedule**********/
  12390. c = 0;
  12391. loc = strstr(sLineWord, "startSchedule");
  12392. memset(sstr ,0, sizeof(sstr) );
  12393. while (loc[3+strlen("startSchedule")+c] != '\"')
  12394. {
  12395. sstr[c] = loc[3+strlen("startSchedule")+c];
  12396. c++;
  12397. }
  12398. sstr[c] = '\0';
  12399. strcpy(tempstartScheduleStr, sstr);
  12400. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  12401. //**********chargingRateUnit**********/
  12402. c = 0;
  12403. loc = strstr(sLineWord, "chargingRateUnit");
  12404. memset(sstr ,0, sizeof(sstr) );
  12405. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12406. {
  12407. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12408. c++;
  12409. }
  12410. sstr[c] = '\0';
  12411. strcpy(tempchargingRateUnitStr, sstr);
  12412. //**********minChargingRate*******/
  12413. c = 0;
  12414. loc = strstr(sLineWord, "minChargingRate");
  12415. if(loc != NULL)
  12416. {
  12417. memset(sstr ,0, sizeof(sstr) );
  12418. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12419. {
  12420. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12421. c++;
  12422. }
  12423. sstr[c] = '\0';
  12424. tempminChargingRateFloat = atof(sstr);
  12425. }
  12426. else
  12427. {
  12428. tempminChargingRateFloat = 0.0;
  12429. }
  12430. //
  12431. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12432. tp.tm_isdst = -1;
  12433. time_t utc = mktime(&tp);
  12434. time_t t = time(NULL);
  12435. diff_t = difftime(t, utc);
  12436. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12437. //parsing strings to words
  12438. i = 0;
  12439. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12440. loc = loc+3+strlen("chargingSchedulePeriod");
  12441. pch = strtok(loc ,"{");
  12442. while (pch != NULL)
  12443. {
  12444. strcpy(SchedulePeriodList[i], pch);
  12445. pch = strtok (NULL, "{");
  12446. i = i + 1;
  12447. }
  12448. n_SchedulePeriods = i;
  12449. for(int i=0;i<n_SchedulePeriods;i++)
  12450. {
  12451. //*************startPeriod****************/
  12452. c = 0;
  12453. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12454. memset(sstr ,0, sizeof(sstr) );
  12455. while (loc[strlen("startPeriod")+2+c] != ',')
  12456. {
  12457. sstr[c] = loc[strlen("startPeriod")+2+c];
  12458. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12459. c++;
  12460. }
  12461. sstr[c] = '\0';
  12462. tempStartPeriodInt = atoi(sstr);
  12463. //*************limit****************/
  12464. c = 0;
  12465. loc = strstr(SchedulePeriodList[i], "limit");
  12466. memset(sstr ,0, sizeof(sstr) );
  12467. while (loc[strlen("limit")+2+c] != ',')
  12468. {
  12469. sstr[c] = loc[strlen("limit")+2+c];
  12470. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12471. c++;
  12472. }
  12473. sstr[c] = '\0';
  12474. tempLimitInt = atof(sstr);
  12475. //*************numberPhases****************/
  12476. c = 0;
  12477. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12478. memset(sstr ,0, sizeof(sstr) );
  12479. while (loc[strlen("numberPhases")+2+c] != '}')
  12480. {
  12481. sstr[c] = loc[strlen("numberPhases")+2+c];
  12482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12483. c++;
  12484. }
  12485. sstr[c] = '\0';
  12486. tempNumberPhasesInt = atoi(sstr);
  12487. if(j == 0)
  12488. {
  12489. ChargePointMaxProfile.Duration = tempdurationInt;
  12490. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  12491. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  12492. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12493. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12494. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12495. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  12496. ChargePointMaxProfile_TEMP.TransactionId = 0;
  12497. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12498. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12499. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12500. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12501. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12502. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12503. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12504. }
  12505. }
  12506. if(MinChargingRate < tempminChargingRateFloat)
  12507. {
  12508. MinChargingRate = tempminChargingRateFloat;
  12509. }
  12510. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12511. if(confirmPeriods < n_SchedulePeriods)
  12512. {
  12513. confirmPeriods = n_SchedulePeriods;
  12514. }
  12515. j = j + 1;
  12516. }
  12517. fclose(fptr1);
  12518. }
  12519. }// the end of access file ChargePointMaxProfile
  12520. //****************************TxDefaultProfile************************************************/
  12521. switch(gunindex + 1)
  12522. {
  12523. case 0:
  12524. strcpy(fname, TxDefaultProfile_0_JSON );
  12525. break;
  12526. case 1:
  12527. strcpy(fname, TxDefaultProfile_1_JSON );
  12528. break;
  12529. case 2:
  12530. strcpy(fname, TxDefaultProfile_2_JSON );
  12531. break;
  12532. default:
  12533. strcpy(fname, TxDefaultProfile_1_JSON );
  12534. break;
  12535. }
  12536. TxDefaultProfileFileIsNull=TRUE;
  12537. if((access(fname,F_OK))!=-1)
  12538. {
  12539. fptr1 = fopen(fname, "r");
  12540. c = 0;
  12541. c = fgetc(fptr1);
  12542. //DEBUG_INFO("c:%d\n",c);
  12543. rewind(fptr1);
  12544. if(c == EOF)
  12545. {
  12546. DEBUG_INFO("\n End of file reached.");
  12547. TxDefaultProfileFileIsNull=TRUE;
  12548. fclose(fptr1);
  12549. }
  12550. else
  12551. {
  12552. TxDefaultProfileFileIsNull=FALSE;
  12553. while(fscanf(fptr1, "%s", word) != EOF)
  12554. {
  12555. if(strcmp(word, "chargingProfileId") == 0)
  12556. {
  12557. n_chargingProfile = n_chargingProfile + 1;
  12558. }
  12559. }
  12560. rewind(fptr1);
  12561. //search Charging Profile Element
  12562. int i = 0;
  12563. int j = 0;
  12564. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12565. #if 0
  12566. /***********connectorId****************/
  12567. c = 0;
  12568. loc = strstr(sLineWord, "connectorId");
  12569. memset(sstr ,0, sizeof(sstr) );
  12570. while (loc[strlen("connectorId")+2+c] != ',')
  12571. {
  12572. sstr[c] = loc[strlen("connectorId")+2+c];
  12573. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12574. c++;
  12575. }
  12576. sstr[c] = '\0';
  12577. tempconnectorIdInt = atoi(sstr);
  12578. #endif
  12579. //***********chargingProfileId**************/
  12580. c = 0;
  12581. loc = strstr(sLineWord, "chargingProfileId");
  12582. //DEBUG_INFO("loc=%s\n",loc);
  12583. memset(sstr ,0, sizeof(sstr) );
  12584. if(loc != NULL)
  12585. {
  12586. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12587. {
  12588. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12589. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12590. c++;
  12591. }
  12592. sstr[c] = '\0';
  12593. tempchargingProfileId = atoi(sstr);
  12594. }
  12595. else
  12596. {
  12597. tempchargingProfileId = 0;
  12598. }
  12599. //***********stackLevel**************/
  12600. c = 0;
  12601. loc = strstr(sLineWord, "stackLevel");
  12602. //DEBUG_INFO("loc=%s\n",loc);
  12603. memset(sstr ,0, sizeof(sstr) );
  12604. if(loc != NULL)
  12605. {
  12606. while (loc[2+strlen("stackLevel")+c] != '\"')
  12607. {
  12608. sstr[c] = loc[2+strlen("stackLevel")+c];
  12609. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12610. c++;
  12611. }
  12612. sstr[c] = '\0';
  12613. tempstackLevel = atoi(sstr);
  12614. }
  12615. else
  12616. {
  12617. tempstackLevel = 0;
  12618. }
  12619. //***********chargingProfilePurpose **************/
  12620. c = 0;
  12621. loc = strstr(sLineWord, "chargingProfilePurpose");
  12622. //DEBUG_INFO("loc=%s\n",loc);
  12623. memset(sstr ,0, sizeof(sstr) );
  12624. if(loc != NULL)
  12625. {
  12626. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12627. {
  12628. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12629. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12630. c++;
  12631. }
  12632. sstr[c] = '\0';
  12633. strcpy(tempchargingProfilePurposeStr,sstr);
  12634. }
  12635. else
  12636. {
  12637. strcpy(tempchargingProfilePurposeStr,"");
  12638. }
  12639. //***********chargingProfileKind **************/
  12640. c = 0;
  12641. loc = strstr(sLineWord, "chargingProfileKind");
  12642. //DEBUG_INFO("loc=%s\n",loc);
  12643. memset(sstr ,0, sizeof(sstr) );
  12644. if(loc != NULL)
  12645. {
  12646. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12647. {
  12648. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12649. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12650. c++;
  12651. }
  12652. sstr[c] = '\0';
  12653. strcpy(tempchargingProfileKindStr,sstr);
  12654. }
  12655. else
  12656. {
  12657. strcpy(tempchargingProfileKindStr,"");
  12658. }
  12659. //***********recurrencyKind **************/
  12660. c = 0;
  12661. loc = strstr(sLineWord, "recurrencyKind");
  12662. //DEBUG_INFO("loc=%s\n",loc);
  12663. memset(sstr ,0, sizeof(sstr) );
  12664. if(loc != NULL)
  12665. {
  12666. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12667. {
  12668. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12669. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12670. c++;
  12671. }
  12672. sstr[c] = '\0';
  12673. strcpy(temprecurrencyKindStr,sstr);
  12674. }
  12675. else
  12676. {
  12677. strcpy(temprecurrencyKindStr,"");
  12678. }
  12679. //***********validFrom**************/
  12680. c = 0;
  12681. loc = strstr(sLineWord, "validFrom");
  12682. if(loc != NULL)
  12683. {
  12684. memset(sstr ,0, sizeof(sstr) );
  12685. while (loc[3+strlen("validFrom")+c] != '\"')
  12686. {
  12687. sstr[c] = loc[3+strlen("validFrom")+c];
  12688. c++;
  12689. }
  12690. sstr[c] = '\0';
  12691. strcpy(tempvalidFromStr,sstr);
  12692. }
  12693. else
  12694. {
  12695. strcpy(tempvalidFromStr,"");
  12696. }
  12697. //***********validTo **************/
  12698. c = 0;
  12699. loc = strstr(sLineWord, "validTo");
  12700. if(loc != NULL)
  12701. {
  12702. memset(sstr ,0, sizeof(sstr) );
  12703. while (loc[3+strlen("validTo")+c] != '\"')
  12704. {
  12705. sstr[c] = loc[3+strlen("validTo")+c];
  12706. c++;
  12707. }
  12708. sstr[c] = '\0';
  12709. strcpy(tempvalidToStr,sstr);
  12710. }
  12711. else
  12712. {
  12713. strcpy(tempvalidToStr,"");
  12714. }
  12715. //***********duration**************/
  12716. c = 0;
  12717. loc = strstr(sLineWord, "duration");
  12718. if(loc != NULL)
  12719. {
  12720. memset(sstr ,0, sizeof(sstr) );
  12721. while (loc[2+strlen("duration")+c] != ',')
  12722. {
  12723. sstr[c] = loc[2+strlen("duration")+c];
  12724. c++;
  12725. }
  12726. sstr[c] = '\0';
  12727. tempdurationInt = atoi(sstr);
  12728. }
  12729. else
  12730. {
  12731. tempdurationInt = 0;
  12732. }
  12733. //**********startSchedule**********/
  12734. c = 0;
  12735. loc = strstr(sLineWord, "startSchedule");
  12736. memset(sstr ,0, sizeof(sstr) );
  12737. while (loc[3+strlen("startSchedule")+c] != '\"')
  12738. {
  12739. sstr[c] = loc[3+strlen("startSchedule")+c];
  12740. c++;
  12741. }
  12742. sstr[c] = '\0';
  12743. strcpy(tempstartScheduleStr, sstr);
  12744. strcpy(TxDefaultProfileScheduleStr, sstr);
  12745. //**********chargingRateUnit**********/
  12746. c = 0;
  12747. loc = strstr(sLineWord, "chargingRateUnit");
  12748. memset(sstr ,0, sizeof(sstr) );
  12749. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12750. {
  12751. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12752. c++;
  12753. }
  12754. sstr[c] = '\0';
  12755. strcpy(tempchargingRateUnitStr, sstr);
  12756. //**********minChargingRate*******/
  12757. c = 0;
  12758. loc = strstr(sLineWord, "minChargingRate");
  12759. if(loc != NULL)
  12760. {
  12761. memset(sstr ,0, sizeof(sstr) );
  12762. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12763. {
  12764. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12765. c++;
  12766. }
  12767. sstr[c] = '\0';
  12768. tempminChargingRateFloat = atof(sstr);
  12769. }
  12770. else
  12771. {
  12772. tempminChargingRateFloat = 0.0;
  12773. }
  12774. //
  12775. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12776. tp.tm_isdst = -1;
  12777. time_t utc = mktime(&tp);
  12778. time_t t = time(NULL);
  12779. diff_t = difftime(t, utc);
  12780. printf("diff between startScheduleStr and now =%f\n",diff_t);
  12781. //parsing strings to words
  12782. i = 0;
  12783. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12784. loc = loc+3+strlen("chargingSchedulePeriod");
  12785. pch = strtok(loc ,"{");
  12786. while (pch != NULL)
  12787. {
  12788. strcpy(SchedulePeriodList[i], pch);
  12789. pch = strtok (NULL, "{");
  12790. i = i + 1;
  12791. }
  12792. n_SchedulePeriods = i;
  12793. for(int i=0;i<n_SchedulePeriods;i++)
  12794. {
  12795. //*************startPeriod****************/
  12796. c = 0;
  12797. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12798. memset(sstr ,0, sizeof(sstr) );
  12799. while (loc[strlen("startPeriod")+2+c] != ',')
  12800. {
  12801. sstr[c] = loc[strlen("startPeriod")+2+c];
  12802. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12803. c++;
  12804. }
  12805. sstr[c] = '\0';
  12806. tempStartPeriodInt = atoi(sstr);
  12807. //*************limit****************/
  12808. c = 0;
  12809. loc = strstr(SchedulePeriodList[i], "limit");
  12810. memset(sstr ,0, sizeof(sstr) );
  12811. while (loc[strlen("limit")+2+c] != ',')
  12812. {
  12813. sstr[c] = loc[strlen("limit")+2+c];
  12814. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12815. c++;
  12816. }
  12817. sstr[c] = '\0';
  12818. tempLimitInt = atof(sstr);
  12819. //*************numberPhases****************/
  12820. c = 0;
  12821. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12822. memset(sstr ,0, sizeof(sstr) );
  12823. while (loc[strlen("numberPhases")+2+c] != '}')
  12824. {
  12825. sstr[c] = loc[strlen("numberPhases")+2+c];
  12826. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12827. c++;
  12828. }
  12829. sstr[c] = '\0';
  12830. tempNumberPhasesInt = atoi(sstr);
  12831. if(j == 0)
  12832. {
  12833. TxDefaultProfile.Duration = tempdurationInt;
  12834. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  12835. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  12836. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12837. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12838. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12839. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  12840. TxDefaultProfile_TEMP.TransactionId = 0;
  12841. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  12842. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12843. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12844. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12845. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12846. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12847. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12848. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12849. }
  12850. else
  12851. {
  12852. //other stack level charging Profile
  12853. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  12854. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  12855. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  12856. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  12857. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  12858. }
  12859. }
  12860. if(MinChargingRate < tempminChargingRateFloat)
  12861. {
  12862. MinChargingRate = tempminChargingRateFloat;
  12863. }
  12864. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12865. if(confirmPeriods < n_SchedulePeriods)
  12866. confirmPeriods = n_SchedulePeriods;
  12867. j = j + 1;
  12868. }
  12869. fclose(fptr1);
  12870. //Stacking Charging Profiles
  12871. for(int l=0; l <(j-1) ;l++)
  12872. {
  12873. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  12874. {
  12875. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  12876. {
  12877. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  12878. {
  12879. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  12880. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  12881. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  12882. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12883. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12884. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12885. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12886. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12887. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12888. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12889. }
  12890. else
  12891. {
  12892. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12893. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12894. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12895. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12896. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12897. }
  12898. }
  12899. }
  12900. }
  12901. //end of Stacking Charging Profiles
  12902. }
  12903. }// the end of ACCESS TxDefaultProfile
  12904. //****************************TxProfile************************************************/
  12905. switch(gunindex + 1)
  12906. {
  12907. case 0:
  12908. break;
  12909. case 1:
  12910. strcpy(fname, TxProfile_1_JSON );
  12911. break;
  12912. case 2:
  12913. strcpy(fname, TxProfile_2_JSON );
  12914. break;
  12915. default:
  12916. strcpy(fname, TxProfile_1_JSON );
  12917. break;
  12918. }
  12919. TxProfileIsNull=TRUE;
  12920. if((access(fname,F_OK))!=-1)
  12921. {
  12922. fptr1 = fopen(fname, "r");
  12923. c = 0;
  12924. c = fgetc(fptr1);
  12925. //DEBUG_INFO("c:%d\n",c);
  12926. rewind(fptr1);
  12927. if(c == EOF)
  12928. {
  12929. DEBUG_INFO("\n End of file reached.");
  12930. TxProfileIsNull=TRUE;
  12931. fclose(fptr1);
  12932. }
  12933. else
  12934. {
  12935. TxProfileIsNull=FALSE;
  12936. while(fscanf(fptr1, "%s", word) != EOF)
  12937. {
  12938. if(strcmp(word, "chargingProfileId") == 0)
  12939. {
  12940. n_chargingProfile = n_chargingProfile + 1;
  12941. }
  12942. }
  12943. rewind(fptr1);
  12944. //search Charging Profile Element
  12945. int i= 0;
  12946. int j= 0;
  12947. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12948. #if 0
  12949. /***********connectorId****************/
  12950. c = 0;
  12951. loc = strstr(sLineWord, "connectorId");
  12952. memset(sstr ,0, sizeof(sstr) );
  12953. while (loc[strlen("connectorId")+2+c] != ',')
  12954. {
  12955. sstr[c] = loc[strlen("connectorId")+2+c];
  12956. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12957. c++;
  12958. }
  12959. sstr[c] = '\0';
  12960. tempconnectorIdInt = atoi(sstr);
  12961. #endif
  12962. //***********chargingProfileId**************/
  12963. c = 0;
  12964. loc = strstr(sLineWord, "chargingProfileId");
  12965. memset(sstr ,0, sizeof(sstr) );
  12966. if(loc != NULL)
  12967. {
  12968. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12969. {
  12970. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12971. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12972. c++;
  12973. }
  12974. sstr[c] = '\0';
  12975. tempchargingProfileId = atoi(sstr);
  12976. }
  12977. else
  12978. {
  12979. tempchargingProfileId = 0;
  12980. }
  12981. //***********transactionId **************/
  12982. c = 0;
  12983. loc = strstr(sLineWord, "transactionId");
  12984. //DEBUG_INFO("loc=%s\n",loc);
  12985. memset(sstr ,0, sizeof(sstr) );
  12986. if(loc != NULL)
  12987. {
  12988. while (loc[2+strlen("transactionId")+c] != '\"')
  12989. {
  12990. sstr[c] = loc[2+strlen("transactionId")+c];
  12991. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12992. c++;
  12993. }
  12994. sstr[c] = '\0';
  12995. temptransactionId = atoi(sstr);
  12996. }
  12997. else
  12998. {
  12999. temptransactionId = 0;
  13000. }
  13001. //***********stackLevel**************/
  13002. c = 0;
  13003. loc = strstr(sLineWord, "stackLevel");
  13004. //DEBUG_INFO("loc=%s\n",loc);
  13005. memset(sstr ,0, sizeof(sstr) );
  13006. if(loc != NULL)
  13007. {
  13008. while (loc[2+strlen("stackLevel")+c] != '\"')
  13009. {
  13010. sstr[c] = loc[2+strlen("stackLevel")+c];
  13011. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13012. c++;
  13013. }
  13014. sstr[c] = '\0';
  13015. tempstackLevel = atoi(sstr);
  13016. }
  13017. else
  13018. {
  13019. tempstackLevel = 0;
  13020. }
  13021. //***********chargingProfilePurpose **************/
  13022. c = 0;
  13023. loc = strstr(sLineWord, "chargingProfilePurpose");
  13024. //DEBUG_INFO("loc=%s\n",loc);
  13025. memset(sstr ,0, sizeof(sstr) );
  13026. if(loc != NULL)
  13027. {
  13028. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13029. {
  13030. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13031. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13032. c++;
  13033. }
  13034. sstr[c] = '\0';
  13035. strcpy(tempchargingProfilePurposeStr,sstr);
  13036. }
  13037. else
  13038. {
  13039. strcpy(tempchargingProfilePurposeStr,"");
  13040. }
  13041. //***********chargingProfileKind **************/
  13042. c = 0;
  13043. loc = strstr(sLineWord, "chargingProfileKind");
  13044. //DEBUG_INFO("loc=%s\n",loc);
  13045. memset(sstr ,0, sizeof(sstr) );
  13046. if(loc != NULL)
  13047. {
  13048. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13049. {
  13050. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13051. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13052. c++;
  13053. }
  13054. sstr[c] = '\0';
  13055. strcpy(tempchargingProfileKindStr,sstr);
  13056. }
  13057. else
  13058. {
  13059. strcpy(tempchargingProfileKindStr,"");
  13060. }
  13061. //***********recurrencyKind **************/
  13062. c = 0;
  13063. loc = strstr(sLineWord, "recurrencyKind");
  13064. //DEBUG_INFO("loc=%s\n",loc);
  13065. memset(sstr ,0, sizeof(sstr) );
  13066. if(loc != NULL)
  13067. {
  13068. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13069. {
  13070. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13071. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13072. c++;
  13073. }
  13074. sstr[c] = '\0';
  13075. strcpy(temprecurrencyKindStr,sstr);
  13076. }
  13077. else
  13078. {
  13079. strcpy(temprecurrencyKindStr,"");
  13080. }
  13081. //***********validFrom**************/
  13082. c = 0;
  13083. loc = strstr(sLineWord, "validFrom");
  13084. if(loc != NULL)
  13085. {
  13086. memset(sstr ,0, sizeof(sstr) );
  13087. while (loc[3+strlen("validFrom")+c] != '\"')
  13088. {
  13089. sstr[c] = loc[3+strlen("validFrom")+c];
  13090. c++;
  13091. }
  13092. sstr[c] = '\0';
  13093. strcpy(tempvalidFromStr,sstr);
  13094. }
  13095. else
  13096. {
  13097. strcpy(tempvalidFromStr,"");
  13098. }
  13099. //***********validTo**************/
  13100. c = 0;
  13101. loc = strstr(sLineWord, "validTo");
  13102. if(loc != NULL)
  13103. {
  13104. memset(sstr ,0, sizeof(sstr) );
  13105. while (loc[3+strlen("validTo")+c] != '\"')
  13106. {
  13107. sstr[c] = loc[3+strlen("validTo")+c];
  13108. c++;
  13109. }
  13110. sstr[c] = '\0';
  13111. strcpy(tempvalidToStr,sstr);
  13112. }
  13113. else
  13114. {
  13115. strcpy(tempvalidToStr,"");
  13116. }
  13117. //***********duration**************/
  13118. c = 0;
  13119. loc = strstr(sLineWord, "duration");
  13120. //DEBUG_INFO("loc=%s\n",loc);
  13121. memset(sstr ,0, sizeof(sstr) );
  13122. if(loc != NULL)
  13123. {
  13124. while (loc[2+strlen("duration")+c] != '\"')
  13125. {
  13126. sstr[c] = loc[2+strlen("duration")+c];
  13127. c++;
  13128. }
  13129. sstr[c] = '\0';
  13130. tempdurationInt = atoi(sstr);
  13131. }
  13132. else
  13133. {
  13134. tempdurationInt = 0;
  13135. }
  13136. //**********startSchedule**********/
  13137. c = 0;
  13138. loc = strstr(sLineWord, "startSchedule");
  13139. memset(sstr ,0, sizeof(sstr) );
  13140. while (loc[3+strlen("startSchedule")+c] != '\"')
  13141. {
  13142. sstr[c] = loc[3+strlen("startSchedule")+c];
  13143. c++;
  13144. }
  13145. sstr[c] = '\0';
  13146. strcpy(tempstartScheduleStr, sstr);
  13147. strcpy(TxProfileScheduleStr, sstr);
  13148. //**********chargingRateUnit**********/
  13149. c = 0;
  13150. loc = strstr(sLineWord, "chargingRateUnit");
  13151. memset(sstr ,0, sizeof(sstr) );
  13152. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13153. {
  13154. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13155. c++;
  13156. }
  13157. sstr[c] = '\0';
  13158. strcpy(tempchargingRateUnitStr, sstr);
  13159. //**********minChargingRate*******/
  13160. c = 0;
  13161. loc = strstr(sLineWord, "minChargingRate");
  13162. if(loc != NULL)
  13163. {
  13164. memset(sstr ,0, sizeof(sstr) );
  13165. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13166. {
  13167. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13168. c++;
  13169. }
  13170. sstr[c] = '\0';
  13171. tempminChargingRateFloat = atof(sstr);
  13172. }
  13173. else
  13174. {
  13175. tempminChargingRateFloat = 0.0;
  13176. }
  13177. //
  13178. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13179. tp.tm_isdst = -1;
  13180. time_t utc = mktime(&tp);
  13181. time_t t = time(NULL);
  13182. diff_t = difftime(t, utc);
  13183. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13184. //parsing strings to words
  13185. i = 0;
  13186. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13187. loc = loc+3+strlen("chargingSchedulePeriod");
  13188. pch = strtok(loc ,"{");
  13189. while (pch != NULL)
  13190. {
  13191. strcpy(SchedulePeriodList[i], pch);
  13192. pch = strtok (NULL, "{");
  13193. i = i + 1;
  13194. }
  13195. n_SchedulePeriods = i;
  13196. for(int i=0;i<n_SchedulePeriods;i++)
  13197. {
  13198. //*************startPeriod****************/
  13199. c = 0;
  13200. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13201. memset(sstr ,0, sizeof(sstr) );
  13202. while (loc[strlen("startPeriod")+2+c] != ',')
  13203. {
  13204. sstr[c] = loc[strlen("startPeriod")+2+c];
  13205. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13206. c++;
  13207. }
  13208. sstr[c] = '\0';
  13209. tempStartPeriodInt = atoi(sstr);
  13210. //*************limit****************/
  13211. c = 0;
  13212. loc = strstr(SchedulePeriodList[i], "limit");
  13213. memset(sstr ,0, sizeof(sstr) );
  13214. while (loc[strlen("limit")+2+c] != ',')
  13215. {
  13216. sstr[c] = loc[strlen("limit")+2+c];
  13217. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13218. c++;
  13219. }
  13220. sstr[c] = '\0';
  13221. tempLimitInt = atof(sstr);
  13222. //*************numberPhases****************/
  13223. c = 0;
  13224. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13225. memset(sstr ,0, sizeof(sstr) );
  13226. while (loc[strlen("numberPhases")+2+c] != '}')
  13227. {
  13228. sstr[c] = loc[strlen("numberPhases")+2+c];
  13229. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13230. c++;
  13231. }
  13232. sstr[c] = '\0';
  13233. tempNumberPhasesInt = atoi(sstr);
  13234. //TxProfile.Duration = durationInt;
  13235. TxProfile.TotalPeriod = n_SchedulePeriods;
  13236. TxProfile.Period[i].Limit = tempLimitInt;
  13237. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13238. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13239. }
  13240. if(MinChargingRate < tempminChargingRateFloat)
  13241. {
  13242. MinChargingRate = tempminChargingRateFloat;
  13243. }
  13244. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13245. if(confirmPeriods < n_SchedulePeriods)
  13246. confirmPeriods = n_SchedulePeriods;
  13247. if(j == 0)
  13248. {
  13249. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13250. TxProfile_TEMP.StackLevel = tempstackLevel;
  13251. TxProfile_TEMP.TransactionId = 0;
  13252. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13253. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13254. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13255. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13256. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13257. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13258. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13259. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13260. }
  13261. }
  13262. fclose(fptr1);
  13263. }
  13264. }// the end of ACCESS TxProfile
  13265. //CompositeSchedule
  13266. int period=0;
  13267. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13268. {
  13269. //TxProfile
  13270. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13271. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13272. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13273. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13274. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13275. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13276. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13277. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13278. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13279. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13280. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13281. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13282. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13283. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13284. {
  13285. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13286. {
  13287. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13288. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13289. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13290. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13291. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13292. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13293. period = period + 1;
  13294. }
  13295. else
  13296. {
  13297. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13298. {
  13299. }
  13300. else
  13301. {
  13302. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13303. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13304. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13305. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13306. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13307. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13308. period = period + 1;
  13309. }
  13310. }
  13311. }
  13312. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13313. {
  13314. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  13315. {
  13316. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13317. {
  13318. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13319. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13320. }
  13321. else
  13322. {
  13323. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13324. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13325. }
  13326. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13327. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13328. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13329. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13330. period = period + 1;
  13331. }
  13332. }
  13333. }
  13334. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13335. {
  13336. //TxDefaultProfile
  13337. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13338. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13339. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13340. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13341. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  13342. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13343. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13344. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13345. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13346. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13347. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13348. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13349. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13350. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13351. {
  13352. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13353. {
  13354. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13355. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13356. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13357. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13358. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13359. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13360. period = period + 1;
  13361. }
  13362. else
  13363. {
  13364. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13365. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13366. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13367. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13368. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13369. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13370. period = period + 1;
  13371. }
  13372. }
  13373. }
  13374. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  13375. {
  13376. //TxDefaultProfile
  13377. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13378. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13379. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13380. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13381. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  13382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13383. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13384. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13385. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13386. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13387. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13388. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13389. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13390. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13391. {
  13392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13394. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13395. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13396. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13397. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13398. period = period + 1;
  13399. }
  13400. }
  13401. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13402. {
  13403. //ChargePointMaxProfile
  13404. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  13405. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  13406. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13407. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  13408. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  13409. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13410. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13411. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  13412. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  13413. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  13414. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  13415. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  13416. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  13417. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  13418. {
  13419. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  13420. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  13421. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  13422. period = period + 1;
  13423. }
  13424. }
  13425. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  13426. {
  13427. //TxProfile
  13428. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13429. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13430. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13431. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13432. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13433. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13434. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13435. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13436. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13437. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13438. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13439. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13440. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13441. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13442. {
  13443. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  13444. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  13445. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  13446. }
  13447. }
  13448. confirmPeriods = period;
  13449. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  13450. 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,"
  13451. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  13452. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  13453. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  13454. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  13455. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  13456. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  13457. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  13458. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  13459. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  13460. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  13461. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  13462. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  13463. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  13464. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  13465. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  13466. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  13467. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  13468. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  13469. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  13470. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  13471. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  13472. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  13473. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  13474. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  13475. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  13476. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  13477. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  13478. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  13479. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  13480. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  13481. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  13482. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  13483. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  13484. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  13485. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  13486. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  13487. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  13488. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  13489. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  13490. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  13491. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  13492. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  13493. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  13494. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  13495. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  13496. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  13497. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  13498. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  13499. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  13500. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  13501. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  13502. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  13503. }
  13504. void LWS_Send(char * str)
  13505. {
  13506. //=====================================================
  13507. // Check InternetConn 0: disconnected, 1: connected
  13508. //====================================================
  13509. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13510. {
  13511. DEBUG_INFO("\n offline now !!!\n");
  13512. return;
  13513. }
  13514. pthread_mutex_lock(&lock);
  13515. memset(SendBuffer,0,SendBufLen);
  13516. sprintf((char *)SendBuffer, "%s", str);
  13517. pthread_mutex_unlock(&lock);
  13518. lws_callback_on_writable(wsi_client);
  13519. lws_service(context, 10000);//timeout_ms
  13520. }