MessageHandler.c 581 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100
  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 HeartBeatCountPerHour = 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 void ChageWebSocketPingInterval(int WebSocketPingInterval);
  157. extern pthread_mutex_t mutex1;
  158. extern struct Charger_Info Charger;
  159. extern sqlite3 *db;
  160. int TransactionMessageAttemptsGet(void);
  161. int TransactionMessageRetryIntervalGet(void);
  162. int GetOcppConnStatus(void);
  163. void SetOcppConnStatus(uint8_t status);
  164. int updateSetting(char *key, char *value);
  165. int setKeyValue(char *key, char *value);
  166. void OCPP_get_TableAuthlocalAllData(void);
  167. void processUnkownKey(void);
  168. struct StructOCPPMeterValue
  169. {
  170. unsigned char TimeStamp[28];
  171. struct StructSampledValue SampledValue[10];
  172. };
  173. struct ClientTime
  174. {
  175. unsigned int Heartbeat;
  176. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  177. unsigned int StartTransaction;
  178. unsigned int StopTransaction;
  179. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  180. }clientTime;
  181. typedef union
  182. {
  183. //Operations Initiated by Central System
  184. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  185. struct
  186. {
  187. //CsMsgValue[0]
  188. unsigned char StatusNotificationReq :1; //bit 0,
  189. unsigned char StatusNotificationConf :1; //bit 0,
  190. unsigned char :6; //bit 2~7
  191. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  192. }CpinitiateMsg;
  193. CpinitiateMsg cpinitateMsg;
  194. //==========================================
  195. // Init all Enumeration & Mapping String
  196. //==========================================
  197. /*ChargePointErrorCode*/
  198. typedef enum {
  199. ConnectorLockFailure,
  200. EVCommunicationError,
  201. GroundFailure,
  202. HighTemperature,
  203. InternalError,
  204. LocalListConflict,
  205. NoError,
  206. OtherError,
  207. OverCurrentFailure,
  208. OverVoltage,
  209. PowerMeterFailure,
  210. PowerSwitchFailure,
  211. ReaderFailure,
  212. ResetFailure,
  213. UnderVoltage,
  214. WeakSignal
  215. } ChargePointErrorCode;
  216. #if 0
  217. static char *ChargePointErrorCodeStr[] = {
  218. MACROSTR(ConnectorLockFailure),
  219. MACROSTR(EVCommunicationError),
  220. MACROSTR(GroundFailure),
  221. MACROSTR(HighTemperature),
  222. MACROSTR(InternalError),
  223. MACROSTR(LocalListConflict),
  224. MACROSTR(NoError),
  225. MACROSTR(OtherError),
  226. MACROSTR(OverCurrentFailure),
  227. MACROSTR(OverVoltage),
  228. MACROSTR(PowerMeterFailure),
  229. MACROSTR(PowerSwitchFailure),
  230. MACROSTR(ReaderFailure),
  231. MACROSTR(ResetFailure),
  232. MACROSTR(UnderVoltage),
  233. MACROSTR(WeakSignal)
  234. };
  235. #endif
  236. /*ChargePointStatus*/
  237. typedef enum {
  238. Available =0,
  239. Preparing,
  240. Charging,
  241. SuspendedEVSE,
  242. SuspendedEV,
  243. Finishing,
  244. Reserved,
  245. Unavailable,
  246. Faulted
  247. } ChargePointStatus;
  248. static char * ChargePointStatusStr[] = {
  249. MACROSTR(Available),
  250. MACROSTR(Preparing),
  251. MACROSTR(Charging),
  252. MACROSTR(SuspendedEVSE),
  253. MACROSTR(SuspendedEV),
  254. MACROSTR(Finishing),
  255. MACROSTR(Reserved),
  256. MACROSTR(Unavailable),
  257. MACROSTR(Faulted)
  258. };
  259. /*AvailabilityType*/
  260. typedef enum {
  261. RegistrationStatus_Accepted,
  262. RegistrationStatus_Pending,
  263. RegistrationStatus_Rejected
  264. } RegistrationStatus;
  265. static char *RegistrationStatusStr[] = {
  266. MACROSTR(Accepted),
  267. MACROSTR(Pending),
  268. MACROSTR(Rejected)
  269. };
  270. /*AvailabilityType*/
  271. typedef enum {
  272. Inoperative,
  273. Operative
  274. } AvailabilityType;
  275. static char *AvailabilityTypeStr[] = {
  276. MACROSTR(Inoperative),
  277. MACROSTR(Operative)
  278. };
  279. /*AvailabilityStatus*/
  280. typedef enum {
  281. Accepted,
  282. Rejected,
  283. Scheduled
  284. } AvailabilityStatus;
  285. static char *AvailabilityStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected),
  288. MACROSTR(Scheduled)
  289. };
  290. /*ConfigurationStatus*/
  291. typedef enum {
  292. ConfigurationStatus_Accepted,
  293. ConfigurationStatus_Rejected,
  294. RebootRequired,
  295. NotSupported
  296. } ConfigurationStatus;
  297. static char *ConfigurationStatusStr[] = {
  298. MACROSTR(Accepted),
  299. MACROSTR(Rejected),
  300. MACROSTR(RebootRequired),
  301. MACROSTR(NotSupported)
  302. };
  303. /*ClearCacheStatus*/
  304. typedef enum {
  305. ClearCacheStatus_Accepted,
  306. ClearCacheStatus_Rejected
  307. } ClearCacheStatus;
  308. static char *ClearCacheStatusStr[] = {
  309. MACROSTR(Accepted),
  310. MACROSTR(Rejected)
  311. };
  312. /*ChargingProfilePurposeType*/
  313. typedef enum {
  314. ChargePointMaxProfile,
  315. TxDefaultProfile,
  316. TxProfile
  317. } ChargingProfilePurposeType;
  318. static char *ChargingProfilePurposeTypeStr[] = {
  319. MACROSTR(ChargePointMaxProfile),
  320. MACROSTR(TxDefaultProfile),
  321. MACROSTR(TxProfile)
  322. };
  323. /*ChargingProfileStatus*/
  324. typedef enum {
  325. ChargingProfileStatus_Accepted,
  326. ChargingProfileStatus_Rejected,
  327. ChargingProfileStatus_NotSupported
  328. } ChargingProfileStatus;
  329. static char *ChargingProfileStatusStr[] = {
  330. MACROSTR(Accepted),
  331. MACROSTR(Rejected),
  332. MACROSTR(NotSupported)
  333. };
  334. /*ClearChargingProfileStatus*/
  335. typedef enum {
  336. ClearChargingProfileStatus_Accepted,
  337. ClearChargingProfileStatus_Unknown
  338. } ClearChargingProfileStatus;
  339. static char *ClearChargingProfileStatusStr[] = {
  340. MACROSTR(Accepted),
  341. MACROSTR(Unknown)
  342. };
  343. /*GetCompositeScheduleStatus*/
  344. typedef enum {
  345. GetCompositeScheduleStatus_Accepted,
  346. GetCompositeScheduleStatus_Rejected
  347. } GetCompositeScheduleStatus;
  348. static char *GetCompositeScheduleStatusStr[] = {
  349. MACROSTR(Accepted),
  350. MACROSTR(Rejected)
  351. };
  352. /*ChargingRateUnitType*/
  353. typedef enum {
  354. ChargingRateUnitType_W,
  355. ChargingRateUnitType_A
  356. } ChargingRateUnitType;
  357. /*AuthorizationStatus*/
  358. typedef enum {
  359. AuthorizationStatus_Accepted ,
  360. AuthorizationStatus_Blocked ,
  361. AuthorizationStatus_Expired ,
  362. AuthorizationStatus_Invalid ,
  363. AuthorizationStatus_ConcurrentTx
  364. } AuthorizationStatus;
  365. /*UpdateType*/
  366. typedef enum {
  367. Differential ,
  368. Full
  369. } UpdateType;
  370. static char *UpdateTypeStr[] = {
  371. MACROSTR(Differential),
  372. MACROSTR(Full)
  373. };
  374. /*UpdateStatus*/
  375. typedef enum {
  376. UpdateStatus_Accepted ,
  377. UpdateStatus_Failed ,
  378. UpdateStatus_NotSupported ,
  379. UpdateStatus_VersionMismatch
  380. } UpdateStatus;
  381. static char *UpdateStatusStr[] = {
  382. MACROSTR(Accepted),
  383. MACROSTR(Failed),
  384. MACROSTR(NotSupported),
  385. MACROSTR(VersionMismatch)
  386. };
  387. /*RemoteStartStopStatus*/
  388. typedef enum {
  389. RemoteStartStopStatus_Accepted,
  390. RemoteStartStopStatus_Rejected
  391. } RemoteStartStopStatus;
  392. static char *RemoteStartStopStatusStr[] = {
  393. MACROSTR(Accepted),
  394. MACROSTR(Rejected)
  395. };
  396. /*ReservationStatus*/
  397. typedef enum {
  398. ReservationStatus_Accepted,
  399. ReservationStatus_Faulted,
  400. ReservationStatus_Occupied,
  401. ReservationStatus_Rejected,
  402. ReservationStatus_Unavailable
  403. } ReservationStatus;
  404. static char *ReservationStatusStr[] = {
  405. MACROSTR(Accepted),
  406. MACROSTR(Faulted),
  407. MACROSTR(Occupied),
  408. MACROSTR(Rejected),
  409. MACROSTR(Unavailable)
  410. };
  411. /*ResetType*/
  412. typedef enum {
  413. Hard,
  414. Soft
  415. } ResetType;
  416. static char *ResetTypeStr[] = {
  417. MACROSTR(Hard),
  418. MACROSTR(Soft)
  419. };
  420. /*ResetStatus*/
  421. typedef enum {
  422. ResetStatus_Accepted,
  423. ResetStatus_Rejected
  424. } ResetStatus;
  425. static char *ResetStatusStr[] = {
  426. MACROSTR(Accepted),
  427. MACROSTR(Rejected)
  428. };
  429. /*DiagnosticsStatus*/
  430. typedef enum {
  431. DiagnosticsStatus_Idle,
  432. DiagnosticsStatus_Uploaded,
  433. DiagnosticsStatus_UploadFailed,
  434. DiagnosticsStatus_Uploading
  435. } DiagnosticsStatus;
  436. static char * DiagnosticsStatusStr[] = {
  437. MACROSTR(Idle),
  438. MACROSTR(Uploaded),
  439. MACROSTR(UploadFailed),
  440. MACROSTR(Uploading)
  441. };
  442. /*FirmwareStatus*/
  443. typedef enum {
  444. FirmwareStatus_Downloaded,
  445. FirmwareStatus_DownloadFailed,
  446. FirmwareStatus_Downloading,
  447. FirmwareStatus_Idle,
  448. FirmwareStatus_InstallationFailed,
  449. FirmwareStatus_Installing,
  450. FirmwareStatus_Installed
  451. } FirmwareStatus;
  452. static char * FirmwareStatusStr[] = {
  453. MACROSTR(Downloaded),
  454. MACROSTR(DownloadFailed),
  455. MACROSTR(Downloading),
  456. MACROSTR(Idle),
  457. MACROSTR(InstallationFailed),
  458. MACROSTR(Installing),
  459. MACROSTR(Installed)
  460. };
  461. /*MessageTrigger*/
  462. typedef enum {
  463. BootNotification,
  464. DiagnosticsStatusNotification,
  465. FirmwareStatusNotification,
  466. Heartbeat,
  467. MeterValues,
  468. StatusNotification
  469. } MessageTrigger;
  470. static char * MessageTriggerStr[] = {
  471. MACROSTR(BootNotification),
  472. MACROSTR(DiagnosticsStatusNotification),
  473. MACROSTR(FirmwareStatusNotification),
  474. MACROSTR(Heartbeat),
  475. MACROSTR(MeterValues),
  476. MACROSTR(StatusNotification)
  477. };
  478. /*TriggerMessageStatus*/
  479. typedef enum {
  480. TriggerMessageStatus_Accepted ,
  481. TriggerMessageStatus_Rejected ,
  482. TriggerMessageStatus_NotImplemented
  483. } TriggerMessageStatus;
  484. static char * TriggerMessageStatusStr[] = {
  485. MACROSTR(Accepted),
  486. MACROSTR(Rejected),
  487. MACROSTR(NotImplemented)
  488. };
  489. /*UnlockStatus*/
  490. typedef enum {
  491. Unlocked,
  492. UnlockFailed,
  493. UnlockStatus_NotSupported
  494. } UnlockStatus;
  495. static char * UnlockStatusStr[] = {
  496. MACROSTR(Unlocked),
  497. MACROSTR(UnlockFailed),
  498. MACROSTR(NotSupported)
  499. };
  500. /*StopTransactionReason*/
  501. typedef enum {
  502. EmergencyStop,
  503. EVDisconnected,
  504. HardReset,
  505. Local,
  506. Other,
  507. PowerLoss,
  508. Reboot,
  509. Remote,
  510. SoftReset,
  511. UnlockCommand,
  512. DeAuthorized
  513. } StopTransactionReason;
  514. #if 0
  515. static char * StopTransactionReasonStr[] = {
  516. MACROSTR(EmergencyStop),
  517. MACROSTR(EVDisconnected),
  518. MACROSTR(HardReset),
  519. MACROSTR(Local),
  520. MACROSTR(Other),
  521. MACROSTR(PowerLoss),
  522. MACROSTR(Reboot),
  523. MACROSTR(Remote),
  524. MACROSTR(SoftReset),
  525. MACROSTR(UnlockCommand),
  526. MACROSTR(DeAuthorized)
  527. };
  528. #endif
  529. /*CancelReservationStatus*/
  530. typedef enum {
  531. CancelReservationStatus_Accepted,
  532. CancelReservationStatus_Rejected
  533. } CancelReservationStatus;
  534. static char * CancelReservationStatusStr[] = {
  535. MACROSTR(Accepted),
  536. MACROSTR(Rejected)
  537. };
  538. /*ReadingContext*/
  539. typedef enum {
  540. ReadingContext_Interruption_Begin,
  541. ReadingContext_Interruption_End,
  542. ReadingContext_Other,
  543. ReadingContext_Sample_Clock,
  544. ReadingContext_Sample_Periodic ,
  545. ReadingContext_Transaction_Begin ,
  546. ReadingContext_Transaction_End,
  547. ReadingContext_Trigger
  548. } ReadingContext;
  549. static char * ReadingContextStr[] = {
  550. MACROSTR(Interruption.Begin),
  551. MACROSTR(Interruption.End),
  552. MACROSTR(Other),
  553. MACROSTR(Sample.Clock),
  554. MACROSTR(Sample.Periodic),
  555. MACROSTR(Transaction.Begin),
  556. MACROSTR(Transaction.End),
  557. MACROSTR(Trigger)
  558. };
  559. /*ValueFormat*/
  560. typedef enum {
  561. Raw,
  562. SignedData
  563. } ValueFormat;
  564. static char * ValueFormatStr[] = {
  565. MACROSTR(Raw),
  566. MACROSTR(SignedData)
  567. };
  568. /*Measurand*/
  569. typedef enum {
  570. Current_Export ,
  571. Current_Import,
  572. Current_Offered,
  573. Energy_Active_Export_Register,
  574. Energy_Active_Import_Register,
  575. Energy_Reactive_Export_Register,
  576. Energy_Reactive_Import_Register,
  577. Energy_Active_Export_Interval,
  578. Energy_Active_Import_Interval,
  579. Energy_Reactive_Export_Interval,
  580. Energy_Reactive_Import_Interval,
  581. Frequency,
  582. Power_Active_Export ,
  583. Power_Active_Import,
  584. Power_Factor,
  585. Power_Offered,
  586. Power_Reactive_Export,
  587. Power_Reactive_Import,
  588. RPM,
  589. SoC,
  590. Temperature ,
  591. Voltage
  592. } Measurand;
  593. static char * MeasurandStr[] = {
  594. MACROSTR(Current.Export),
  595. MACROSTR(Current.Import),
  596. MACROSTR(Current.Offered),
  597. MACROSTR(Energy.Active.Export.Register),
  598. MACROSTR(Energy.Active.Import.Register),
  599. MACROSTR(Energy.Reactive.Export.Register),
  600. MACROSTR(Energy.Reactive.Import.Register),
  601. MACROSTR(Energy.Active.Export.Interval),
  602. MACROSTR(Energy.Active.Import.Interval),
  603. MACROSTR(Energy.Reactive.Export.Interval),
  604. MACROSTR(Energy.Reactive.Import.Interval),
  605. MACROSTR(Frequency),
  606. MACROSTR(Power.Active.Export),
  607. MACROSTR(Power.Active.Import),
  608. MACROSTR(Power.Factor),
  609. MACROSTR(Power.Offered),
  610. MACROSTR(Power.Reactive.ExportMACROSTR),
  611. MACROSTR(Power.Reactive.Import),
  612. MACROSTR(RPM),
  613. MACROSTR(SoC),
  614. MACROSTR(Temperature),
  615. MACROSTR(Voltage)
  616. };
  617. /*Location*/
  618. typedef enum {
  619. Location_Body,
  620. Location_Cable,
  621. Location_EV,
  622. Location_Inlet ,
  623. Location_Outlet
  624. } Location;
  625. static char * LocationStr[] = {
  626. MACROSTR(Body),
  627. MACROSTR(Cable),
  628. MACROSTR(EV),
  629. MACROSTR(Inlet),
  630. MACROSTR(Outlet)
  631. };
  632. /*Phase*/
  633. typedef enum {
  634. L1,
  635. L2,
  636. L3,
  637. N,
  638. L1_N,
  639. L2_N,
  640. L3_N,
  641. L1_L2,
  642. L2_L3,
  643. L3_L1
  644. } Phase;
  645. static char * PhaseStr[] = {
  646. MACROSTR(L1),
  647. MACROSTR(L2),
  648. MACROSTR(L3),
  649. MACROSTR(N),
  650. MACROSTR(L1-N),
  651. MACROSTR(L2-N),
  652. MACROSTR(L3-N),
  653. MACROSTR(L1-L2),
  654. MACROSTR(L2-L3),
  655. MACROSTR(L3-L1)
  656. };
  657. /*UnitOfMeasure*/
  658. typedef enum {
  659. UnitOfMeasure_Wh,
  660. UnitOfMeasure_kWh ,
  661. UnitOfMeasure_varh ,
  662. UnitOfMeasure_kvarh ,
  663. UnitOfMeasure_W ,
  664. UnitOfMeasure_kW ,
  665. UnitOfMeasure_VA ,
  666. UnitOfMeasure_kVA ,
  667. UnitOfMeasure_var ,
  668. UnitOfMeasure_kvar ,
  669. UnitOfMeasure_A ,
  670. UnitOfMeasure_V ,
  671. UnitOfMeasure_Celsius ,
  672. UnitOfMeasure_Fahrenheit ,
  673. UnitOfMeasure_K ,
  674. UnitOfMeasure_Percent
  675. } UnitOfMeasure;
  676. static char * UnitOfMeasureStr[] = {
  677. MACROSTR(Wh),
  678. MACROSTR(kWh),
  679. MACROSTR(varh),
  680. MACROSTR(kvarh),
  681. MACROSTR(W),
  682. MACROSTR(kW),
  683. MACROSTR(VA),
  684. MACROSTR(kVA),
  685. MACROSTR(var),
  686. MACROSTR(kvar),
  687. MACROSTR(A),
  688. MACROSTR(V),
  689. MACROSTR(Celsius),
  690. MACROSTR(Fahrenheit),
  691. MACROSTR(K),
  692. MACROSTR(Percent)
  693. };
  694. #if 0
  695. /*Configuration enum*/
  696. enum CoreProfile {
  697. AllowOfflineTxForUnknownId=0,
  698. AuthorizationCacheEnabled,
  699. AuthorizeRemoteTxRequests,
  700. BlinkRepeat,
  701. ClockAlignedDataInterval,
  702. ConnectionTimeOut,
  703. GetConfigurationMaxKeys,
  704. HeartbeatInterval,
  705. LightIntensity,
  706. LocalAuthorizeOffline,
  707. LocalPreAuthorize,
  708. MaxEnergyOnInvalidId,
  709. MeterValuesAlignedData,
  710. MeterValuesAlignedDataMaxLength,
  711. MeterValuesSampledData,
  712. MeterValuesSampledDataMaxLength,
  713. MeterValueSampleInterval,
  714. MinimumStatusDuration,
  715. NumberOfConnectors,
  716. ResetRetries,
  717. ConnectorPhaseRotation,
  718. ConnectorPhaseRotationMaxLength,
  719. StopTransactionOnEVSideDisconnect,
  720. StopTransactionOnInvalidId,
  721. StopTxnAlignedData,
  722. StopTxnAlignedDataMaxLength,
  723. StopTxnSampledData,
  724. StopTxnSampledDataMaxLength,
  725. SupportedFeatureProfiles,
  726. SupportedFeatureProfilesMaxLength,
  727. TransactionMessageAttempts,
  728. TransactionMessageRetryInterval,
  729. UnlockConnectorOnEVSideDisconnect,
  730. WebSocketPingInterval,
  731. _CoreProfile_CNT
  732. };
  733. #endif
  734. enum LocalAuthListManagementProfile{
  735. LocalAuthListEnabled=0,
  736. LocalAuthListMaxLength,
  737. SendLocalListMaxLength,
  738. _LocalAuthListManagementProfile_CNT
  739. };
  740. enum ReservationProfile{
  741. ReserveConnectorZeroSupported
  742. };
  743. enum SmartChargingProfile{
  744. ChargeProfileMaxStackLevel,
  745. ChargingScheduleAllowedChargingRateUnit,
  746. ChargingScheduleMaxPeriods,
  747. ConnectorSwitch3to1PhaseSupported,
  748. MaxChargingProfilesInstalled
  749. };
  750. enum ChargerSystemStatus{
  751. ChargerSystemStatus_Booting,
  752. ChargerSystemStatus_Idle,
  753. ChargerSystemStatus_Authorizing,
  754. ChargerSystemStatus_Preparing,
  755. ChargerSystemStatus_Charging,
  756. ChargerSystemStatus_Terminating,
  757. ChargerSystemStatus_Alarm,
  758. ChargerSystemStatus_Fault
  759. };
  760. enum GetConfigurationKey {
  761. GetConfiguration_AllowOfflineTxForUnknownId=0,
  762. GetConfiguration_AuthorizationCacheEnabled,
  763. GetConfiguration_AuthorizeRemoteTxRequests,
  764. GetConfiguration_BlinkRepeat,
  765. GetConfiguration_ClockAlignedDataInterval,
  766. GetConfiguration_ConnectionTimeOut,
  767. GetConfiguration_GetConfigurationMaxKeys,
  768. GetConfiguration_HeartbeatInterval,
  769. GetConfiguration_LightIntensity,
  770. GetConfiguration_LocalAuthorizeOffline,
  771. GetConfiguration_LocalPreAuthorize,
  772. GetConfiguration_MaxEnergyOnInvalidId,
  773. GetConfiguration_MeterValuesAlignedData,
  774. GetConfiguration_MeterValuesAlignedDataMaxLength,
  775. GetConfiguration_MeterValuesSampledData,
  776. GetConfiguration_MeterValuesSampledDataMaxLength,
  777. GetConfiguration_MeterValueSampleInterval,
  778. GetConfiguration_MinimumStatusDuration,
  779. GetConfiguration_NumberOfConnectors,
  780. GetConfiguration_ResetRetries,
  781. GetConfiguration_ConnectorPhaseRotation,
  782. GetConfiguration_ConnectorPhaseRotationMaxLength,
  783. GetConfiguration_StopTransactionOnEVSideDisconnect,
  784. GetConfiguration_StopTransactionOnInvalidId,
  785. GetConfiguration_StopTxnAlignedData,
  786. GetConfiguration_StopTxnAlignedDataMaxLength,
  787. GetConfiguration_StopTxnSampledData,
  788. GetConfiguration_StopTxnSampledDataMaxLength,
  789. GetConfiguration_SupportedFeatureProfiles,
  790. GetConfiguration_SupportedFeatureProfilesMaxLength,
  791. GetConfiguration_TransactionMessageAttempts,
  792. GetConfiguration_TransactionMessageRetryInterval,
  793. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  794. GetConfiguration_WebSocketPingInterval,
  795. GetConfiguration_LocalAuthListEnabled,
  796. GetConfiguration_LocalAuthListMaxLength,
  797. GetConfiguration_SendLocalListMaxLength,
  798. GetConfiguration_ReserveConnectorZeroSupported,
  799. GetConfiguration_ChargeProfileMaxStackLevel,
  800. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  801. GetConfiguration_ChargingScheduleMaxPeriods,
  802. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  803. GetConfiguration_MaxChargingProfilesInstalled,
  804. };
  805. //GetConfiguration Array
  806. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  807. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  808. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  809. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  810. //==========================================
  811. // Init all share memory
  812. //==========================================
  813. int InitShareMemory()
  814. {
  815. int result = PASS;
  816. int MeterSMId;
  817. //creat ShmSysConfigAndInfo
  818. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  819. {
  820. #ifdef SystemLogMessage
  821. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  822. #endif
  823. result = FAIL;
  824. }
  825. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  826. {
  827. #ifdef SystemLogMessage
  828. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  829. #endif
  830. result = FAIL;
  831. }
  832. else
  833. {}
  834. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  835. {
  836. #ifdef SystemLogMessage
  837. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  838. #endif
  839. result = FAIL;
  840. }
  841. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  842. {
  843. #ifdef SystemLogMessage
  844. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  845. #endif
  846. result = FAIL;
  847. }
  848. else
  849. {}
  850. //creat ShmPsuData
  851. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  852. {
  853. #ifdef SystemLogMessage
  854. DEBUG_ERROR("shmget ShmPsuData NG\n");
  855. #endif
  856. result = FAIL;
  857. }
  858. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  859. {
  860. #ifdef SystemLogMessage
  861. DEBUG_ERROR("shmat ShmPsuData NG\n");
  862. #endif
  863. result = FAIL;
  864. }
  865. else
  866. {}
  867. //creat ShmOCPP16Data
  868. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  872. #endif
  873. result = FAIL;
  874. }
  875. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  876. {
  877. #ifdef SystemLogMessage
  878. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  879. #endif
  880. result = FAIL;
  881. }
  882. else
  883. {}
  884. /****************************** For Initial Settings************************************************/
  885. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  886. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  887. {
  888. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  889. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  890. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  891. }
  892. // Charger PRE_SYS_MODE
  893. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  894. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  895. clientTime.Heartbeat=time((time_t*)NULL);
  896. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  897. {
  898. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  899. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  900. }
  901. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  902. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  903. // allocate Configuration memory address
  904. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  905. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  906. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  907. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  909. {
  910. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  911. DEBUG_INFO("DC ...\n");
  912. }
  913. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  914. {
  915. SystemInitial = AC_QUANTITY;
  916. DEBUG_INFO("AC ...\n");
  917. }
  918. //Status Setting
  919. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  920. {
  921. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  922. }
  923. for (int index = 0; index < CCS_QUANTITY; index++)
  924. {
  925. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  926. }
  927. for (int index = 0; index < GB_QUANTITY; index++)
  928. {
  929. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  930. }
  931. for (int index = 0; index < AC_QUANTITY; index++)
  932. {
  933. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  934. }
  935. return result;
  936. }
  937. int ProcessShareMemory()
  938. {
  939. if(InitShareMemory() == FAIL)
  940. {
  941. #ifdef SystemLogMessage
  942. DEBUG_ERROR("InitShareMemory NG\n");
  943. #endif
  944. if(ShmStatusCodeData!=NULL)
  945. {
  946. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  947. }
  948. sleep(5);
  949. return FAIL;
  950. }
  951. return PASS;
  952. }
  953. //---------------------------------------------
  954. // new:
  955. // enum SYSTEM_STATUS
  956. // {
  957. // SYS_MODE_BOOTING = 0,
  958. // SYS_MODE_IDLE = 1,
  959. // SYS_MODE_AUTHORIZING = 2,
  960. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  961. // SYS_MODE_REASSIGN = 4,
  962. // SYS_MODE_PREPARING = 5,
  963. // SYS_MODE_PREPARE_FOR_EV = 6,
  964. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  965. // SYS_MODE_CHARGING = 8,
  966. // SYS_MODE_TERMINATING = 9,
  967. // SYS_MODE_COMPLETE = 10,
  968. // SYS_MODE_ALARM = 11,
  969. // SYS_MODE_FAULT = 12,
  970. // SYS_MODE_RESERVATION = 13,
  971. // SYS_MODE_BOOKING = 14,
  972. // SYS_MODE_MAINTAIN = 15,
  973. // SYS_MODE_DEBUG = 16,
  974. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  975. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  976. // SYS_MODE_UPDATE = 19
  977. // };
  978. //
  979. //
  980. //-----------------------------------------
  981. void CheckSystemValue(void)
  982. {
  983. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  984. int IdleModeCnt = 0;
  985. char filenmae[100]={0};
  986. char str[100]={0};
  987. //===============================
  988. // send Heartbeat
  989. //===============================
  990. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  991. {
  992. printf("Heartbeat !!!\n");
  993. //parameter for test
  994. sendHeartbeatRequest(0);
  995. //==============================================
  996. // Reset Waiting Time
  997. //==============================================
  998. clientTime.Heartbeat=time((time_t*)NULL);
  999. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1000. }
  1001. //==============================================
  1002. // Update firmware request
  1003. //==============================================
  1004. if(isUpdateRequest == TRUE )
  1005. {
  1006. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1007. {
  1008. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1009. {
  1010. //check SystemStatus
  1011. /*************************DC*******************************/
  1012. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1013. {
  1014. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1015. {
  1016. IdleModeCnt = IdleModeCnt + 1;
  1017. }
  1018. }
  1019. for (int index = 0; index < CCS_QUANTITY; index++)
  1020. {
  1021. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1022. {
  1023. IdleModeCnt = IdleModeCnt + 1;
  1024. }
  1025. }
  1026. for (int index = 0; index < GB_QUANTITY; index++)
  1027. {
  1028. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1029. {
  1030. IdleModeCnt = IdleModeCnt + 1;
  1031. }
  1032. }
  1033. }
  1034. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1035. {
  1036. isUpdateRequest = FALSE;
  1037. }
  1038. }
  1039. else
  1040. {
  1041. /*************************AC*******************************/
  1042. for (int index = 0; index < AC_QUANTITY; index++)
  1043. {
  1044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1045. {
  1046. IdleModeCnt = IdleModeCnt + 1;
  1047. }
  1048. }
  1049. if(IdleModeCnt == AC_QUANTITY)
  1050. {
  1051. isUpdateRequest = FALSE;
  1052. }
  1053. }
  1054. }
  1055. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1056. {
  1057. //===============================
  1058. // CSU Trigger Reset Conf
  1059. //===============================
  1060. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1061. {
  1062. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1063. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1064. {
  1065. server_sign = FALSE;
  1066. }
  1067. }
  1068. //===============================
  1069. // CSU Trigger Authorize Request
  1070. //===============================
  1071. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1072. {
  1073. sendAuthorizeRequest(0);
  1074. authorizeRetryTimes = authorizeRetryTimes + 1;
  1075. // authenrequest = TRUE
  1076. if(authorizeRetryTimes < 3)
  1077. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1078. }
  1079. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1080. {
  1081. authorizeRetryTimes = 0;
  1082. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1083. server_sign = FALSE;
  1084. }
  1085. 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))
  1086. {
  1087. sendAuthorizeRequest(0);
  1088. }
  1089. //===============================
  1090. // CSU Trigger Smart Charging Profilw
  1091. //===============================
  1092. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1093. {
  1094. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1095. GetChargingProfileRequest(gun_index);
  1096. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1097. }
  1098. //==============================================
  1099. // Charger start transaction
  1100. //==============================================
  1101. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1102. {
  1103. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1104. sendStartTransactionRequest(gun_index);
  1105. clientTime.StartTransaction = time((time_t*)NULL);
  1106. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1107. }
  1108. //==============================================
  1109. // Charger stop transaction
  1110. //==============================================
  1111. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1112. {
  1113. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1114. sendStopTransactionRequest(gun_index);
  1115. clientTime.StopTransaction = time((time_t*)NULL);
  1116. }
  1117. //==============================================
  1118. // Charger status report
  1119. //==============================================
  1120. /* Check Mode Change */
  1121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1122. {
  1123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1124. {
  1125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1126. {
  1127. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1128. {
  1129. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1130. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1131. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1132. statusModeChage[gun_index] = TRUE;
  1133. }
  1134. }
  1135. }
  1136. for (int index = 0; index < CCS_QUANTITY; index++)
  1137. {
  1138. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1139. {
  1140. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1141. {
  1142. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1143. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1144. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1145. statusModeChage[gun_index] = TRUE;
  1146. }
  1147. }
  1148. }
  1149. for (int index = 0; index < GB_QUANTITY; index++)
  1150. {
  1151. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1152. {
  1153. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1154. {
  1155. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1156. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1157. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1158. statusModeChage[gun_index] = TRUE;
  1159. }
  1160. }
  1161. }
  1162. }
  1163. else //AC
  1164. {
  1165. for (int index = 0; index < AC_QUANTITY; index++)
  1166. {
  1167. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1168. {
  1169. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1170. {
  1171. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1172. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1173. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1174. statusModeChage[gun_index] = TRUE;
  1175. }
  1176. }
  1177. }// END OF FOR
  1178. }// END OF ELSE
  1179. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1180. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1181. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1182. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1183. {
  1184. if(SystemInitial != 0)
  1185. SystemInitial = SystemInitial -1;
  1186. sendStatusNotificationRequest(gun_index);
  1187. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1188. statusModeChage[gun_index] = FALSE;
  1189. }
  1190. //==============================================
  1191. // Meter report
  1192. //==============================================
  1193. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1194. {
  1195. //check Transaction active
  1196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1197. {
  1198. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1199. {
  1200. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1201. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1202. {
  1203. meterValueSend[gun_index] =1;
  1204. }
  1205. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1206. {
  1207. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1208. if((access(filenmae,F_OK))!=-1)
  1209. {
  1210. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1211. sprintf(str,"rm -f %s",filenmae);
  1212. system(str);
  1213. }
  1214. }
  1215. }// End for CHAdeMO
  1216. for (int index = 0; index < CCS_QUANTITY; index++)
  1217. {
  1218. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1219. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1220. {
  1221. meterValueSend[gun_index] =1;
  1222. }
  1223. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1224. {
  1225. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1226. if((access(filenmae,F_OK))!=-1)
  1227. {
  1228. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1229. sprintf(str,"rm -f %s",filenmae);
  1230. system(str);
  1231. }
  1232. }
  1233. } // End for CCS
  1234. for (int index = 0; index < GB_QUANTITY; index++)
  1235. {
  1236. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1237. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1238. {
  1239. meterValueSend[gun_index] =1;
  1240. }
  1241. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1242. {
  1243. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1244. if((access(filenmae,F_OK))!=-1)
  1245. {
  1246. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1247. sprintf(str,"rm -f %s",filenmae);
  1248. system(str);
  1249. }
  1250. }
  1251. }// End for GB
  1252. }
  1253. else
  1254. {
  1255. for (int index = 0; index < AC_QUANTITY; index++)
  1256. {
  1257. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1258. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1259. {
  1260. meterValueSend[gun_index] =1;
  1261. }
  1262. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1263. {
  1264. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1265. if((access(filenmae,F_OK))!=-1)
  1266. {
  1267. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1268. sprintf(str,"rm -f %s",filenmae);
  1269. system(str);
  1270. }
  1271. }
  1272. }//End for AC
  1273. }//END OF ELSE
  1274. // sleep(1);
  1275. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1276. if(meterValueSend[gun_index] == 1)
  1277. sendMeterValuesRequest(gun_index);
  1278. }
  1279. //==============================================
  1280. // Check Connector reserved
  1281. //==============================================
  1282. //===============================
  1283. // Check if Reserve is expired
  1284. //===============================
  1285. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1286. {
  1287. double diff_t;
  1288. struct tm tp;
  1289. // current time
  1290. time_t t = time(NULL);
  1291. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1292. tp.tm_isdst = -1;
  1293. time_t utc = mktime(&tp);
  1294. diff_t = difftime(utc, t);
  1295. if(diff_t <= 0)
  1296. {
  1297. DEBUG_INFO("reserve expired !!! \n");
  1298. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1299. }
  1300. }//END OF Check if Reserve is expired
  1301. //==========================================
  1302. // csu trigger FirmwareStatusNotificationReq
  1303. //==========================================
  1304. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1305. {
  1306. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1307. }
  1308. //==========================================
  1309. // csu trigger CancelReservationConf
  1310. //==========================================
  1311. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1312. {
  1313. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1314. }
  1315. //==========================================
  1316. // csu trigger ChangeAvailabilityConf
  1317. //==========================================
  1318. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1319. {
  1320. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1321. }
  1322. //==========================================
  1323. // csu trigger UnlockConnectorConf
  1324. //==========================================
  1325. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1326. {
  1327. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1328. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1329. }
  1330. //==========================================
  1331. // csu trigger ReserveNowConf
  1332. //==========================================
  1333. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1334. {
  1335. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1336. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1337. }
  1338. //==========================================
  1339. // csu trigger DataTransferReq
  1340. //==========================================
  1341. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1342. {
  1343. sendDataTransferRequest(gun_index);
  1344. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1345. }
  1346. }
  1347. }
  1348. //==========================================
  1349. // send request routine
  1350. //==========================================
  1351. int sendAuthorizeRequest(int gun_index)
  1352. {
  1353. mtrace();
  1354. int result = FAIL;
  1355. char message[100]={0};
  1356. char guid[37];
  1357. char tempdata[65]={0};
  1358. DEBUG_INFO("sendAuthorizeRequest \n");
  1359. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1360. //Local Authorize
  1361. if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1362. {
  1363. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1364. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1365. {
  1366. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1367. {
  1368. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1369. }
  1370. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1371. {
  1372. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1373. }
  1374. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1375. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1376. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1377. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1378. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1379. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1380. authorizeRetryTimes = 0;
  1381. return result;
  1382. }
  1383. else
  1384. {
  1385. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1386. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1387. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1388. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1389. result = PASS;
  1390. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1391. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1392. authorizeRetryTimes = 0;
  1393. return result;
  1394. }
  1395. }
  1396. //initailize struct Authorize
  1397. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1398. //get data from shared memory
  1399. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1400. random_uuid(guid);
  1401. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1402. LWS_Send(message);
  1403. sprintf(tempdata, "Authorize,%d", gun_index);
  1404. if(hashmap_operation(0, guid, tempdata) == 1)
  1405. {
  1406. result = PASS;
  1407. DEBUG_ERROR("Authorize mapItem pass\n");
  1408. }
  1409. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1410. return result;
  1411. }
  1412. int sendBootNotificationRequest(void)
  1413. {
  1414. mtrace();
  1415. int result = FAIL;
  1416. char message[500]={0}, payload[700]={0};
  1417. char guid[37]={0};
  1418. char tempdata[65]={0};
  1419. int IsGunCharging = FALSE;
  1420. //check Transaction active
  1421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1422. {
  1423. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1424. {
  1425. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1426. {
  1427. IsGunCharging = TRUE;
  1428. }
  1429. }
  1430. for (int index = 0; index < CCS_QUANTITY; index++)
  1431. {
  1432. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1433. {
  1434. IsGunCharging = TRUE;
  1435. }
  1436. }
  1437. for (int index = 0; index < GB_QUANTITY; index++)
  1438. {
  1439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1440. {
  1441. IsGunCharging = TRUE;
  1442. }
  1443. }
  1444. }
  1445. else
  1446. {
  1447. for (int index = 0; index < AC_QUANTITY; index++)
  1448. {
  1449. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1450. {
  1451. IsGunCharging = TRUE;
  1452. }
  1453. }
  1454. }
  1455. if(IsGunCharging == TRUE)
  1456. {
  1457. server_sign = TRUE;
  1458. return result;
  1459. }
  1460. // Fill BootNotification fields
  1461. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1462. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1463. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1464. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1465. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1466. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1467. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1468. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1469. ShmOCPP16Data->ChargeBoxId
  1470. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1471. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1472. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1473. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1474. ,ShmOCPP16Data->BootNotification.CpIccid
  1475. ,ShmOCPP16Data->BootNotification.CpImsi
  1476. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1477. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1478. random_uuid(guid);
  1479. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1480. LWS_Send(message);
  1481. sprintf(tempdata, "BootNotification,0");
  1482. 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*/)
  1483. {
  1484. result = PASS;
  1485. }
  1486. memset(queuedata, 0, sizeof(queuedata));
  1487. strcpy(queuedata,message);
  1488. return result;
  1489. }
  1490. int sendDataTransferRequest(int gun_index)
  1491. {
  1492. mtrace();
  1493. char message[1000]={0};
  1494. char guid[37]={0};
  1495. char tempdata[65]={0};
  1496. int result = FAIL;
  1497. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1498. random_uuid(guid);
  1499. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1500. MESSAGE_TYPE_CALL,
  1501. guid,
  1502. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1503. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1504. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1505. LWS_Send(message);
  1506. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1507. 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*/)
  1508. {
  1509. result = PASS;
  1510. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1511. }
  1512. return result;
  1513. }
  1514. int sendDiagnosticsStatusNotificationRequest(char *status)
  1515. {
  1516. mtrace();
  1517. int result = FAIL;
  1518. char message[110]={0};
  1519. char guid[37]={0};
  1520. char tempdata[65]={0};
  1521. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1522. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1523. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1524. random_uuid(guid);
  1525. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1526. LWS_Send(message);
  1527. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1528. if(hashmap_operation(0, guid, tempdata) == 1)
  1529. {
  1530. result = PASS;
  1531. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1532. }
  1533. //#ifdef SystemLogMessage
  1534. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1535. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1536. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1537. //#endif
  1538. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1539. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1540. //record status
  1541. if(strcmp(status,"Idle")==0)
  1542. {
  1543. DiagnosticsStatusNotificationStatus = 0;
  1544. }
  1545. else if(strcmp(status,"Uploaded")==0)
  1546. {
  1547. DiagnosticsStatusNotificationStatus = 1;
  1548. }
  1549. else if(strcmp(status,"UploadFailed")==0)
  1550. {
  1551. DiagnosticsStatusNotificationStatus = 2;
  1552. }
  1553. else if(strcmp(status,"Uploading")==0)
  1554. {
  1555. DiagnosticsStatusNotificationStatus = 3;
  1556. }
  1557. return result;
  1558. }
  1559. int sendFirmwareStatusNotificationRequest(char *status)
  1560. {
  1561. mtrace();
  1562. int result = FAIL;
  1563. char message[110]={0};
  1564. char guid[37]={0};
  1565. char tempdata[65]={0};
  1566. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1567. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1568. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1569. random_uuid(guid);
  1570. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1571. LWS_Send(message);
  1572. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1573. 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*/)
  1574. {
  1575. result = PASS;
  1576. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1577. }
  1578. //#ifdef SystemLogMessage
  1579. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1580. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1581. //#endif
  1582. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1583. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1584. //record status
  1585. if(strcmp(status,"Downloaded")==0)
  1586. {
  1587. FirmwareStatusNotificationStatus = 0;
  1588. }
  1589. else if(strcmp(status,"DownloadFailed")==0)
  1590. {
  1591. FirmwareStatusNotificationStatus = 1;
  1592. }
  1593. else if(strcmp(status,"Downloading")==0)
  1594. {
  1595. FirmwareStatusNotificationStatus = 2;
  1596. }
  1597. else if(strcmp(status,"Idle")==0)
  1598. {
  1599. FirmwareStatusNotificationStatus = 3;
  1600. }
  1601. else if(strcmp(status,"InstallationFailed")==0)
  1602. {
  1603. FirmwareStatusNotificationStatus = 4;
  1604. }
  1605. else if(strcmp(status,"Installing")==0)
  1606. {
  1607. FirmwareStatusNotificationStatus = 5;
  1608. }
  1609. else if(strcmp(status,"Installed")==0)
  1610. {
  1611. FirmwareStatusNotificationStatus = 6;
  1612. }
  1613. return result;
  1614. }
  1615. int sendHeartbeatRequest(int gun_index)
  1616. {
  1617. mtrace();
  1618. int result = FAIL;
  1619. char message[80]={0};
  1620. char guid[37]={0};
  1621. char tempdata[65]={0};
  1622. random_uuid(guid);
  1623. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1624. , MESSAGE_TYPE_CALL
  1625. , guid );
  1626. LWS_Send(message);
  1627. sprintf(tempdata, "Heartbeat,%d", 0);
  1628. 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*/)
  1629. {
  1630. result = PASS;
  1631. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1632. }
  1633. return result;
  1634. }
  1635. int sendStartTransactionRequest(int gun_index)
  1636. {
  1637. mtrace();
  1638. int result = FAIL;
  1639. char message[250]={0};
  1640. char guid[37]={0};
  1641. struct timeval tmnow;
  1642. struct tm *tm;
  1643. char buf[28];//, usec_buf[6];
  1644. char tempdata[65]={0};
  1645. DEBUG_INFO("sendStartTransactionRequest...");
  1646. gettimeofday(&tmnow, NULL);
  1647. time_t t;
  1648. t = time(NULL);
  1649. /*UTC time and date*/
  1650. tm = gmtime(&t);
  1651. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1652. #if 0 // remove temporally
  1653. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1654. strcat(buf,".");
  1655. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1656. strcat(buf,usec_buf);
  1657. #endif
  1658. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1659. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1660. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1662. {
  1663. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1664. {
  1665. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1666. {
  1667. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1668. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1669. }
  1670. }
  1671. for (int index = 0; index < CCS_QUANTITY; index++)
  1672. {
  1673. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1674. {
  1675. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1676. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1677. }
  1678. }
  1679. for (int index = 0; index < GB_QUANTITY; index++)
  1680. {
  1681. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1682. {
  1683. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1684. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1685. }
  1686. }
  1687. }
  1688. else
  1689. {
  1690. for (int index = 0; index < AC_QUANTITY; index++)
  1691. {
  1692. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1693. {
  1694. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1695. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1696. }
  1697. }
  1698. }//END OF ELSE
  1699. random_uuid(guid);
  1700. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1701. , MESSAGE_TYPE_CALL
  1702. , guid
  1703. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1704. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1705. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1706. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1707. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1708. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1709. 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*/)
  1710. {
  1711. result = PASS;
  1712. }
  1713. strcpy(queuedata, message);
  1714. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1715. LWS_Send(message);
  1716. #if 0
  1717. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1718. 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*/)
  1719. {
  1720. result = PASS;
  1721. }
  1722. strcpy(queuedata, message);
  1723. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1724. #endif
  1725. //#ifdef SystemLogMessage
  1726. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1727. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1728. //#endif
  1729. return result;
  1730. }
  1731. int sendStatusNotificationRequest(int gun_index)
  1732. {
  1733. mtrace();
  1734. int result = FAIL;
  1735. char message[600]={0};
  1736. char guid[37];
  1737. int currentStatus = 0;
  1738. struct timeval tmnow;
  1739. struct tm *tm;
  1740. char buf[28];//, usec_buf[6];
  1741. char tempdata[65]={0};
  1742. gettimeofday(&tmnow, NULL);
  1743. time_t t;
  1744. t = time(NULL);
  1745. /*UTC time and date*/
  1746. tm = gmtime(&t);
  1747. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1748. #if 0 // remove temporally
  1749. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1750. strcat(buf,".");
  1751. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1752. strcat(buf,usec_buf);
  1753. #endif
  1754. printf("%s",buf);
  1755. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1756. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1757. // it's option
  1758. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1759. /*
  1760. enum _SYSTEM_STATUS
  1761. {
  1762. S_BOOTING = 0,
  1763. S_IDLE, = 1
  1764. S_AUTHORIZING, =2
  1765. S_REASSIGN_CHECK, =3
  1766. S_REASSIGN, =4
  1767. S_PRECHARGE, =5
  1768. S_PREPARING_FOR_EV, =6
  1769. S_PREPARING_FOR_EVSE, =7
  1770. S_CHARGING, =8
  1771. S_TERMINATING, =9
  1772. S_COMPLETE, =10
  1773. S_ALARM, =11
  1774. S_FAULT =12
  1775. }
  1776. */
  1777. //check Transaction active
  1778. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1779. {
  1780. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1781. {
  1782. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1783. {
  1784. currentStatus = 0; //OCPP Status: Available
  1785. }
  1786. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1787. {
  1788. currentStatus = 1; //OCPP Status: Preparing
  1789. }
  1790. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1791. {
  1792. currentStatus = 2; //OCPP Status: Charging
  1793. }
  1794. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1795. {
  1796. currentStatus = 5; //OCPP Status: Finishing
  1797. }
  1798. 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
  1799. {
  1800. currentStatus = 4; //OCPP Status: SuspendedEV
  1801. }
  1802. 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
  1803. {
  1804. currentStatus = 7; //OCPP Status: Unavailable
  1805. }
  1806. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1807. {
  1808. currentStatus = 8; //OCPP Status: Faulted
  1809. }
  1810. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1811. {
  1812. currentStatus = 6; //OCPP Status: Reserved
  1813. }
  1814. }//end of for CHAdeMO_QUANTITY
  1815. for (int index = 0; index < CCS_QUANTITY; index++)
  1816. {
  1817. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1818. {
  1819. currentStatus = 0; //OCPP Status: Available
  1820. }
  1821. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1822. {
  1823. currentStatus = 1; //OCPP Status: Preparing
  1824. }
  1825. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1826. {
  1827. currentStatus = 2; //OCPP Status: Charging
  1828. }
  1829. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1830. {
  1831. currentStatus = 5; //OCPP Status: Finishing
  1832. }
  1833. 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
  1834. {
  1835. currentStatus = 4; //OCPP Status: SuspendedEV
  1836. }
  1837. 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
  1838. {
  1839. currentStatus = 7; //OCPP Status : Unavailable
  1840. }
  1841. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1842. {
  1843. currentStatus = 8; //OCPP Status: Faulted
  1844. }
  1845. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1846. {
  1847. currentStatus = 6; //OCPP Status: Reserved
  1848. }
  1849. }
  1850. for (int index = 0; index < GB_QUANTITY; index++)
  1851. {
  1852. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1853. {
  1854. currentStatus = 0; //OCPP Status: Available
  1855. }
  1856. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1857. {
  1858. currentStatus = 1; //OCPP Status: Preparing
  1859. }
  1860. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1861. {
  1862. currentStatus = 2; //OCPP Status: Charging
  1863. }
  1864. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1865. {
  1866. currentStatus = 5; //OCPP Status: Finishing
  1867. }
  1868. 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
  1869. {
  1870. currentStatus = 4; //OCPP Status: SuspendedEV
  1871. }
  1872. 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
  1873. {
  1874. currentStatus = 7; //OCPP Status: Unavailable
  1875. }
  1876. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1877. {
  1878. currentStatus = 8; //OCPP Status: Faulted
  1879. }
  1880. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1881. {
  1882. currentStatus = 6; //OCPP Status: Reserved
  1883. }
  1884. }
  1885. }
  1886. else
  1887. {
  1888. for (int index = 0; index < AC_QUANTITY; index++)
  1889. {
  1890. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1891. {
  1892. currentStatus = 0; //OCPP Status: Available
  1893. }
  1894. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1895. {
  1896. currentStatus = 1; //OCPP Status: Preparing
  1897. }
  1898. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1899. {
  1900. currentStatus = 2; //OCPP Status: Charging
  1901. }
  1902. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1903. {
  1904. currentStatus = 5; //OCPP Status: Finishing
  1905. }
  1906. 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
  1907. {
  1908. currentStatus = 4; //OCPP Status: SuspendedEV
  1909. }
  1910. 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
  1911. {
  1912. currentStatus = 7; //OCPP Status: Unavailable
  1913. }
  1914. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1915. {
  1916. currentStatus = 8; //OCPP Status: Faulted
  1917. }
  1918. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1919. {
  1920. currentStatus = 6; //OCPP Status: Reserved
  1921. }
  1922. }//end of for AC_QUANTITY
  1923. }//END OF ELSE
  1924. //it's option
  1925. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1926. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1927. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1928. random_uuid(guid);
  1929. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1930. , MESSAGE_TYPE_CALL
  1931. , guid
  1932. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1933. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1934. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1935. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1936. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1937. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1938. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  1939. LWS_Send(message);
  1940. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  1941. 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*/)
  1942. {
  1943. //DEBUG_ERROR("statusNotification mapitem pass");
  1944. result = PASS;
  1945. }
  1946. return result;
  1947. }
  1948. int sendStopTransactionRequest(int gun_index)
  1949. {
  1950. mtrace();
  1951. int result = FAIL;
  1952. //char message[1500]={0};
  1953. char guid[37]={0};
  1954. char tempdata[65]={0};
  1955. //int idx_sample=0;
  1956. DEBUG_ERROR("sendStopTransactionRequest \n");
  1957. memset(queuedata, 0, sizeof(queuedata));
  1958. //ENERGY_ACTIVE_IMPORT_REGISTER
  1959. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1960. {
  1961. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1962. {
  1963. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1964. {
  1965. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1966. }
  1967. }// END OF CHAdeMO_QUANTITY
  1968. for (int index = 0; index < CCS_QUANTITY; index++)
  1969. {
  1970. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1971. {
  1972. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1973. }
  1974. }// END OF CCS_QUANTITY
  1975. for (int index = 0; index < GB_QUANTITY; index++)
  1976. {
  1977. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1978. {
  1979. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1980. }
  1981. }// END OF GB_QUANTITY
  1982. }
  1983. else
  1984. {
  1985. for (int index = 0; index < AC_QUANTITY; index++)
  1986. {
  1987. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1988. {
  1989. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1990. }
  1991. }// END OF AC_QUANTITY
  1992. }//END OF ELSE
  1993. //Stop Transaction Time
  1994. struct timeval tmnow;
  1995. struct tm *tm;
  1996. char buf[28];//, usec_buf[6];
  1997. gettimeofday(&tmnow, NULL);
  1998. time_t t;
  1999. t = time(NULL);
  2000. /*UTC time and date*/
  2001. tm = gmtime(&t);
  2002. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2004. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2005. random_uuid(guid);
  2006. /***********************************transactionData******************************************************/
  2007. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2009. //=================================
  2010. // Transaction_Begin
  2011. //=================================
  2012. // Energy.Active.Export.Interval
  2013. //idx_sample=0;
  2014. 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
  2015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2017. 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*/]);
  2018. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2019. {
  2020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2021. }
  2022. else
  2023. {
  2024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2025. }
  2026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2028. //=================================
  2029. // Transaction_End
  2030. //=================================
  2031. //Current.Export
  2032. //idx_sample=1;
  2033. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2034. {
  2035. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2036. {
  2037. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2038. {
  2039. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2040. }
  2041. }
  2042. for (int index = 0; index < CCS_QUANTITY; index++)
  2043. {
  2044. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2045. {
  2046. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2047. }
  2048. }
  2049. for (int index = 0; index < GB_QUANTITY; index++)
  2050. {
  2051. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2052. {
  2053. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2054. }
  2055. }
  2056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2057. }
  2058. else
  2059. {
  2060. for (int index = 0; index < AC_QUANTITY; index++)
  2061. {
  2062. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2063. {
  2064. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2065. }
  2066. }
  2067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2068. }// END FOR AC ELSE
  2069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2072. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2075. //Energy.Active.Export.Interval
  2076. //idx_sample=2;
  2077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2078. {
  2079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2080. {
  2081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2082. {
  2083. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2084. }
  2085. }
  2086. for (int index = 0; index < CCS_QUANTITY; index++)
  2087. {
  2088. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2089. {
  2090. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2091. }
  2092. }
  2093. for (int index = 0; index < GB_QUANTITY; index++)
  2094. {
  2095. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2096. {
  2097. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2098. }
  2099. }
  2100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2101. }
  2102. else
  2103. {
  2104. for (int index = 0; index < AC_QUANTITY; index++)
  2105. {
  2106. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2107. {
  2108. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2109. }
  2110. }
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2112. }// END FOR AC ELSE
  2113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval]);
  2116. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2119. //Power.Active.Export
  2120. //idx_sample=3;
  2121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2122. {
  2123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2124. {
  2125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2126. {
  2127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2128. }
  2129. }
  2130. for (int index = 0; index < CCS_QUANTITY; index++)
  2131. {
  2132. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2133. {
  2134. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2135. }
  2136. }
  2137. for (int index = 0; index < GB_QUANTITY; index++)
  2138. {
  2139. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2140. {
  2141. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2142. }
  2143. }
  2144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2145. }
  2146. else
  2147. {
  2148. for (int index = 0; index < AC_QUANTITY; index++)
  2149. {
  2150. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2151. {
  2152. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2153. }
  2154. }
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2156. }// END FOR AC ELSE
  2157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export]);
  2160. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2163. //Voltage
  2164. //idx_sample=4;
  2165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2166. {
  2167. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2168. {
  2169. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2170. {
  2171. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2172. }
  2173. }
  2174. for (int index = 0; index < CCS_QUANTITY; index++)
  2175. {
  2176. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2177. {
  2178. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2179. }
  2180. }
  2181. for (int index = 0; index < GB_QUANTITY; index++)
  2182. {
  2183. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2184. {
  2185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2186. }
  2187. }
  2188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2189. }
  2190. else
  2191. {
  2192. for (int index = 0; index < AC_QUANTITY; index++)
  2193. {
  2194. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2195. {
  2196. 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
  2197. }
  2198. }
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2200. }// END FOR AC ELSE
  2201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2204. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2207. //SoC
  2208. //idx_sample=5;
  2209. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2210. {
  2211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2212. {
  2213. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2214. {
  2215. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2216. }
  2217. }
  2218. for (int index = 0; index < CCS_QUANTITY; index++)
  2219. {
  2220. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2221. {
  2222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2223. }
  2224. }
  2225. for (int index = 0; index < GB_QUANTITY; index++)
  2226. {
  2227. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2228. {
  2229. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2230. }
  2231. }
  2232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2238. } // END FOR DC CASE
  2239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2240. {
  2241. 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\" } ] } ] } ]"
  2242. ,MESSAGE_TYPE_CALL
  2243. ,guid
  2244. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2245. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2246. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2247. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2248. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2249. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2250. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2251. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2252. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2253. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2254. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2255. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2256. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2257. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2258. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2259. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2260. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2261. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2262. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2263. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2264. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2265. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2266. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2267. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2268. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2269. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2270. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2271. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2272. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2273. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2274. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2275. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2276. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2277. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2278. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2279. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2280. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2281. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2282. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2283. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2284. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2285. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2286. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2287. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2288. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2289. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2290. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2291. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2292. );
  2293. }
  2294. else
  2295. {
  2296. 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\" } ] } ] } ]"
  2297. ,MESSAGE_TYPE_CALL
  2298. ,guid
  2299. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2300. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2301. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2303. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2304. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2333. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2334. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2335. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2336. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2337. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2338. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2339. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2340. );
  2341. }
  2342. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2343. if(hashmap_operation(0, guid, tempdata) == 1)
  2344. {
  2345. result = PASS;
  2346. DEBUG_INFO("StopTransaction mapitem pass\n");
  2347. }
  2348. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2349. LWS_Send(queuedata);
  2350. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2351. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2352. {
  2353. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2354. }
  2355. #if 0
  2356. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2357. if(hashmap_operation(0, guid, tempdata) == 1)
  2358. {
  2359. result = PASS;
  2360. DEBUG_INFO("StopTransaction mapitem pass\n");
  2361. }
  2362. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2363. #endif
  2364. //for test
  2365. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2366. return result;
  2367. }
  2368. int sendMeterValuesRequest(int gun_index)
  2369. {
  2370. mtrace();
  2371. int result = FAIL;
  2372. // char message[1500]={0};
  2373. char guid[37]={0};
  2374. //int idx_sample=0;
  2375. //int length = 0;
  2376. char tempdata[65]={0};
  2377. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2378. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2379. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2380. {
  2381. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2382. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2383. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2384. return result;
  2385. }
  2386. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2387. {
  2388. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2389. }
  2390. memset(queuedata, 0, sizeof(queuedata));
  2391. //set value
  2392. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2393. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2394. random_uuid(guid);
  2395. //UTC Date time
  2396. struct timeval tmnow;
  2397. struct tm *tm;
  2398. char buf[28];//, usec_buf[6];
  2399. gettimeofday(&tmnow, NULL);
  2400. time_t t;
  2401. t = time(NULL);
  2402. /*UTC time and date*/
  2403. tm = gmtime(&t);
  2404. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2406. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2407. //idx_sample=0;
  2408. //********************************(1)Current.Export************************************************/
  2409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2410. {
  2411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2412. {
  2413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2414. {
  2415. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2416. }
  2417. }
  2418. for (int index = 0; index < CCS_QUANTITY; index++)
  2419. {
  2420. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2421. {
  2422. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2423. }
  2424. }
  2425. for (int index = 0; index < GB_QUANTITY; index++)
  2426. {
  2427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2428. {
  2429. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2430. }
  2431. }
  2432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2433. }
  2434. else
  2435. {
  2436. for (int index = 0; index < AC_QUANTITY; index++)
  2437. {
  2438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2439. {
  2440. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2441. }
  2442. }
  2443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2444. }// END FOR AC ELSE
  2445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2448. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2451. //idx_sample=1;
  2452. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2454. {
  2455. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2456. {
  2457. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2458. {
  2459. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2460. }
  2461. }
  2462. for (int index = 0; index < CCS_QUANTITY; index++)
  2463. {
  2464. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2465. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2466. {
  2467. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2468. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2469. }
  2470. }
  2471. for (int index = 0; index < GB_QUANTITY; index++)
  2472. {
  2473. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2474. {
  2475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2476. }
  2477. }
  2478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2479. }
  2480. else
  2481. {
  2482. for (int index = 0; index < AC_QUANTITY; index++)
  2483. {
  2484. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2485. {
  2486. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2487. }
  2488. }
  2489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2490. }//END FOR AC ELSE
  2491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2494. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2497. //idx_sample=2;
  2498. //********************************(4)Power.Active.Export************************************************/
  2499. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2500. {
  2501. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2502. {
  2503. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2504. {
  2505. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2506. }
  2507. }
  2508. for (int index = 0; index < CCS_QUANTITY; index++)
  2509. {
  2510. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2511. {
  2512. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2513. }
  2514. }
  2515. for (int index = 0; index < GB_QUANTITY; index++)
  2516. {
  2517. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2518. {
  2519. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2521. }
  2522. }
  2523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2524. }
  2525. else
  2526. {
  2527. for (int index = 0; index < AC_QUANTITY; index++)
  2528. {
  2529. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2530. {
  2531. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2532. }
  2533. }
  2534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2535. }// END FOR AC ELSE
  2536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2537. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2538. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2539. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2540. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2542. //idx_sample=3;
  2543. //***********************************************(5)VOLTAGE******************************************************/
  2544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2545. {
  2546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2547. {
  2548. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2549. {
  2550. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2551. }
  2552. }
  2553. for (int index = 0; index < CCS_QUANTITY; index++)
  2554. {
  2555. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2556. {
  2557. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2558. }
  2559. }
  2560. for (int index = 0; index < GB_QUANTITY; index++)
  2561. {
  2562. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2563. {
  2564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2565. }
  2566. }
  2567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2568. }
  2569. else
  2570. {
  2571. for (int index = 0; index < AC_QUANTITY; index++)
  2572. {
  2573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2574. {
  2575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2576. }
  2577. }
  2578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2579. }//END FOR AC ELSE
  2580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2583. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2587. {
  2588. //idx_sample=4;
  2589. //sampledValue = NULL;
  2590. //***********************************************(6)SOC******************************************************/
  2591. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2592. {
  2593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2594. {
  2595. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2596. }
  2597. }
  2598. for (int index = 0; index < CCS_QUANTITY; index++)
  2599. {
  2600. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2601. {
  2602. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2603. }
  2604. }
  2605. for (int index = 0; index < GB_QUANTITY; index++)
  2606. {
  2607. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2608. {
  2609. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2610. }
  2611. }
  2612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2618. }
  2619. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2620. {
  2621. 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\"}]}]}]"
  2622. ,MESSAGE_TYPE_CALL
  2623. ,guid
  2624. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2625. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2626. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2651. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2652. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2653. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2654. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2655. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2656. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2657. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2658. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2659. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2660. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2662. );
  2663. }
  2664. else
  2665. {
  2666. 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\"}]}]}]"
  2667. ,MESSAGE_TYPE_CALL
  2668. ,guid
  2669. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2670. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2671. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2700. );
  2701. }
  2702. // Put request guid to hash map
  2703. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2704. 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*/)
  2705. {
  2706. result = PASS;
  2707. DEBUG_INFO("MeterValues mapitem pass\n");
  2708. }
  2709. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2710. LWS_Send(queuedata);
  2711. #if 0
  2712. // Put request guid to hash map
  2713. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2714. 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*/)
  2715. {
  2716. result = PASS;
  2717. DEBUG_INFO("MeterValues mapitem pass\n");
  2718. }
  2719. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2720. #endif
  2721. return result;
  2722. }
  2723. //==========================================
  2724. // send confirm routine
  2725. //==========================================
  2726. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2727. {
  2728. mtrace();
  2729. int result = FAIL;
  2730. char message[100]={0};
  2731. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2732. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2733. LWS_Send(message);
  2734. result = TRUE;
  2735. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2736. return result;
  2737. }
  2738. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2739. {
  2740. mtrace();
  2741. int result = FAIL;
  2742. char message[100]={0};
  2743. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\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 sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2750. {
  2751. mtrace();
  2752. int result = FAIL;
  2753. char message[100]={0};
  2754. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2755. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2756. LWS_Send(message);
  2757. result = TRUE;
  2758. return result;
  2759. }
  2760. int sendClearCacheConfirmation(char *uuid,char *payload)
  2761. {
  2762. mtrace();
  2763. int result = FAIL;
  2764. char message[500]={0};
  2765. // int count = 0;
  2766. // int gun_index = 0;
  2767. // char guid[37];
  2768. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2769. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2770. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2771. LWS_Send(message);
  2772. return result;
  2773. }
  2774. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2775. {
  2776. mtrace();
  2777. int result = FAIL;
  2778. char message[500]={0};
  2779. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2780. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2781. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2782. LWS_Send(message);
  2783. return result;
  2784. }
  2785. int sendDataTransferConfirmation(char *uuid,char *payload)
  2786. {
  2787. mtrace();
  2788. char statusStr[20]={0};
  2789. char dataStr[10]={0};
  2790. char sstr[20]={0};
  2791. int c = 0;
  2792. char *loc;
  2793. int result = FAIL;
  2794. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2795. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2796. /**********************status**************************/
  2797. loc = strstr(payload, "status");
  2798. memset(sstr ,0, sizeof(sstr) );
  2799. c = 0;
  2800. while (loc[3+strlen("status")+c] != '\"')
  2801. {
  2802. sstr[c] = loc[3+strlen("status")+c];
  2803. c++;
  2804. }
  2805. sstr[c] = '\0';
  2806. strcpy(statusStr, sstr);
  2807. /**********************data**************************/
  2808. loc = strstr(payload, "data");
  2809. memset(sstr ,0, sizeof(sstr) );
  2810. c = 0;
  2811. while (loc[3+strlen("data")+c] != '\"')
  2812. {
  2813. sstr[c] = loc[3+strlen("data")+c];
  2814. c++;
  2815. }
  2816. sstr[c] = '\0';
  2817. strcpy(dataStr, sstr);
  2818. return result;
  2819. }
  2820. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2821. {
  2822. mtrace();
  2823. int result = FAIL;
  2824. char message[1000]={0};
  2825. double diff_f = 0.0;
  2826. int diff_i = 0;
  2827. int diffSeconds = 0;
  2828. struct tm tp;
  2829. int TimeZero = FALSE;
  2830. int CompositeScheduleIndex = 0;
  2831. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2832. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2833. {
  2834. TimeZero = TRUE;
  2835. }
  2836. else
  2837. {
  2838. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2839. }
  2840. if(TimeZero == FALSE)
  2841. {
  2842. tp.tm_isdst = -1;
  2843. time_t utc = mktime(&tp);
  2844. time_t t = time(NULL);
  2845. diff_f = difftime(t, utc);
  2846. diff_i = (int)diff_f;
  2847. diffSeconds = diff_i % 86400;//86400 seconds/day
  2848. }
  2849. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2850. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2851. #if 0 //remove temporally
  2852. 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}"
  2853. ,MESSAGE_TYPE_CALLRESULT
  2854. ,uuid
  2855. ,payload
  2856. ,connectorIdInt
  2857. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2858. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2859. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2860. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2861. #endif
  2862. if(nPeriod == 0)
  2863. {
  2864. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2865. ,MESSAGE_TYPE_CALLRESULT
  2866. ,uuid
  2867. ,payload
  2868. ,connectorIdInt
  2869. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2870. }
  2871. else
  2872. {
  2873. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2874. ,MESSAGE_TYPE_CALLRESULT
  2875. ,uuid
  2876. ,payload
  2877. ,connectorIdInt
  2878. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2879. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2880. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2881. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2882. int len = nPeriod;
  2883. //Last Period StartPriod is less than diffSeconds
  2884. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2885. {
  2886. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2887. , 0
  2888. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2889. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2890. }
  2891. else
  2892. {
  2893. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2894. {
  2895. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2896. {
  2897. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2898. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2899. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2900. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2901. }
  2902. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2903. {
  2904. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2905. , (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*/))
  2906. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2907. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2908. }
  2909. }
  2910. }
  2911. sprintf(message + strlen(message), "]}}]");
  2912. }
  2913. LWS_Send(message);
  2914. result = TRUE;
  2915. return result;
  2916. }
  2917. int sendGetConfigurationConfirmation(char *uuid)
  2918. {
  2919. mtrace();
  2920. int result = FAIL;
  2921. int MaxKeySupported = 0;
  2922. int sentConfigurationNumber= 0;
  2923. int sentunConfigurationNumber= 0;
  2924. char message[4000]={0};
  2925. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2926. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2927. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  2928. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  2929. ,MESSAGE_TYPE_CALLRESULT
  2930. ,uuid );
  2931. //configuration key
  2932. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2933. {
  2934. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2935. {
  2936. if (sentConfigurationNumber == 0)
  2937. {
  2938. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  2939. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2940. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2941. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2942. }
  2943. else
  2944. {
  2945. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2946. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2947. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2948. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2949. }
  2950. sentConfigurationNumber = sentConfigurationNumber + 1;
  2951. }
  2952. }
  2953. sprintf(message + strlen(message), "]");
  2954. if(UnknownKeynum != 0)
  2955. {
  2956. sprintf(message + strlen(message), ",\"unknownKey\":[");
  2957. //unkown key
  2958. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  2959. {
  2960. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  2961. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  2962. if(sentunConfigurationNumber == 0)
  2963. {
  2964. sprintf(message + strlen(message), "\"%s\""
  2965. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2966. }
  2967. else
  2968. {
  2969. sprintf(message + strlen(message), ",\"%s\""
  2970. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2971. }
  2972. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  2973. }
  2974. sprintf(message + strlen(message), "]");
  2975. }
  2976. sprintf(message + strlen(message), "} ]");
  2977. LWS_Send(message);
  2978. return result;
  2979. }
  2980. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  2981. {
  2982. mtrace();
  2983. int result = FAIL;
  2984. char message[400]={0};
  2985. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  2986. if(strcmp(payload,"")==0)
  2987. {
  2988. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  2989. }
  2990. else
  2991. {
  2992. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  2993. }
  2994. LWS_Send(message);
  2995. result = TRUE;
  2996. return result;
  2997. }
  2998. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  2999. {
  3000. mtrace();
  3001. int result = FAIL;
  3002. char message[80]={0};
  3003. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3004. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3005. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3006. LWS_Send(message);
  3007. result = TRUE;
  3008. return result;
  3009. }
  3010. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3011. {
  3012. mtrace();
  3013. int result = FAIL;
  3014. char message[80]={0};
  3015. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3016. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3017. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3018. LWS_Send(message);
  3019. result = TRUE;
  3020. return result;
  3021. }
  3022. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3023. {
  3024. mtrace();
  3025. int result = FAIL;
  3026. char message[80]={0};
  3027. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3028. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3029. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3030. LWS_Send(message);
  3031. result = TRUE;
  3032. return result;
  3033. }
  3034. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3035. {
  3036. mtrace();
  3037. int result = FAIL;
  3038. char message[80]={0};
  3039. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3040. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3041. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3042. LWS_Send(message);
  3043. result = TRUE;
  3044. return result;
  3045. }
  3046. int sendResetConfirmation(char *uuid,char *payload)
  3047. {
  3048. mtrace();
  3049. int result = FAIL;
  3050. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3051. char message[80]={0};
  3052. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3053. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3054. LWS_Send(message);
  3055. result = TRUE;
  3056. return result;
  3057. }
  3058. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3059. {
  3060. mtrace();
  3061. int result = FAIL;
  3062. char message[500]={0};
  3063. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3064. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3065. LWS_Send(message);
  3066. result = TRUE;
  3067. return result;
  3068. }
  3069. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3070. {
  3071. mtrace();
  3072. int result = FAIL;
  3073. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3074. char message[80]={0};
  3075. DEBUG_INFO("sendSetChargingProfileConfirmation\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 sendTriggerMessageConfirmation(char *uuid,char *payload)
  3082. {
  3083. mtrace();
  3084. int result = FAIL;
  3085. char message[80]={0};
  3086. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3087. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3088. LWS_Send(message);
  3089. result = TRUE;
  3090. return result;
  3091. }
  3092. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3093. {
  3094. mtrace();
  3095. int result = FAIL;
  3096. char message[80]={0};
  3097. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3098. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3099. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3100. LWS_Send(message);
  3101. result = TRUE;
  3102. return result;
  3103. }
  3104. int sendUpdateFirmwareConfirmation(char *uuid)
  3105. {
  3106. mtrace();
  3107. int result = FAIL;
  3108. char message[60]={0};
  3109. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3110. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3111. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3112. LWS_Send(message);
  3113. result = TRUE;
  3114. return result;
  3115. }
  3116. //==========================================
  3117. // send CallError routine
  3118. //==========================================
  3119. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3120. {
  3121. mtrace();
  3122. //int result = FAIL;
  3123. char message[220]={0};
  3124. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3125. #ifdef SystemLogMessage
  3126. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3127. uniqueId, action, errorCode, errorDescription);
  3128. #endif
  3129. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3130. LWS_Send(message);
  3131. //result = TRUE;
  3132. }
  3133. //==========================================
  3134. // Handle server request routine Start
  3135. //==========================================
  3136. #define GUN_NUM 1
  3137. int handleCancelReservationRequest(char *uuid, char *payload)
  3138. {
  3139. mtrace();
  3140. int result = FAIL;
  3141. int gunNO = 0;
  3142. int reservationIdInt =0;
  3143. char comfirmstr[20];
  3144. int c = 0;
  3145. char *loc;
  3146. char sstr[100]={0};
  3147. DEBUG_INFO("handle CancelReservationRequest\n");
  3148. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3149. c = 0;
  3150. loc = strstr(payload, "reservationId");
  3151. memset(sstr ,0, sizeof(sstr) );
  3152. while (loc[strlen("reservationId")+2+c] != '}')
  3153. {
  3154. sstr[c] = loc[strlen("reservationId")+2+c];
  3155. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3156. c++;
  3157. }
  3158. sstr[c] = '\0';
  3159. reservationIdInt = atoi(sstr);
  3160. memset(comfirmstr, 0, sizeof comfirmstr);
  3161. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3162. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3163. //check Transaction active
  3164. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3165. {
  3166. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3167. {
  3168. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3169. {
  3170. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3171. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3172. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3173. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3174. goto end;
  3175. }
  3176. }
  3177. for (int index = 0; index < CCS_QUANTITY; index++)
  3178. {
  3179. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3180. {
  3181. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3182. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3183. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3184. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3185. goto end;
  3186. }
  3187. }
  3188. for (int index = 0; index < GB_QUANTITY; index++)
  3189. {
  3190. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3191. {
  3192. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3193. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3194. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3195. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3196. goto end;
  3197. }
  3198. }
  3199. }
  3200. else
  3201. {
  3202. for (int index = 0; index < AC_QUANTITY; index++)
  3203. {
  3204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3205. {
  3206. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3207. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3208. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3209. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3210. goto end;
  3211. }
  3212. }
  3213. }// END FOR AC ELSE
  3214. //The reservationId does NOT match the reservationId
  3215. sendCancelReservationConfirmation(uuid, comfirmstr);
  3216. end:
  3217. // Fill in ocpp packet uuid
  3218. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3219. return result;
  3220. }
  3221. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3222. {
  3223. mtrace();
  3224. int result = FAIL;
  3225. int gunIndex = 0;
  3226. char sstr[90]={0};
  3227. char typeStr[16]={0};
  3228. char comfirmstr[20];
  3229. int specificId = FALSE;
  3230. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3231. char *loc;
  3232. //int intervalInt = 0;
  3233. int c = 0;
  3234. /*** connectorId ****/
  3235. c = 0;
  3236. loc = strstr(payload, "connectorId");
  3237. memset(sstr ,0, sizeof(sstr) );
  3238. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3239. {
  3240. sstr[c] = loc[strlen("connectorId")+2+c];
  3241. c++;
  3242. }
  3243. sstr[c] = '\0';
  3244. gunIndex = atoi(sstr);
  3245. /***type ****/
  3246. loc = strstr(payload, "type");
  3247. memset(sstr ,0, sizeof(sstr) );
  3248. c = 0;
  3249. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3250. {
  3251. sstr[c] = loc[3+strlen("type")+c];
  3252. c++;
  3253. }
  3254. sstr[c] = '\0';
  3255. strcpy(typeStr, sstr);
  3256. if(gunIndex != 0)
  3257. {
  3258. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3259. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3260. }
  3261. else
  3262. {
  3263. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3264. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3265. }
  3266. memset(comfirmstr, 0, sizeof comfirmstr);
  3267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3268. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3269. {
  3270. specificId = TRUE;
  3271. }
  3272. if(specificId == FALSE)
  3273. goto end;
  3274. if(gunIndex != 0)
  3275. {
  3276. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3277. }
  3278. else
  3279. {
  3280. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3281. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3282. }
  3283. /*
  3284. enum SYSTEM_STATUS
  3285. {
  3286. SYS_MODE_BOOTING = 0,
  3287. SYS_MODE_IDLE = 1,
  3288. SYS_MODE_AUTHORIZING = 2,
  3289. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3290. SYS_MODE_REASSIGN = 4,
  3291. SYS_MODE_PREPARING = 5,
  3292. SYS_MODE_PREPARE_FOR_EV = 6,
  3293. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3294. SYS_MODE_CHARGING = 8,
  3295. SYS_MODE_TERMINATING = 9,
  3296. SYS_MODE_COMPLETE = 10,
  3297. SYS_MODE_ALARM = 11,
  3298. SYS_MODE_FAULT = 12,
  3299. SYS_MODE_RESERVATION = 13,
  3300. SYS_MODE_BOOKING = 14,
  3301. SYS_MODE_MAINTAIN = 15,
  3302. SYS_MODE_DEBUG = 16,
  3303. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3304. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3305. SYS_MODE_UPDATE = 19
  3306. };
  3307. */
  3308. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3309. {
  3310. //check Transaction active
  3311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3312. {
  3313. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3314. {
  3315. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3316. {
  3317. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3318. {
  3319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3320. }
  3321. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3322. {
  3323. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3324. }
  3325. else
  3326. {
  3327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3328. }
  3329. goto end;
  3330. }
  3331. }//END FOR CHAdeMO_QUANTITY
  3332. for (int index = 0; index < CCS_QUANTITY; index++)
  3333. {
  3334. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3335. {
  3336. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3337. {
  3338. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3339. }
  3340. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3341. {
  3342. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3343. }
  3344. else
  3345. {
  3346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3347. }
  3348. goto end;
  3349. }
  3350. }//END FOR CCS_QUANTITY
  3351. for (int index = 0; index < GB_QUANTITY; index++)
  3352. {
  3353. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3354. {
  3355. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3356. {
  3357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3358. }
  3359. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3360. {
  3361. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3362. }
  3363. else
  3364. {
  3365. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3366. }
  3367. goto end;
  3368. }
  3369. }// END FOR GB_QUANTITY
  3370. }
  3371. else
  3372. {
  3373. for (int index = 0; index < AC_QUANTITY; index++)
  3374. {
  3375. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3376. {
  3377. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3378. {
  3379. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3380. }
  3381. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3382. {
  3383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3384. }
  3385. else
  3386. {
  3387. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3388. }
  3389. goto end;
  3390. }
  3391. }//END FOR AC_QUANTITY
  3392. }// END FOR AC ELSE
  3393. }//END FOR AvailabilityTypeStr[Inoperative]
  3394. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3395. {
  3396. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3397. //check Transaction active
  3398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3399. {
  3400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3401. {
  3402. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3403. {
  3404. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3405. goto end;
  3406. }
  3407. }//END FOR CHAdeMO_QUANTITY
  3408. for (int index = 0; index < CCS_QUANTITY; index++)
  3409. {
  3410. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3411. {
  3412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3413. goto end;
  3414. }
  3415. }//END FOR CCS_QUANTITY
  3416. for (int index = 0; index < GB_QUANTITY; index++)
  3417. {
  3418. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3419. {
  3420. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3421. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3422. goto end;
  3423. }
  3424. }// END FOR GB_QUANTITY
  3425. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3426. }
  3427. else
  3428. {
  3429. for (int index = 0; index < AC_QUANTITY; index++)
  3430. {
  3431. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3432. {
  3433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3434. goto end;
  3435. }
  3436. }//END FOR CHAdeMO_QUANTITY
  3437. }//END FOR AC ELSE
  3438. }//END FOR AvailabilityTypeStr[Operative]
  3439. end:
  3440. if(gunIndex != 0)
  3441. {
  3442. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3443. }
  3444. else
  3445. {
  3446. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3447. }
  3448. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3449. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3450. return result;
  3451. }
  3452. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3453. {
  3454. mtrace();
  3455. int result = FAIL;
  3456. char sstr[100]={0};
  3457. char keystr[40]={0};
  3458. char valuestr[100]={0};
  3459. char *loc;
  3460. int c = 0;
  3461. char comfirmstr[20]={0};
  3462. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3463. /***key ****/
  3464. loc = strstr(payload, "key");
  3465. memset(sstr ,0, sizeof(sstr) );
  3466. c = 0;
  3467. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3468. {
  3469. sstr[c] = loc[3+strlen("key")+c];
  3470. c++;
  3471. }
  3472. sstr[c] = '\0';
  3473. strcpy(keystr, sstr);
  3474. //DEBUG_INFO( "keystr=%s\n",keystr);
  3475. /***value ****/
  3476. loc = strstr(payload, "value");
  3477. memset(sstr ,0, sizeof(sstr) );
  3478. c = 0;
  3479. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3480. {
  3481. sstr[c] = loc[3+strlen("value")+c];
  3482. c++;
  3483. }
  3484. sstr[c] = '\0';
  3485. strcpy(valuestr, sstr);
  3486. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3487. if((uuid==NULL) || (payload ==NULL) )
  3488. {
  3489. #ifdef Debug
  3490. DEBUG_INFO("payload is null\n");
  3491. #endif
  3492. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3493. }
  3494. else
  3495. {
  3496. int status = setKeyValue(keystr, valuestr);
  3497. switch(status)
  3498. {
  3499. case ConfigurationStatus_Accepted:
  3500. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3501. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3502. StoreConfigurationTable();
  3503. break;
  3504. case ConfigurationStatus_Rejected:
  3505. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3506. break;
  3507. case RebootRequired:
  3508. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3509. StoreConfigurationTable();
  3510. break;
  3511. case NotSupported:
  3512. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3513. break;
  3514. default:
  3515. break;
  3516. }
  3517. }
  3518. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3519. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3520. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3521. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  3522. {
  3523. ChageWebSocketPingInterval(atoi(valuestr));
  3524. }
  3525. return result;
  3526. }
  3527. int handleClearCacheRequest(char *uuid, char *payload)
  3528. {
  3529. mtrace();
  3530. int result = FAIL;
  3531. char comfirmstr[20];
  3532. int fd;
  3533. char rmFileCmd[100]={0};
  3534. struct stat stats;
  3535. DEBUG_INFO("handle ClearCacheRequest\n");
  3536. stat("/Storage/OCPP", &stats);
  3537. // Check for directory existence
  3538. if (S_ISDIR(stats.st_mode) == 1)
  3539. {
  3540. //DEBUG_ERROR("\n OCPP directory exist \n");
  3541. }
  3542. else
  3543. {
  3544. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3545. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3546. system(rmFileCmd);
  3547. }
  3548. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3549. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3550. {
  3551. DEBUG_INFO("AuthorizationCache file exist.\n");
  3552. }
  3553. else
  3554. {
  3555. DEBUG_INFO("AuthorizationCache file not exist\n");
  3556. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3557. if(log == NULL)
  3558. {
  3559. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3560. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3561. goto end;
  3562. }
  3563. else
  3564. {
  3565. fclose(log);
  3566. }
  3567. }
  3568. fd = open(AuthorizationCache_JSON,O_RDWR);
  3569. if(fd < 0)
  3570. {
  3571. DEBUG_INFO("open AuthorizationCache file failed\n");
  3572. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3573. }
  3574. else
  3575. {
  3576. DEBUG_INFO("open AuthorizationCache file successful\n");
  3577. //* 清空? 件 */
  3578. ftruncate(fd,0);
  3579. //* ? 新设置? 件? 移??*/
  3580. lseek(fd,0,SEEK_SET);
  3581. close(fd);
  3582. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3583. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3584. }
  3585. end:
  3586. sendClearCacheConfirmation(uuid, comfirmstr);
  3587. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3588. return result;
  3589. }
  3590. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3591. {
  3592. mtrace();
  3593. int result = FAIL;
  3594. int resultRename;
  3595. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3596. char chargingProfilePurposeStr[26]={0};
  3597. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3598. char tempchargingProfilePurposeStr[26]={0};
  3599. char sstr[160]={0};//sstr[200]={ 0 };
  3600. char str[100]={0};
  3601. int c = 0;
  3602. //int i = 0;
  3603. //char * pch;
  3604. char *loc;
  3605. char fname[200];
  3606. char comfirmstr[20]={0};
  3607. char word[1000]={0};
  3608. int clearflag = FALSE;
  3609. int chargingProfileIdIsNULL = FALSE;
  3610. int connectorIsNULL = FALSE;
  3611. int chargingProfilePurposeIsNULL = FALSE;
  3612. int stackLevelIsNULL = FALSE;
  3613. int GotoEnd = FALSE;
  3614. FILE *fptr1, *fptr2;
  3615. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json";
  3616. int n_chargingProfile=0;
  3617. char sLineWord[1060]={0};
  3618. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3619. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3620. //***id ****/
  3621. c = 0;
  3622. loc = strstr(payload, "id");
  3623. memset(sstr ,0, sizeof(sstr) );
  3624. if(loc == NULL)
  3625. {
  3626. chargingProfileIdIsNULL = TRUE;
  3627. }
  3628. else
  3629. {
  3630. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3631. {
  3632. sstr[c] = loc[strlen("id")+2+c];
  3633. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3634. c++;
  3635. }
  3636. sstr[c] = '\0';
  3637. chargingProfileIdInt = atoi(sstr);
  3638. }
  3639. //***connectorId ****/
  3640. c=0;
  3641. loc = strstr(payload, "connectorId");
  3642. memset(sstr ,0, sizeof(sstr) );
  3643. if(loc == NULL)
  3644. {
  3645. connectorIsNULL = TRUE;
  3646. }
  3647. else
  3648. {
  3649. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3650. {
  3651. sstr[c] = loc[strlen("connectorId")+2+c];
  3652. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3653. c++;
  3654. }
  3655. sstr[c] = '\0';
  3656. connectorIdInt = atoi(sstr);
  3657. }
  3658. //***chargingProfilePurpose ****/
  3659. loc = strstr(payload, "chargingProfilePurpose");
  3660. memset(sstr ,0, sizeof(sstr) );
  3661. c = 0;
  3662. if(loc == NULL)
  3663. {
  3664. chargingProfilePurposeIsNULL = TRUE;
  3665. }
  3666. else
  3667. {
  3668. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3669. {
  3670. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3671. c++;
  3672. }
  3673. sstr[c] = '\0';
  3674. strcpy(chargingProfilePurposeStr, sstr);
  3675. }
  3676. //***stackLevel ****/
  3677. c=0;
  3678. loc = strstr(payload, "stackLevel");
  3679. memset(sstr ,0, sizeof(sstr) );
  3680. if(loc == NULL)
  3681. {
  3682. stackLevelIsNULL = TRUE;
  3683. }
  3684. else
  3685. {
  3686. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3687. {
  3688. sstr[c] = loc[strlen("stackLevel")+2+c];
  3689. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3690. c++;
  3691. }
  3692. sstr[c] = '\0';
  3693. stackLevelInt = atoi(sstr);
  3694. }
  3695. if(connectorIsNULL == FALSE)
  3696. {
  3697. switch(connectorIdInt)
  3698. {
  3699. case 0:
  3700. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3701. {
  3702. strcpy(fname, ChargePointMaxProfile_JSON);
  3703. }
  3704. else
  3705. {
  3706. strcpy(fname, TxDefaultProfile_0_JSON);
  3707. }
  3708. break;
  3709. case 1:
  3710. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3711. {
  3712. strcpy(fname, TxDefaultProfile_1_JSON);
  3713. }
  3714. // else
  3715. // {
  3716. // strcpy(fname, TxProfile_1_JSON);
  3717. // }
  3718. break;
  3719. case 2:
  3720. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3721. {
  3722. strcpy(fname, TxDefaultProfile_2_JSON);
  3723. }
  3724. // else
  3725. // {
  3726. // strcpy(fname, TxProfile_2_JSON);
  3727. // }
  3728. break;
  3729. default:
  3730. strcpy(fname, ChargePointMaxProfile_JSON );
  3731. break;
  3732. }
  3733. }
  3734. else
  3735. {
  3736. strcpy(fname, ChargePointMaxProfile_JSON );
  3737. }
  3738. fptr1 = fopen(fname, "r");
  3739. if (!fptr1)
  3740. {
  3741. //file not exist
  3742. DEBUG_INFO("Unable to open the input file!!\n");
  3743. fptr1 = fopen(fname, "w+");
  3744. }
  3745. fclose(fptr1);
  3746. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  3747. {
  3748. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3749. goto end;
  3750. }
  3751. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3752. {
  3753. //clear file in C
  3754. sprintf(str,"rm -f %s",fname);
  3755. system(str);
  3756. // clear temp file
  3757. sprintf(str,"rm -f %s",temp);
  3758. system(str);
  3759. #if 0
  3760. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3761. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3762. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3763. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3764. fclose(fopen(TxProfile_1_JSON, "w"));
  3765. fclose(fopen(TxProfile_2_JSON, "w"));
  3766. #endif
  3767. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3768. goto end;
  3769. }
  3770. else
  3771. {
  3772. fptr1 = fopen(fname, "r");
  3773. fptr2 = fopen(temp, "w+");
  3774. while(fscanf(fptr1, "%s", word) != EOF)
  3775. {
  3776. //DEBUG_INFO("word=%s\n",word);
  3777. if(strcmp(word, "chargingProfileId") == 0)
  3778. {
  3779. n_chargingProfile = n_chargingProfile + 1;
  3780. DEBUG_INFO("chargingProfileId Found\n");
  3781. }
  3782. }
  3783. rewind(fptr1);
  3784. //search Charging Profile Element
  3785. //int i= 0;
  3786. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3787. {
  3788. //*************************tempconnectorIdInt*********************************/
  3789. loc = strstr(sLineWord, "connectorId");
  3790. c = 0;
  3791. memset(sstr ,0, sizeof(sstr) );
  3792. while (loc[strlen("connectorId")+2+c] != ',')
  3793. {
  3794. sstr[c] = loc[strlen("connectorId")+2+c];
  3795. c++;
  3796. }
  3797. sstr[c] = '\0';
  3798. tempconnectorIdInt = atoi(sstr);
  3799. //chargingProfileId
  3800. c = 0;
  3801. loc = strstr(sLineWord, "chargingProfileId");
  3802. memset(sstr ,0, sizeof(sstr) );
  3803. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3804. {
  3805. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3806. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3807. c++;
  3808. }
  3809. sstr[c] = '\0';
  3810. tempchargingProfileIdInt = atoi(sstr);
  3811. //stackLevel
  3812. c = 0;
  3813. loc = strstr(sLineWord, "stackLevel");
  3814. memset(sstr ,0, sizeof(sstr) );
  3815. while (loc[strlen("stackLevel")+2+c] != ',')
  3816. {
  3817. sstr[c] = loc[strlen("stackLevel")+2+c];
  3818. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3819. c++;
  3820. }
  3821. sstr[c] = '\0';
  3822. tempstackLevelInt = atoi(sstr);
  3823. c = 0;
  3824. loc = strstr(sLineWord, "chargingProfilePurpose");
  3825. memset(sstr ,0, sizeof(sstr) );
  3826. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3827. {
  3828. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3829. c++;
  3830. }
  3831. sstr[c] = '\0';
  3832. strcpy(tempchargingProfilePurposeStr, sstr);
  3833. if(chargingProfileIdIsNULL == FALSE)
  3834. {
  3835. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3836. {
  3837. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3838. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3839. clearflag = TRUE;
  3840. continue;
  3841. }
  3842. else
  3843. {
  3844. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3845. //json_object_array_add(newHeatMap, jsonitem);
  3846. fprintf(fptr2, sLineWord);//writing data into file
  3847. }
  3848. }
  3849. else
  3850. {
  3851. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3852. {
  3853. if(stackLevelIsNULL == TRUE)//((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3854. {
  3855. fclose(fptr1);
  3856. fclose(fptr2);
  3857. sprintf(str,"rm -f %s",fname);
  3858. system(str);
  3859. // clear temp file
  3860. sprintf(str,"rm -f %s",temp);
  3861. system(str);
  3862. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3863. clearflag = TRUE;
  3864. GotoEnd = TRUE;
  3865. break;
  3866. }
  3867. else if((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt))
  3868. {
  3869. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3870. clearflag = TRUE;
  3871. continue;
  3872. }
  3873. }
  3874. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3875. {
  3876. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3877. {
  3878. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3879. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3880. {
  3881. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3882. clearflag = TRUE;
  3883. continue;
  3884. }
  3885. }
  3886. }
  3887. else
  3888. {
  3889. //json_object_array_add(newHeatMap, jsonitem);
  3890. fprintf(fptr2, sLineWord);//writing data into file
  3891. }
  3892. }
  3893. memset(sLineWord, 0, sizeof sLineWord);
  3894. }
  3895. if((clearflag == FALSE) && (GotoEnd == TRUE))
  3896. {
  3897. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3898. sprintf(str,"rm -f %s",temp);
  3899. system(str);
  3900. goto end;
  3901. }
  3902. else
  3903. {
  3904. goto end;
  3905. }
  3906. fclose(fptr1);
  3907. fclose(fptr2);
  3908. sprintf(str,"rm -f %s",fname);
  3909. system(str);
  3910. resultRename = rename(temp, fname);
  3911. if(resultRename == 0)
  3912. {
  3913. DEBUG_INFO("File ChargingProfile renamed successfully");
  3914. }
  3915. else
  3916. {
  3917. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  3918. }
  3919. }
  3920. end:
  3921. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3922. return result;
  3923. }
  3924. int handleDataTransferRequest(char *uuid, char *payload)
  3925. {
  3926. mtrace();
  3927. int result = FAIL;
  3928. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  3929. char tempvendorId[255]={0};
  3930. char tempmessageId[50]={0};
  3931. char tempdata[50]={0};
  3932. char sstr[160]={0};//sstr[200]={ 0 };
  3933. char message[80]={0};
  3934. int c = 0;
  3935. char *loc;
  3936. DEBUG_INFO("handle DataTransferRequest\n");
  3937. if((uuid != NULL) && (payload != NULL))
  3938. {
  3939. //===============================
  3940. // vendorId
  3941. //===============================
  3942. c = 0;
  3943. loc = strstr(payload, "vendorId");
  3944. while (loc[strlen("vendorId")+3+c] != '\"')
  3945. {
  3946. sstr[c] = loc[strlen("vendorId")+3+c];
  3947. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3948. c++;
  3949. }
  3950. sstr[c] = '\0';
  3951. strcpy(tempvendorId,sstr);
  3952. //===============================
  3953. // messageId
  3954. //===============================
  3955. memset(sstr ,0, sizeof(sstr) );
  3956. c = 0;
  3957. loc = strstr(payload, "messageId");
  3958. while (loc[strlen("messageId")+3+c] != '\"')
  3959. {
  3960. sstr[c] = loc[strlen("messageId")+3+c];
  3961. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3962. c++;
  3963. }
  3964. sstr[c] = '\0';
  3965. strcpy(tempmessageId,sstr);
  3966. //===============================
  3967. // data
  3968. //===============================
  3969. memset(sstr ,0, sizeof(sstr) );
  3970. c = 0;
  3971. loc = strstr(payload, "data");
  3972. printf("loc=%s\n",loc);
  3973. while (loc[strlen("data")+3+c] != '\"')
  3974. {
  3975. sstr[c] = loc[strlen("data")+3+c];
  3976. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3977. c++;
  3978. }
  3979. sstr[c] = '\0';
  3980. strcpy(tempdata,sstr);
  3981. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  3982. }
  3983. else
  3984. {
  3985. char guid[37]={0};
  3986. random_uuid(guid);
  3987. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  3988. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  3989. }
  3990. LWS_Send(message);
  3991. return result;
  3992. }
  3993. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  3994. {
  3995. mtrace();
  3996. int result = FAIL;
  3997. int connectorIdInt, durationInt;
  3998. char chargingRateUnitStr[4]={0};
  3999. //int tempconnectorIdInt,
  4000. int tempdurationInt;
  4001. float tempminChargingRateFloat = 0.0;
  4002. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4003. int tempStartPeriodInt=0;
  4004. float tempLimitInt=0.0;//0.1;
  4005. int tempNumberPhasesInt=0;
  4006. char fname[200];
  4007. char comfirmstr[20];
  4008. //float totallimit =0.0;
  4009. float MinChargingRate =0.0;
  4010. //double diff_t;
  4011. //struct tm tp;
  4012. FILE *fptr1;
  4013. int c = 0;
  4014. //int i = 0;
  4015. char * pch;
  4016. char *loc;
  4017. char sstr[200]={ 0 };
  4018. int n_chargingProfile = 0;
  4019. int n_SchedulePeriods = 0;
  4020. char SchedulePeriodList[10][200]={0};
  4021. char sLineWord[800]={0};
  4022. //int n_periods = 0;
  4023. char word[1000]={0};
  4024. int confirmPeriods = 0;
  4025. struct StructProfile ChargePointMaxProfile;
  4026. struct StructProfile TxDefaultProfile;
  4027. struct StructProfile TxProfile;
  4028. struct StructProfile TxDefaultProfiletemp[2]={0};
  4029. int TxDefaultProfileFileIsNull=FALSE;
  4030. int ChargePointMaxProfileIsNull=FALSE;
  4031. int TxProfileIsNull=FALSE;
  4032. int CompositeSceduleIndex = 0;
  4033. char ChargePointMaxProfileScheduleStr[30]={0};
  4034. char TxDefaultProfileScheduleStr[30]={0};
  4035. char TxProfileScheduleStr[30]={0};
  4036. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4037. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4038. memset(&TxProfile,0,sizeof(struct StructProfile));
  4039. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4040. c=0;
  4041. loc = strstr(payload, "connectorId");
  4042. memset(sstr ,0, sizeof(sstr) );
  4043. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4044. {
  4045. sstr[c] = loc[strlen("connectorId")+2+c];
  4046. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4047. c++;
  4048. }
  4049. sstr[c] = '\0';
  4050. connectorIdInt = atoi(sstr);
  4051. c=0;
  4052. loc = strstr(payload, "duration");
  4053. memset(sstr ,0, sizeof(sstr) );
  4054. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4055. {
  4056. sstr[c] = loc[strlen("duration")+2+c];
  4057. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4058. c++;
  4059. }
  4060. sstr[c] = '\0';
  4061. durationInt = atoi(sstr);
  4062. c = 0;
  4063. loc = strstr(payload, "chargingRateUnit");
  4064. memset(sstr ,0, sizeof(sstr) );
  4065. if(loc == NULL)
  4066. {
  4067. }
  4068. else
  4069. {
  4070. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4071. {
  4072. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4073. c++;
  4074. }
  4075. sstr[c] = '\0';
  4076. strcpy(chargingRateUnitStr, sstr);
  4077. }
  4078. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4079. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4080. if(connectorIdInt==0) // connectorId is 0
  4081. {
  4082. //******************************ChargePointMaxProfile*****************************************************/
  4083. strcpy(fname, ChargePointMaxProfile_JSON );
  4084. char word[30]={0};
  4085. char sLineWord[1060]={0};
  4086. int n_chargingProfile=0;
  4087. ChargePointMaxProfileIsNull=TRUE;
  4088. if((access(fname,F_OK))!=-1)
  4089. {
  4090. fptr1 = fopen(fname, "r");
  4091. int c;
  4092. c = fgetc(fptr1);
  4093. //DEBUG_INFO("c:%d\n",c);
  4094. rewind(fptr1);
  4095. if(c == EOF)
  4096. {
  4097. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4098. ChargePointMaxProfileIsNull=TRUE;
  4099. fclose(fptr1);
  4100. }
  4101. else
  4102. {
  4103. ChargePointMaxProfileIsNull=FALSE;
  4104. while(fscanf(fptr1, "%s", word) != EOF)
  4105. {
  4106. if(strcmp(word, "chargingProfileId") == 0)
  4107. {
  4108. n_chargingProfile = n_chargingProfile + 1;
  4109. printf("Found\n");
  4110. }
  4111. }
  4112. rewind(fptr1);
  4113. //search Charging Profile Element
  4114. int i= 0;
  4115. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4116. #if 0
  4117. /***********connectorId****************/
  4118. c = 0;
  4119. loc = strstr(sLineWord, "connectorId");
  4120. // printf("loc=%s\n",loc);
  4121. memset(sstr ,0, sizeof(sstr) );
  4122. while (loc[strlen("connectorId")+2+c] != ',')
  4123. {
  4124. sstr[c] = loc[strlen("connectorId")+2+c];
  4125. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4126. c++;
  4127. }
  4128. sstr[c] = '\0';
  4129. tempconnectorIdInt = atoi(sstr);
  4130. #endif
  4131. //***********validFrom**************/
  4132. c = 0;
  4133. loc = strstr(sLineWord, "validFrom");
  4134. //DEBUG_INFO("loc=%s\n",loc);
  4135. memset(sstr ,0, sizeof(sstr) );
  4136. if(loc != NULL)
  4137. {
  4138. while (loc[3+strlen("validFrom")+c] != '\"')
  4139. {
  4140. sstr[c] = loc[3+strlen("validFrom")+c];
  4141. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4142. c++;
  4143. }
  4144. sstr[c] = '\0';
  4145. DEBUG_INFO("validFrom=%s\n",sstr);
  4146. strcpy(tempvalidFromStr,sstr);
  4147. }
  4148. else
  4149. {
  4150. strcpy(tempvalidFromStr,"");
  4151. }
  4152. //**********startSchedule**********/
  4153. c = 0;
  4154. loc = strstr(sLineWord, "startSchedule");
  4155. //DEBUG_INFO("loc=%s\n",loc);
  4156. memset(sstr ,0, sizeof(sstr) );
  4157. while (loc[3+strlen("startSchedule")+c] != '\"')
  4158. {
  4159. sstr[c] = loc[3+strlen("startSchedule")+c];
  4160. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4161. c++;
  4162. }
  4163. sstr[c] = '\0';
  4164. strcpy(tempstartScheduleStr, sstr);
  4165. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4166. //**********chargingRateUnit**********/
  4167. c = 0;
  4168. loc = strstr(sLineWord, "chargingRateUnit");
  4169. memset(sstr ,0, sizeof(sstr) );
  4170. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4171. {
  4172. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4173. c++;
  4174. }
  4175. sstr[c] = '\0';
  4176. strcpy(tempchargingRateUnitStr, sstr);
  4177. //**********minChargingRate*******/
  4178. c = 0;
  4179. loc = strstr(sLineWord, "minChargingRate");
  4180. //printf("loc=%s\n",loc);
  4181. if(loc != NULL)
  4182. {
  4183. memset(sstr ,0, sizeof(sstr) );
  4184. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4185. {
  4186. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4187. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4188. c++;
  4189. }
  4190. sstr[c] = '\0';
  4191. tempminChargingRateFloat = atof(sstr);
  4192. }
  4193. else
  4194. {
  4195. tempminChargingRateFloat = 0.0;
  4196. }
  4197. //
  4198. #if 0
  4199. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4200. tp.tm_isdst = -1;
  4201. time_t utc = mktime(&tp);
  4202. // current time
  4203. time_t t = time(NULL);
  4204. #endif
  4205. //diff_t = difftime(t, utc);
  4206. //parsing strings to words
  4207. i = 0;
  4208. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4209. loc = loc+3+strlen("chargingSchedulePeriod");
  4210. pch = strtok(loc ,"{");
  4211. while (pch != NULL)
  4212. {
  4213. strcpy(SchedulePeriodList[i], pch);
  4214. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4215. //printf ("%s\n",pch);
  4216. pch = strtok (NULL, "{");
  4217. i = i + 1;
  4218. }
  4219. n_SchedulePeriods = i;
  4220. for(int i=0;i<n_SchedulePeriods;i++)
  4221. {
  4222. //*************startPeriod****************/
  4223. c = 0;
  4224. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4225. memset(sstr ,0, sizeof(sstr) );
  4226. while (loc[strlen("startPeriod")+2+c] != ',')
  4227. {
  4228. sstr[c] = loc[strlen("startPeriod")+2+c];
  4229. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4230. c++;
  4231. }
  4232. sstr[c] = '\0';
  4233. tempStartPeriodInt = atoi(sstr);
  4234. //*************limit****************/
  4235. c = 0;
  4236. loc = strstr(SchedulePeriodList[i], "limit");
  4237. memset(sstr ,0, sizeof(sstr) );
  4238. while (loc[strlen("limit")+2+c] != ',')
  4239. {
  4240. sstr[c] = loc[strlen("limit")+2+c];
  4241. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4242. c++;
  4243. }
  4244. sstr[c] = '\0';
  4245. tempLimitInt = atof(sstr);
  4246. //*************numberPhases****************/
  4247. c = 0;
  4248. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4249. memset(sstr ,0, sizeof(sstr) );
  4250. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4251. {
  4252. sstr[c] = loc[strlen("numberPhases")+2+c];
  4253. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4254. c++;
  4255. }
  4256. sstr[c] = '\0';
  4257. tempNumberPhasesInt = atoi(sstr);
  4258. ChargePointMaxProfile.Duration = durationInt;
  4259. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4260. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4261. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4262. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4263. }
  4264. if(MinChargingRate < tempminChargingRateFloat)
  4265. MinChargingRate = tempminChargingRateFloat;
  4266. }
  4267. }// End of file ChargingProfile
  4268. } //THE END OF ACCESS ChargePointMaxProfile
  4269. //******************************TxDefaultProfile***********************************************/
  4270. strcpy(fname, TxDefaultProfile_0_JSON);
  4271. memset(word, 0, 30);
  4272. memset(sLineWord, 0, 1060);
  4273. //char word[30]={0};
  4274. //char sLineWord[1060]={0};
  4275. n_chargingProfile=0;
  4276. TxDefaultProfileFileIsNull=TRUE;
  4277. if((access(fname,F_OK))!=-1)
  4278. {
  4279. fptr1 = fopen(fname, "r");
  4280. c = 0;
  4281. c = fgetc(fptr1);
  4282. //DEBUG_INFO("c:%d\n",c);
  4283. rewind(fptr1);
  4284. if(c == EOF)
  4285. {
  4286. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4287. TxDefaultProfileFileIsNull=TRUE;
  4288. fclose(fptr1);
  4289. }
  4290. else
  4291. {
  4292. TxDefaultProfileFileIsNull=FALSE;
  4293. while(fscanf(fptr1, "%s", word) != EOF)
  4294. {
  4295. if(strcmp(word, "chargingProfileId") == 0)
  4296. {
  4297. n_chargingProfile = n_chargingProfile + 1;
  4298. printf("Found\n");
  4299. }
  4300. }
  4301. rewind(fptr1);
  4302. //search Charging Profile Element
  4303. int i= 0;
  4304. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4305. #if 0
  4306. /***********connectorId****************/
  4307. c = 0;
  4308. loc = strstr(sLineWord, "connectorId");
  4309. // printf("loc=%s\n",loc);
  4310. memset(sstr ,0, sizeof(sstr) );
  4311. while (loc[strlen("connectorId")+2+c] != ',')
  4312. {
  4313. sstr[c] = loc[strlen("connectorId")+2+c];
  4314. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4315. c++;
  4316. }
  4317. sstr[c] = '\0';
  4318. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4319. tempconnectorIdInt = atoi(sstr);
  4320. #endif
  4321. //***********validFrom**************/
  4322. c = 0;
  4323. loc = strstr(sLineWord, "validFrom");
  4324. //DEBUG_INFO("loc=%s\n",loc);
  4325. memset(sstr ,0, sizeof(sstr) );
  4326. if(loc != NULL)
  4327. {
  4328. while (loc[3+strlen("validFrom")+c] != '\"')
  4329. {
  4330. sstr[c] = loc[3+strlen("validFrom")+c];
  4331. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4332. c++;
  4333. }
  4334. sstr[c] = '\0';
  4335. DEBUG_INFO("validFrom=%s\n",sstr);
  4336. strcpy(tempvalidFromStr,sstr);
  4337. }
  4338. else
  4339. {
  4340. strcpy(tempvalidFromStr,"");
  4341. }
  4342. //**********startSchedule**********/
  4343. c = 0;
  4344. loc = strstr(sLineWord, "startSchedule");
  4345. //DEBUG_INFO("loc=%s\n",loc);
  4346. memset(sstr ,0, sizeof(sstr) );
  4347. while (loc[3+strlen("startSchedule")+c] != '\"')
  4348. {
  4349. sstr[c] = loc[3+strlen("startSchedule")+c];
  4350. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4351. c++;
  4352. }
  4353. sstr[c] = '\0';
  4354. strcpy(tempstartScheduleStr, sstr);
  4355. strcpy(TxDefaultProfileScheduleStr, sstr);
  4356. DEBUG_INFO(" debug 3-1\n");
  4357. //**********chargingRateUnit**********/
  4358. c = 0;
  4359. loc = strstr(sLineWord, "chargingRateUnit");
  4360. memset(sstr ,0, sizeof(sstr) );
  4361. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4362. {
  4363. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4364. c++;
  4365. }
  4366. sstr[c] = '\0';
  4367. strcpy(tempchargingRateUnitStr, sstr);
  4368. //**********minChargingRate*******/
  4369. c = 0;
  4370. loc = strstr(sLineWord, "minChargingRate");
  4371. //printf("loc=%s\n",loc);
  4372. if(loc != NULL)
  4373. {
  4374. memset(sstr ,0, sizeof(sstr) );
  4375. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4376. {
  4377. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4378. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4379. c++;
  4380. }
  4381. sstr[c] = '\0';
  4382. tempminChargingRateFloat = atof(sstr);
  4383. }
  4384. else
  4385. {
  4386. tempminChargingRateFloat = 0.0;
  4387. }
  4388. #if 0
  4389. //
  4390. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4391. tp.tm_isdst = -1;
  4392. time_t utc = mktime(&tp);
  4393. // current time
  4394. time_t t = time(NULL);
  4395. //diff_t = difftime(t, utc);
  4396. #endif
  4397. //parsing strings to words
  4398. i = 0;
  4399. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4400. loc = loc+3+strlen("chargingSchedulePeriod");
  4401. pch = strtok(loc ,"{");
  4402. while (pch != NULL)
  4403. {
  4404. strcpy(SchedulePeriodList[i], pch);
  4405. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4406. //printf ("%s\n",pch);
  4407. pch = strtok (NULL, "{");
  4408. i = i + 1;
  4409. }
  4410. n_SchedulePeriods = i;
  4411. for(int i=0;i<n_SchedulePeriods;i++)
  4412. {
  4413. //*************startPeriod****************/
  4414. c = 0;
  4415. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4416. memset(sstr ,0, sizeof(sstr) );
  4417. while (loc[strlen("startPeriod")+2+c] != ',')
  4418. {
  4419. sstr[c] = loc[strlen("startPeriod")+2+c];
  4420. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4421. c++;
  4422. }
  4423. sstr[c] = '\0';
  4424. tempStartPeriodInt = atoi(sstr);
  4425. //*************limit****************/
  4426. c = 0;
  4427. loc = strstr(SchedulePeriodList[i], "limit");
  4428. memset(sstr ,0, sizeof(sstr) );
  4429. while (loc[strlen("limit")+2+c] != ',')
  4430. {
  4431. sstr[c] = loc[strlen("limit")+2+c];
  4432. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4433. c++;
  4434. }
  4435. sstr[c] = '\0';
  4436. tempLimitInt = atof(sstr);
  4437. //*************numberPhases****************/
  4438. c = 0;
  4439. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4440. memset(sstr ,0, sizeof(sstr) );
  4441. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4442. {
  4443. sstr[c] = loc[strlen("numberPhases")+2+c];
  4444. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4445. c++;
  4446. }
  4447. sstr[c] = '\0';
  4448. tempNumberPhasesInt = atoi(sstr);
  4449. TxDefaultProfile.Duration = durationInt;
  4450. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4451. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4452. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4453. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4454. }
  4455. if(MinChargingRate < tempminChargingRateFloat)
  4456. MinChargingRate = tempminChargingRateFloat;
  4457. }
  4458. }
  4459. }// the end of ACCESS TxDefaultProfile
  4460. // Composite Schedule
  4461. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4462. {
  4463. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4464. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4465. {
  4466. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4467. {
  4468. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4469. }
  4470. else
  4471. {
  4472. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4473. }
  4474. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4475. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4476. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4477. }
  4478. }
  4479. //* Define temporary variables */
  4480. struct tm *gtime;
  4481. time_t now;
  4482. char buf[28];
  4483. /* Read the current system time */
  4484. time(&now);
  4485. /* Convert the system time to GMT (now UTC) */
  4486. gtime = gmtime(&now);
  4487. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4488. // make .conf
  4489. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4490. //MaxChargingProfilesInstalled is 10
  4491. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4492. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4493. //nPeriod = 1;
  4494. if(chargingRateUnitStr[0] != 0)
  4495. {
  4496. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4497. }
  4498. else
  4499. {
  4500. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4501. }
  4502. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4503. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4504. confirmPeriods = 1;
  4505. }
  4506. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4507. {
  4508. //*****************************ChargePointMaxProfile******************************************/
  4509. strcpy(fname, ChargePointMaxProfile_JSON);
  4510. ChargePointMaxProfileIsNull=TRUE;
  4511. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4512. {
  4513. fptr1 = fopen(fname, "r");
  4514. int c;
  4515. c = fgetc(fptr1);
  4516. //DEBUG_INFO("c:%d\n",c);
  4517. rewind(fptr1);
  4518. if(c == EOF)
  4519. {
  4520. DEBUG_INFO("\n End of file reached.");
  4521. ChargePointMaxProfileIsNull=TRUE;
  4522. fclose(fptr1);
  4523. }
  4524. else
  4525. {
  4526. ChargePointMaxProfileIsNull=FALSE;
  4527. while(fscanf(fptr1, "%s", word) != EOF)
  4528. {
  4529. if(strcmp(word, "chargingProfileId") == 0)
  4530. {
  4531. n_chargingProfile = n_chargingProfile + 1;
  4532. }
  4533. }
  4534. rewind(fptr1);
  4535. //search Charging Profile Element
  4536. int i = 0;
  4537. int j = 0;
  4538. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4539. #if 0
  4540. /***********connectorId****************/
  4541. c = 0;
  4542. loc = strstr(sLineWord, "connectorId");
  4543. memset(sstr ,0, sizeof(sstr) );
  4544. while (loc[strlen("connectorId")+2+c] != ',')
  4545. {
  4546. sstr[c] = loc[strlen("connectorId")+2+c];
  4547. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4548. c++;
  4549. }
  4550. sstr[c] = '\0';
  4551. tempconnectorIdInt = atoi(sstr);
  4552. #endif
  4553. //***********validFrom**************/
  4554. c = 0;
  4555. loc = strstr(sLineWord, "validFrom");
  4556. if(loc != NULL)
  4557. {
  4558. memset(sstr ,0, sizeof(sstr) );
  4559. while (loc[3+strlen("validFrom")+c] != '\"')
  4560. {
  4561. sstr[c] = loc[3+strlen("validFrom")+c];
  4562. c++;
  4563. }
  4564. sstr[c] = '\0';
  4565. strcpy(tempvalidFromStr,sstr);
  4566. }
  4567. else
  4568. {
  4569. strcpy(tempvalidFromStr,"");
  4570. }
  4571. //***********validFrom**************/
  4572. c = 0;
  4573. loc = strstr(sLineWord, "duration");
  4574. if(loc != NULL)
  4575. {
  4576. memset(sstr ,0, sizeof(sstr) );
  4577. while (loc[2+strlen("duration")+c] != ',')
  4578. {
  4579. sstr[c] = loc[2+strlen("duration")+c];
  4580. c++;
  4581. }
  4582. sstr[c] = '\0';
  4583. tempdurationInt = atoi(sstr);
  4584. }
  4585. else
  4586. {
  4587. tempdurationInt = 0;
  4588. }
  4589. //**********startSchedule**********/
  4590. c = 0;
  4591. loc = strstr(sLineWord, "startSchedule");
  4592. memset(sstr ,0, sizeof(sstr) );
  4593. while (loc[3+strlen("startSchedule")+c] != '\"')
  4594. {
  4595. sstr[c] = loc[3+strlen("startSchedule")+c];
  4596. c++;
  4597. }
  4598. sstr[c] = '\0';
  4599. strcpy(tempstartScheduleStr, sstr);
  4600. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4601. //**********chargingRateUnit**********/
  4602. c = 0;
  4603. loc = strstr(sLineWord, "chargingRateUnit");
  4604. memset(sstr ,0, sizeof(sstr) );
  4605. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4606. {
  4607. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4608. c++;
  4609. }
  4610. sstr[c] = '\0';
  4611. strcpy(tempchargingRateUnitStr, sstr);
  4612. //**********minChargingRate*******/
  4613. c = 0;
  4614. loc = strstr(sLineWord, "minChargingRate");
  4615. if(loc != NULL)
  4616. {
  4617. memset(sstr ,0, sizeof(sstr) );
  4618. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4619. {
  4620. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4621. c++;
  4622. }
  4623. sstr[c] = '\0';
  4624. tempminChargingRateFloat = atof(sstr);
  4625. }
  4626. else
  4627. {
  4628. tempminChargingRateFloat = 0.0;
  4629. }
  4630. #if 0
  4631. //
  4632. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4633. tp.tm_isdst = -1;
  4634. time_t utc = mktime(&tp);
  4635. time_t t = time(NULL);
  4636. //diff_t = difftime(t, utc);
  4637. #endif
  4638. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4639. //DEBUG_INFO(" debug 5 -1\n");
  4640. //parsing strings to words
  4641. i = 0;
  4642. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4643. loc = loc+3+strlen("chargingSchedulePeriod");
  4644. pch = strtok(loc ,"{");
  4645. while (pch != NULL)
  4646. {
  4647. strcpy(SchedulePeriodList[i], pch);
  4648. pch = strtok (NULL, "{");
  4649. i = i + 1;
  4650. }
  4651. n_SchedulePeriods = i;
  4652. for(int i=0;i<n_SchedulePeriods;i++)
  4653. {
  4654. //*************startPeriod****************/
  4655. c = 0;
  4656. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4657. memset(sstr ,0, sizeof(sstr) );
  4658. while (loc[strlen("startPeriod")+2+c] != ',')
  4659. {
  4660. sstr[c] = loc[strlen("startPeriod")+2+c];
  4661. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4662. c++;
  4663. }
  4664. sstr[c] = '\0';
  4665. tempStartPeriodInt = atoi(sstr);
  4666. //*************limit****************/
  4667. c = 0;
  4668. loc = strstr(SchedulePeriodList[i], "limit");
  4669. memset(sstr ,0, sizeof(sstr) );
  4670. while (loc[strlen("limit")+2+c] != ',')
  4671. {
  4672. sstr[c] = loc[strlen("limit")+2+c];
  4673. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4674. c++;
  4675. }
  4676. sstr[c] = '\0';
  4677. tempLimitInt = atof(sstr);
  4678. //*************numberPhases****************/
  4679. c = 0;
  4680. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4681. memset(sstr ,0, sizeof(sstr) );
  4682. while (loc[strlen("numberPhases")+2+c] != '}')
  4683. {
  4684. sstr[c] = loc[strlen("numberPhases")+2+c];
  4685. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4686. c++;
  4687. }
  4688. sstr[c] = '\0';
  4689. tempNumberPhasesInt = atoi(sstr);
  4690. if(j == 0)
  4691. {
  4692. ChargePointMaxProfile.Duration = tempdurationInt;
  4693. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4694. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4695. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4696. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4697. }
  4698. }
  4699. if(MinChargingRate < tempminChargingRateFloat)
  4700. {
  4701. MinChargingRate = tempminChargingRateFloat;
  4702. }
  4703. if(confirmPeriods < n_SchedulePeriods)
  4704. {
  4705. confirmPeriods = n_SchedulePeriods;
  4706. }
  4707. j = j + 1;
  4708. }
  4709. fclose(fptr1);
  4710. }
  4711. }// the end of access file ChargePointMaxProfile
  4712. //****************************TxDefaultProfile************************************************/
  4713. switch(connectorIdInt)
  4714. {
  4715. case 0:
  4716. break;
  4717. case 1:
  4718. strcpy(fname, TxDefaultProfile_1_JSON );
  4719. break;
  4720. case 2:
  4721. strcpy(fname, TxDefaultProfile_2_JSON );
  4722. break;
  4723. default:
  4724. strcpy(fname, TxDefaultProfile_1_JSON );
  4725. break;
  4726. }
  4727. TxDefaultProfileFileIsNull=TRUE;
  4728. if((access(fname,F_OK))!=-1)
  4729. {
  4730. fptr1 = fopen(fname, "r");
  4731. c = 0;
  4732. c = fgetc(fptr1);
  4733. //DEBUG_INFO("c:%d\n",c);
  4734. rewind(fptr1);
  4735. if(c == EOF)
  4736. {
  4737. DEBUG_INFO("\n End of file reached.");
  4738. TxDefaultProfileFileIsNull=TRUE;
  4739. fclose(fptr1);
  4740. }
  4741. else
  4742. {
  4743. TxDefaultProfileFileIsNull=FALSE;
  4744. while(fscanf(fptr1, "%s", word) != EOF)
  4745. {
  4746. if(strcmp(word, "chargingProfileId") == 0)
  4747. {
  4748. n_chargingProfile = n_chargingProfile + 1;
  4749. }
  4750. }
  4751. rewind(fptr1);
  4752. //search Charging Profile Element
  4753. int i = 0;
  4754. int j = 0;
  4755. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4756. //DEBUG_INFO(" 1-1\n");
  4757. #if 0
  4758. /***********connectorId****************/
  4759. c = 0;
  4760. loc = strstr(sLineWord, "connectorId");
  4761. memset(sstr ,0, sizeof(sstr) );
  4762. while (loc[strlen("connectorId")+2+c] != ',')
  4763. {
  4764. sstr[c] = loc[strlen("connectorId")+2+c];
  4765. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4766. c++;
  4767. }
  4768. sstr[c] = '\0';
  4769. tempconnectorIdInt = atoi(sstr);
  4770. #endif
  4771. //***********validFrom**************/
  4772. c = 0;
  4773. loc = strstr(sLineWord, "validFrom");
  4774. if(loc != NULL)
  4775. {
  4776. memset(sstr ,0, sizeof(sstr) );
  4777. while (loc[3+strlen("validFrom")+c] != '\"')
  4778. {
  4779. sstr[c] = loc[3+strlen("validFrom")+c];
  4780. c++;
  4781. }
  4782. sstr[c] = '\0';
  4783. strcpy(tempvalidFromStr,sstr);
  4784. }
  4785. else
  4786. {
  4787. strcpy(tempvalidFromStr,"");
  4788. }
  4789. //***********validFrom**************/
  4790. c = 0;
  4791. loc = strstr(sLineWord, "duration");
  4792. if(loc != NULL)
  4793. {
  4794. memset(sstr ,0, sizeof(sstr) );
  4795. while (loc[2+strlen("duration")+c] != ',')
  4796. {
  4797. sstr[c] = loc[2+strlen("duration")+c];
  4798. c++;
  4799. }
  4800. sstr[c] = '\0';
  4801. tempdurationInt = atoi(sstr);
  4802. }
  4803. else
  4804. {
  4805. tempdurationInt = 0;
  4806. }
  4807. //**********startSchedule**********/
  4808. c = 0;
  4809. loc = strstr(sLineWord, "startSchedule");
  4810. memset(sstr ,0, sizeof(sstr) );
  4811. while (loc[3+strlen("startSchedule")+c] != '\"')
  4812. {
  4813. sstr[c] = loc[3+strlen("startSchedule")+c];
  4814. c++;
  4815. }
  4816. sstr[c] = '\0';
  4817. strcpy(tempstartScheduleStr, sstr);
  4818. strcpy(TxDefaultProfileScheduleStr, sstr);
  4819. //**********chargingRateUnit**********/
  4820. c = 0;
  4821. loc = strstr(sLineWord, "chargingRateUnit");
  4822. memset(sstr ,0, sizeof(sstr) );
  4823. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4824. {
  4825. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4826. c++;
  4827. }
  4828. sstr[c] = '\0';
  4829. strcpy(tempchargingRateUnitStr, sstr);
  4830. //**********minChargingRate*******/
  4831. c = 0;
  4832. loc = strstr(sLineWord, "minChargingRate");
  4833. if(loc != NULL)
  4834. {
  4835. memset(sstr ,0, sizeof(sstr) );
  4836. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4837. {
  4838. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4839. c++;
  4840. }
  4841. sstr[c] = '\0';
  4842. tempminChargingRateFloat = atof(sstr);
  4843. }
  4844. else
  4845. {
  4846. tempminChargingRateFloat = 0.0;
  4847. }
  4848. #if 0
  4849. //
  4850. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4851. tp.tm_isdst = -1;
  4852. time_t utc = mktime(&tp);
  4853. time_t t = time(NULL);
  4854. //diff_t = difftime(t, utc);
  4855. #endif
  4856. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4857. //parsing strings to words
  4858. i = 0;
  4859. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4860. loc = loc+3+strlen("chargingSchedulePeriod");
  4861. pch = strtok(loc ,"{");
  4862. while (pch != NULL)
  4863. {
  4864. strcpy(SchedulePeriodList[i], pch);
  4865. pch = strtok (NULL, "{");
  4866. i = i + 1;
  4867. }
  4868. n_SchedulePeriods = i;
  4869. for(int i=0;i<n_SchedulePeriods;i++)
  4870. {
  4871. //*************startPeriod****************/
  4872. c = 0;
  4873. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4874. memset(sstr ,0, sizeof(sstr) );
  4875. while (loc[strlen("startPeriod")+2+c] != ',')
  4876. {
  4877. sstr[c] = loc[strlen("startPeriod")+2+c];
  4878. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4879. c++;
  4880. }
  4881. sstr[c] = '\0';
  4882. tempStartPeriodInt = atoi(sstr);
  4883. //*************limit****************/
  4884. c = 0;
  4885. loc = strstr(SchedulePeriodList[i], "limit");
  4886. memset(sstr ,0, sizeof(sstr) );
  4887. while (loc[strlen("limit")+2+c] != ',')
  4888. {
  4889. sstr[c] = loc[strlen("limit")+2+c];
  4890. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4891. c++;
  4892. }
  4893. sstr[c] = '\0';
  4894. tempLimitInt = atof(sstr);
  4895. //*************numberPhases****************/
  4896. c = 0;
  4897. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4898. memset(sstr ,0, sizeof(sstr) );
  4899. while (loc[strlen("numberPhases")+2+c] != '}')
  4900. {
  4901. sstr[c] = loc[strlen("numberPhases")+2+c];
  4902. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4903. c++;
  4904. }
  4905. sstr[c] = '\0';
  4906. tempNumberPhasesInt = atoi(sstr);
  4907. if(j == 0)
  4908. {
  4909. TxDefaultProfile.Duration = tempdurationInt;
  4910. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4911. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4912. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4913. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4914. }
  4915. else
  4916. {
  4917. //other stack level charging Profile
  4918. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  4919. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  4920. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  4921. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  4922. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  4923. }
  4924. }
  4925. if(MinChargingRate < tempminChargingRateFloat)
  4926. MinChargingRate = tempminChargingRateFloat;
  4927. if(confirmPeriods < n_SchedulePeriods)
  4928. confirmPeriods = n_SchedulePeriods;
  4929. j = j + 1;
  4930. //DEBUG_INFO(" 1-2\n");
  4931. }
  4932. fclose(fptr1);
  4933. //Stacking Charging Profiles
  4934. for(int l=0; l <(j-1) ;l++)
  4935. {
  4936. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  4937. {
  4938. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  4939. {
  4940. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  4941. {
  4942. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  4943. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  4944. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  4945. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4946. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4947. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4948. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4949. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4950. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4951. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4952. }
  4953. else
  4954. {
  4955. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4956. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4957. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4958. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4959. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4960. }
  4961. }
  4962. }
  4963. }
  4964. //end of Stacking Charging Profiles
  4965. }
  4966. }// the end of ACCESS TxDefaultProfile
  4967. //****************************TxProfile************************************************/
  4968. switch(connectorIdInt)
  4969. {
  4970. case 0:
  4971. break;
  4972. case 1:
  4973. strcpy(fname, TxProfile_1_JSON );
  4974. break;
  4975. case 2:
  4976. strcpy(fname, TxProfile_2_JSON );
  4977. break;
  4978. default:
  4979. strcpy(fname, TxProfile_1_JSON );
  4980. break;
  4981. }
  4982. TxProfileIsNull=TRUE;
  4983. if((access(fname,F_OK))!=-1)
  4984. {
  4985. fptr1 = fopen(fname, "r");
  4986. c = 0;
  4987. c = fgetc(fptr1);
  4988. //DEBUG_INFO("c:%d\n",c);
  4989. rewind(fptr1);
  4990. if(c == EOF)
  4991. {
  4992. DEBUG_INFO("\n End of file reached.");
  4993. TxProfileIsNull=TRUE;
  4994. fclose(fptr1);
  4995. }
  4996. else
  4997. {
  4998. TxProfileIsNull=FALSE;
  4999. while(fscanf(fptr1, "%s", word) != EOF)
  5000. {
  5001. if(strcmp(word, "chargingProfileId") == 0)
  5002. {
  5003. n_chargingProfile = n_chargingProfile + 1;
  5004. }
  5005. }
  5006. rewind(fptr1);
  5007. //search Charging Profile Element
  5008. int i= 0;
  5009. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5010. #if 0
  5011. /***********connectorId****************/
  5012. c = 0;
  5013. loc = strstr(sLineWord, "connectorId");
  5014. memset(sstr ,0, sizeof(sstr) );
  5015. while (loc[strlen("connectorId")+2+c] != ',')
  5016. {
  5017. sstr[c] = loc[strlen("connectorId")+2+c];
  5018. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5019. c++;
  5020. }
  5021. sstr[c] = '\0';
  5022. tempconnectorIdInt = atoi(sstr);
  5023. #endif
  5024. //***********validFrom**************/
  5025. c = 0;
  5026. loc = strstr(sLineWord, "validFrom");
  5027. if(loc != NULL)
  5028. {
  5029. memset(sstr ,0, sizeof(sstr) );
  5030. while (loc[3+strlen("validFrom")+c] != '\"')
  5031. {
  5032. sstr[c] = loc[3+strlen("validFrom")+c];
  5033. c++;
  5034. }
  5035. sstr[c] = '\0';
  5036. strcpy(tempvalidFromStr,sstr);
  5037. }
  5038. else
  5039. {
  5040. strcpy(tempvalidFromStr,"");
  5041. }
  5042. //**********startSchedule**********/
  5043. c = 0;
  5044. loc = strstr(sLineWord, "startSchedule");
  5045. memset(sstr ,0, sizeof(sstr) );
  5046. while (loc[3+strlen("startSchedule")+c] != '\"')
  5047. {
  5048. sstr[c] = loc[3+strlen("startSchedule")+c];
  5049. c++;
  5050. }
  5051. sstr[c] = '\0';
  5052. strcpy(tempstartScheduleStr, sstr);
  5053. strcpy(TxProfileScheduleStr, sstr);
  5054. //**********chargingRateUnit**********/
  5055. c = 0;
  5056. loc = strstr(sLineWord, "chargingRateUnit");
  5057. memset(sstr ,0, sizeof(sstr) );
  5058. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5059. {
  5060. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5061. c++;
  5062. }
  5063. sstr[c] = '\0';
  5064. strcpy(tempchargingRateUnitStr, sstr);
  5065. //**********minChargingRate*******/
  5066. c = 0;
  5067. loc = strstr(sLineWord, "minChargingRate");
  5068. if(loc != NULL)
  5069. {
  5070. memset(sstr ,0, sizeof(sstr) );
  5071. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5072. {
  5073. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5074. c++;
  5075. }
  5076. sstr[c] = '\0';
  5077. tempminChargingRateFloat = atof(sstr);
  5078. }
  5079. else
  5080. {
  5081. tempminChargingRateFloat = 0.0;
  5082. }
  5083. #if 0
  5084. //
  5085. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5086. tp.tm_isdst = -1;
  5087. time_t utc = mktime(&tp);
  5088. time_t t = time(NULL);
  5089. //diff_t = difftime(t, utc);
  5090. #endif
  5091. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5092. //parsing strings to words
  5093. i = 0;
  5094. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5095. loc = loc+3+strlen("chargingSchedulePeriod");
  5096. pch = strtok(loc ,"{");
  5097. while (pch != NULL)
  5098. {
  5099. strcpy(SchedulePeriodList[i], pch);
  5100. pch = strtok (NULL, "{");
  5101. i = i + 1;
  5102. }
  5103. n_SchedulePeriods = i;
  5104. for(int i=0;i<n_SchedulePeriods;i++)
  5105. {
  5106. //*************startPeriod****************/
  5107. c = 0;
  5108. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5109. memset(sstr ,0, sizeof(sstr) );
  5110. while (loc[strlen("startPeriod")+2+c] != ',')
  5111. {
  5112. sstr[c] = loc[strlen("startPeriod")+2+c];
  5113. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5114. c++;
  5115. }
  5116. sstr[c] = '\0';
  5117. tempStartPeriodInt = atoi(sstr);
  5118. //*************limit****************/
  5119. c = 0;
  5120. loc = strstr(SchedulePeriodList[i], "limit");
  5121. memset(sstr ,0, sizeof(sstr) );
  5122. while (loc[strlen("limit")+2+c] != ',')
  5123. {
  5124. sstr[c] = loc[strlen("limit")+2+c];
  5125. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5126. c++;
  5127. }
  5128. sstr[c] = '\0';
  5129. tempLimitInt = atof(sstr);
  5130. //*************numberPhases****************/
  5131. c = 0;
  5132. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5133. memset(sstr ,0, sizeof(sstr) );
  5134. while (loc[strlen("numberPhases")+2+c] != '}')
  5135. {
  5136. sstr[c] = loc[strlen("numberPhases")+2+c];
  5137. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5138. c++;
  5139. }
  5140. sstr[c] = '\0';
  5141. tempNumberPhasesInt = atoi(sstr);
  5142. TxProfile.Duration = durationInt;
  5143. TxProfile.TotalPeriod = n_SchedulePeriods;
  5144. TxProfile.Period[i].Limit = tempLimitInt;
  5145. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5146. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5147. }
  5148. if(MinChargingRate < tempminChargingRateFloat)
  5149. MinChargingRate = tempminChargingRateFloat;
  5150. if(confirmPeriods < n_SchedulePeriods)
  5151. confirmPeriods = n_SchedulePeriods;
  5152. }
  5153. fclose(fptr1);
  5154. }
  5155. }// the end of ACCESS TxProfile
  5156. //CompositeSchedule
  5157. int period=0;
  5158. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5159. {
  5160. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5161. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5162. {
  5163. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5164. {
  5165. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5166. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5167. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5168. period = period + 1;
  5169. }
  5170. else
  5171. {
  5172. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5173. {
  5174. }
  5175. else
  5176. {
  5177. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5178. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5179. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5180. period = period + 1;
  5181. }
  5182. }
  5183. }
  5184. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5185. {
  5186. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5187. {
  5188. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5189. {
  5190. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5191. }
  5192. else
  5193. {
  5194. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5195. }
  5196. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5197. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5198. period = period + 1;
  5199. }
  5200. }
  5201. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5202. {
  5203. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5204. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5205. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5206. period = period + 1;
  5207. }
  5208. }
  5209. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5210. {
  5211. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5212. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5213. {
  5214. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5215. {
  5216. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5217. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5218. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5219. period = period + 1;
  5220. }
  5221. else
  5222. {
  5223. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5224. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5225. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5226. period = period + 1;
  5227. }
  5228. }
  5229. }
  5230. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5231. {
  5232. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5233. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5234. {
  5235. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5236. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5237. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5238. period = period + 1;
  5239. }
  5240. }
  5241. confirmPeriods = period;
  5242. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5243. //* Define temporary variables */
  5244. struct tm *gtime;
  5245. time_t now;
  5246. char buf[28];
  5247. //* Read the current system time */
  5248. time(&now);
  5249. //* Convert the system time to GMT (now UTC) */
  5250. gtime = gmtime(&now);
  5251. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5252. // make .conf
  5253. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5254. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5255. //DEBUG_INFO(" debug 11\n");
  5256. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5257. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5258. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5259. }
  5260. else
  5261. {
  5262. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5263. }
  5264. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5265. return result;
  5266. }
  5267. int handleGetConfigurationRequest(char *uuid, char *payload)
  5268. {
  5269. mtrace();
  5270. int result = FAIL;
  5271. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5272. //struct json_object *jsonitem;
  5273. int MaxKeySupported = 0;
  5274. int n_keys = 0;
  5275. char requestKey[43][50]={0};
  5276. char search[]="[";
  5277. char sstr[500]={ 0 };
  5278. //int pos;
  5279. int l, c = 0;
  5280. int i = 0;
  5281. char *delim = "\",\"";
  5282. char * pch;
  5283. char *loc = strstr(payload, search);
  5284. //********************* Parsing String ***********************************/
  5285. if(loc == NULL) {
  5286. DEBUG_INFO("no key match in Configuration \n");
  5287. }
  5288. else {
  5289. //pos = loc - payload;
  5290. l = strlen(loc)-4;
  5291. while (c < l)
  5292. {
  5293. sstr[c] = loc[c+2];
  5294. c++;
  5295. }
  5296. sstr[c] = '\0';
  5297. //parsing strings to words
  5298. pch = strtok(sstr,delim);
  5299. if(pch == NULL)
  5300. {
  5301. strcpy(requestKey[0], sstr);
  5302. }
  5303. else
  5304. {
  5305. while (pch != NULL)
  5306. {
  5307. strcpy(requestKey[i], pch);
  5308. pch = strtok (NULL, delim);
  5309. i = i + 1;
  5310. }
  5311. n_keys = i;
  5312. }
  5313. }
  5314. UnknownKeynum = 0;
  5315. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5316. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5317. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5318. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5319. if(n_keys != 0)
  5320. {
  5321. for(int i=0;i<n_keys;i++)
  5322. {
  5323. getKeyValue(requestKey[i]);
  5324. //json_object_put(jsonitem);
  5325. }
  5326. }
  5327. else
  5328. {
  5329. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5330. getKeyValue("");
  5331. }
  5332. processUnkownKey();
  5333. sendGetConfigurationConfirmation(uuid);
  5334. return result;
  5335. }
  5336. static char fnamePlusPath[100]={0};
  5337. static char fnamePWithNoPath[60]={0};
  5338. void checkUploadLog(void)
  5339. {
  5340. FILE *fp;
  5341. /* Open the command for reading. */
  5342. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  5343. if (fp == NULL) {
  5344. printf("Failed to run command\n" );
  5345. exit(1);
  5346. }
  5347. int ftppathlen = 0;
  5348. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5349. int i = 0;
  5350. /* Read the output a line at a time - output it. */
  5351. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  5352. if(i==0)
  5353. {
  5354. ftppathlen = strlen(fnamePlusPath);
  5355. printf("%s\n", fnamePlusPath);
  5356. fnamePlusPath[ftppathlen]='\0';
  5357. break;
  5358. }
  5359. i= i+1;
  5360. }
  5361. /* close */
  5362. pclose(fp);
  5363. for(int k=0; k< sizeof(fnamePlusPath); k++)
  5364. {
  5365. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  5366. {
  5367. fnamePlusPath[k]='\0';
  5368. }
  5369. }
  5370. i=1;
  5371. //char fname[60]={0};
  5372. while(i < ftppathlen)
  5373. {
  5374. int len=ftppathlen-i;
  5375. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  5376. {
  5377. printf("compare '/' all right\n");
  5378. break;
  5379. }
  5380. i=i+1;
  5381. }
  5382. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  5383. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  5384. fnamePWithNoPath[i+1] = '\0';
  5385. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  5386. {
  5387. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  5388. {
  5389. fnamePWithNoPath[j]='\0';
  5390. }
  5391. }
  5392. FILE* fp1 = fopen(fnamePlusPath, "r");
  5393. if (fp1)
  5394. {
  5395. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  5396. // file exists
  5397. fclose(fp1);
  5398. }
  5399. else
  5400. {
  5401. // file doesn't exist
  5402. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  5403. }
  5404. }
  5405. static char GetDiagnosticspayloadData[300]={0};
  5406. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5407. {
  5408. mtrace();
  5409. int result = FAIL;
  5410. pthread_t t; // pthread 變數
  5411. system("exec /root/logPackTools 'log' 6");
  5412. #if 0
  5413. //char buffer [128];
  5414. time (&rawtime);
  5415. //printf("%ld\n", rawtime);
  5416. timeinfo = localtime (&rawtime);
  5417. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5418. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5419. if((access(fnamePlusPath,F_OK))!=-1)
  5420. {
  5421. DEBUG_INFO("fnamePlusPath exist.\n");
  5422. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5423. }
  5424. else
  5425. {
  5426. DEBUG_INFO("fnamePlusPath not exist!\n");
  5427. }
  5428. #endif
  5429. checkUploadLog();
  5430. memset(GetDiagnosticspayloadData, 0, 300);
  5431. strcpy(GetDiagnosticspayloadData, payload);
  5432. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  5433. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5434. return result;
  5435. }
  5436. void* GetDiagnosticsProcess(void* data)
  5437. {
  5438. pthread_detach(pthread_self());
  5439. mtrace();
  5440. int retriesInt=0, retryIntervalInt=0;
  5441. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5442. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5443. 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};
  5444. int port=0;
  5445. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5446. int c = 0;
  5447. char *loc;
  5448. int isSuccess = FALSE;
  5449. char ftpbuf[200]={0};
  5450. //char temp[100]={0};
  5451. char * pch;
  5452. // [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"}]
  5453. char str[300]={ 0 };
  5454. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5455. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5456. DEBUG_INFO("GetDiagnosticsProcess\n");
  5457. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5458. //****************location*******************/
  5459. c = 0;
  5460. memset(sstr ,0, sizeof(sstr) );
  5461. loc = strstr(str, "location");
  5462. while (loc[3+strlen("location")+c] != '\"')
  5463. {
  5464. sstr[c] = loc[3+strlen("location")+c];
  5465. c++;
  5466. }
  5467. sstr[c] = '\0';
  5468. strcpy(locationstr,sstr);
  5469. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5470. if(strcmp(locationstr,"")==0)
  5471. {
  5472. DEBUG_INFO("location is <Empty>!\n");
  5473. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5474. goto end;
  5475. }
  5476. //****************retries*******************/
  5477. c = 0;
  5478. loc = strstr(str, "retries");
  5479. if(loc == NULL)
  5480. {
  5481. retriesIsNULL = TRUE;
  5482. }
  5483. else
  5484. {
  5485. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5486. {
  5487. sstr[c] = loc[strlen("retries")+2+c];
  5488. c++;
  5489. }
  5490. sstr[c] = '\0';
  5491. retriesInt = atoi(sstr);
  5492. }
  5493. if(retriesIsNULL == TRUE)
  5494. {
  5495. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  5496. }
  5497. //****************retryInterval*******************/
  5498. c = 0;
  5499. loc = strstr(str, "retryInterval");
  5500. if(loc == NULL)
  5501. {
  5502. retryIntervalIsNULL = TRUE;
  5503. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  5504. }
  5505. else
  5506. {
  5507. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  5508. {
  5509. sstr[c] = loc[strlen("retryInterval")+2+c];
  5510. c++;
  5511. }
  5512. sstr[c] = '\0';
  5513. retryIntervalInt = atoi(sstr);
  5514. }
  5515. //****************startTime*******************/
  5516. c = 0;
  5517. memset(sstr ,0, sizeof(sstr) );
  5518. loc = strstr(str, "startTime");
  5519. if(loc == NULL)
  5520. {
  5521. startTimeIsNULL = TRUE;
  5522. }
  5523. else
  5524. {
  5525. while (loc[3+strlen("startTime")+c] != '\"')
  5526. {
  5527. sstr[c] = loc[3+strlen("startTime")+c];
  5528. c++;
  5529. }
  5530. sstr[c] = '\0';
  5531. strcpy(startTimestr,sstr);
  5532. }
  5533. //****************stopTime*******************/
  5534. c = 0;
  5535. memset(sstr ,0, sizeof(sstr) );
  5536. loc = strstr(str, "stopTime");
  5537. if(loc == NULL)
  5538. {
  5539. stopTimeIsNULL = TRUE;
  5540. }
  5541. else
  5542. {
  5543. while (loc[3+strlen("stopTime")+c] != '\"')
  5544. {
  5545. sstr[c] = loc[3+strlen("stopTime")+c];
  5546. c++;
  5547. }
  5548. sstr[c] = '\0';
  5549. strcpy(stopTimestr,sstr);
  5550. }
  5551. memset(protocol, 0, sizeof(protocol));
  5552. memset(user, 0, sizeof(user) );
  5553. memset(password, 0, sizeof(password));
  5554. memset(host, 0, sizeof(host));
  5555. memset(path, 0, sizeof(path));
  5556. memset(ftppath, 0, sizeof(ftppath));
  5557. memset(host1, 0, sizeof(host1));
  5558. memset(path1, 0, sizeof(path1));
  5559. /*location: ftp://user:password@host:port/path*/
  5560. #if 0
  5561. time_t rawtime;
  5562. struct tm * timeinfo;
  5563. //char buffer [128];
  5564. time (&rawtime);
  5565. //printf("%ld\n", rawtime);
  5566. timeinfo = localtime (&rawtime);
  5567. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5568. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5569. #endif
  5570. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5571. if((access(fnamePlusPath,F_OK))!=-1)
  5572. {
  5573. DEBUG_INFO("fnamePlusPath exist.\n");
  5574. }
  5575. else
  5576. {
  5577. DEBUG_INFO("fnamePlusPath not exist!\n");
  5578. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5579. goto end;
  5580. }
  5581. pch=strchr(locationstr,'@');
  5582. if(pch==NULL)
  5583. {
  5584. sscanf(locationstr,
  5585. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5586. protocol, host, &port, path);
  5587. strcpy(user,"anonymous");
  5588. strcpy(password,"");
  5589. }
  5590. else
  5591. {
  5592. //DEBUG_INFO("pch=%s\n", pch);
  5593. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5594. protocol, user, password, host, &port, path);
  5595. }
  5596. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5597. {
  5598. DEBUG_INFO("protocol is not ftp/http ! \n");
  5599. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5600. goto end;
  5601. }
  5602. if(strncmp(locationstr,"http", 4) == 0)
  5603. {
  5604. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  5605. sprintf(ftppath,"/%s", path);
  5606. do{
  5607. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5608. sleep(retryIntervalInt);
  5609. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5610. if(!isSuccess)
  5611. {
  5612. DEBUG_INFO("Diagnostics fail.\n");
  5613. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5614. }
  5615. else
  5616. {
  5617. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5618. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5619. }
  5620. }
  5621. else
  5622. {
  5623. sscanf(host,"%[^/]%s",host1, path1);
  5624. sprintf(ftppath,"%s", path1);
  5625. int ftppathlen=strlen(ftppath);
  5626. int i=1;
  5627. char filenametemp[50];
  5628. while(i < ftppathlen)
  5629. {
  5630. int len=ftppathlen-i;
  5631. if(ftppath[len]== 47) // '/' ascll code: 47
  5632. {
  5633. DEBUG_INFO("find '/' all right\n");
  5634. break;
  5635. }
  5636. i=i+1;
  5637. }
  5638. memset(filenametemp, 0, sizeof(filenametemp));
  5639. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5640. filenametemp[i+1] = 0;
  5641. memset(ftpbuf, 0, sizeof(ftpbuf));
  5642. if(port == 0)
  5643. port = 21;
  5644. do{
  5645. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  5646. sleep(retryIntervalInt);
  5647. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5648. if(!isSuccess)
  5649. {
  5650. DEBUG_INFO("Diagnostics fail.\n");
  5651. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5652. }
  5653. else
  5654. {
  5655. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5656. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5657. }
  5658. }
  5659. end:
  5660. DiagnosticsStatusNotificationStatus = 0; //Idle
  5661. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5662. }
  5663. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5664. {
  5665. mtrace();
  5666. int result = FAIL;
  5667. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5668. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5669. {
  5670. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5671. localversion = -1;
  5672. }
  5673. else
  5674. {
  5675. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5676. OCPP_getListVerion();
  5677. }
  5678. //from db.OCPP_getListVerion
  5679. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5680. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5681. sendGetLocalListVersionConfirmation(uuid,"");
  5682. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5683. return result;
  5684. }
  5685. int handleRemoteStartRequest(char *uuid, char *payload)
  5686. {
  5687. mtrace();
  5688. int result = FAIL;
  5689. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5690. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5691. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5692. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5693. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5694. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5695. int chargingSchedulePeriodCount = 0;
  5696. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5697. int c = 0;
  5698. char *loc;
  5699. char comfirmstr[20]={0};
  5700. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5701. if(server_pending == TRUE)
  5702. {
  5703. return 0;
  5704. }
  5705. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5706. //**********connectorId****************/
  5707. c = 0;
  5708. memset(sstr ,0, sizeof(sstr) );
  5709. loc = strstr(payload, "connectorId");
  5710. if(loc == NULL)
  5711. {
  5712. connectorIdIsNULL = TRUE;
  5713. }
  5714. else
  5715. {
  5716. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5717. {
  5718. sstr[c] = loc[strlen("connectorId")+2+c];
  5719. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5720. c++;
  5721. }
  5722. sstr[c] = '\0';
  5723. connectorIdInt = atoi(sstr);
  5724. }
  5725. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  5726. {
  5727. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5728. goto end;
  5729. }
  5730. //****************idTag*******************/
  5731. c = 0;
  5732. memset(sstr ,0, sizeof(sstr) );
  5733. loc = strstr(payload, "idTag");
  5734. while (loc[3+strlen("idTag")+c] != '\"')
  5735. {
  5736. sstr[c] = loc[3+strlen("idTag")+c];
  5737. c++;
  5738. }
  5739. sstr[c] = '\0';
  5740. strcpy(idTagstr,sstr);
  5741. //****************chargingProfile*******************/
  5742. c = 0;
  5743. memset(sstr ,0, sizeof(sstr) );
  5744. loc = strstr(payload, "chargingProfile");
  5745. if(loc == NULL)
  5746. {
  5747. chargingProfileIsNULL = TRUE;
  5748. }
  5749. else
  5750. {
  5751. //****************chargingProfileId*******************/
  5752. c=0;
  5753. loc = strstr(payload, "chargingProfileId");
  5754. memset(sstr ,0, sizeof(sstr) );
  5755. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5756. {
  5757. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5758. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5759. c++;
  5760. }
  5761. sstr[c] = '\0';
  5762. chargingProfileIdInt = atoi(sstr);
  5763. //****************transactionId*******************/
  5764. loc = strstr(payload, "transactionId");
  5765. if(loc == NULL)
  5766. {
  5767. transactionIdIsNULL = TRUE;
  5768. }
  5769. else
  5770. {
  5771. c=0;
  5772. memset(sstr ,0, sizeof(sstr) );
  5773. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5774. {
  5775. sstr[c] = loc[strlen("transactionId")+2+c];
  5776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5777. c++;
  5778. }
  5779. sstr[c] = '\0';
  5780. transactionIdInt = atoi(sstr);
  5781. }
  5782. //****************stackLevel*******************/
  5783. c=0;
  5784. loc = strstr(payload, "stackLevel");
  5785. memset(sstr ,0, sizeof(sstr) );
  5786. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5787. {
  5788. sstr[c] = loc[strlen("stackLevel")+2+c];
  5789. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5790. c++;
  5791. }
  5792. sstr[c] = '\0';
  5793. stackLevelInt = atoi(sstr);
  5794. //****************chargingProfilePurpose*******************/
  5795. c = 0;
  5796. memset(sstr ,0, sizeof(sstr) );
  5797. loc = strstr(payload, "chargingProfilePurpose");
  5798. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5799. {
  5800. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5801. c++;
  5802. }
  5803. sstr[c] = '\0';
  5804. strcpy(chargingProfilePurposestr,sstr);
  5805. //****************chargingProfileKind*******************/
  5806. c = 0;
  5807. memset(sstr ,0, sizeof(sstr) );
  5808. loc = strstr(payload, "chargingProfileKind");
  5809. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5810. {
  5811. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5812. c++;
  5813. }
  5814. sstr[c] = '\0';
  5815. strcpy(chargingProfileKindstr,sstr);
  5816. //****************recurrencyKind*******************/
  5817. loc = strstr(payload, "recurrencyKind");
  5818. if(loc == NULL)
  5819. {
  5820. recurrencyKindIsNULL = TRUE;
  5821. }
  5822. else
  5823. {
  5824. c = 0;
  5825. memset(sstr ,0, sizeof(sstr) );
  5826. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5827. {
  5828. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5829. c++;
  5830. }
  5831. sstr[c] = '\0';
  5832. strcpy(recurrencyKindstr,sstr);
  5833. }
  5834. //****************validFrom*******************/
  5835. loc = strstr(payload, "validFrom");
  5836. if(loc == NULL)
  5837. {
  5838. validFromIsNULL = TRUE;
  5839. }
  5840. else
  5841. {
  5842. c = 0;
  5843. memset(sstr ,0, sizeof(sstr) );
  5844. while (loc[3+strlen("validFrom")+c] != '\"')
  5845. {
  5846. sstr[c] = loc[3+strlen("validFrom")+c];
  5847. c++;
  5848. }
  5849. sstr[c] = '\0';
  5850. strcpy(validFromstr,sstr);
  5851. }
  5852. //****************validTo*******************/
  5853. loc = strstr(payload, "validTo");
  5854. if(loc == NULL)
  5855. {
  5856. validToIsNULL = TRUE;
  5857. }
  5858. else
  5859. {
  5860. c = 0;
  5861. memset(sstr ,0, sizeof(sstr) );
  5862. while (loc[3+strlen("validTo")+c] != '\"')
  5863. {
  5864. sstr[c] = loc[3+strlen("validTo")+c];
  5865. c++;
  5866. }
  5867. sstr[c] = '\0';
  5868. strcpy(validTostr,sstr);
  5869. }
  5870. //****************chargingSchedule*******************/
  5871. loc = strstr(payload, "chargingSchedule");
  5872. if(loc != NULL)
  5873. {
  5874. //****************duration*******************/
  5875. loc = strstr(payload, "duration");
  5876. if(loc == NULL)
  5877. {
  5878. durationIsNULL = TRUE;
  5879. }
  5880. else
  5881. {
  5882. c=0;
  5883. memset(sstr ,0, sizeof(sstr) );
  5884. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5885. {
  5886. sstr[c] = loc[strlen("duration")+2+c];
  5887. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5888. c++;
  5889. }
  5890. sstr[c] = '\0';
  5891. durationInt = atoi(sstr);
  5892. }
  5893. //****************startSchedule******************/
  5894. loc = strstr(payload, "startSchedule");
  5895. if(loc == NULL)
  5896. {
  5897. startScheduleIsNULL = TRUE;
  5898. }
  5899. else
  5900. {
  5901. c = 0;
  5902. memset(sstr ,0, sizeof(sstr) );
  5903. while (loc[3+strlen("startSchedule")+c] != '\"')
  5904. {
  5905. sstr[c] = loc[3+strlen("startSchedule")+c];
  5906. c++;
  5907. }
  5908. sstr[c] = '\0';
  5909. strcpy(startSchedulestr,sstr);
  5910. }
  5911. //****************chargingRateUnit*******************/
  5912. c = 0;
  5913. memset(sstr ,0, sizeof(sstr) );
  5914. loc = strstr(payload, "chargingRateUnit");
  5915. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5916. {
  5917. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5918. c++;
  5919. }
  5920. sstr[c] = '\0';
  5921. strcpy(chargingRateUnitstr,sstr);
  5922. //****************minChargingRate*******************/
  5923. loc = strstr(payload, "minChargingRate");
  5924. if(loc == NULL)
  5925. {
  5926. minChargingRateIsNULL = TRUE;
  5927. }
  5928. else
  5929. {
  5930. c=0;
  5931. memset(sstr ,0, sizeof(sstr) );
  5932. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5933. {
  5934. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5935. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5936. c++;
  5937. }
  5938. sstr[c] = '\0';
  5939. minChargingRateflaot = atof(sstr);
  5940. }
  5941. //****************chargingSchedulePeriod count*******************/
  5942. int what_len = strlen("startPeriod");
  5943. char *where = payload;
  5944. while ((where = strstr(where, "startPeriod"))) {
  5945. where += what_len;
  5946. chargingSchedulePeriodCount++;
  5947. }
  5948. where = payload;
  5949. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5950. {
  5951. //****************startPeriod*******************/
  5952. c=0;
  5953. loc = strstr(where, "startPeriod");
  5954. memset(sstr ,0, sizeof(sstr) );
  5955. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5956. {
  5957. sstr[c] = loc[strlen("startPeriod")+2+c];
  5958. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5959. c++;
  5960. }
  5961. sstr[c] = '\0';
  5962. startPeriodInt[periodNums] = atoi(sstr);
  5963. //****************limit*******************/
  5964. c=0;
  5965. loc = strstr(where, "limit");
  5966. memset(sstr ,0, sizeof(sstr) );
  5967. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5968. {
  5969. sstr[c] = loc[strlen("limit")+2+c];
  5970. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5971. c++;
  5972. }
  5973. sstr[c] = '\0';
  5974. limitflaot[periodNums] = atof(sstr);
  5975. //****************numberPhases*******************/
  5976. loc = strstr(where, "numberPhases");
  5977. if(loc == NULL)
  5978. {
  5979. numberPhasesIsNULL = TRUE;
  5980. }
  5981. else
  5982. {
  5983. c=0;
  5984. memset(sstr ,0, sizeof(sstr) );
  5985. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  5986. {
  5987. sstr[c] = loc[strlen("numberPhases")+2+c];
  5988. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5989. c++;
  5990. }
  5991. sstr[c] = '\0';
  5992. numberPhasesInt[periodNums] = atoi(sstr);
  5993. }
  5994. where = loc;
  5995. }
  5996. }
  5997. }
  5998. /*
  5999. enum _SYSTEM_STATUS
  6000. {
  6001. S_BOOTING = 0,
  6002. S_IDLE, = 1
  6003. S_AUTHORIZING, =2
  6004. S_REASSIGN_CHECK, =3
  6005. S_REASSIGN, =4
  6006. S_PRECHARGE, =5
  6007. S_PREPARING_FOR_EV, =6
  6008. S_PREPARING_FOR_EVSE, =7
  6009. S_CHARGING, =8
  6010. S_TERMINATING, =9
  6011. S_COMPLETE, =10
  6012. S_ALARM, =11
  6013. S_FAULT =12
  6014. }
  6015. */
  6016. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6017. {
  6018. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6019. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6020. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6021. //check Transaction active
  6022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6023. {
  6024. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6025. {
  6026. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6027. {
  6028. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6029. {
  6030. //Reserved
  6031. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6032. }
  6033. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6034. {
  6035. //Reserved
  6036. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6037. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6038. goto end;
  6039. }
  6040. else
  6041. {
  6042. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6043. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6044. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6045. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6046. {
  6047. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6048. goto end;
  6049. }
  6050. }//END FOR ELSE
  6051. }
  6052. }// END FOR CHAdeMO_QUANTITY
  6053. for (int index = 0; index < CCS_QUANTITY; index++)
  6054. {
  6055. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6056. {
  6057. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6058. {
  6059. //Reserved
  6060. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6061. }
  6062. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6063. {
  6064. //Reserved
  6065. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6066. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6067. goto end;
  6068. }
  6069. else
  6070. {
  6071. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6072. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6073. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6074. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6075. {
  6076. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6077. goto end;
  6078. }
  6079. }// END FOR ELSE
  6080. }
  6081. }// END FOR CCS_QUANTITY
  6082. for (int index = 0; index < GB_QUANTITY; index++)
  6083. {
  6084. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6085. {
  6086. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6087. {
  6088. //Reserved
  6089. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6090. }
  6091. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6092. {
  6093. //Reserved
  6094. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6095. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6096. goto end;
  6097. }
  6098. else
  6099. {
  6100. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6101. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6102. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6103. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6104. {
  6105. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6106. goto end;
  6107. }
  6108. }// END FOR ELSE
  6109. }
  6110. } // END FOR GB_QUANTITY
  6111. }
  6112. else
  6113. {
  6114. for (int index = 0; index < AC_QUANTITY; index++)
  6115. {
  6116. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6117. {
  6118. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6119. {
  6120. //Reserved
  6121. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6122. }
  6123. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6124. {
  6125. //Reserved
  6126. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6127. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6128. goto end;
  6129. }
  6130. else
  6131. {
  6132. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6133. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6134. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6135. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6136. {
  6137. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6138. goto end;
  6139. }
  6140. }//END FOR ELSE
  6141. }
  6142. }// END FOR AC_QUANTITY
  6143. }
  6144. if(chargingProfileIsNULL == FALSE)
  6145. {
  6146. //ChargingProfile
  6147. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6148. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6149. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6150. if(recurrencyKindIsNULL == FALSE) //OPTION
  6151. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6152. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6153. if(transactionIdIsNULL == FALSE) // OPTION
  6154. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6155. if(validFromIsNULL == FALSE) // OPTION
  6156. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6157. if(validToIsNULL == FALSE) //OPTION
  6158. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6159. //ChargingSchedule
  6160. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6161. if(durationIsNULL == FALSE) //OPTION
  6162. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6163. if(minChargingRateIsNULL == FALSE) //OPTION
  6164. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6165. if(startScheduleIsNULL == FALSE) //OPTION
  6166. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6167. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6168. {
  6169. //ChargingSchedulePeriod
  6170. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6171. if(numberPhasesIsNULL == FALSE)
  6172. {
  6173. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6174. }
  6175. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6176. }
  6177. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  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. else
  6188. {
  6189. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6190. }
  6191. }
  6192. else
  6193. {
  6194. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6195. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6196. //memset idTag
  6197. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6198. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6199. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6200. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6201. }
  6202. }
  6203. else
  6204. {
  6205. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6206. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6207. }
  6208. end:
  6209. if(connectorIdIsNULL == FALSE)
  6210. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6211. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6212. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6213. //OCPP send RemoteStartConfirmation by first.
  6214. sendRemoteStartConfirmation(uuid, comfirmstr);
  6215. return result;
  6216. }
  6217. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6218. {
  6219. mtrace();
  6220. int result = FAIL;
  6221. int match = FALSE;
  6222. int GunNO = 0;
  6223. int transactionIdInt=0;
  6224. int transactionIdIsNULL= FALSE;
  6225. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6226. int c = 0;
  6227. char *loc;
  6228. char comfirmstr[20];
  6229. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6230. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6231. if(server_pending == TRUE)
  6232. {
  6233. return 0;
  6234. }
  6235. c=0;
  6236. loc = strstr(payload, "transactionId");
  6237. if(loc == NULL)
  6238. {
  6239. transactionIdIsNULL= TRUE;
  6240. }
  6241. else
  6242. {
  6243. memset(sstr ,0, sizeof(sstr) );
  6244. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6245. {
  6246. sstr[c] = loc[strlen("transactionId")+2+c];
  6247. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6248. c++;
  6249. }
  6250. sstr[c] = '\0';
  6251. transactionIdInt = atoi(sstr);
  6252. }
  6253. if(transactionIdIsNULL == FALSE)
  6254. {
  6255. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6256. {
  6257. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6258. {
  6259. //check Transaction active
  6260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6261. {
  6262. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6263. {
  6264. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6265. {
  6266. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6267. {
  6268. match = TRUE;
  6269. GunNO = gun_index;
  6270. }
  6271. }
  6272. }// END FOR CHAdeMO_QUANTITY
  6273. for (int index = 0; index < CCS_QUANTITY; index++)
  6274. {
  6275. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6276. {
  6277. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6278. {
  6279. match = TRUE;
  6280. GunNO = gun_index;
  6281. }
  6282. }
  6283. }// END FOR CCS_QUANTITY
  6284. for (int index = 0; index < GB_QUANTITY; index++)
  6285. {
  6286. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6287. {
  6288. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6289. {
  6290. match = TRUE;
  6291. GunNO = gun_index;
  6292. }
  6293. }
  6294. }// END FOR GB_QUANTITY
  6295. }
  6296. else
  6297. {
  6298. for (int index = 0; index < AC_QUANTITY; index++)
  6299. {
  6300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6301. {
  6302. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  6303. {
  6304. match = TRUE;
  6305. GunNO = gun_index;
  6306. }
  6307. }
  6308. }// END FOR CHAdeMO_QUANTITY
  6309. }// END FOR AC ELSE
  6310. }// CHECK IF ResponseTransactionId == transactionIdInt
  6311. }//END FOR
  6312. if( match == TRUE)
  6313. {
  6314. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6316. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6317. }
  6318. else
  6319. {
  6320. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6321. }
  6322. }
  6323. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6324. return result;
  6325. }
  6326. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6327. {
  6328. mtrace();
  6329. int result = FAIL;
  6330. int connectorIdInt=0, reservationIdInt=0;
  6331. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6332. char comfirmstr[20]={0};
  6333. char sstr[180]={ 0 };
  6334. int c = 0;
  6335. char *loc;
  6336. //char *ptr;
  6337. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6338. //***(1)connectorId ****/
  6339. c=0;
  6340. loc = strstr(payload, "connectorId");
  6341. memset(sstr ,0, sizeof(sstr) );
  6342. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  6343. {
  6344. sstr[c] = loc[strlen("connectorId")+2+c];
  6345. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6346. c++;
  6347. }
  6348. sstr[c] = '\0';
  6349. connectorIdInt = atoi(sstr);
  6350. //***(2)expiryDate ****/
  6351. loc = strstr(payload, "expiryDate");
  6352. memset(sstr ,0, sizeof(sstr) );
  6353. c = 0;
  6354. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6355. {
  6356. sstr[c] = loc[3+strlen("expiryDate")+c];
  6357. c++;
  6358. }
  6359. sstr[c] = '\0';
  6360. strcpy(expiryDatestr, sstr);
  6361. //***(3)idTag ****/
  6362. loc = strstr(payload, "idTag");
  6363. memset(sstr ,0, sizeof(sstr) );
  6364. c = 0;
  6365. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6366. {
  6367. sstr[c] = loc[3+strlen("idTag")+c];
  6368. c++;
  6369. }
  6370. sstr[c] = '\0';
  6371. strcpy(idTagstr, sstr);
  6372. //***(4)parentIdTag ****/
  6373. loc = strstr(payload, "parentIdTag");
  6374. memset(sstr ,0, sizeof(sstr) );
  6375. c = 0;
  6376. if(loc == NULL)
  6377. {
  6378. strcpy(parentIdTagstr, "");
  6379. }
  6380. else
  6381. {
  6382. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6383. {
  6384. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6385. c++;
  6386. }
  6387. sstr[c] = '\0';
  6388. strcpy(parentIdTagstr, sstr);
  6389. }
  6390. //***(5)reservationId ****/
  6391. c=0;
  6392. loc = strstr(payload, "reservationId");
  6393. memset(sstr ,0, sizeof(sstr) );
  6394. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6395. {
  6396. sstr[c] = loc[strlen("reservationId")+2+c];
  6397. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6398. c++;
  6399. }
  6400. sstr[c] = '\0';
  6401. reservationIdInt = atoi(sstr);
  6402. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6403. /*
  6404. enum SYSTEM_STATUS
  6405. {
  6406. SYS_MODE_BOOTING = 0,
  6407. SYS_MODE_IDLE = 1,
  6408. SYS_MODE_AUTHORIZING = 2,
  6409. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  6410. SYS_MODE_REASSIGN = 4,
  6411. SYS_MODE_PREPARING = 5,
  6412. SYS_MODE_PREPARE_FOR_EV = 6,
  6413. SYS_MODE_PREPARE_FOR_EVSE = 7,
  6414. SYS_MODE_CHARGING = 8,
  6415. SYS_MODE_TERMINATING = 9,
  6416. SYS_MODE_COMPLETE = 10,
  6417. SYS_MODE_ALARM = 11,
  6418. SYS_MODE_FAULT = 12,
  6419. SYS_MODE_RESERVATION = 13,
  6420. SYS_MODE_BOOKING = 14,
  6421. SYS_MODE_MAINTAIN = 15,
  6422. SYS_MODE_DEBUG = 16,
  6423. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  6424. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  6425. SYS_MODE_UPDATE = 19
  6426. };
  6427. */
  6428. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6429. {
  6430. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6431. goto end;
  6432. }
  6433. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  6434. {
  6435. //check Transaction active
  6436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6437. {
  6438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6439. {
  6440. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6441. {
  6442. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6443. {
  6444. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6445. {
  6446. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6447. {
  6448. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6449. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6450. }
  6451. 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'))
  6452. {
  6453. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6454. }
  6455. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6456. {
  6457. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6458. }
  6459. else
  6460. {
  6461. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6462. }
  6463. }
  6464. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6465. {
  6466. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6467. }
  6468. }
  6469. else
  6470. {
  6471. //replace reservation
  6472. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6473. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6474. }
  6475. }
  6476. } // END FOR CHAdeMO_QUANTITY
  6477. for (int index = 0; index < CCS_QUANTITY; index++)
  6478. {
  6479. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6480. {
  6481. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6482. {
  6483. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6484. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6485. {
  6486. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6487. {
  6488. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6489. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6490. }
  6491. 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'))
  6492. {
  6493. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6494. }
  6495. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6496. {
  6497. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6498. }
  6499. else
  6500. {
  6501. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6502. }
  6503. }
  6504. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6505. {
  6506. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6507. }
  6508. }
  6509. else
  6510. {
  6511. //replace reservation
  6512. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6513. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6514. }
  6515. }
  6516. } // END FOR CCS_QUANTITY
  6517. for (int index = 0; index < GB_QUANTITY; index++)
  6518. {
  6519. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6520. {
  6521. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6522. {
  6523. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6524. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6525. {
  6526. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6527. {
  6528. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6529. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6530. }
  6531. 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'))
  6532. {
  6533. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6534. }
  6535. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6536. {
  6537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6538. }
  6539. else
  6540. {
  6541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6542. }
  6543. }
  6544. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6545. {
  6546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6547. }
  6548. }
  6549. else
  6550. {
  6551. //replace reservation
  6552. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6553. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6554. }
  6555. }
  6556. }// END FOR GB_QUANTITY
  6557. }
  6558. else
  6559. {
  6560. for (int index = 0; index < AC_QUANTITY; index++)
  6561. {
  6562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6563. {
  6564. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6565. {
  6566. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6567. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6568. {
  6569. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6570. {
  6571. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6572. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6573. }
  6574. 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'))
  6575. {
  6576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6577. }
  6578. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6579. {
  6580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6581. }
  6582. else
  6583. {
  6584. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6585. }
  6586. }
  6587. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6588. {
  6589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6590. }
  6591. }
  6592. else
  6593. {
  6594. //replace reservation
  6595. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6596. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6597. }
  6598. }
  6599. } // END FOR AC_QUANTITY
  6600. }//END FOR AC ELSE
  6601. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6602. }
  6603. else if(connectorIdInt == 0)
  6604. {
  6605. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6606. {
  6607. //check Transaction active
  6608. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6609. {
  6610. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6611. {
  6612. 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'))
  6613. {
  6614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6615. goto end;
  6616. }
  6617. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6618. {
  6619. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6620. goto end;
  6621. }
  6622. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6623. {
  6624. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6625. goto end;
  6626. }
  6627. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6628. {
  6629. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6630. goto end;
  6631. }
  6632. }
  6633. }// END FOR CHAdeMO_QUANTITY
  6634. for (int index = 0; index < CCS_QUANTITY; index++)
  6635. {
  6636. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6637. {
  6638. 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'))
  6639. {
  6640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6641. }
  6642. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6643. {
  6644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6645. }
  6646. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6647. {
  6648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6649. }
  6650. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6651. {
  6652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6653. }
  6654. }
  6655. } // END FOR CCS_QUANTITY
  6656. for (int index = 0; index < GB_QUANTITY; index++)
  6657. {
  6658. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6659. {
  6660. 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'))
  6661. {
  6662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6663. }
  6664. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6665. {
  6666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6667. }
  6668. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6669. {
  6670. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6671. }
  6672. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6673. {
  6674. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6675. }
  6676. }
  6677. } // END FOR GB_QUANTITY
  6678. }
  6679. else
  6680. {
  6681. for (int index = 0; index < AC_QUANTITY; index++)
  6682. {
  6683. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6684. {
  6685. 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'))
  6686. {
  6687. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6688. goto end;
  6689. }
  6690. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6691. {
  6692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6693. goto end;
  6694. }
  6695. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6696. {
  6697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6698. goto end;
  6699. }
  6700. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6701. {
  6702. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6703. goto end;
  6704. }
  6705. }
  6706. }// END FOR AC_QUANTITY
  6707. }
  6708. //The connectorId is 0
  6709. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6711. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6712. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6713. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6714. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6715. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6716. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6717. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6718. result = TRUE;
  6719. return result;
  6720. }
  6721. else
  6722. {
  6723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6724. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6725. }
  6726. if(strcmp(comfirmstr,"Accepted") == 0)
  6727. {
  6728. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6729. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6730. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6731. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6732. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6733. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6734. result = TRUE;
  6735. return result;
  6736. }
  6737. end:
  6738. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6739. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6740. return result;
  6741. }
  6742. int handleResetRequest(char *uuid, char *payload)
  6743. {
  6744. mtrace();
  6745. int result = FAIL;
  6746. char sstr[10]={0};
  6747. char typestr[10]={0};
  6748. char comfirmstr[20]={0};
  6749. int c = 0;
  6750. char *loc;
  6751. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6752. DEBUG_INFO("handleResetRequest ...\n");
  6753. loc = strstr(payload, "type");
  6754. memset(sstr ,0, sizeof(sstr) );
  6755. c = 0;
  6756. while (loc[3+strlen("type")+c] != '\"')
  6757. {
  6758. sstr[c] = loc[3+strlen("type")+c];
  6759. c++;
  6760. }
  6761. sstr[c] = '\0';
  6762. strcpy(typestr,sstr);
  6763. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6764. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6765. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6766. {
  6767. //check Transaction active
  6768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6769. {
  6770. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6771. {
  6772. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6773. {
  6774. //0: unplug, 1: Plug-in
  6775. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6776. }
  6777. }
  6778. for (int index = 0; index < CCS_QUANTITY; index++)
  6779. {
  6780. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6781. {
  6782. //0: unplug, 1: Plug-in
  6783. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6784. }
  6785. }
  6786. for (int index = 0; index < GB_QUANTITY; index++)
  6787. {
  6788. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6789. {
  6790. //0: unplug, 1: Plug-in
  6791. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6792. }
  6793. }
  6794. }
  6795. else
  6796. {
  6797. for (int index = 0; index < AC_QUANTITY; index++)
  6798. {
  6799. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6800. {
  6801. //0: unplug, 1: Plug-in
  6802. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6803. }
  6804. }
  6805. }// END FOR AC ELSE
  6806. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6807. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6808. result = TRUE;
  6809. return result;
  6810. }
  6811. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6812. {
  6813. //check Transaction active
  6814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6815. {
  6816. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6817. {
  6818. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6819. {
  6820. //0: unplug, 1: Plug-in
  6821. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6822. }
  6823. }
  6824. for (int index = 0; index < CCS_QUANTITY; index++)
  6825. {
  6826. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6827. {
  6828. //0: unplug, 1: Plug-in
  6829. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6830. }
  6831. }
  6832. for (int index = 0; index < GB_QUANTITY; index++)
  6833. {
  6834. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6835. {
  6836. //0: unplug, 1: Plug-in
  6837. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6838. }
  6839. }
  6840. }
  6841. else
  6842. {
  6843. for (int index = 0; index < AC_QUANTITY; index++)
  6844. {
  6845. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6846. {
  6847. //0: unplug, 1: Plug-in
  6848. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6849. }
  6850. }
  6851. }// END FOR AC ELSE
  6852. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6853. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6854. result = TRUE;
  6855. return result;
  6856. }
  6857. else
  6858. {
  6859. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6860. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6861. goto errorend;
  6862. }
  6863. errorend:
  6864. sendResetConfirmation(uuid, comfirmstr);
  6865. return result;
  6866. }
  6867. int handleSendLocalListRequest(char *uuid, char *payload)
  6868. {
  6869. mtrace();
  6870. int result = FAIL;
  6871. int listVersionInt;
  6872. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6873. char listsearch[]="listVersion";
  6874. char updateTypesearch[]="updateType";
  6875. char localAuthorizationListsearch[]="localAuthorizationList";
  6876. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6877. char CardList[500][160]={0};
  6878. char updateTypestr[15]={0};
  6879. char idTagstr[20]={0};
  6880. char parentIdTag[20]={0};
  6881. char expiryDate[30]={0};
  6882. char idTagstatus[16]={0};
  6883. int c = 0;
  6884. int i = 0;
  6885. char *delim1 = "}";
  6886. char * pch;
  6887. char *loc;
  6888. //char *ptr;
  6889. char comfirmstr[20];
  6890. //int n_localAuthorizations = 0;
  6891. int checkState_Faulted = FALSE;
  6892. DEBUG_INFO("handleSendLocalListRequest\n");
  6893. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6894. {
  6895. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6896. goto end;
  6897. }
  6898. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6899. {
  6900. //check Charge Point state
  6901. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6902. {
  6903. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6904. {
  6905. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6906. }
  6907. }
  6908. for (int index = 0; index < CCS_QUANTITY; index++)
  6909. {
  6910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6911. {
  6912. checkState_Faulted = TRUE; //OCPP Status
  6913. }
  6914. }
  6915. for (int index = 0; index < GB_QUANTITY; index++)
  6916. {
  6917. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6918. {
  6919. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6920. }
  6921. }
  6922. }
  6923. else
  6924. {
  6925. //check Charge Point state
  6926. for (int index = 0; index < AC_QUANTITY; index++)
  6927. {
  6928. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6929. {
  6930. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6931. }
  6932. }
  6933. }// END FOR AC ELSE
  6934. if(checkState_Faulted == TRUE)
  6935. {
  6936. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6937. goto end;
  6938. }
  6939. //listVersion
  6940. c = 0;
  6941. loc = strstr(payload, listsearch);
  6942. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  6943. {
  6944. sstr[c] = loc[strlen("listVersion")+2+c];
  6945. c++;
  6946. }
  6947. sstr[c] = '\0';
  6948. listVersionInt = atoi(sstr);
  6949. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6950. //updateType
  6951. loc = strstr(payload, updateTypesearch);
  6952. c = 0;
  6953. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6954. {
  6955. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6956. c++;
  6957. }
  6958. sstr[c] = '\0';
  6959. strcpy(updateTypestr, sstr);
  6960. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6961. //localAuthorizationList
  6962. memset(sstr ,0, sizeof(sstr) );
  6963. loc = strstr(payload, localAuthorizationListsearch);
  6964. if(loc != NULL) // localAuthorizationList is not NULL
  6965. {
  6966. //Check UpdateType
  6967. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6968. {
  6969. //Local list full update
  6970. printf("Local list full update.\n");
  6971. OCPP_cleanLocalList();
  6972. }
  6973. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6974. {
  6975. //Local list different update
  6976. printf("Local list different update.\n");
  6977. OCPP_getListVerion();
  6978. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6979. {
  6980. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6981. goto end;
  6982. }
  6983. }
  6984. else
  6985. {
  6986. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6987. goto end;
  6988. }
  6989. c = 0;
  6990. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6991. {
  6992. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6993. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6994. c++;
  6995. }
  6996. sstr[c] = '\0';
  6997. //DEBUG_INFO("sstr=%s\n", sstr);
  6998. //parsing strings to words
  6999. i = 0;
  7000. pch = strtok(sstr,delim1);
  7001. while (pch != NULL)
  7002. {
  7003. strcpy(CardList[i], pch);
  7004. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7005. pch = strtok (NULL, delim1);
  7006. i = i + 1;
  7007. }
  7008. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7009. //local Authorizations List Numbers
  7010. //n_localAuthorizations = i;
  7011. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7012. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7013. c= 0;
  7014. while(c < i)
  7015. {
  7016. //Search "IdToken"
  7017. memset(sstr ,0, sizeof(sstr) );
  7018. loc = strstr(CardList[c], "idTag");
  7019. int j = 0;
  7020. while (loc[3+strlen("idTag")+j] != '\"')
  7021. {
  7022. sstr[j] = loc[3+strlen("idTag")+j];
  7023. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7024. j++;
  7025. }
  7026. sstr[j] = '\0';
  7027. strcpy(idTagstr, sstr);
  7028. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7029. //Search "expiryDate"
  7030. memset(sstr ,0, sizeof(sstr) );
  7031. loc = strstr(CardList[c], "expiryDate");
  7032. j = 0;
  7033. if(loc != NULL)
  7034. {
  7035. while (loc[3+strlen("expiryDate")+j] != '\"')
  7036. {
  7037. sstr[j] = loc[3+strlen("expiryDate")+j];
  7038. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7039. j++;
  7040. }
  7041. sstr[j] = '\0';
  7042. strcpy(expiryDate, sstr);
  7043. }
  7044. else
  7045. {
  7046. strcpy(expiryDate, "");
  7047. }
  7048. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7049. //Search "parentIdTag"
  7050. memset(sstr ,0, sizeof(sstr) );
  7051. loc = strstr(CardList[c], "parentIdTag");
  7052. j = 0;
  7053. if(loc != NULL)
  7054. {
  7055. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7056. {
  7057. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7058. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7059. j++;
  7060. }
  7061. sstr[j] = '\0';
  7062. strcpy(parentIdTag, sstr);
  7063. }
  7064. else
  7065. {
  7066. strcpy(parentIdTag, "");
  7067. }
  7068. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7069. //Search "status"
  7070. memset(sstr ,0, sizeof(sstr) );
  7071. loc = strstr(CardList[c], "status");
  7072. j = 0;
  7073. while (loc[3+strlen("status")+j] != '\"')
  7074. {
  7075. sstr[j] = loc[3+strlen("status")+j];
  7076. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7077. j++;
  7078. }
  7079. sstr[j] = '\0';
  7080. strcpy(idTagstatus, sstr);
  7081. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7082. OCPP_getIdTag(idTagstr);
  7083. //OCPP_getIdTag("test"); For Test
  7084. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7085. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7086. {
  7087. //Local list full update
  7088. DEBUG_INFO("Local list full update.\n");
  7089. // update list
  7090. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7091. OCPP_get_TableAuthlocalAllData();
  7092. }
  7093. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7094. {
  7095. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7096. {
  7097. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7098. }
  7099. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7100. {
  7101. OCPP_deleteIdTag(idTagstr);
  7102. }
  7103. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7104. {
  7105. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7106. }
  7107. }
  7108. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7109. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7110. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7111. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7112. c++;
  7113. }
  7114. }
  7115. else
  7116. {
  7117. //Check UpdateType
  7118. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7119. {
  7120. //Local list full update
  7121. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7122. OCPP_cleanLocalList();
  7123. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7124. goto end;
  7125. }
  7126. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7127. {
  7128. //Local list different update
  7129. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7130. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7131. goto end;
  7132. }
  7133. }
  7134. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7135. end:
  7136. sendSendLocalListConfirmation(uuid, comfirmstr);
  7137. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7138. return result;
  7139. }
  7140. #define MAX 200
  7141. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7142. {
  7143. mtrace();
  7144. int result = FAIL;
  7145. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7146. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7147. char chargingProfilePurposeStr[30]={0};
  7148. char chargingProfileKindStr[16]={0};
  7149. char recurrencyKindStr[10]={0};
  7150. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7151. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7152. int chargingSchedulePeriodCount = 0;
  7153. //int updateflag = FALSE;
  7154. char comfirmstr[20]={0};
  7155. int meet= FALSE;
  7156. char sstr[10]={0};
  7157. int c = 0;
  7158. char *loc;
  7159. FILE *fptr1;//, *fptr2;
  7160. //int lno=0;//, linectr = 0;
  7161. //int modifyflag = FALSE;
  7162. char filename[MAX]={0};
  7163. char tempfile[] = "/Storage/OCPP/temp.json";
  7164. //int resultRename=0;
  7165. char rmFileCmd[50]={0};
  7166. char tempchargingProfilePurposeStr[30]={0};
  7167. //[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}}}]
  7168. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7169. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7170. //*********************connectorId***************************/
  7171. loc = strstr(payload, "connectorId");
  7172. c = 0;
  7173. memset(sstr ,0, sizeof(sstr) );
  7174. while (loc[strlen("connectorId")+2+c] != ',')
  7175. {
  7176. sstr[c] = loc[strlen("connectorId")+2+c];
  7177. c++;
  7178. }
  7179. sstr[c] = '\0';
  7180. connectorIdInt = atoi(sstr);
  7181. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7182. {
  7183. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7184. }
  7185. else
  7186. {
  7187. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7188. }
  7189. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7190. //*********************chargingProfileId***************************/
  7191. loc = strstr(payload, "chargingProfileId");
  7192. c = 0;
  7193. memset(sstr ,0, sizeof(sstr) );
  7194. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7195. {
  7196. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7197. c++;
  7198. }
  7199. sstr[c] = '\0';
  7200. chargingProfileIdInt = atoi(sstr);
  7201. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7202. {
  7203. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7204. }
  7205. else
  7206. {
  7207. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7208. }
  7209. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7210. //*********************transactionId***************************/
  7211. loc = strstr(payload, "transactionId");
  7212. if(loc != NULL)
  7213. {
  7214. c = 0;
  7215. memset(sstr ,0, sizeof(sstr) );
  7216. while (loc[strlen("transactionId")+2+c] != ',')
  7217. {
  7218. sstr[c] = loc[strlen("transactionId")+2+c];
  7219. c++;
  7220. }
  7221. sstr[c] = '\0';
  7222. transactionIdInt = atoi(sstr);
  7223. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7224. {
  7225. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7226. }
  7227. else
  7228. {
  7229. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7230. }
  7231. }
  7232. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7233. //*********************stackLevel***************************/
  7234. loc = strstr(payload, "stackLevel");
  7235. c = 0;
  7236. memset(sstr ,0, sizeof(sstr) );
  7237. while (loc[strlen("stackLevel")+2+c] != ',')
  7238. {
  7239. sstr[c] = loc[strlen("stackLevel")+2+c];
  7240. c++;
  7241. }
  7242. sstr[c] = '\0';
  7243. stackLevelInt = atoi(sstr);
  7244. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7245. {
  7246. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7247. }
  7248. else
  7249. {
  7250. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7251. }
  7252. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7253. //*********************chargingProfilePurpose***************************/
  7254. loc = strstr(payload, "chargingProfilePurpose");
  7255. c = 0;
  7256. memset(sstr ,0, sizeof(sstr) );
  7257. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7258. {
  7259. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7260. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7261. c++;
  7262. }
  7263. sstr[c] = '\0';
  7264. strcpy(chargingProfilePurposeStr,sstr);
  7265. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7266. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7267. {
  7268. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7269. }
  7270. else
  7271. {
  7272. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7273. }
  7274. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7275. //*********************chargingProfileKind***************************/
  7276. loc = strstr(payload, "chargingProfileKind");
  7277. c = 0;
  7278. memset(sstr ,0, sizeof(sstr) );
  7279. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7280. {
  7281. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7282. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7283. c++;
  7284. }
  7285. sstr[c] = '\0';
  7286. strcpy(chargingProfileKindStr,sstr);
  7287. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7288. {
  7289. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7290. }
  7291. else
  7292. {
  7293. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7294. }
  7295. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7296. //*********************recurrencyKind***************************/
  7297. loc = strstr(payload, "recurrencyKind");
  7298. if(loc != NULL)
  7299. {
  7300. c = 0;
  7301. memset(sstr ,0, sizeof(sstr) );
  7302. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7303. {
  7304. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7305. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7306. c++;
  7307. }
  7308. sstr[c] = '\0';
  7309. strcpy(recurrencyKindStr,sstr);
  7310. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7311. {
  7312. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7313. }
  7314. else
  7315. {
  7316. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7317. }
  7318. }
  7319. else
  7320. {
  7321. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7322. {
  7323. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  7324. }
  7325. else
  7326. {
  7327. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  7328. }
  7329. }
  7330. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7331. //*********************validFrom***************************/
  7332. loc = strstr(payload, "validFrom");
  7333. if(loc != NULL)
  7334. {
  7335. c = 0;
  7336. memset(sstr ,0, sizeof(sstr) );
  7337. while (loc[3+strlen("validFrom")+c] != '\"')
  7338. {
  7339. sstr[c] = loc[3+strlen("validFrom")+c];
  7340. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7341. c++;
  7342. }
  7343. sstr[c] = '\0';
  7344. strcpy(validFromStr,sstr);
  7345. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7346. {
  7347. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7348. }
  7349. else
  7350. {
  7351. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7352. }
  7353. }
  7354. else
  7355. {
  7356. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7357. {
  7358. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  7359. }
  7360. else
  7361. {
  7362. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  7363. }
  7364. }
  7365. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7366. //*********************validTo***************************/
  7367. loc = strstr(payload, "validTo");
  7368. if(loc != NULL)
  7369. {
  7370. c = 0;
  7371. memset(sstr ,0, sizeof(sstr) );
  7372. while (loc[3+strlen("validTo")+c] != '\"')
  7373. {
  7374. sstr[c] = loc[3+strlen("validTo")+c];
  7375. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7376. c++;
  7377. }
  7378. sstr[c] = '\0';
  7379. strcpy(validToStr,sstr);
  7380. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7381. {
  7382. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7383. }
  7384. else
  7385. {
  7386. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7387. }
  7388. }
  7389. else
  7390. {
  7391. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7392. {
  7393. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  7394. }
  7395. else
  7396. {
  7397. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  7398. }
  7399. }
  7400. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7401. //*********************duration***************************/
  7402. loc = strstr(payload, "duration");
  7403. if(loc != NULL)
  7404. {
  7405. c = 0;
  7406. memset(sstr ,0, sizeof(sstr) );
  7407. while (loc[strlen("duration")+2+c] != ',')
  7408. {
  7409. sstr[c] = loc[strlen("duration")+2+c];
  7410. c++;
  7411. }
  7412. sstr[c] = '\0';
  7413. durationInt = atoi(sstr);
  7414. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7415. {
  7416. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7417. }
  7418. else
  7419. {
  7420. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7421. }
  7422. }
  7423. else
  7424. {
  7425. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7426. {
  7427. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  7428. }
  7429. else
  7430. {
  7431. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  7432. }
  7433. }
  7434. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7435. //*********************startSchedule***************************/
  7436. loc = strstr(payload, "startSchedule");
  7437. if(loc != NULL)
  7438. {
  7439. c = 0;
  7440. memset(sstr ,0, sizeof(sstr) );
  7441. while (loc[3+strlen("startSchedule")+c] != '\"')
  7442. {
  7443. sstr[c] = loc[3+strlen("startSchedule")+c];
  7444. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7445. c++;
  7446. }
  7447. sstr[c] = '\0';
  7448. strcpy(startScheduleStr,sstr);
  7449. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7450. {
  7451. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7452. }
  7453. else
  7454. {
  7455. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7456. }
  7457. }
  7458. else
  7459. {
  7460. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7461. {
  7462. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7463. }
  7464. else
  7465. {
  7466. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  7467. }
  7468. }
  7469. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7470. //*********************chargingRateUnit***************************/
  7471. loc = strstr(payload, "chargingRateUnit");
  7472. if(loc != NULL)
  7473. {
  7474. c = 0;
  7475. memset(sstr ,0, sizeof(sstr) );
  7476. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7477. {
  7478. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7479. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7480. c++;
  7481. }
  7482. sstr[c] = '\0';
  7483. strcpy(chargingRateUnitStr,sstr);
  7484. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7485. {
  7486. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7487. }
  7488. else
  7489. {
  7490. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7491. }
  7492. }
  7493. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7494. //****************chargingSchedulePeriod count start*******************/
  7495. int what_len = strlen("startPeriod");
  7496. char tempChargingProfile[1000]={0};
  7497. strcpy(tempChargingProfile,(const char*)payload);
  7498. char *where = tempChargingProfile;
  7499. if (what_len)
  7500. {
  7501. while ((where = strstr(where, "startPeriod"))) {
  7502. where += what_len;
  7503. chargingSchedulePeriodCount++;
  7504. }
  7505. }
  7506. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7507. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7508. //where = payload;
  7509. int templength = 0;
  7510. //int searchstart = 0;
  7511. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7512. {
  7513. //****************startPeriod*******************/
  7514. c=0;
  7515. loc = strstr(tempChargingProfile + templength, "startPeriod");
  7516. memset(sstr ,0, sizeof(sstr) );
  7517. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7518. {
  7519. sstr[c] = loc[strlen("startPeriod")+2+c];
  7520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7521. c++;
  7522. }
  7523. sstr[c] = '\0';
  7524. startPeriodInt[periodNums] = atoi(sstr);
  7525. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7526. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7527. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7528. {
  7529. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7530. }
  7531. else
  7532. {
  7533. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7534. }
  7535. templength = strlen("startPeriod")+2+c;
  7536. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7537. //****************limit*******************/
  7538. c=0;
  7539. loc = strstr(tempChargingProfile + templength, "limit");
  7540. memset(sstr ,0, sizeof(sstr) );
  7541. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7542. {
  7543. sstr[c] = loc[strlen("limit")+2+c];
  7544. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7545. c++;
  7546. }
  7547. sstr[c] = '\0';
  7548. limitflaot[periodNums] = atof(sstr);
  7549. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7550. {
  7551. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7552. }
  7553. else
  7554. {
  7555. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7556. }
  7557. templength = templength + strlen("limit")+2+c;
  7558. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7559. //****************numberPhases*******************/
  7560. loc = strstr(tempChargingProfile + templength, "numberPhases");
  7561. if(loc != NULL)
  7562. {
  7563. c=0;
  7564. memset(sstr ,0, sizeof(sstr) );
  7565. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7566. {
  7567. sstr[c] = loc[strlen("numberPhases")+2+c];
  7568. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7569. c++;
  7570. }
  7571. sstr[c] = '\0';
  7572. numberPhasesInt[periodNums] = atoi(sstr);
  7573. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7574. {
  7575. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7576. }
  7577. else
  7578. {
  7579. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7580. }
  7581. templength = templength + strlen("numberPhases")+2+c;
  7582. }
  7583. //where = loc;
  7584. }
  7585. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7586. //****************chargingSchedulePeriod count end*******************/
  7587. //*********************minChargingRate***************************/
  7588. loc = strstr(payload, "minChargingRate");
  7589. if(loc != NULL)
  7590. {
  7591. c = 0;
  7592. memset(sstr ,0, sizeof(sstr) );
  7593. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7594. {
  7595. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7596. c++;
  7597. }
  7598. sstr[c] = '\0';
  7599. minChargingRateFloat = atof(sstr);
  7600. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7601. {
  7602. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7603. }
  7604. else
  7605. {
  7606. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7607. }
  7608. }
  7609. else
  7610. {
  7611. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7612. {
  7613. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7614. }
  7615. else
  7616. {
  7617. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  7618. }
  7619. }
  7620. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7621. {
  7622. //printf("set chargingProfile 1-2\n");
  7623. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7624. if(connectorIdInt != 0)
  7625. {
  7626. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7627. goto end;
  7628. }
  7629. strcpy(filename, ChargePointMaxProfile_JSON );
  7630. fptr1 = fopen(filename, "r");
  7631. if (!fptr1)
  7632. {
  7633. //file not exist
  7634. DEBUG_INFO("Unable to open the input file!!\n");
  7635. fptr1 = fopen(filename, "w+");
  7636. }
  7637. fclose(fptr1);
  7638. }
  7639. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7640. {
  7641. //printf("set chargingProfile 1-3\n");
  7642. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7643. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7644. {
  7645. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7646. goto end;
  7647. }
  7648. switch(connectorIdInt)
  7649. {
  7650. case 0:
  7651. strcpy(filename, TxDefaultProfile_0_JSON );
  7652. break;
  7653. case 1:
  7654. strcpy(filename, TxDefaultProfile_1_JSON );
  7655. break;
  7656. case 2:
  7657. strcpy(filename, TxDefaultProfile_2_JSON );
  7658. break;
  7659. default:
  7660. strcpy(filename, TxDefaultProfile_0_JSON );
  7661. break;
  7662. }
  7663. fptr1 = fopen(filename, "r");
  7664. if (!fptr1)
  7665. {
  7666. //file not exist
  7667. //DEBUG_INFO("Unable to open the input file!!\n");
  7668. fptr1 = fopen(filename, "w+");
  7669. }
  7670. fclose(fptr1);
  7671. }
  7672. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7673. {
  7674. //printf("set chargingProfile 1-4\n");
  7675. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7676. //check Transaction active
  7677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7678. {
  7679. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7680. {
  7681. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7682. {
  7683. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7684. {
  7685. meet = TRUE;
  7686. break;
  7687. }
  7688. }
  7689. }
  7690. }
  7691. for (int index = 0; index < CCS_QUANTITY; index++)
  7692. {
  7693. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7694. {
  7695. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7696. {
  7697. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7698. {
  7699. meet = TRUE;
  7700. break;
  7701. }
  7702. }
  7703. }
  7704. }
  7705. for (int index = 0; index < GB_QUANTITY; index++)
  7706. {
  7707. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7708. {
  7709. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7710. {
  7711. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7712. {
  7713. meet = TRUE;
  7714. break;
  7715. }
  7716. }
  7717. }
  7718. }
  7719. if(meet == FALSE)
  7720. {
  7721. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7722. goto end;
  7723. }
  7724. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7725. {
  7726. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7727. goto end;
  7728. }
  7729. switch(connectorIdInt)
  7730. {
  7731. case 0:
  7732. break;
  7733. case 1:
  7734. strcpy(filename, TxProfile_1_JSON);
  7735. break;
  7736. case 2:
  7737. strcpy(filename, TxProfile_2_JSON);
  7738. break;
  7739. default:
  7740. strcpy(filename, TxProfile_1_JSON);
  7741. break;
  7742. }
  7743. fptr1 = fopen(filename, "r");
  7744. if (!fptr1)
  7745. {
  7746. //file not exist
  7747. DEBUG_INFO("Unable to open the input file!!\n");
  7748. fptr1 = fopen(filename, "w+");
  7749. }
  7750. fclose(fptr1);
  7751. }
  7752. //**********************************Write to File********************************************************/
  7753. FILE *infile;
  7754. FILE *outfile;
  7755. // open file for writing
  7756. infile = fopen (filename, "r");
  7757. outfile = fopen (tempfile, "w");
  7758. int d =0;
  7759. d = fgetc(infile);
  7760. //DEBUG_INFO("d:%d\n",d);
  7761. rewind(infile);
  7762. //*检测到文件结束标识返回1,否则返回0。*/
  7763. if(d == EOF)
  7764. {
  7765. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7766. fprintf(outfile,"%s\n",payload);
  7767. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7768. fclose(infile);
  7769. fclose(outfile);
  7770. sprintf(rmFileCmd,"rm -f %s",filename);
  7771. system(rmFileCmd);
  7772. rename(tempfile, filename);
  7773. #if 0
  7774. resultRename = rename(tempfile, filename);
  7775. if(resultRename == 0)
  7776. {
  7777. DEBUG_INFO("File chargingProfile renamed successfully");
  7778. }
  7779. else
  7780. {
  7781. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7782. }
  7783. #endif
  7784. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7785. //system(rmFileCmd);
  7786. }
  7787. else
  7788. {
  7789. char buf[1000]={0};
  7790. int ChargingProfileAdded = FALSE;
  7791. while (fgets(buf, sizeof(buf), infile) != NULL)
  7792. {
  7793. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7794. //*************************tempconnectorIdInt*********************************/
  7795. loc = strstr(buf, "connectorId");
  7796. c = 0;
  7797. memset(sstr ,0, sizeof(sstr) );
  7798. while (loc[strlen("connectorId")+2+c] != ',')
  7799. {
  7800. sstr[c] = loc[strlen("connectorId")+2+c];
  7801. c++;
  7802. }
  7803. sstr[c] = '\0';
  7804. tempconnectorIdInt = atoi(sstr);
  7805. //*************************tempchargingProfileIdInt*********************************/
  7806. loc = strstr(buf, "chargingProfileId");
  7807. c = 0;
  7808. memset(sstr ,0, sizeof(sstr) );
  7809. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7810. {
  7811. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7812. c++;
  7813. }
  7814. sstr[c] = '\0';
  7815. tempchargingProfileIdInt = atoi(sstr);
  7816. //*************************tempstackLevelInt*********************************/
  7817. loc = strstr(buf, "stackLevel");
  7818. c = 0;
  7819. memset(sstr ,0, sizeof(sstr) );
  7820. while (loc[strlen("stackLevel")+2+c] != ',')
  7821. {
  7822. sstr[c] = loc[strlen("stackLevel")+2+c];
  7823. c++;
  7824. }
  7825. sstr[c] = '\0';
  7826. tempstackLevelInt = atoi(sstr);
  7827. //*************************tempchargingProfilePurposeStr*********************************/
  7828. loc = strstr(payload, "chargingProfilePurpose");
  7829. c = 0;
  7830. memset(sstr ,0, sizeof(sstr) );
  7831. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7832. {
  7833. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7834. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7835. c++;
  7836. }
  7837. sstr[c] = '\0';
  7838. strcpy(tempchargingProfilePurposeStr,sstr);
  7839. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7840. {
  7841. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7842. {
  7843. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7844. if(ChargingProfileAdded == FALSE)
  7845. {
  7846. fprintf(outfile,"%s\n",payload);
  7847. ChargingProfileAdded = TRUE;
  7848. }
  7849. }
  7850. else
  7851. {
  7852. if(tempstackLevelInt < stackLevelInt)
  7853. {
  7854. if(ChargingProfileAdded == FALSE)
  7855. {
  7856. fprintf(outfile,"%s\n",payload);
  7857. ChargingProfileAdded = TRUE;
  7858. fprintf(outfile,"%s\n",buf);
  7859. }
  7860. else
  7861. {
  7862. fprintf(outfile,"%s\n",buf);
  7863. }
  7864. }
  7865. else
  7866. {
  7867. if(ChargingProfileAdded == FALSE)
  7868. {
  7869. fprintf(outfile,"%s\n",buf);
  7870. fprintf(outfile,"%s\n",payload);
  7871. ChargingProfileAdded = TRUE;
  7872. }
  7873. else
  7874. {
  7875. fprintf(outfile,"%s\n",buf);
  7876. }
  7877. }
  7878. }
  7879. }
  7880. else
  7881. {
  7882. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7883. {
  7884. if(ChargingProfileAdded == FALSE)
  7885. {
  7886. fprintf(outfile,"%s\n",payload);
  7887. ChargingProfileAdded = TRUE;
  7888. fprintf(outfile,"%s\n",buf);
  7889. }
  7890. else
  7891. {
  7892. fprintf(outfile,"%s\n",buf);
  7893. }
  7894. }
  7895. else if(tempstackLevelInt < stackLevelInt)
  7896. {
  7897. if(ChargingProfileAdded == FALSE)
  7898. {
  7899. fprintf(outfile,"%s\n",payload);
  7900. ChargingProfileAdded = TRUE;
  7901. fprintf(outfile,"%s\n",buf);
  7902. }
  7903. else
  7904. {
  7905. fprintf(outfile,"%s\n",buf);
  7906. }
  7907. }
  7908. else
  7909. {
  7910. if(ChargingProfileAdded == FALSE)
  7911. {
  7912. fprintf(outfile,"%s\n",buf);
  7913. fprintf(outfile,"%s\n",payload);
  7914. ChargingProfileAdded = TRUE;
  7915. }
  7916. else
  7917. {
  7918. fprintf(outfile,"%s\n",buf);
  7919. }
  7920. }
  7921. }
  7922. } // end of while loop
  7923. fclose(infile);
  7924. fclose(outfile);
  7925. sprintf(rmFileCmd,"rm -f %s",filename);
  7926. system(rmFileCmd);
  7927. rename(tempfile, filename);
  7928. #if 0
  7929. resultRename = rename(tempfile, filename);
  7930. if(resultRename == 0)
  7931. {
  7932. DEBUG_INFO("File chargingProfile renamed successfully");
  7933. }
  7934. else
  7935. {
  7936. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7937. }
  7938. #endif
  7939. result = TRUE;
  7940. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7941. }
  7942. end:
  7943. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7944. return result;
  7945. return result;
  7946. }
  7947. int handleTriggerMessageRequest(char *uuid, char *payload)
  7948. {
  7949. mtrace();
  7950. int result = FAIL;
  7951. int connectorIdIsNULL = FALSE;
  7952. int connectorIdInt =0;
  7953. char sstr[40]={0};
  7954. char requestedMessagestr[40]={0};
  7955. char comfirmstr[20]={0};
  7956. int c = 0;
  7957. char *loc;
  7958. DEBUG_INFO("handleTriggerMessageRequest\n");
  7959. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7960. c = 0;
  7961. loc = strstr(payload, "requestedMessage");
  7962. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7963. {
  7964. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7965. c++;
  7966. }
  7967. sstr[c] = '\0';
  7968. strcpy(requestedMessagestr, sstr);
  7969. c = 0;
  7970. loc = strstr(payload, "connectorId");
  7971. if(loc == NULL)
  7972. {
  7973. connectorIdIsNULL = TRUE;
  7974. }
  7975. else
  7976. {
  7977. memset(sstr ,0, sizeof(sstr) );
  7978. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7979. {
  7980. sstr[c] = loc[strlen("connectorId")+2+c];
  7981. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7982. c++;
  7983. }
  7984. sstr[c] = '\0';
  7985. connectorIdInt = atoi(sstr);
  7986. }
  7987. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7988. {
  7989. //connectorIdInt = json_object_get_int(connectorId);
  7990. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7991. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7992. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7993. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7994. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7995. }
  7996. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7997. {
  7998. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7999. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8000. return TRUE;
  8001. }
  8002. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8003. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8004. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8005. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8006. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8007. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8008. {
  8009. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8010. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8011. return TRUE;
  8012. }
  8013. else
  8014. {
  8015. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8016. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8017. }
  8018. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8019. {
  8020. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8021. {
  8022. FirmwareStatusNotificationStatus = 3;
  8023. }
  8024. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8025. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8026. }
  8027. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8028. {
  8029. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8030. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8031. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8032. }
  8033. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8034. {
  8035. sendBootNotificationRequest();
  8036. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8037. }
  8038. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8039. {
  8040. sendHeartbeatRequest(connectorIdInt);
  8041. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8042. }
  8043. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8044. {
  8045. if(connectorIdIsNULL == FALSE)
  8046. {
  8047. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8048. {
  8049. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8050. sendMeterValuesRequest(connectorIdInt -1);
  8051. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8052. }
  8053. }
  8054. else
  8055. {
  8056. for(int idx=0;idx< gunTotalNumber;idx++)
  8057. {
  8058. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8059. sendMeterValuesRequest(idx);
  8060. }
  8061. }
  8062. }
  8063. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8064. {
  8065. if(connectorIdIsNULL == FALSE)
  8066. {
  8067. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8068. {
  8069. sendStatusNotificationRequest(connectorIdInt -1);
  8070. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8071. }
  8072. }
  8073. else
  8074. {
  8075. for(int idx=0;idx< gunTotalNumber;idx++)
  8076. sendStatusNotificationRequest(idx);
  8077. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8078. }
  8079. }
  8080. return result;
  8081. }
  8082. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8083. {
  8084. mtrace();
  8085. int result = FAIL;
  8086. char sstr[6]={0};
  8087. int connectorIdInt =0;
  8088. char comfirmstr[20]={0};
  8089. int c = 0;
  8090. char *loc;
  8091. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8092. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8093. c = 0;
  8094. loc = strstr(payload, "connectorId");
  8095. memset(sstr ,0, sizeof(sstr) );
  8096. while (loc[strlen("connectorId")+2+c] != '}')
  8097. {
  8098. sstr[c] = loc[strlen("connectorId")+2+c];
  8099. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8100. c++;
  8101. }
  8102. sstr[c] = '\0';
  8103. connectorIdInt = atoi(sstr);
  8104. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8105. if(gunTotalNumber == 0)
  8106. {
  8107. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8108. goto end;
  8109. }
  8110. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8111. {
  8112. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8113. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8114. goto end;
  8115. }
  8116. else
  8117. {
  8118. //check Transaction active
  8119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8120. {
  8121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8122. {
  8123. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8124. {
  8125. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8126. }
  8127. }
  8128. for (int index = 0; index < CCS_QUANTITY; index++)
  8129. {
  8130. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8131. {
  8132. //stop Transaction
  8133. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8134. }
  8135. }
  8136. for (int index = 0; index < GB_QUANTITY; index++)
  8137. {
  8138. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8139. {
  8140. //stop Transaction
  8141. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8142. }
  8143. }
  8144. }
  8145. else
  8146. {
  8147. for (int index = 0; index < AC_QUANTITY; index++)
  8148. {
  8149. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8150. {
  8151. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8152. }
  8153. }
  8154. }// END FOR AC ELSE
  8155. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8156. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8157. result = TRUE;
  8158. return result;
  8159. }
  8160. end:
  8161. //json_object_put(obj); --- remove temporally
  8162. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8163. return result;
  8164. }
  8165. static char UpdateFirmwarepayloadData[300]={0};
  8166. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8167. {
  8168. mtrace();
  8169. int result = FAIL;
  8170. pthread_t t;
  8171. sendUpdateFirmwareConfirmation(uuid);
  8172. memset(UpdateFirmwarepayloadData, 0, 300);
  8173. strcpy(UpdateFirmwarepayloadData, payload);
  8174. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8175. ////pthread_join(t, NULL); //
  8176. //pthread_detach(t);
  8177. //sendUpdateFirmwareConfirmation(uuid);
  8178. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8179. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8180. return result;
  8181. }
  8182. void *UpdateFirmwareProcess(void *data)
  8183. {
  8184. pthread_detach(pthread_self());
  8185. mtrace();
  8186. int retriesInt =0, retryIntervalInt=0;
  8187. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8188. int port=0;
  8189. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8190. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8191. //char comfirmstr[20];
  8192. int isSuccess = 0;
  8193. char ftpbuf[200];
  8194. char temp[100];
  8195. char * pch;
  8196. int retriesISNULL=FALSE;
  8197. int retryInterval=FALSE;
  8198. int c = 0;
  8199. //int i = 0;
  8200. char *loc;
  8201. char sstr[300]={ 0 };
  8202. char str[300]={ 0 };
  8203. //char *str = (char*) data; // ? ?輸入資 ?
  8204. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8205. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8206. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8207. //***************location **************/
  8208. loc = strstr(str, "location");
  8209. memset(sstr ,0, sizeof(sstr) );
  8210. c = 0;
  8211. while (loc[3+strlen("location")+c] != '\"')
  8212. {
  8213. sstr[c] = loc[3+strlen("location")+c];
  8214. c++;
  8215. }
  8216. sstr[c] = '\0';
  8217. strcpy(locationstr, sstr);
  8218. //***************retries**************/
  8219. c = 0;
  8220. loc = strstr(str, "retries");
  8221. if(loc == NULL)
  8222. {
  8223. retriesISNULL=TRUE;
  8224. }
  8225. else
  8226. {
  8227. memset(sstr ,0, sizeof(sstr) );
  8228. while (loc[strlen("retries")+2+c] != ',')
  8229. {
  8230. sstr[c] = loc[strlen("retries")+2+c];
  8231. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8232. c++;
  8233. }
  8234. sstr[c] = '\0';
  8235. }
  8236. if(retriesISNULL == FALSE)
  8237. {
  8238. retriesInt = atoi(sstr);
  8239. }
  8240. //***************retrieveDate **************/
  8241. loc = strstr(str, "retrieveDate");
  8242. memset(sstr ,0, sizeof(sstr) );
  8243. c = 0;
  8244. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8245. {
  8246. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8247. c++;
  8248. }
  8249. sstr[c] = '\0';
  8250. strcpy(retrieveDatestr, sstr);
  8251. //***************retryInterval **************/
  8252. c = 0;
  8253. loc = strstr(str, "retryInterval");
  8254. memset(sstr ,0, sizeof(sstr) );
  8255. if(loc == NULL)
  8256. {
  8257. retryInterval=TRUE;
  8258. }
  8259. else
  8260. {
  8261. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8262. {
  8263. sstr[c] = loc[strlen("retryInterval")+2+c];
  8264. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8265. c++;
  8266. }
  8267. sstr[c] = '\0';
  8268. }
  8269. if(retryInterval==FALSE)
  8270. {
  8271. retryIntervalInt = atoi(sstr);
  8272. }
  8273. memset(ftppath, 0, sizeof(ftppath));
  8274. memset(path, 0, sizeof(path));
  8275. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8276. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8277. if(strncmp(locationstr,"http", 4) == 0)
  8278. {
  8279. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8280. protocol, host, path);
  8281. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8282. // protocol, user, password, host, path);
  8283. sprintf(ftppath,"/%s", path);
  8284. //DEBUG_INFO("protocol =%s\n",protocol);
  8285. //DEBUG_INFO("host =%s\n",host);
  8286. //DEBUG_INFO("path =%s\n",path);
  8287. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8288. int ftppathlen=strlen(ftppath);
  8289. int i=1;
  8290. char filenametemp[50];
  8291. while(i < ftppathlen)
  8292. {
  8293. int len=ftppathlen-i;
  8294. if(ftppath[len]== 47) // '/' ascll code: 47
  8295. {
  8296. DEBUG_INFO("compare '/' all right\n");
  8297. break;
  8298. }
  8299. i=i+1;
  8300. }
  8301. memset(filenametemp, 0, sizeof(filenametemp));
  8302. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8303. filenametemp[i+1] = 0;
  8304. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8305. do{
  8306. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8307. sleep(retryIntervalInt);
  8308. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8309. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8310. if(!isSuccess)
  8311. {
  8312. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8313. }
  8314. else
  8315. {
  8316. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8317. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8318. isUpdateRequest = TRUE;
  8319. }
  8320. }
  8321. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8322. {
  8323. memset(ftpbuf, 0, sizeof(ftpbuf));
  8324. memset(temp, 0, sizeof(temp));
  8325. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8326. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8327. int ftppathlen=strlen(ftpbuf);
  8328. int i=1;
  8329. char filenametemp[50];
  8330. while(i < ftppathlen)
  8331. {
  8332. int len=ftppathlen-i;
  8333. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8334. {
  8335. DEBUG_INFO(" compare '/' all right\n");
  8336. break;
  8337. }
  8338. i=i+1;
  8339. }
  8340. memset(filenametemp, 0, sizeof(filenametemp));
  8341. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8342. filenametemp[i+1] = 0;
  8343. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8344. pch=strchr(temp,'@');
  8345. if(pch==NULL)
  8346. {
  8347. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8348. protocol, host, &port, path);
  8349. strcpy(user,"anonymous");
  8350. strcpy(password,"");
  8351. }
  8352. else
  8353. {
  8354. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8355. protocol, user, password, host, &port, path);
  8356. }
  8357. sscanf(host,"%[^/]%s",host1, path1);
  8358. sprintf(ftppath,"%s", path1);
  8359. //DEBUG_INFO("protocol =%s\n",protocol);
  8360. //DEBUG_INFO("user =%s\n",user);
  8361. //DEBUG_INFO("password =%s\n",password);
  8362. //DEBUG_INFO("host1 =%s\n",host1);
  8363. //DEBUG_INFO("port =%d\n",port);
  8364. //DEBUG_INFO("path1 =%s\n",path1);
  8365. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8366. //ftpFile(host, user, password, port, ftppath, fname);
  8367. //download firmware pthred
  8368. if(port == 0)
  8369. {
  8370. port = 21;
  8371. }
  8372. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8373. do{
  8374. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8375. sleep(retryIntervalInt);
  8376. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8377. if(!isSuccess)
  8378. {
  8379. //BulldogUtil.sleepMs(interval*1000);
  8380. DEBUG_INFO("Update firmware request and download file fail.\n");
  8381. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8382. }
  8383. else
  8384. {
  8385. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8386. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8387. isUpdateRequest = TRUE;
  8388. }
  8389. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8390. }
  8391. else
  8392. {
  8393. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8394. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8395. }
  8396. pthread_exit(NULL);
  8397. }
  8398. //==========================================
  8399. // Handle server response routine
  8400. //==========================================
  8401. void handleAuthorizeResponse(char *payload, int gun_index)
  8402. {
  8403. mtrace();
  8404. char expiryDatestr[30]={0};
  8405. char parentIdTagstr[20]={0};
  8406. char statusstr[20]={0};
  8407. char expiryDatestrtemp[30]={0};
  8408. char parentIdTagstrtemp[20]={0};
  8409. char IdTagstrtemp[20]={0};
  8410. char statusstrtemp[20]={0};
  8411. int expiryDateISNULL=FALSE;
  8412. int parentIdTagISNULL=FALSE;
  8413. char sstr[160]={ 0 };
  8414. char* filename = AuthorizationCache_JSON;
  8415. char tempfile[] = "/Storage/OCPP/temp.json";
  8416. int c = 0;
  8417. char *loc;
  8418. int resultRename=0;
  8419. int responseIdTagInfoAsZero= 0;
  8420. char rmFileCmd[50]={0};
  8421. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8422. //***********expiryDate*************/
  8423. loc = strstr(payload, "expiryDate");
  8424. memset(sstr ,0, sizeof(sstr) );
  8425. c = 0;
  8426. if(loc == NULL)
  8427. {
  8428. expiryDateISNULL = TRUE;
  8429. }
  8430. else
  8431. {
  8432. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8433. {
  8434. sstr[c] = loc[3+strlen("expiryDate")+c];
  8435. c++;
  8436. }
  8437. sstr[c] = '\0';
  8438. strcpy(expiryDatestr, sstr);
  8439. }
  8440. //***********parentIdTag*************/
  8441. loc = strstr(payload, "parentIdTag");
  8442. memset(sstr ,0, sizeof(sstr) );
  8443. c = 0;
  8444. if(loc == NULL)
  8445. {
  8446. parentIdTagISNULL = TRUE;
  8447. }
  8448. else
  8449. {
  8450. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8451. {
  8452. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8453. c++;
  8454. }
  8455. sstr[c] = '\0';
  8456. strcpy(parentIdTagstr, sstr);
  8457. }
  8458. //***********status*************/
  8459. loc = strstr(payload, "status");
  8460. memset(sstr ,0, sizeof(sstr) );
  8461. c = 0;
  8462. while (loc[3+strlen("status")+c] != '\"')
  8463. {
  8464. sstr[c] = loc[3+strlen("status")+c];
  8465. c++;
  8466. }
  8467. sstr[c] = '\0';
  8468. strcpy(statusstr, sstr);
  8469. if(expiryDateISNULL == FALSE)
  8470. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8471. if(parentIdTagISNULL == FALSE)
  8472. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8473. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8474. //Update idTag information to authorization cache if supproted
  8475. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8476. {
  8477. if((access(filename,F_OK))!=-1)
  8478. {
  8479. printf("AuthorizationCache exist.\n");
  8480. }
  8481. else
  8482. {
  8483. printf("AuthorizationCache not exist\n");
  8484. FILE *log = fopen(filename, "w+");
  8485. if(log == NULL)
  8486. {
  8487. printf("log is NULL\n");
  8488. goto out;
  8489. }
  8490. else
  8491. {
  8492. fclose(log);
  8493. }
  8494. }
  8495. FILE *infile;
  8496. FILE *outfile;
  8497. // open file for writing
  8498. infile = fopen (filename, "r");
  8499. outfile = fopen (tempfile, "w");
  8500. //*检测到文件结束标识返回1,否则返回0。*/
  8501. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8502. int c;
  8503. c = fgetc(infile);
  8504. //DEBUG_INFO("c:%d\n",c);
  8505. rewind(infile);
  8506. if(c == EOF)
  8507. {
  8508. DEBUG_INFO("Orignal File is NULL\n");
  8509. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8510. {
  8511. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8512. }
  8513. else
  8514. {
  8515. strcpy(expiryDatestrtemp, "");
  8516. }
  8517. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8518. {
  8519. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8520. }
  8521. else
  8522. {
  8523. //write Authorize IdTag
  8524. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8525. }
  8526. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8527. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8528. fclose(infile);
  8529. fclose(outfile);
  8530. sprintf(rmFileCmd,"rm -f %s",filename);
  8531. system(rmFileCmd);
  8532. resultRename = rename(tempfile, filename);
  8533. if(resultRename == 0)
  8534. {
  8535. printf("File renamed successfully");
  8536. }
  8537. else
  8538. {
  8539. printf("Error: unable to rename the file");
  8540. }
  8541. }
  8542. else
  8543. {
  8544. char buf[160]={0};
  8545. while (fgets(buf, sizeof(buf), infile) != NULL)
  8546. {
  8547. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8548. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8549. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8550. memset(statusstr, 0, sizeof(statusstrtemp));
  8551. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8552. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8553. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8554. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8555. //------------------IdTag-----------------------
  8556. loc = strstr(buf, "idTag");
  8557. memset(sstr ,0, sizeof(sstr) );
  8558. c = 0;
  8559. while (loc[3+strlen("idTag")+c] != '\"')
  8560. {
  8561. sstr[c] = loc[3+strlen("idTag")+c];
  8562. c++;
  8563. }
  8564. sstr[c] = '\0';
  8565. strcpy(IdTagstrtemp,sstr);
  8566. //*********************expiryDate***************/
  8567. loc = strstr(buf, "expiryDate");
  8568. memset(sstr ,0, sizeof(sstr) );
  8569. c = 0;
  8570. while (loc[3+strlen("expiryDate")+c] != '\"')
  8571. {
  8572. sstr[c] = loc[3+strlen("expiryDate")+c];
  8573. c++;
  8574. }
  8575. sstr[c] = '\0';
  8576. strcpy(expiryDatestr,sstr);
  8577. //*********************parentIdTag***************/
  8578. loc = strstr(buf, "parentIdTag");
  8579. memset(sstr ,0, sizeof(sstr) );
  8580. c = 0;
  8581. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8582. {
  8583. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8584. c++;
  8585. }
  8586. sstr[c] = '\0';
  8587. strcpy(parentIdTagstr,sstr);
  8588. //*********************status***************/
  8589. loc = strstr(buf, "status");
  8590. memset(sstr ,0, sizeof(sstr) );
  8591. c = 0;
  8592. while (loc[3+strlen("status")+c] != '\"')
  8593. {
  8594. sstr[c] = loc[3+strlen("status")+c];
  8595. c++;
  8596. }
  8597. sstr[c] = '\0';
  8598. strcpy(statusstr,sstr);
  8599. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8600. {
  8601. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8602. responseIdTagInfoAsZero = 1;
  8603. }
  8604. else
  8605. {
  8606. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8607. }
  8608. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8609. {
  8610. //modify item
  8611. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8612. {
  8613. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8614. }
  8615. else
  8616. {
  8617. strcpy(expiryDatestrtemp, "");
  8618. }
  8619. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8620. {
  8621. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8622. }
  8623. else
  8624. {
  8625. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8626. }
  8627. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8628. }
  8629. else
  8630. {
  8631. //wrie original item
  8632. strcpy(expiryDatestrtemp, expiryDatestr);
  8633. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8634. strcpy(statusstrtemp, statusstr);
  8635. }
  8636. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8637. }
  8638. fclose(infile);
  8639. fclose(outfile);
  8640. sprintf(rmFileCmd,"rm -f %s",filename);
  8641. system(rmFileCmd);
  8642. resultRename = rename(tempfile, filename);
  8643. if(resultRename == 0)
  8644. {
  8645. DEBUG_INFO("File renamed successfully");
  8646. }
  8647. else
  8648. {
  8649. DEBUG_INFO("Error: unable to rename the file");
  8650. }
  8651. }
  8652. }
  8653. out:
  8654. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8655. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8656. authorizeRetryTimes = 0;
  8657. }
  8658. void handleBootNotificationResponse(char *payload, int gun_index)
  8659. {
  8660. mtrace();
  8661. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8662. char statusStr[12]={0};
  8663. char currentTimeStr[30]={0};
  8664. char *loc;
  8665. int intervalInt = 0;
  8666. int c = 0;
  8667. //double diff_t;
  8668. struct tm tp;
  8669. char buf[28]={0};
  8670. char timebuf[50]={0};
  8671. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8672. //*** interval ****/
  8673. c = 0;
  8674. loc = strstr(payload, "interval");
  8675. //printf("loc=%s\n",loc);
  8676. memset(sstr ,0, sizeof(sstr) );
  8677. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8678. {
  8679. sstr[c] = loc[strlen("interval")+2+c];
  8680. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8681. c++;
  8682. }
  8683. sstr[c] = '\0';
  8684. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8685. intervalInt = atoi(sstr);
  8686. //***status ****/
  8687. loc = strstr(payload, "status");
  8688. memset(sstr ,0, sizeof(sstr) );
  8689. c = 0;
  8690. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8691. {
  8692. sstr[c] = loc[3+strlen("status")+c];
  8693. c++;
  8694. }
  8695. sstr[c] = '\0';
  8696. strcpy(statusStr, sstr);
  8697. //***currentTime ****/
  8698. loc = strstr(payload, "currentTime");
  8699. //printf("loc=%s\n",loc);
  8700. memset(sstr ,0, sizeof(sstr) );
  8701. c = 0;
  8702. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8703. {
  8704. sstr[c] = loc[3+strlen("currentTime")+c];
  8705. c++;
  8706. }
  8707. sstr[c] = '\0';
  8708. strcpy(currentTimeStr, sstr);
  8709. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8710. HeartBeatWaitTime = BootNotificationInterval;
  8711. clientTime.Heartbeat=time((time_t*)NULL);
  8712. //write back to ShmOCPP16Data->BootNotification
  8713. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8714. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8715. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8716. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8717. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8718. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8719. {
  8720. server_sign = TRUE;
  8721. server_pending =FALSE;
  8722. }
  8723. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8724. {
  8725. server_pending = TRUE;
  8726. }
  8727. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8728. tp.tm_isdst = -1;
  8729. //time_t utc = mktime(&tp);
  8730. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8731. memset(timebuf, 0, sizeof timebuf);
  8732. sprintf(timebuf,"date -s '%s'",buf);
  8733. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8734. system(timebuf);
  8735. //==============================================
  8736. // RTC sync
  8737. //==============================================
  8738. system("/sbin/hwclock -w --systohc");
  8739. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8740. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8741. }
  8742. void handleDataTransferResponse(char *payload, int gun_index)
  8743. {
  8744. char sstr[160]={0};//sstr[200]={ 0 };
  8745. int c = 0;
  8746. char *loc;
  8747. DEBUG_INFO("handleDataTransferResponse ...\n");
  8748. loc = strstr(payload, "status");
  8749. printf("loc=%s\n",loc);
  8750. c = 0;
  8751. while (loc[3+strlen("status")+c] != '\"')
  8752. {
  8753. sstr[c] = loc[3+strlen("status")+c];
  8754. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8755. c++;
  8756. }
  8757. sstr[c] = '\0';
  8758. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8759. }
  8760. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8761. {
  8762. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8763. //struct json_object *obj;
  8764. // obj = json_tokener_parse(payload);
  8765. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8766. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8767. //No fields are defined.
  8768. }
  8769. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8770. {
  8771. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8772. //struct json_object *obj;
  8773. // obj = json_tokener_parse(payload);
  8774. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8775. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8776. //No fields are defined.
  8777. }
  8778. void handleHeartbeatResponse(char *payload, int gun_index)
  8779. {
  8780. mtrace();
  8781. //double diff_t;
  8782. struct tm tp;
  8783. char buf[28]={0};
  8784. char timebuf[50]={0};
  8785. char sstr[30]={ 0 };
  8786. int c = 0;
  8787. char *loc;
  8788. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8789. c = 0;
  8790. loc = strstr(payload, "currentTime");
  8791. memset(sstr ,0, sizeof(sstr) );
  8792. while (loc[3+strlen("currentTime")+c] != '\"')
  8793. {
  8794. sstr[c] = loc[3+strlen("currentTime")+c];
  8795. c++;
  8796. }
  8797. sstr[c] = '\0';
  8798. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8799. // #ifdef SystemLogMessage
  8800. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8801. // #endif
  8802. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8803. tp.tm_isdst = -1;
  8804. //time_t utc = mktime(&tp);
  8805. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8806. memset(timebuf, 0, sizeof timebuf);
  8807. sprintf(timebuf,"date -s '%s'",buf);
  8808. system(timebuf);
  8809. //==============================================
  8810. // RTC sync
  8811. //==============================================
  8812. system("/sbin/hwclock -w --systohc");
  8813. if(FirstHeartBeat == 0)
  8814. {
  8815. FirstHeartBeat = 1;
  8816. }
  8817. HeartBeatWithNOResponse = 0;
  8818. //--------Print Out HeartBeat log
  8819. {
  8820. double diff_t;
  8821. struct tm tp,tp1;
  8822. // BootNotification Receive Time
  8823. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8824. tp.tm_isdst = -1;
  8825. time_t BootNotificationReceiveTime = mktime(&tp);
  8826. //HeartBeat Receive Time
  8827. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  8828. tp1.tm_isdst = -1;
  8829. time_t HeartBeatReceiveTime = mktime(&tp1);
  8830. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  8831. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  8832. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  8833. {
  8834. HeartBeatCountPerHour = (int)diff_t / 3600;
  8835. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8836. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8837. }
  8838. }
  8839. }
  8840. void handleMeterValuesResponse(char *payload, int gun_index)
  8841. {
  8842. mtrace();
  8843. //struct json_object *obj;
  8844. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8845. //No fields are defined.
  8846. }
  8847. void handleStartTransactionResponse(char *payload, int gun_index)
  8848. {
  8849. mtrace();
  8850. char sstr[28]={ 0 };
  8851. int c = 0;
  8852. char *loc;
  8853. int transactionIdInt = 0;
  8854. FILE *outfile;
  8855. char data[100]={0};
  8856. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8857. DEBUG_INFO("handleStartTransactionResponse\n");
  8858. //****************expiryDate********************/
  8859. loc = strstr(payload, "expiryDate");
  8860. if(loc == NULL)
  8861. {
  8862. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8863. }
  8864. else
  8865. {
  8866. c = 0;
  8867. memset(sstr ,0, sizeof(sstr) );
  8868. while (loc[3+strlen("expiryDate")+c] != '\"')
  8869. {
  8870. sstr[c] = loc[3+strlen("expiryDate")+c];
  8871. c++;
  8872. }
  8873. sstr[c] = '\0';
  8874. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8875. }
  8876. //****************parentIdTag********************/
  8877. loc = strstr(payload, "parentIdTag");
  8878. if(loc == NULL)
  8879. {
  8880. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8881. }
  8882. else
  8883. {
  8884. c = 0;
  8885. memset(sstr ,0, sizeof(sstr) );
  8886. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8887. {
  8888. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8889. c++;
  8890. }
  8891. sstr[c] = '\0';
  8892. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8893. }
  8894. //****************status********************/
  8895. loc = strstr(payload, "status");
  8896. if(loc == NULL)
  8897. {
  8898. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8899. }
  8900. else
  8901. {
  8902. c = 0;
  8903. memset(sstr ,0, sizeof(sstr) );
  8904. while (loc[3+strlen("status")+c] != '\"')
  8905. {
  8906. sstr[c] = loc[3+strlen("status")+c];
  8907. c++;
  8908. }
  8909. sstr[c] = '\0';
  8910. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8911. }
  8912. //****************transactionId********************/
  8913. c=0;
  8914. loc = strstr(payload, "transactionId");
  8915. memset(sstr ,0, sizeof(sstr) );
  8916. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8917. {
  8918. sstr[c] = loc[strlen("transactionId")+2+c];
  8919. c++;
  8920. }
  8921. sstr[c] = '\0';
  8922. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8923. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8924. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8925. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8926. //-----------Start : write to the Queue TransactionId file -----------------//
  8927. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  8928. {
  8929. //DEBUG_INFO("QueueTransactionId exist.\n");
  8930. }
  8931. else
  8932. {
  8933. //DEBUG_INFO("QueueTransactionId not exist\n");
  8934. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  8935. if(log == NULL)
  8936. {
  8937. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  8938. return ;
  8939. }
  8940. else
  8941. {
  8942. fclose(log);
  8943. }
  8944. }
  8945. // open file for writing
  8946. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  8947. //DEBUG_INFO("data=%s\n",data);
  8948. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  8949. fputs(data, outfile);
  8950. //fputs("\n", outfile);
  8951. fclose (outfile);
  8952. //-------------End: write to the Queue TransactionId file------------------------------------------//
  8953. TransactionId[gun_index] = transactionIdInt;
  8954. //DEBUG_INFO("gun_index: %d\n", gun_index);
  8955. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  8956. #ifdef SystemLogMessage
  8957. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8958. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8959. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8960. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8961. #endif
  8962. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8963. {
  8964. //add Charging Record
  8965. SettingChargingRecord(gun_index, transactionIdInt);
  8966. }
  8967. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8968. }
  8969. void handleStatusNotificationResponse(char *payload, int gun_index)
  8970. {
  8971. mtrace();
  8972. printf("handleStatusNotificationResponse\n");
  8973. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8974. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8975. }
  8976. void handleStopTransactionnResponse(char *payload, int gun_index)
  8977. {
  8978. mtrace();
  8979. char sstr[30]={ 0 };
  8980. int c = 0;
  8981. char *loc;
  8982. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8983. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8984. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8985. loc = strstr(payload, "idTagInfo");
  8986. //***********************idTagInfo************************/
  8987. if(loc != NULL)
  8988. {
  8989. //***********************expiryDate************************/
  8990. loc = strstr(payload, "expiryDate");
  8991. if(loc != NULL)
  8992. {
  8993. memset(sstr ,0, sizeof(sstr) );
  8994. c = 0;
  8995. while (loc[3+strlen("expiryDate")+c] != '\"')
  8996. {
  8997. sstr[c] = loc[3+strlen("expiryDate")+c];
  8998. c++;
  8999. }
  9000. sstr[c] = '\0';
  9001. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9002. }
  9003. //***********************parentIdTag************************/
  9004. loc = strstr(payload, "parentIdTag");
  9005. if(loc != NULL)
  9006. {
  9007. memset(sstr ,0, sizeof(sstr) );
  9008. c = 0;
  9009. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9010. {
  9011. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9012. c++;
  9013. }
  9014. sstr[c] = '\0';
  9015. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9016. }
  9017. //***********************status************************/
  9018. loc = strstr(payload, "status");
  9019. memset(sstr ,0, sizeof(sstr) );
  9020. c = 0;
  9021. while (loc[3+strlen("status")+c] != '\"')
  9022. {
  9023. sstr[c] = loc[3+strlen("status")+c];
  9024. c++;
  9025. }
  9026. sstr[c] = '\0';
  9027. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9028. }
  9029. #ifdef SystemLogMessage
  9030. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9031. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9032. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9033. #endif
  9034. }
  9035. //==========================================
  9036. // Handle Error routine
  9037. //==========================================
  9038. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9039. {
  9040. mtrace();
  9041. #ifdef SystemLogMessage
  9042. DEBUG_INFO("errorCode: %s\n", errorCode);
  9043. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9044. DEBUG_INFO("errorDetails: %s\n", payload);
  9045. #endif
  9046. }
  9047. //===============================================
  9048. // Common routine
  9049. //===============================================
  9050. int initialConfigurationTable(void)
  9051. {
  9052. FILE *fp;
  9053. FILE *outfile;
  9054. char str[200]={0};
  9055. char sstr[100]={0};
  9056. int c = 0;
  9057. char *loc;
  9058. printf("initialConfigurationTable \n");
  9059. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9060. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9061. {
  9062. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9063. if(outfile == NULL) {
  9064. DEBUG_INFO("Error opening file");
  9065. return FALSE;
  9066. }
  9067. /*Core Profile*/
  9068. //AllowOfflineTxForUnknownId
  9069. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9070. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  9074. //AuthorizationCacheEnabled
  9075. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9079. //AuthorizeRemoteTxRequests
  9080. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9084. //BlinkRepeat
  9085. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9089. //ClockAlignedDataInterval
  9090. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9094. //ConnectionTimeOut
  9095. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9099. //GetConfigurationMaxKeys
  9100. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9104. // HeartbeatInterval
  9105. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9109. // LightIntensity
  9110. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9114. // LocalAuthorizeOffline
  9115. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9119. // LocalPreAuthorize
  9120. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9124. // MaxEnergyOnInvalidId
  9125. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9128. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9130. // MeterValuesAlignedData
  9131. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9135. // MeterValuesAlignedDataMaxLength
  9136. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9140. // MeterValuesSampledData
  9141. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9145. // MeterValuesSampledDataMaxLength
  9146. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9150. // MeterValueSampleInterval
  9151. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9155. // MinimumStatusDuration
  9156. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9160. // NumberOfConnectors
  9161. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9164. {
  9165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9166. }
  9167. else
  9168. {
  9169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9170. }
  9171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9172. // ResetRetries
  9173. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9177. // ConnectorPhaseRotation
  9178. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9182. // ConnectorPhaseRotationMaxLength
  9183. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9187. // StopTransactionOnEVSideDisconnect
  9188. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9192. // StopTransactionOnInvalidId
  9193. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9197. // StopTxnAlignedData
  9198. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9202. // StopTxnAlignedDataMaxLength
  9203. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9207. // StopTxnSampledData
  9208. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9212. // StopTxnSampledDataMaxLength
  9213. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9215. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9216. {
  9217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9218. }
  9219. else
  9220. {
  9221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9222. }
  9223. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9225. // SupportedFeatureProfiles
  9226. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  9230. // SupportedFeatureProfilesMaxLength
  9231. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9235. // TransactionMessageAttempts
  9236. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9239. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9241. // TransactionMessageRetryInterval
  9242. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9245. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9247. // UnlockConnectorOnEVSideDisconnect
  9248. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9252. // WebSocketPingInterval
  9253. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9257. //* Local Auth List Management Profile*/
  9258. #if 0
  9259. //For OCTT Test Case
  9260. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9263. #endif
  9264. #if 1
  9265. //LocalAuthListEnabled
  9266. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9270. #endif
  9271. //LocalAuthListMaxLength
  9272. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9276. //SendLocalListMaxLength
  9277. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9281. //ReserveConnectorZeroSupported
  9282. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9286. //* Smart Charging Profile */
  9287. //ChargeProfileMaxStackLevel
  9288. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9292. // ChargingScheduleAllowedChargingRateUnit
  9293. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9297. // ChargingScheduleMaxPeriods
  9298. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9302. // ConnectorSwitch3to1PhaseSupported
  9303. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9307. // MaxChargingProfilesInstalled
  9308. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9312. fclose(outfile);
  9313. }
  9314. else
  9315. {
  9316. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9317. char keystr[60]={0};
  9318. char readonlystr[10]={0};
  9319. char valuestr[100]={0};
  9320. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  9321. if(fp == NULL) {
  9322. DEBUG_INFO("Error opening file");
  9323. return FALSE;
  9324. }
  9325. while( fgets (str, sizeof(str), fp)!=NULL )
  9326. {
  9327. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9328. //*************************key*********************************/
  9329. loc = strstr(str, "key");
  9330. c = 0;
  9331. memset(sstr ,0, sizeof(sstr) );
  9332. while (loc[strlen("key")+3+c] != '\"')
  9333. {
  9334. sstr[c] = loc[strlen("key")+3+c];
  9335. c++;
  9336. }
  9337. sstr[c] = '\0';
  9338. strcpy(keystr,sstr);
  9339. //*************************readonly*********************************/
  9340. loc = strstr(str, "readonly");
  9341. c = 0;
  9342. memset(sstr ,0, sizeof(sstr) );
  9343. while (loc[strlen("readonly")+2+c] != ',')
  9344. {
  9345. sstr[c] = loc[strlen("readonly")+2+c];
  9346. c++;
  9347. }
  9348. sstr[c] = '\0';
  9349. strcpy(readonlystr,sstr);
  9350. //*************************value*********************************/
  9351. loc = strstr(str, "value");
  9352. c = 0;
  9353. memset(sstr ,0, sizeof(sstr) );
  9354. while (loc[strlen("value")+3+c] != '\"')
  9355. {
  9356. sstr[c] = loc[strlen("value")+3+c];
  9357. c++;
  9358. }
  9359. sstr[c] = '\0';
  9360. strcpy(valuestr,sstr);
  9361. // DEBUG_INFO("keystr=%s\n",keystr);
  9362. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9363. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9364. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9365. {
  9366. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9367. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9369. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9370. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9371. }
  9372. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9373. {
  9374. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9375. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9377. }
  9378. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9379. {
  9380. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9382. }
  9383. if(strcmp(keystr, "BlinkRepeat") == 0)
  9384. {
  9385. //Charger.BlinkRepeat = Integer.parseInt(value);
  9386. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9388. }
  9389. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9390. {
  9391. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9393. }
  9394. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9395. {
  9396. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9398. }
  9399. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9400. {
  9401. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9403. }
  9404. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9405. {
  9406. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9408. HeartBeatWaitTime = atoi(valuestr);
  9409. }
  9410. if(strcmp(keystr, "LightIntensity") == 0)
  9411. {
  9412. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9414. }
  9415. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9416. {
  9417. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9419. }
  9420. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9421. {
  9422. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9424. }
  9425. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9426. {
  9427. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9429. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9430. }
  9431. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9432. {
  9433. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9435. }
  9436. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9437. {
  9438. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9440. }
  9441. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9442. {
  9443. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9445. }
  9446. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9447. {
  9448. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9450. }
  9451. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9452. {
  9453. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9455. }
  9456. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9457. {
  9458. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9460. }
  9461. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9462. {
  9463. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9465. }
  9466. if(strcmp(keystr, "ResetRetries") == 0)
  9467. {
  9468. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9470. }
  9471. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9472. {
  9473. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9475. }
  9476. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9477. {
  9478. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9480. }
  9481. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  9482. {
  9483. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  9485. }
  9486. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  9487. {
  9488. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  9490. }
  9491. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  9492. {
  9493. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  9495. }
  9496. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  9497. {
  9498. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9500. }
  9501. if(strcmp(keystr, "StopTxnSampledData") == 0)
  9502. {
  9503. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  9505. }
  9506. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  9507. {
  9508. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9510. }
  9511. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  9512. {
  9513. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  9515. }
  9516. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  9517. {
  9518. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  9520. }
  9521. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  9522. {
  9523. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  9525. TransactionMessageAttemptsValue = atoi(valuestr);
  9526. }
  9527. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  9528. {
  9529. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  9531. TransactionMessageRetryIntervalValue = atoi(valuestr);
  9532. }
  9533. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  9534. {
  9535. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  9537. }
  9538. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  9539. {
  9540. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  9542. }
  9543. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  9544. {
  9545. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  9547. }
  9548. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  9549. {
  9550. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  9552. }
  9553. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  9554. {
  9555. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  9557. }
  9558. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  9559. {
  9560. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  9562. }
  9563. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  9564. {
  9565. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  9567. }
  9568. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  9569. {
  9570. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  9572. }
  9573. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  9574. {
  9575. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  9577. }
  9578. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  9579. {
  9580. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  9582. }
  9583. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  9584. {
  9585. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  9587. }
  9588. }
  9589. fclose(fp);
  9590. }
  9591. return 0;
  9592. }
  9593. void StoreConfigurationTable(void)
  9594. {
  9595. FILE *outfile;
  9596. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9597. if(outfile == NULL)
  9598. {
  9599. DEBUG_INFO("Error opening file");
  9600. return ;
  9601. }
  9602. /*Core Profile*/
  9603. //AllowOfflineTxForUnknownId
  9604. /*
  9605. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9606. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9609. */
  9610. //DEBUG_INFO("data=%s\n",data);
  9611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9612. //AuthorizationCacheEnabled
  9613. /*
  9614. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9617. */
  9618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9619. //AuthorizeRemoteTxRequests
  9620. /*
  9621. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9624. */
  9625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9626. //BlinkRepeat
  9627. /*
  9628. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9631. */
  9632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9633. //ClockAlignedDataInterval
  9634. /*
  9635. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9638. */
  9639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9640. //ConnectionTimeOut
  9641. /*
  9642. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9645. */
  9646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9647. //GetConfigurationMaxKeys
  9648. /*
  9649. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9652. */
  9653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9654. // HeartbeatInterval
  9655. /*
  9656. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9659. */
  9660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9661. // LightIntensity
  9662. /*
  9663. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9666. */
  9667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9668. // LocalAuthorizeOffline
  9669. /*
  9670. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9673. */
  9674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9675. // LocalPreAuthorize
  9676. /*
  9677. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9680. */
  9681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9682. // MaxEnergyOnInvalidId
  9683. /*
  9684. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9687. */
  9688. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9690. // MeterValuesAlignedData
  9691. /*
  9692. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9695. */
  9696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9697. // MeterValuesAlignedDataMaxLength
  9698. /*
  9699. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9702. */
  9703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9704. // MeterValuesSampledData
  9705. /*
  9706. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9709. */
  9710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9711. // MeterValuesSampledDataMaxLength
  9712. /*
  9713. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9716. */
  9717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9718. // MeterValueSampleInterval
  9719. /*
  9720. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9723. */
  9724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9725. // MinimumStatusDuration
  9726. /*
  9727. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9730. */
  9731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9732. // NumberOfConnectors
  9733. /*
  9734. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9736. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9737. {
  9738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9739. }
  9740. else
  9741. {
  9742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9743. }
  9744. */
  9745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9746. // ResetRetries
  9747. /*
  9748. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9751. */
  9752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9753. // ConnectorPhaseRotation
  9754. /*
  9755. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9758. */
  9759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9760. // ConnectorPhaseRotationMaxLength
  9761. /*
  9762. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9765. */
  9766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9767. // StopTransactionOnEVSideDisconnect
  9768. /*
  9769. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9772. */
  9773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9774. // StopTransactionOnInvalidId
  9775. /*
  9776. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9779. */
  9780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9781. // StopTxnAlignedData
  9782. /*
  9783. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9786. */
  9787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9788. // StopTxnAlignedDataMaxLength
  9789. /*
  9790. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9793. */
  9794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9795. // StopTxnSampledData
  9796. /*
  9797. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9800. */
  9801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9802. // StopTxnSampledDataMaxLength
  9803. /*
  9804. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9807. */
  9808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9809. // SupportedFeatureProfiles
  9810. /*
  9811. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9814. */
  9815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  9816. // SupportedFeatureProfilesMaxLength
  9817. /*
  9818. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9821. */
  9822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  9823. // TransactionMessageAttempts
  9824. /*
  9825. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9828. */
  9829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9830. // TransactionMessageRetryInterval
  9831. /*
  9832. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9835. */
  9836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9837. // UnlockConnectorOnEVSideDisconnect
  9838. /*
  9839. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9842. */
  9843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  9844. // WebSocketPingInterval
  9845. /*
  9846. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9849. */
  9850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  9851. //* Local Auth List Management Profile*/
  9852. //LocalAuthListEnabled
  9853. /*
  9854. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9857. */
  9858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9859. //LocalAuthListMaxLength
  9860. /*
  9861. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9864. */
  9865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  9866. //SendLocalListMaxLength
  9867. /*
  9868. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9871. */
  9872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  9873. //ReserveConnectorZeroSupported
  9874. /*
  9875. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9878. */
  9879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9880. //* Smart Charging Profile */
  9881. //ChargeProfileMaxStackLevel
  9882. /*
  9883. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9886. */
  9887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9888. // ChargingScheduleAllowedChargingRateUnit
  9889. /*
  9890. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9893. */
  9894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9895. // ChargingScheduleMaxPeriods
  9896. /*
  9897. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9900. */
  9901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9902. // ConnectorSwitch3to1PhaseSupported
  9903. /*
  9904. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9907. */
  9908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9909. // MaxChargingProfilesInstalled
  9910. /*
  9911. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9914. */
  9915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9916. fclose(outfile);
  9917. }
  9918. void getKeyValue(char *keyReq)
  9919. {
  9920. int isEmpty = FALSE;
  9921. int isKnowKey = FALSE;
  9922. //int unKnowIndex = 0;
  9923. DEBUG_INFO("getKeyValue \n");
  9924. DEBUG_INFO("keyReq=%s \n",keyReq);
  9925. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9926. isEmpty = TRUE;
  9927. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9928. {
  9929. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  9930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9933. {
  9934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9935. }
  9936. else
  9937. {
  9938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9939. }
  9940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9941. isKnowKey = TRUE;
  9942. }
  9943. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9944. {
  9945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9948. {
  9949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9950. }
  9951. else
  9952. {
  9953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9954. }
  9955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9956. isKnowKey = TRUE;
  9957. }
  9958. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9959. {
  9960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9963. {
  9964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9965. }
  9966. else
  9967. {
  9968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9969. }
  9970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9971. isKnowKey = TRUE;
  9972. }
  9973. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9974. {
  9975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9978. {
  9979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9980. }
  9981. else
  9982. {
  9983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9984. }
  9985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9986. isKnowKey = TRUE;
  9987. }
  9988. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9989. {
  9990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9993. {
  9994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9995. }
  9996. else
  9997. {
  9998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9999. }
  10000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10001. isKnowKey = TRUE;
  10002. }
  10003. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10004. {
  10005. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10008. {
  10009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10010. }
  10011. else
  10012. {
  10013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10014. }
  10015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10016. isKnowKey = TRUE;
  10017. }
  10018. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10019. {
  10020. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10023. {
  10024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10025. }
  10026. else
  10027. {
  10028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10029. }
  10030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10031. isKnowKey = TRUE;
  10032. }
  10033. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10034. {
  10035. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10038. {
  10039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10040. }
  10041. else
  10042. {
  10043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10044. }
  10045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10046. isKnowKey = TRUE;
  10047. }
  10048. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10049. {
  10050. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10053. {
  10054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10055. }
  10056. else
  10057. {
  10058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10059. }
  10060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10061. isKnowKey = TRUE;
  10062. }
  10063. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10064. {
  10065. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10068. {
  10069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10070. }
  10071. else
  10072. {
  10073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10074. }
  10075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10076. isKnowKey = TRUE;
  10077. }
  10078. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10079. {
  10080. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10083. {
  10084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10085. }
  10086. else
  10087. {
  10088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10089. }
  10090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10091. isKnowKey = TRUE;
  10092. }
  10093. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10094. {
  10095. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10098. {
  10099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10100. }
  10101. else
  10102. {
  10103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10104. }
  10105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10106. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10107. isKnowKey = TRUE;
  10108. }
  10109. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10110. {
  10111. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10114. {
  10115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10116. }
  10117. else
  10118. {
  10119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10120. }
  10121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10122. isKnowKey = TRUE;
  10123. }
  10124. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10125. {
  10126. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10129. {
  10130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10131. }
  10132. else
  10133. {
  10134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10135. }
  10136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10137. isKnowKey = TRUE;
  10138. }
  10139. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10140. {
  10141. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10144. {
  10145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10146. }
  10147. else
  10148. {
  10149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10150. }
  10151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10152. isKnowKey = TRUE;
  10153. }
  10154. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10155. {
  10156. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10158. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10159. {
  10160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10161. }
  10162. else
  10163. {
  10164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10165. }
  10166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10167. isKnowKey = TRUE;
  10168. }
  10169. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10170. {
  10171. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10174. {
  10175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10176. }
  10177. else
  10178. {
  10179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10180. }
  10181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10182. isKnowKey = TRUE;
  10183. }
  10184. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10185. {
  10186. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10189. {
  10190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10191. }
  10192. else
  10193. {
  10194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10195. }
  10196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10197. isKnowKey = TRUE;
  10198. }
  10199. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10200. {
  10201. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10204. {
  10205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10206. }
  10207. else
  10208. {
  10209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10210. }
  10211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10212. isKnowKey = TRUE;
  10213. }
  10214. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10215. {
  10216. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10219. {
  10220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10221. }
  10222. else
  10223. {
  10224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10225. }
  10226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10227. isKnowKey = TRUE;
  10228. }
  10229. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10230. {
  10231. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10233. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10234. {
  10235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10236. }
  10237. else
  10238. {
  10239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10240. }
  10241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10242. isKnowKey = TRUE;
  10243. }
  10244. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10245. {
  10246. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10248. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10249. {
  10250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10251. }
  10252. else
  10253. {
  10254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10255. }
  10256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10257. isKnowKey = TRUE;
  10258. }
  10259. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10260. {
  10261. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10263. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10264. {
  10265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10266. }
  10267. else
  10268. {
  10269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10270. }
  10271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10272. isKnowKey = TRUE;
  10273. }
  10274. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10275. {
  10276. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10278. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10279. {
  10280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10281. }
  10282. else
  10283. {
  10284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10285. }
  10286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10287. isKnowKey = TRUE;
  10288. }
  10289. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10290. {
  10291. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10294. {
  10295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10296. }
  10297. else
  10298. {
  10299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10300. }
  10301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10302. isKnowKey = TRUE;
  10303. }
  10304. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10305. {
  10306. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10309. {
  10310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10311. }
  10312. else
  10313. {
  10314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10315. }
  10316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10317. isKnowKey = TRUE;
  10318. }
  10319. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10320. {
  10321. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10323. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10324. {
  10325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10326. }
  10327. else
  10328. {
  10329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10330. }
  10331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10332. isKnowKey = TRUE;
  10333. }
  10334. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10335. {
  10336. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10338. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10339. {
  10340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10341. }
  10342. else
  10343. {
  10344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10345. }
  10346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10347. isKnowKey = TRUE;
  10348. }
  10349. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10350. {
  10351. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10353. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10354. {
  10355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10356. }
  10357. else
  10358. {
  10359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10360. }
  10361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10362. isKnowKey = TRUE;
  10363. }
  10364. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10365. {
  10366. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10368. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10369. {
  10370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10371. }
  10372. else
  10373. {
  10374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10375. }
  10376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10377. isKnowKey = TRUE;
  10378. }
  10379. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10380. {
  10381. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10384. {
  10385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10386. }
  10387. else
  10388. {
  10389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10390. }
  10391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10392. isKnowKey = TRUE;
  10393. }
  10394. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10395. {
  10396. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10399. {
  10400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10401. }
  10402. else
  10403. {
  10404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10405. }
  10406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10407. isKnowKey = TRUE;
  10408. }
  10409. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10410. {
  10411. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10414. {
  10415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10416. }
  10417. else
  10418. {
  10419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10420. }
  10421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10422. isKnowKey = TRUE;
  10423. }
  10424. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10425. {
  10426. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10429. {
  10430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10431. }
  10432. else
  10433. {
  10434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10435. }
  10436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10437. isKnowKey = TRUE;
  10438. }
  10439. #if 0
  10440. //For OCTT Test Case
  10441. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10442. {
  10443. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10445. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10446. {
  10447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10448. }
  10449. else
  10450. {
  10451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10452. }
  10453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10454. isKnowKey = TRUE;
  10455. }
  10456. #endif
  10457. #if 1
  10458. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10459. {
  10460. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10462. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10463. {
  10464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10465. }
  10466. else
  10467. {
  10468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10469. }
  10470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10471. isKnowKey = TRUE;
  10472. }
  10473. #endif
  10474. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10475. {
  10476. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10478. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10479. {
  10480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10481. }
  10482. else
  10483. {
  10484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10485. }
  10486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  10487. isKnowKey = TRUE;
  10488. }
  10489. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  10490. {
  10491. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  10492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  10493. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  10494. {
  10495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10496. }
  10497. else
  10498. {
  10499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10500. }
  10501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  10502. isKnowKey = TRUE;
  10503. }
  10504. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  10505. {
  10506. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  10507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  10508. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  10509. {
  10510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  10511. }
  10512. else
  10513. {
  10514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  10515. }
  10516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10517. isKnowKey = TRUE;
  10518. }
  10519. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  10520. {
  10521. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  10522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  10523. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  10524. {
  10525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  10526. }
  10527. else
  10528. {
  10529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  10530. }
  10531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10532. isKnowKey = TRUE;
  10533. }
  10534. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  10535. {
  10536. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  10537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  10538. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  10539. {
  10540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  10541. }
  10542. else
  10543. {
  10544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  10545. }
  10546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10547. isKnowKey = TRUE;
  10548. }
  10549. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  10550. {
  10551. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  10552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  10553. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  10554. {
  10555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  10556. }
  10557. else
  10558. {
  10559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  10560. }
  10561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10562. isKnowKey = TRUE;
  10563. }
  10564. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  10565. {
  10566. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  10567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  10568. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  10569. {
  10570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  10571. }
  10572. else
  10573. {
  10574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  10575. }
  10576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10577. isKnowKey = TRUE;
  10578. }
  10579. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  10580. {
  10581. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  10582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  10583. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  10584. {
  10585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  10586. }
  10587. else
  10588. {
  10589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  10590. }
  10591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10592. isKnowKey = TRUE;
  10593. }
  10594. //=========================================================
  10595. if(!isEmpty && !isKnowKey)
  10596. {
  10597. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  10598. strcpy(unknownkey[UnknownKeynum], keyReq);
  10599. UnknownKeynum = UnknownKeynum + 1;
  10600. }
  10601. }
  10602. void processUnkownKey(void)
  10603. {
  10604. DEBUG_INFO("processUnkownKey\n");
  10605. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  10606. for(int index=0; index < UnknownKeynum; index++)
  10607. {
  10608. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  10609. {
  10610. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  10611. }
  10612. }
  10613. }
  10614. int setKeyValue(char *key, char *value)
  10615. {
  10616. int isSuccess = NotSupported;
  10617. int check_ascii=0;
  10618. char str[10]={0};
  10619. #ifdef Debug
  10620. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  10621. #endif
  10622. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  10623. {
  10624. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10626. {
  10627. strcpy(str, (const char*)value);
  10628. for(int i = 0; str[i]; i++){
  10629. str[i] = tolower(str[i]);
  10630. }
  10631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10632. isSuccess = ConfigurationStatus_Accepted;
  10633. }
  10634. else
  10635. {
  10636. isSuccess = ConfigurationStatus_Rejected;
  10637. }
  10638. }
  10639. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  10640. {
  10641. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10642. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10643. {
  10644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  10645. isSuccess = ConfigurationStatus_Accepted;
  10646. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  10647. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  10648. }
  10649. else
  10650. {
  10651. isSuccess = ConfigurationStatus_Rejected;
  10652. }
  10653. }
  10654. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  10655. {
  10656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10657. {
  10658. strcpy(str, (const char*)value);
  10659. for(int i = 0; str[i]; i++)
  10660. {
  10661. str[i] = tolower(str[i]);
  10662. }
  10663. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  10664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10665. isSuccess = ConfigurationStatus_Accepted;
  10666. }
  10667. else
  10668. {
  10669. isSuccess = ConfigurationStatus_Rejected;
  10670. }
  10671. }
  10672. if(strcmp(key, "BlinkRepeat") == 0)
  10673. {
  10674. //Charger.BlinkRepeat = Integer.parseInt(value);
  10675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10676. {
  10677. check_ascii = value[0];
  10678. if( (check_ascii < 48) || (check_ascii > 57) )
  10679. {
  10680. isSuccess = ConfigurationStatus_Rejected;
  10681. }
  10682. else
  10683. {
  10684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  10685. isSuccess = ConfigurationStatus_Accepted;
  10686. }
  10687. }
  10688. else
  10689. {
  10690. isSuccess = ConfigurationStatus_Rejected;
  10691. }
  10692. }
  10693. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  10694. {
  10695. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10696. {
  10697. check_ascii = value[0];
  10698. if( (check_ascii < 48) || (check_ascii > 57) )
  10699. {
  10700. isSuccess = ConfigurationStatus_Rejected;
  10701. }
  10702. else
  10703. {
  10704. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  10705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  10706. isSuccess = ConfigurationStatus_Accepted;
  10707. }
  10708. }
  10709. else
  10710. {
  10711. isSuccess = ConfigurationStatus_Rejected;
  10712. }
  10713. }
  10714. if(strcmp(key, "ConnectionTimeOut") == 0 )
  10715. {
  10716. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10717. {
  10718. check_ascii = value[0];
  10719. if( (check_ascii < 48) || (check_ascii > 57) )
  10720. {
  10721. isSuccess = ConfigurationStatus_Rejected;
  10722. }
  10723. else
  10724. {
  10725. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  10726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  10727. isSuccess = ConfigurationStatus_Accepted;
  10728. }
  10729. }
  10730. else
  10731. {
  10732. isSuccess = ConfigurationStatus_Rejected;
  10733. }
  10734. }
  10735. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  10736. {
  10737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10738. {
  10739. check_ascii = value[0];
  10740. if( (check_ascii < 48) || (check_ascii > 57) )
  10741. {
  10742. isSuccess = ConfigurationStatus_Rejected;
  10743. }
  10744. else
  10745. {
  10746. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  10748. isSuccess = ConfigurationStatus_Accepted;
  10749. }
  10750. }
  10751. else
  10752. {
  10753. isSuccess = ConfigurationStatus_Rejected;
  10754. }
  10755. }
  10756. if(strcmp(key, "HeartbeatInterval") == 0)
  10757. {
  10758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10759. {
  10760. check_ascii = value[0];
  10761. if( (check_ascii < 48) || (check_ascii > 57) )
  10762. {
  10763. isSuccess = ConfigurationStatus_Rejected;
  10764. }
  10765. else
  10766. {
  10767. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  10769. HeartBeatWaitTime = atoi(value);
  10770. isSuccess = ConfigurationStatus_Accepted;
  10771. }
  10772. }
  10773. else
  10774. {
  10775. isSuccess = ConfigurationStatus_Rejected;
  10776. }
  10777. }
  10778. if(strcmp(key, "LightIntensity") == 0)
  10779. {
  10780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10781. {
  10782. check_ascii = value[0];
  10783. if( (check_ascii < 48) || (check_ascii > 57) )
  10784. {
  10785. isSuccess = ConfigurationStatus_Rejected;
  10786. }
  10787. else
  10788. {
  10789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10790. isSuccess = ConfigurationStatus_Accepted;
  10791. }
  10792. }
  10793. else
  10794. {
  10795. isSuccess = ConfigurationStatus_Rejected;
  10796. }
  10797. }
  10798. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10799. {
  10800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10801. {
  10802. strcpy(str, (const char*)value);
  10803. for(int i = 0; str[i]; i++)
  10804. {
  10805. str[i] = tolower(str[i]);
  10806. }
  10807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10808. isSuccess = ConfigurationStatus_Accepted;
  10809. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10810. }
  10811. else
  10812. {
  10813. isSuccess = ConfigurationStatus_Rejected;
  10814. }
  10815. }
  10816. if(strcmp(key, "LocalPreAuthorize") == 0)
  10817. {
  10818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10819. {
  10820. strcpy(str, (const char*)value);
  10821. for(int i = 0; str[i]; i++)
  10822. {
  10823. str[i] = tolower(str[i]);
  10824. }
  10825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10826. isSuccess = ConfigurationStatus_Accepted;
  10827. }
  10828. else
  10829. {
  10830. isSuccess = ConfigurationStatus_Rejected;
  10831. }
  10832. }
  10833. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10834. {
  10835. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10836. {
  10837. check_ascii = value[0];
  10838. if( (check_ascii < 48) || (check_ascii > 57) )
  10839. {
  10840. isSuccess = ConfigurationStatus_Rejected;
  10841. }
  10842. else
  10843. {
  10844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10845. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  10846. isSuccess = ConfigurationStatus_Accepted;
  10847. }
  10848. }
  10849. else
  10850. {
  10851. isSuccess = ConfigurationStatus_Rejected;
  10852. }
  10853. }
  10854. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10855. {
  10856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10857. {
  10858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10859. isSuccess = ConfigurationStatus_Accepted;
  10860. }
  10861. else
  10862. {
  10863. isSuccess = ConfigurationStatus_Rejected;
  10864. }
  10865. }
  10866. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  10867. {
  10868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10869. {
  10870. check_ascii = value[0];
  10871. if( (check_ascii < 48) || (check_ascii > 57) )
  10872. {
  10873. isSuccess = ConfigurationStatus_Rejected;
  10874. }
  10875. else
  10876. {
  10877. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  10879. isSuccess = ConfigurationStatus_Accepted;
  10880. }
  10881. }
  10882. else
  10883. {
  10884. isSuccess = ConfigurationStatus_Rejected;
  10885. }
  10886. }
  10887. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10888. {
  10889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10890. {
  10891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10892. isSuccess = ConfigurationStatus_Accepted;
  10893. }
  10894. else
  10895. {
  10896. isSuccess = ConfigurationStatus_Rejected;
  10897. }
  10898. }
  10899. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  10900. {
  10901. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10902. {
  10903. check_ascii = value[0];
  10904. if( (check_ascii < 48) || (check_ascii > 57) )
  10905. {
  10906. isSuccess = ConfigurationStatus_Rejected;
  10907. }
  10908. else
  10909. {
  10910. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  10912. isSuccess = ConfigurationStatus_Accepted;
  10913. }
  10914. }
  10915. else
  10916. {
  10917. isSuccess = ConfigurationStatus_Rejected;
  10918. }
  10919. }
  10920. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10921. {
  10922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10923. {
  10924. check_ascii = value[0];
  10925. if( (check_ascii < 48) || (check_ascii > 57) )
  10926. {
  10927. isSuccess = ConfigurationStatus_Rejected;
  10928. }
  10929. else
  10930. {
  10931. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10933. isSuccess = ConfigurationStatus_Accepted;
  10934. }
  10935. }
  10936. else
  10937. {
  10938. isSuccess = ConfigurationStatus_Rejected;
  10939. }
  10940. }
  10941. if(strcmp(key, "MinimumStatusDuration") == 0)
  10942. {
  10943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10944. {
  10945. check_ascii = value[0];
  10946. if( (check_ascii < 48) || (check_ascii > 57) )
  10947. {
  10948. isSuccess = ConfigurationStatus_Rejected;
  10949. }
  10950. else
  10951. {
  10952. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10954. isSuccess = ConfigurationStatus_Accepted;
  10955. }
  10956. }
  10957. else
  10958. {
  10959. isSuccess = ConfigurationStatus_Rejected;
  10960. }
  10961. }
  10962. if(strcmp(key, "NumberOfConnectors") == 0)
  10963. {
  10964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10965. {
  10966. check_ascii = value[0];
  10967. if( (check_ascii < 48) || (check_ascii > 57) )
  10968. {
  10969. isSuccess = ConfigurationStatus_Rejected;
  10970. }
  10971. else
  10972. {
  10973. //Charger.ResetRetries = Integer.parseInt(value);
  10974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  10975. isSuccess = ConfigurationStatus_Accepted;
  10976. }
  10977. }
  10978. else
  10979. {
  10980. isSuccess = ConfigurationStatus_Rejected;
  10981. }
  10982. }
  10983. if(strcmp(key, "ResetRetries") == 0)
  10984. {
  10985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10986. {
  10987. check_ascii = value[0];
  10988. if( (check_ascii < 48) || (check_ascii > 57) )
  10989. {
  10990. isSuccess = ConfigurationStatus_Rejected;
  10991. }
  10992. else
  10993. {
  10994. //Charger.ResetRetries = Integer.parseInt(value);
  10995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10996. isSuccess = ConfigurationStatus_Accepted;
  10997. }
  10998. }
  10999. else
  11000. {
  11001. isSuccess = ConfigurationStatus_Rejected;
  11002. }
  11003. }
  11004. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11005. {
  11006. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11007. {
  11008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  11009. isSuccess = ConfigurationStatus_Accepted;
  11010. }
  11011. else
  11012. {
  11013. isSuccess = ConfigurationStatus_Rejected;
  11014. }
  11015. }
  11016. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11017. {
  11018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11019. {
  11020. check_ascii = value[0];
  11021. if( (check_ascii < 48) || (check_ascii > 57) )
  11022. {
  11023. isSuccess = ConfigurationStatus_Rejected;
  11024. }
  11025. else
  11026. {
  11027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11028. isSuccess = ConfigurationStatus_Accepted;
  11029. }
  11030. }
  11031. else
  11032. {
  11033. isSuccess = ConfigurationStatus_Rejected;
  11034. }
  11035. }
  11036. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11037. {
  11038. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11039. {
  11040. strcpy(str, (const char*)value);
  11041. for(int i = 0; str[i]; i++)
  11042. {
  11043. str[i] = tolower(str[i]);
  11044. }
  11045. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11047. isSuccess = ConfigurationStatus_Accepted;
  11048. }
  11049. else
  11050. {
  11051. isSuccess = ConfigurationStatus_Rejected;
  11052. }
  11053. }
  11054. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11055. {
  11056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11057. {
  11058. strcpy(str, (const char*)value);
  11059. for(int i = 0; str[i]; i++)
  11060. {
  11061. str[i] = tolower(str[i]);
  11062. }
  11063. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11065. isSuccess = ConfigurationStatus_Accepted;
  11066. }
  11067. else
  11068. {
  11069. isSuccess = ConfigurationStatus_Rejected;
  11070. }
  11071. }
  11072. if(strcmp(key, "StopTxnAlignedData") == 0)
  11073. {
  11074. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11075. {
  11076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11077. isSuccess = ConfigurationStatus_Accepted;
  11078. }
  11079. else
  11080. {
  11081. isSuccess = ConfigurationStatus_Rejected;
  11082. }
  11083. }
  11084. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11085. {
  11086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11087. {
  11088. check_ascii = value[0];
  11089. if( (check_ascii < 48) || (check_ascii > 57) )
  11090. {
  11091. isSuccess = ConfigurationStatus_Rejected;
  11092. }
  11093. else
  11094. {
  11095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11096. isSuccess = ConfigurationStatus_Accepted;
  11097. }
  11098. }
  11099. else
  11100. {
  11101. isSuccess = ConfigurationStatus_Rejected;
  11102. }
  11103. }
  11104. if(strcmp(key, "StopTxnSampledData") == 0)
  11105. {
  11106. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11107. {
  11108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11109. isSuccess = ConfigurationStatus_Accepted;
  11110. }
  11111. else
  11112. {
  11113. isSuccess = ConfigurationStatus_Rejected;
  11114. }
  11115. }
  11116. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11117. {
  11118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11119. {
  11120. check_ascii = value[0];
  11121. if( (check_ascii < 48) || (check_ascii > 57) )
  11122. {
  11123. isSuccess = ConfigurationStatus_Rejected;
  11124. }
  11125. else
  11126. {
  11127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11128. isSuccess = ConfigurationStatus_Accepted;
  11129. }
  11130. }
  11131. else
  11132. {
  11133. isSuccess = ConfigurationStatus_Rejected;
  11134. }
  11135. }
  11136. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11137. {
  11138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11139. {
  11140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11141. isSuccess = ConfigurationStatus_Accepted;
  11142. }
  11143. else
  11144. {
  11145. isSuccess = ConfigurationStatus_Rejected;
  11146. }
  11147. }
  11148. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11149. {
  11150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11151. {
  11152. check_ascii = value[0];
  11153. if( (check_ascii < 48) || (check_ascii > 57) )
  11154. {
  11155. isSuccess = ConfigurationStatus_Rejected;
  11156. }
  11157. else
  11158. {
  11159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11160. isSuccess = ConfigurationStatus_Accepted;
  11161. }
  11162. }
  11163. else
  11164. {
  11165. isSuccess = ConfigurationStatus_Rejected;
  11166. }
  11167. }
  11168. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11169. {
  11170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11171. {
  11172. check_ascii = value[0];
  11173. if( (check_ascii < 48) || (check_ascii > 57) )
  11174. {
  11175. isSuccess = ConfigurationStatus_Rejected;
  11176. }
  11177. else
  11178. {
  11179. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11181. TransactionMessageAttemptsValue = atoi(value);
  11182. isSuccess = ConfigurationStatus_Accepted;
  11183. }
  11184. }
  11185. else
  11186. {
  11187. isSuccess = ConfigurationStatus_Rejected;
  11188. }
  11189. }
  11190. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11191. {
  11192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11193. {
  11194. check_ascii = value[0];
  11195. if( (check_ascii < 48) || (check_ascii > 57) )
  11196. {
  11197. isSuccess = ConfigurationStatus_Rejected;
  11198. }
  11199. else
  11200. {
  11201. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11203. TransactionMessageRetryIntervalValue = atoi(value);
  11204. isSuccess = ConfigurationStatus_Accepted;
  11205. }
  11206. }
  11207. else
  11208. {
  11209. isSuccess = ConfigurationStatus_Rejected;
  11210. }
  11211. }
  11212. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11213. {
  11214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11215. {
  11216. strcpy(str, (const char*)value);
  11217. for(int i = 0; str[i]; i++)
  11218. {
  11219. str[i] = tolower(str[i]);
  11220. }
  11221. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11223. isSuccess = ConfigurationStatus_Accepted;
  11224. }
  11225. else
  11226. {
  11227. isSuccess = ConfigurationStatus_Rejected;
  11228. }
  11229. }
  11230. if(strcmp(key, "WebSocketPingInterval") == 0)
  11231. {
  11232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11233. {
  11234. check_ascii = value[0];
  11235. if( (check_ascii < 48) || (check_ascii > 57) )
  11236. {
  11237. isSuccess = ConfigurationStatus_Rejected;
  11238. }
  11239. else
  11240. {
  11241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11242. isSuccess = ConfigurationStatus_Accepted;
  11243. }
  11244. }
  11245. else
  11246. {
  11247. isSuccess = ConfigurationStatus_Rejected;
  11248. }
  11249. }
  11250. #if 0
  11251. //For OCPP Test Case
  11252. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11253. {
  11254. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11255. {
  11256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11257. isSuccess = ConfigurationStatus_Accepted;
  11258. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11259. }
  11260. else
  11261. {
  11262. isSuccess = ConfigurationStatus_Rejected;
  11263. }
  11264. }
  11265. #endif
  11266. #if 1
  11267. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11268. {
  11269. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].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.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11277. isSuccess = ConfigurationStatus_Accepted;
  11278. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11279. }
  11280. else
  11281. {
  11282. isSuccess = ConfigurationStatus_Rejected;
  11283. }
  11284. }
  11285. #endif
  11286. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11287. {
  11288. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11289. {
  11290. check_ascii = value[0];
  11291. if( (check_ascii < 48) || (check_ascii > 57) )
  11292. {
  11293. isSuccess = ConfigurationStatus_Rejected;
  11294. }
  11295. else
  11296. {
  11297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11298. isSuccess = ConfigurationStatus_Accepted;
  11299. }
  11300. }
  11301. else
  11302. {
  11303. isSuccess = ConfigurationStatus_Rejected;
  11304. }
  11305. }
  11306. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11307. {
  11308. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11309. {
  11310. check_ascii = value[0];
  11311. if( (check_ascii < 48) || (check_ascii > 57) )
  11312. {
  11313. isSuccess = ConfigurationStatus_Rejected;
  11314. }
  11315. else
  11316. {
  11317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11318. isSuccess = ConfigurationStatus_Accepted;
  11319. }
  11320. }
  11321. else
  11322. {
  11323. isSuccess = ConfigurationStatus_Rejected;
  11324. }
  11325. }
  11326. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11327. {
  11328. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11329. {
  11330. strcpy(str, (const char*)value);
  11331. for(int i = 0; str[i]; i++)
  11332. {
  11333. str[i] = tolower(str[i]);
  11334. }
  11335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11336. isSuccess = ConfigurationStatus_Accepted;
  11337. }
  11338. else
  11339. {
  11340. isSuccess = ConfigurationStatus_Rejected;
  11341. }
  11342. }
  11343. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11344. {
  11345. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11346. {
  11347. check_ascii = value[0];
  11348. if( (check_ascii < 48) || (check_ascii > 57) )
  11349. {
  11350. isSuccess = ConfigurationStatus_Rejected;
  11351. }
  11352. else
  11353. {
  11354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11355. isSuccess = ConfigurationStatus_Accepted;
  11356. }
  11357. }
  11358. else
  11359. {
  11360. isSuccess = ConfigurationStatus_Rejected;
  11361. }
  11362. }
  11363. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11364. {
  11365. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11366. {
  11367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11368. isSuccess = ConfigurationStatus_Accepted;
  11369. }
  11370. else
  11371. {
  11372. isSuccess = ConfigurationStatus_Rejected;
  11373. }
  11374. }
  11375. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11376. {
  11377. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11378. {
  11379. check_ascii = value[0];
  11380. if( (check_ascii < 48) || (check_ascii > 57) )
  11381. {
  11382. isSuccess = ConfigurationStatus_Rejected;
  11383. }
  11384. else
  11385. {
  11386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11387. isSuccess = ConfigurationStatus_Accepted;
  11388. }
  11389. }
  11390. else
  11391. {
  11392. isSuccess = ConfigurationStatus_Rejected;
  11393. }
  11394. }
  11395. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11396. {
  11397. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11398. {
  11399. strcpy(str, (const char*)value);
  11400. for(int i = 0; str[i]; i++)
  11401. {
  11402. str[i] = tolower(str[i]);
  11403. }
  11404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11405. isSuccess = ConfigurationStatus_Accepted;
  11406. }
  11407. else
  11408. {
  11409. isSuccess = ConfigurationStatus_Rejected;
  11410. }
  11411. }
  11412. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11413. {
  11414. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11415. {
  11416. check_ascii = value[0];
  11417. if( (check_ascii < 48) || (check_ascii > 57) )
  11418. {
  11419. isSuccess = ConfigurationStatus_Rejected;
  11420. }
  11421. else
  11422. {
  11423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11424. isSuccess = ConfigurationStatus_Accepted;
  11425. }
  11426. }
  11427. else
  11428. {
  11429. isSuccess = ConfigurationStatus_Rejected;
  11430. }
  11431. }
  11432. return isSuccess;
  11433. }
  11434. int updateSetting(char *key, char *value)
  11435. {
  11436. mtrace();
  11437. int isSuccess = FALSE;
  11438. char string[1000]={0}, buffer[1000]={0};
  11439. char strtemp[50]={0};
  11440. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11441. int pos, c = 0;
  11442. char *loc;
  11443. int pos1=0;
  11444. FILE *f = fopen("/var/www/settings1", "r");
  11445. if(f == NULL)
  11446. {
  11447. #ifdef Debug
  11448. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11449. #endif
  11450. return isSuccess;
  11451. }
  11452. fseek(f, 0, SEEK_END);
  11453. long fsize = ftell(f);
  11454. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11455. fread(string, 1, fsize, f);
  11456. fclose(f);
  11457. string[fsize] = 0;
  11458. loc = strstr(string, key);
  11459. if(loc != NULL)
  11460. {
  11461. DEBUG_INFO("key exist!\n");
  11462. pos = loc - string-1;
  11463. f = fopen("/var/www/settings1", "w");
  11464. strncpy(buffer, string, pos);
  11465. fprintf(f, "%s", buffer);
  11466. memset(sstr ,0, sizeof(sstr) );
  11467. c = 0;
  11468. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11469. {
  11470. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11471. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11472. c++;
  11473. }
  11474. sstr[c] = '\0';
  11475. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11476. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11477. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11478. memset(buffer ,0, sizeof(buffer) );
  11479. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11480. //printf("buffer=%s",buffer);
  11481. fprintf(f, "%s", buffer);
  11482. fclose(f);
  11483. }
  11484. else
  11485. {
  11486. printf("key not exist!\n");
  11487. f = fopen("/var/www/settings1", "w+");
  11488. fputs(string, f);
  11489. fseek(f, -1, SEEK_CUR);
  11490. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  11491. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  11492. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  11493. fclose(f);
  11494. }
  11495. isSuccess = TRUE;
  11496. return isSuccess;
  11497. }
  11498. int TransactionMessageAttemptsGet(void)
  11499. {
  11500. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11501. }
  11502. int FirstHeartBeatResponse(void)
  11503. {
  11504. return FirstHeartBeat;
  11505. }
  11506. int TransactionMessageRetryIntervalGet(void)
  11507. {
  11508. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11509. }
  11510. #define SA struct sockaddr
  11511. #define MAXBUF 1024
  11512. //static int m_socket_data;
  11513. //static int sockfd;
  11514. int ReadHttpStatus(int sock){
  11515. //char c;
  11516. char buff[1024]="",*ptr=buff+1;
  11517. int bytes_received, status;
  11518. DEBUG_INFO("Begin Response ..\n");
  11519. while((bytes_received = recv(sock, ptr, 1, 0))){
  11520. if(bytes_received==-1){
  11521. perror("ReadHttpStatus");
  11522. exit(1);
  11523. }
  11524. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  11525. ptr++;
  11526. }
  11527. *ptr=0;
  11528. ptr=buff+1;
  11529. sscanf(ptr,"%*s %d ", &status);
  11530. DEBUG_INFO("%s\n",ptr);
  11531. DEBUG_INFO("status=%d\n",status);
  11532. DEBUG_INFO("End Response ..\n");
  11533. return (bytes_received>0)?status:0;
  11534. }
  11535. //the only filed that it parsed is 'Content-Length'
  11536. int ParseHeader(int sock){
  11537. //char c;
  11538. char buff[1024]="",*ptr=buff+4;
  11539. int bytes_received;
  11540. DEBUG_INFO("Begin HEADER ..\n");
  11541. while((bytes_received = recv(sock, ptr, 1, 0))){
  11542. if(bytes_received==-1){
  11543. perror("Parse Header");
  11544. exit(1);
  11545. }
  11546. if(
  11547. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  11548. (ptr[-1]=='\r') && (*ptr=='\n' )
  11549. ) break;
  11550. ptr++;
  11551. }
  11552. *ptr=0;
  11553. ptr=buff+4;
  11554. //printf("%s",ptr);
  11555. if(bytes_received){
  11556. ptr=strstr(ptr,"Content-Length:");
  11557. if(ptr){
  11558. sscanf(ptr,"%*s %d",&bytes_received);
  11559. }else
  11560. bytes_received=-1; //unknown size
  11561. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  11562. }
  11563. DEBUG_INFO("End HEADER ..\n");
  11564. return bytes_received ;
  11565. }
  11566. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  11567. {
  11568. char rmFileCmd[100]={0};
  11569. char FilePath[100]={0};
  11570. char ftpbuf[200];
  11571. int systemresult;
  11572. //DEBUG_INFO("filename=%s\n",filename);
  11573. //DEBUG_INFO("url=%s\n",url);
  11574. sprintf(FilePath,"/mnt/%s",filename);
  11575. if((access(FilePath,F_OK))!=-1)
  11576. {
  11577. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11578. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11579. system(rmFileCmd);
  11580. }
  11581. memset(ftpbuf, 0, sizeof(ftpbuf));
  11582. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  11583. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11584. systemresult = system(ftpbuf);
  11585. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11586. if(systemresult != 0)
  11587. {
  11588. DEBUG_INFO("http DownLoad error!\n");
  11589. return FALSE;
  11590. }
  11591. return TRUE;
  11592. }
  11593. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  11594. {
  11595. char rmFileCmd[100]={0};
  11596. char FilePath[100]={0};
  11597. char ftpbuf[200];
  11598. int systemresult;
  11599. //char temp[100];
  11600. #if 0
  11601. struct hostent* server;
  11602. char *IPbuffer;
  11603. server = gethostbyname(location);
  11604. // To convert an Internet network
  11605. // address into ASCII string
  11606. IPbuffer = inet_ntoa(*((struct in_addr*)
  11607. server->h_addr_list[0]));
  11608. #endif
  11609. sprintf(FilePath,"/mnt/%s",filename);
  11610. if((access(FilePath,F_OK))!=-1)
  11611. {
  11612. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11613. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11614. system(rmFileCmd);
  11615. }
  11616. memset(ftpbuf, 0, sizeof(ftpbuf));
  11617. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  11618. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  11619. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11620. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11621. systemresult = system(ftpbuf);
  11622. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11623. if(systemresult != 0)
  11624. {
  11625. printf("wget error!\n");
  11626. return FALSE;
  11627. }
  11628. return TRUE;
  11629. }
  11630. int httpUploadFile(char *location, char *path, char *filename,char *url)
  11631. {
  11632. char rmFileCmd[100]={0};
  11633. char FilePath[100]={0};
  11634. char ftpbuf[200];
  11635. char filenametemp[60]={0};
  11636. int systemresult;
  11637. //DEBUG_INFO("filename=%s\n",filename);
  11638. //DEBUG_INFO("url=%s\n",url);
  11639. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  11640. if((access(FilePath,F_OK))!=-1)
  11641. {
  11642. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11643. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11644. system(rmFileCmd);
  11645. }
  11646. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  11647. if(fp == NULL)
  11648. {
  11649. DEBUG_INFO("log is NULL\n");
  11650. return FALSE;
  11651. }
  11652. else
  11653. {
  11654. fprintf(fp, "%s\n", url);
  11655. sscanf(filename, "%*2[.]%s", filenametemp);
  11656. fprintf(fp, "%s\n", filenametemp);
  11657. fclose(fp);
  11658. }
  11659. memset(ftpbuf, 0, sizeof(ftpbuf));
  11660. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  11661. systemresult = system(ftpbuf);
  11662. DEBUG_INFO("systemresult=%d\n",systemresult);
  11663. if(systemresult != 0)
  11664. {
  11665. DEBUG_INFO("http upload error!\n");
  11666. return FALSE;
  11667. }
  11668. return TRUE;
  11669. }
  11670. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  11671. {
  11672. struct hostent* server;
  11673. char *IPbuffer;
  11674. char ftpbuf[200];
  11675. int systemresult;
  11676. // To retrieve host information
  11677. server = gethostbyname(location);
  11678. // To convert an Internet network
  11679. // address into ASCII string
  11680. IPbuffer = inet_ntoa(*((struct in_addr*)
  11681. server->h_addr_list[0]));
  11682. memset(ftpbuf, 0, sizeof(ftpbuf));
  11683. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  11684. /* format : ftpput -u username -p passwd IP target source*/
  11685. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  11686. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11687. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11688. systemresult = system(ftpbuf);
  11689. DEBUG_INFO("systemresult=%d\n",systemresult);
  11690. if(systemresult != 0)
  11691. {
  11692. DEBUG_INFO("ftpput error!\n");
  11693. return FALSE;
  11694. }
  11695. return TRUE;
  11696. }
  11697. int SettingChargingRecord(int target, int transactionId)
  11698. {
  11699. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11700. {
  11701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11702. {
  11703. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11704. {
  11705. addBuff(target, transactionId, 0);
  11706. return TRUE;
  11707. }
  11708. }
  11709. for (int index = 0; index < CCS_QUANTITY; index++)
  11710. {
  11711. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11712. {
  11713. addBuff(target, transactionId, 0);
  11714. return TRUE;
  11715. }
  11716. }
  11717. for (int index = 0; index < GB_QUANTITY; index++)
  11718. {
  11719. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11720. {
  11721. addBuff(target, transactionId, 0);
  11722. return TRUE;
  11723. }
  11724. }
  11725. }
  11726. else
  11727. {
  11728. for (int index = 0; index < AC_QUANTITY; index++)
  11729. {
  11730. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11731. {
  11732. addBuff(target, transactionId, 0);
  11733. return TRUE;
  11734. }
  11735. }
  11736. }
  11737. return FALSE;
  11738. }
  11739. int addBuff(int gun_idx, int user_id, int cmd_sn)
  11740. {
  11741. int isSuccess = FALSE;
  11742. //char *query = NULL;
  11743. sqlite3_stmt *stmt;
  11744. int rc; // return code
  11745. char str[20];
  11746. sprintf(str,"%d",user_id);
  11747. 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 */
  11748. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  11749. rc = sqlite3_step(stmt); /* 3 */
  11750. if (rc != SQLITE_DONE) {
  11751. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  11752. goto out;
  11753. }
  11754. sqlite3_finalize(stmt);
  11755. // free(query);
  11756. out:
  11757. //----------------------
  11758. // close SQLite database
  11759. //----------------------
  11760. sqlite3_close(db);
  11761. printf("database closed.\n");
  11762. return isSuccess;
  11763. }
  11764. /**
  11765. * Place the contents of the specified file into a memory buffer
  11766. *
  11767. * @param[in] filename The path and name of the file to read
  11768. * @param[out] filebuffer A pointer to the contents in memory
  11769. * @return status 0 success, 1 on failure
  11770. */
  11771. int get_file_contents(const char* filename, char** outbuffer) {
  11772. FILE* file = NULL;
  11773. long filesize;
  11774. const int blocksize = 1;
  11775. size_t readsize;
  11776. char* filebuffer;
  11777. // Open the file
  11778. file = fopen(filename, "r");
  11779. if (NULL == file)
  11780. {
  11781. printf("'%s' not opened\n", filename);
  11782. exit(EXIT_FAILURE);
  11783. }
  11784. // Determine the file size
  11785. fseek(file, 0, SEEK_END);
  11786. filesize = ftell(file);
  11787. rewind (file);
  11788. // Allocate memory for the file contents
  11789. filebuffer = (char*) malloc(sizeof(char) * filesize);
  11790. *outbuffer = filebuffer;
  11791. if (filebuffer == NULL)
  11792. {
  11793. fputs ("malloc out-of-memory", stderr);
  11794. exit(EXIT_FAILURE);
  11795. }
  11796. // Read in the file
  11797. readsize = fread(filebuffer, blocksize, filesize, file);
  11798. if (readsize != filesize)
  11799. {
  11800. fputs ("didn't read file completely",stderr);
  11801. exit(EXIT_FAILURE);
  11802. }
  11803. // Clean exit
  11804. fclose(file);
  11805. return EXIT_SUCCESS;
  11806. }
  11807. static int selectSqlCount = 0;
  11808. static int callback(void *data, int argc, char **argv, char **azColName){
  11809. int i;
  11810. printf("%s: ", (const char*)data);
  11811. selectSqlCount = argc;
  11812. for(i = 0; i<argc; i++){
  11813. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  11814. }
  11815. printf("\n");
  11816. return 0;
  11817. }
  11818. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  11819. //int i;
  11820. //printf("%s:\n", (const char*)data);
  11821. localversion = argv[5] ? atoi(argv[5]) : 0;
  11822. printf("localversion=%d\n", localversion);
  11823. return 0;
  11824. }
  11825. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  11826. //int i;
  11827. //printf("%s:\n", (const char*)data);
  11828. //idTag
  11829. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  11830. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  11831. //parentIdTag
  11832. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  11833. //expir_date
  11834. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  11835. //status
  11836. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  11837. //version
  11838. idTagQuery.listVersionInt = atoi(argv[5]);
  11839. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  11840. return 0;
  11841. }
  11842. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  11843. int i;
  11844. //printf("%s:\n", (const char*)data);
  11845. #if 1
  11846. for(i=0; i<argc; i++){
  11847. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  11848. }
  11849. //printf("");
  11850. #endif
  11851. // localversion = argv[5] ? atoi(argv[5]) : 0;
  11852. // printf("localversion=%d\n", localversion);
  11853. return 0;
  11854. }
  11855. /** sqlite3_exec的回调。
  11856. *
  11857. * 向控制台打印查询的结果。
  11858. *
  11859. * @param in data 传递给回调函数的数据。
  11860. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  11861. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  11862. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  11863. * @return 状态码。
  11864. */
  11865. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  11866. {
  11867. for (int i = 0; i < n_columns; i++)
  11868. {
  11869. DEBUG_INFO("%s/t", col_values[i]);
  11870. }
  11871. DEBUG_INFO("/n");
  11872. return 0;
  11873. }
  11874. void OCPP_getListVerion()
  11875. {
  11876. int rc = 0;
  11877. // const char* data = "Callback function called";
  11878. char sql[100];
  11879. char zErrMsg[100];
  11880. memset(sql, 0, 100);
  11881. memset(zErrMsg, 0, 100);
  11882. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  11883. /* Execute SQL statement */
  11884. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  11885. DEBUG_INFO("rc=%d\n",rc);
  11886. if( rc != SQLITE_OK ){
  11887. DEBUG_INFO("SQL error: %s", zErrMsg);
  11888. //sqlite3_free(zErrMsg);
  11889. }else{
  11890. DEBUG_INFO("Operation done successfully");
  11891. }
  11892. }
  11893. void OCPP_getIdTag(char *idTag)
  11894. {
  11895. int rc = 0;
  11896. // const char* data = "Callback function called";
  11897. char sql[100];
  11898. char zErrMsg[100];
  11899. memset(sql, 0, 100);
  11900. memset(zErrMsg, 0, 100);
  11901. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  11902. memset(&idTagQuery, 0, sizeof(idTagQuery));
  11903. DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  11904. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11905. /* Execute SQL statement */
  11906. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  11907. if( rc != SQLITE_OK ){
  11908. DEBUG_INFO("SQL error: %s", zErrMsg);
  11909. //sqlite3_free(zErrMsg);
  11910. }else{
  11911. printf("Operation done successfully");
  11912. }
  11913. //return ver;
  11914. }
  11915. void OCPP_get_TableAuthlocalAllData(void)
  11916. {
  11917. int rc = 0;
  11918. // const char* data = "Callback function called";
  11919. char sql[100];
  11920. char zErrMsg[100];
  11921. memset(sql, 0, 100);
  11922. memset(zErrMsg, 0, 100);
  11923. sprintf(sql,"select * from ocpp_auth_local ");
  11924. /* Execute SQL statement */
  11925. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  11926. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  11927. if( rc != SQLITE_OK ){
  11928. DEBUG_INFO("SQL error: %s", zErrMsg);
  11929. //sqlite3_free(zErrMsg);
  11930. }else{
  11931. DEBUG_INFO("Operation done successfully");
  11932. }
  11933. //return ver;
  11934. }
  11935. int OCPP_cleanLocalList()
  11936. {
  11937. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  11938. char *errMsg = 0;
  11939. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  11940. if (SQLITE_OK != rc)
  11941. {
  11942. DEBUG_INFO("%s\n",errMsg);
  11943. return FALSE;
  11944. }
  11945. else
  11946. {
  11947. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  11948. }
  11949. return TRUE;
  11950. }
  11951. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11952. {
  11953. int isSuccess = FALSE;
  11954. int ret = 0;
  11955. //const char* data = "Callback function called";
  11956. char sql[200];
  11957. char zErrMsg[100];
  11958. memset(sql, 0, 200);
  11959. memset(zErrMsg, 0, 100);
  11960. 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);
  11961. //* Execute SQL statement */
  11962. //zErrMsg = 0;
  11963. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  11964. if( ret != SQLITE_OK ){
  11965. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  11966. // free(zErrMsg);
  11967. // free(sql);
  11968. return isSuccess;
  11969. }
  11970. DEBUG_INFO("successfully Insert records created\n");
  11971. isSuccess = TRUE;
  11972. return isSuccess;
  11973. }
  11974. void OCPP_deleteIdTag(char *idTag)
  11975. {
  11976. //int ver = 0;
  11977. //int isSuccess = FALSE;
  11978. int rc = 0;
  11979. char sql[100];
  11980. char zErrMsg[100];
  11981. memset(sql, 0, 100);
  11982. memset(zErrMsg, 0, 100);
  11983. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  11984. //* Execute SQL statement */
  11985. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  11986. if( rc != SQLITE_OK ){
  11987. DEBUG_INFO("SQL error: %s", zErrMsg);
  11988. //sqlite3_free(zErrMsg);
  11989. }else{
  11990. DEBUG_INFO("Operation done successfully");
  11991. }
  11992. }
  11993. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11994. {
  11995. int isSuccess = FALSE;
  11996. int ret = 0;
  11997. const char* data = "Callback function called";
  11998. char sql[200];
  11999. char zErrMsg[100];
  12000. memset(sql, 0, 200);
  12001. memset(zErrMsg, 0, 100);
  12002. //* selectFromTable */
  12003. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  12004. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12005. //* Execute SQL statement */
  12006. selectSqlCount = 0;
  12007. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12008. if( ret != SQLITE_OK ){
  12009. printf("Error SQL: %s\n", zErrMsg);
  12010. }
  12011. printf("successfully select operation done\n");
  12012. memset(sql, 0, 200);
  12013. memset(zErrMsg, 0, 100);
  12014. if(selectSqlCount == 0)
  12015. {
  12016. //Insert
  12017. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  12018. 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);
  12019. DEBUG_INFO("sql:%s\n", sql);
  12020. //* Execute SQL statement */
  12021. //zErrMsg = 0;
  12022. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  12023. if( ret != SQLITE_OK ){
  12024. printf("SQL error: %s\n", zErrMsg);
  12025. return isSuccess;
  12026. }
  12027. DEBUG_INFO("successfully Insert records created\n");
  12028. isSuccess = TRUE;
  12029. }
  12030. else
  12031. {
  12032. //Update
  12033. //* Create merged SQL statement */
  12034. 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);
  12035. /* Execute SQL statement */
  12036. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  12037. if( ret != SQLITE_OK ){
  12038. printf("SQL error: %s\n", zErrMsg);
  12039. //sqlite3_free(zErrMsg);
  12040. //sqlite3_free(sql);
  12041. return isSuccess;
  12042. }
  12043. DEBUG_INFO("Successfully operation done \n");
  12044. isSuccess = TRUE;
  12045. }
  12046. return isSuccess;
  12047. }
  12048. int GetOcppServerURL()
  12049. {
  12050. int result = FALSE;
  12051. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12052. memset(OcppHost, 0, sizeof(OcppHost));
  12053. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12054. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12055. {
  12056. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  12057. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12058. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12059. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12060. result = TRUE;
  12061. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12062. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12063. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12064. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12065. goto End;
  12066. }
  12067. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12068. {
  12069. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  12070. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12071. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12072. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12073. result = TRUE;
  12074. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  12075. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  12076. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  12077. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  12078. goto End;
  12079. }
  12080. else
  12081. {
  12082. strcpy(OcppHost,"");
  12083. }
  12084. End:
  12085. return result;
  12086. }
  12087. int GetOcppPath()
  12088. {
  12089. int result = FALSE;
  12090. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12091. {
  12092. if(OcppTempPath == NULL)
  12093. {
  12094. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12095. }
  12096. else
  12097. {
  12098. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12099. }
  12100. result = TRUE;
  12101. goto End;
  12102. }
  12103. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12104. {
  12105. if(OcppTempPath == NULL)
  12106. {
  12107. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12108. }
  12109. else
  12110. {
  12111. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12112. }
  12113. result = TRUE;
  12114. goto End;
  12115. }
  12116. else
  12117. {
  12118. strcpy(OcppPath,"");
  12119. }
  12120. End:
  12121. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12122. return result;
  12123. }
  12124. int GetOcppPort()
  12125. {
  12126. return OcppPort;
  12127. }
  12128. int GetOcppConnStatus(void)
  12129. {
  12130. return ShmOCPP16Data->OcppConnStatus;
  12131. }
  12132. void SetOcppConnStatus(uint8_t status)
  12133. {
  12134. ShmOCPP16Data->OcppConnStatus = status;
  12135. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12136. if(status == FALSE)
  12137. {
  12138. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12139. {
  12140. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12141. }
  12142. else
  12143. {
  12144. SystemInitial = AC_QUANTITY;
  12145. }
  12146. }
  12147. }
  12148. int GetHeartBeatWithNOResponse(void)
  12149. {
  12150. return HeartBeatWithNOResponse;
  12151. }
  12152. void SetHeartBeatWithNOResponse(void)
  12153. {
  12154. HeartBeatWithNOResponse = 0;
  12155. }
  12156. void splitstring(char *src,const char *separator,char **dest,int *num) {
  12157. /*
  12158. src 源字串的首地址(buf的地址)
  12159. separator 指定的分割字元
  12160. dest 接收子字串的陣列
  12161. num 分割後子字串的個數
  12162. */
  12163. char *pNext;
  12164. int count = 0;
  12165. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  12166. return;
  12167. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  12168. return;
  12169. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  12170. while(pNext != NULL) {
  12171. *dest++ = pNext;
  12172. ++count;
  12173. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  12174. }
  12175. *num = count;
  12176. }
  12177. int GetTransactionId(int gunindex, unsigned char idTag[])
  12178. {
  12179. char ch;
  12180. FILE *fptr1;
  12181. int temptransactionId;
  12182. char str[100]={0};
  12183. temptransactionId = 0;
  12184. /*------ Read the file ----------------*/
  12185. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12186. ch=fgetc(fptr1);
  12187. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12188. rewind(fptr1);
  12189. if(ch!=EOF)
  12190. {
  12191. // printf("%c",ch);
  12192. while (fgets(str, 100, fptr1) != NULL)
  12193. {
  12194. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12195. if(str[0]=='\0')
  12196. {
  12197. break;
  12198. }
  12199. char *revbuf[8] = {0}; //存放分割後的子字串
  12200. int num = 0;//分割後子字串的個數
  12201. printf(" Now the content of the file 44444 is : \n");
  12202. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12203. printf(" Now the content of the file 5555 is : \n");
  12204. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12205. {
  12206. temptransactionId = atoi(revbuf[2]);
  12207. break;
  12208. }
  12209. }
  12210. }
  12211. fclose(fptr1);
  12212. /*------- End of reading ---------------*/
  12213. return temptransactionId;
  12214. }
  12215. void SetTransactionIdZero(int transactionId)
  12216. {
  12217. //TransactionId[gunindex] = 0;
  12218. char ch;
  12219. FILE *fptr1, *fptr2;
  12220. int temptransactionId;
  12221. char str[100]={0}, temp[] = "/Storage/OCPP/temp.txt";
  12222. printf("\n\n Delete a specific line from a file :\n");
  12223. printf("-----------------------------------------\n");
  12224. //scanf("%s",fname);
  12225. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12226. if (!fptr1)
  12227. {
  12228. printf(" File not found or unable to open the input file!!\n");
  12229. return ;
  12230. }
  12231. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12232. if (!fptr2)
  12233. {
  12234. printf("Unable to open a temporary file to write!!\n");
  12235. fclose(fptr1);
  12236. return ;
  12237. }
  12238. ch=fgetc(fptr1);
  12239. //printf(" Now the content of the file %s is : \n",fname);
  12240. rewind(fptr1);
  12241. if(ch!=EOF)
  12242. {
  12243. // copy all contents to the temporary file except the specific line
  12244. while (fgets(str, 100, fptr1) != NULL)
  12245. {
  12246. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12247. if(str[0]=='\0')
  12248. {
  12249. break;
  12250. }
  12251. char *revbuf[8] = {0}; //存放分割後的子字串
  12252. int num = 0;//分割後子字串的個數
  12253. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12254. temptransactionId = atoi(revbuf[2]);
  12255. if(transactionId != temptransactionId)
  12256. {
  12257. fprintf(fptr2, "%s", str);
  12258. }
  12259. }
  12260. }
  12261. fclose(fptr1);
  12262. fclose(fptr2);
  12263. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12264. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12265. /*------ Read the file ----------------*/
  12266. }
  12267. int InternetDisconnect(void)
  12268. {
  12269. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12270. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12271. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12272. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12273. }
  12274. void GetChargingProfileRequest(int gunindex)
  12275. {
  12276. mtrace();
  12277. //int connectorIdInt, durationInt;
  12278. //char chargingRateUnitStr[4]={0};
  12279. int tempdurationInt = 0;
  12280. int tempchargingProfileId = 0;
  12281. int tempstackLevel = 0;
  12282. int temptransactionId = 0;
  12283. float tempminChargingRateFloat = 0.0;
  12284. char tempchargingProfilePurposeStr[24]={0};
  12285. char tempchargingProfileKindStr[12]={0};
  12286. char temprecurrencyKindStr[8]={0};
  12287. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12288. char tempvalidToStr[28]={0};
  12289. int tempStartPeriodInt = 0;
  12290. float tempLimitInt = 0.0;//0.1;
  12291. int tempNumberPhasesInt=0;
  12292. char fname[200];
  12293. //char comfirmstr[20];
  12294. float MinChargingRate =0.0;
  12295. double diff_t;
  12296. struct tm tp;
  12297. FILE *fptr1;//, *fptr2;
  12298. int c = 0;
  12299. char * pch;
  12300. char *loc;
  12301. char sstr[200]={ 0 };
  12302. int n_chargingProfile = 0;
  12303. int n_SchedulePeriods = 0;
  12304. char SchedulePeriodList[10][200]={0};
  12305. char sLineWord[800]={0};
  12306. char word[1000]={0};
  12307. int confirmPeriods = 0;
  12308. struct StructProfile ChargePointMaxProfile;
  12309. struct StructProfile TxDefaultProfile;
  12310. struct StructProfile TxProfile;
  12311. struct StructProfile TxDefaultProfiletemp[2]={0};
  12312. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12313. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12314. struct StructChargingProfile TxProfile_TEMP={0};
  12315. int TxDefaultProfileFileIsNull=FALSE;
  12316. int ChargePointMaxProfileIsNull=FALSE;
  12317. int TxProfileIsNull=FALSE;
  12318. // int CompositeSceduleIndex = 0;
  12319. char ChargePointMaxProfileScheduleStr[30]={0};
  12320. char TxDefaultProfileScheduleStr[30]={0};
  12321. char TxProfileScheduleStr[30]={0};
  12322. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12323. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12324. memset(&TxProfile,0,sizeof(struct StructProfile));
  12325. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  12326. DEBUG_INFO("GetChargingProfileRequest\n");
  12327. //*****************************ChargePointMaxProfile******************************************/
  12328. strcpy(fname, ChargePointMaxProfile_JSON);
  12329. ChargePointMaxProfileIsNull=TRUE;
  12330. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12331. {
  12332. fptr1 = fopen(fname, "r");
  12333. int c;
  12334. c = fgetc(fptr1);
  12335. //DEBUG_INFO("c:%d\n",c);
  12336. rewind(fptr1);
  12337. if(c == EOF)
  12338. {
  12339. DEBUG_INFO("\n End of file reached.");
  12340. ChargePointMaxProfileIsNull=TRUE;
  12341. fclose(fptr1);
  12342. }
  12343. else
  12344. {
  12345. ChargePointMaxProfileIsNull=FALSE;
  12346. while(fscanf(fptr1, "%s", word) != EOF)
  12347. {
  12348. if(strcmp(word, "chargingProfileId") == 0)
  12349. {
  12350. n_chargingProfile = n_chargingProfile + 1;
  12351. }
  12352. }
  12353. rewind(fptr1);
  12354. //search Charging Profile Element
  12355. int i = 0;
  12356. int j = 0;
  12357. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12358. //***********chargingProfileId**************/
  12359. c = 0;
  12360. loc = strstr(sLineWord, "chargingProfileId");
  12361. //DEBUG_INFO("loc=%s\n",loc);
  12362. memset(sstr ,0, sizeof(sstr) );
  12363. if(loc != NULL)
  12364. {
  12365. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12366. {
  12367. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12369. c++;
  12370. }
  12371. sstr[c] = '\0';
  12372. tempchargingProfileId = atoi(sstr);
  12373. }
  12374. else
  12375. {
  12376. tempchargingProfileId = 0;
  12377. }
  12378. //***********stackLevel**************/
  12379. c = 0;
  12380. loc = strstr(sLineWord, "stackLevel");
  12381. //DEBUG_INFO("loc=%s\n",loc);
  12382. memset(sstr ,0, sizeof(sstr) );
  12383. if(loc != NULL)
  12384. {
  12385. while (loc[2+strlen("stackLevel")+c] != '\"')
  12386. {
  12387. sstr[c] = loc[2+strlen("stackLevel")+c];
  12388. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12389. c++;
  12390. }
  12391. sstr[c] = '\0';
  12392. tempstackLevel = atoi(sstr);
  12393. }
  12394. else
  12395. {
  12396. tempstackLevel = 0;
  12397. }
  12398. //***********chargingProfilePurpose **************/
  12399. c = 0;
  12400. loc = strstr(sLineWord, "chargingProfilePurpose");
  12401. //DEBUG_INFO("loc=%s\n",loc);
  12402. memset(sstr ,0, sizeof(sstr) );
  12403. if(loc != NULL)
  12404. {
  12405. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12406. {
  12407. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12408. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12409. c++;
  12410. }
  12411. sstr[c] = '\0';
  12412. strcpy(tempchargingProfilePurposeStr,sstr);
  12413. }
  12414. else
  12415. {
  12416. strcpy(tempchargingProfilePurposeStr,"");
  12417. }
  12418. //***********chargingProfileKind **************/
  12419. c = 0;
  12420. loc = strstr(sLineWord, "chargingProfileKind");
  12421. //DEBUG_INFO("loc=%s\n",loc);
  12422. memset(sstr ,0, sizeof(sstr) );
  12423. if(loc != NULL)
  12424. {
  12425. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12426. {
  12427. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12428. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12429. c++;
  12430. }
  12431. sstr[c] = '\0';
  12432. strcpy(tempchargingProfileKindStr,sstr);
  12433. }
  12434. else
  12435. {
  12436. strcpy(tempchargingProfileKindStr,"");
  12437. }
  12438. //***********recurrencyKind **************/
  12439. c = 0;
  12440. loc = strstr(sLineWord, "recurrencyKind");
  12441. //DEBUG_INFO("loc=%s\n",loc);
  12442. memset(sstr ,0, sizeof(sstr) );
  12443. if(loc != NULL)
  12444. {
  12445. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12446. {
  12447. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12448. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12449. c++;
  12450. }
  12451. sstr[c] = '\0';
  12452. strcpy(temprecurrencyKindStr,sstr);
  12453. }
  12454. else
  12455. {
  12456. strcpy(temprecurrencyKindStr,"");
  12457. }
  12458. //***********validFrom**************/
  12459. c = 0;
  12460. loc = strstr(sLineWord, "validFrom");
  12461. //DEBUG_INFO("loc=%s\n",loc);
  12462. memset(sstr ,0, sizeof(sstr) );
  12463. if(loc != NULL)
  12464. {
  12465. while (loc[3+strlen("validFrom")+c] != '\"')
  12466. {
  12467. sstr[c] = loc[3+strlen("validFrom")+c];
  12468. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12469. c++;
  12470. }
  12471. sstr[c] = '\0';
  12472. strcpy(tempvalidFromStr,sstr);
  12473. }
  12474. else
  12475. {
  12476. strcpy(tempvalidFromStr,"");
  12477. }
  12478. //***********validTo **************/
  12479. c = 0;
  12480. loc = strstr(sLineWord, "validTo");
  12481. //DEBUG_INFO("loc=%s\n",loc);
  12482. memset(sstr ,0, sizeof(sstr) );
  12483. if(loc != NULL)
  12484. {
  12485. while (loc[3+strlen("validTo")+c] != '\"')
  12486. {
  12487. sstr[c] = loc[3+strlen("validTo")+c];
  12488. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12489. c++;
  12490. }
  12491. sstr[c] = '\0';
  12492. strcpy(tempvalidToStr,sstr);
  12493. }
  12494. else
  12495. {
  12496. strcpy(tempvalidToStr,"");
  12497. }
  12498. //***********validFrom**************/
  12499. c = 0;
  12500. loc = strstr(sLineWord, "validFrom");
  12501. if(loc != NULL)
  12502. {
  12503. memset(sstr ,0, sizeof(sstr) );
  12504. while (loc[3+strlen("validFrom")+c] != '\"')
  12505. {
  12506. sstr[c] = loc[3+strlen("validFrom")+c];
  12507. c++;
  12508. }
  12509. sstr[c] = '\0';
  12510. strcpy(tempvalidFromStr,sstr);
  12511. }
  12512. else
  12513. {
  12514. strcpy(tempvalidFromStr,"");
  12515. }
  12516. //***********validTo **************/
  12517. c = 0;
  12518. loc = strstr(sLineWord, "validTo");
  12519. if(loc != NULL)
  12520. {
  12521. memset(sstr ,0, sizeof(sstr) );
  12522. while (loc[3+strlen("validTo")+c] != '\"')
  12523. {
  12524. sstr[c] = loc[3+strlen("validTo")+c];
  12525. c++;
  12526. }
  12527. sstr[c] = '\0';
  12528. strcpy(tempvalidToStr,sstr);
  12529. }
  12530. else
  12531. {
  12532. strcpy(tempvalidToStr,"");
  12533. }
  12534. //***********duration**************/
  12535. c = 0;
  12536. loc = strstr(sLineWord, "duration");
  12537. if(loc != NULL)
  12538. {
  12539. memset(sstr ,0, sizeof(sstr) );
  12540. while (loc[2+strlen("duration")+c] != ',')
  12541. {
  12542. sstr[c] = loc[2+strlen("duration")+c];
  12543. c++;
  12544. }
  12545. sstr[c] = '\0';
  12546. tempdurationInt = atoi(sstr);
  12547. }
  12548. else
  12549. {
  12550. tempdurationInt = 0;
  12551. }
  12552. //**********startSchedule**********/
  12553. c = 0;
  12554. loc = strstr(sLineWord, "startSchedule");
  12555. memset(sstr ,0, sizeof(sstr) );
  12556. while (loc[3+strlen("startSchedule")+c] != '\"')
  12557. {
  12558. sstr[c] = loc[3+strlen("startSchedule")+c];
  12559. c++;
  12560. }
  12561. sstr[c] = '\0';
  12562. strcpy(tempstartScheduleStr, sstr);
  12563. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  12564. //**********chargingRateUnit**********/
  12565. c = 0;
  12566. loc = strstr(sLineWord, "chargingRateUnit");
  12567. memset(sstr ,0, sizeof(sstr) );
  12568. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12569. {
  12570. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12571. c++;
  12572. }
  12573. sstr[c] = '\0';
  12574. strcpy(tempchargingRateUnitStr, sstr);
  12575. //**********minChargingRate*******/
  12576. c = 0;
  12577. loc = strstr(sLineWord, "minChargingRate");
  12578. if(loc != NULL)
  12579. {
  12580. memset(sstr ,0, sizeof(sstr) );
  12581. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12582. {
  12583. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12584. c++;
  12585. }
  12586. sstr[c] = '\0';
  12587. tempminChargingRateFloat = atof(sstr);
  12588. }
  12589. else
  12590. {
  12591. tempminChargingRateFloat = 0.0;
  12592. }
  12593. //
  12594. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12595. tp.tm_isdst = -1;
  12596. time_t utc = mktime(&tp);
  12597. time_t t = time(NULL);
  12598. diff_t = difftime(t, utc);
  12599. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12600. //parsing strings to words
  12601. i = 0;
  12602. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12603. loc = loc+3+strlen("chargingSchedulePeriod");
  12604. pch = strtok(loc ,"{");
  12605. while (pch != NULL)
  12606. {
  12607. strcpy(SchedulePeriodList[i], pch);
  12608. pch = strtok (NULL, "{");
  12609. i = i + 1;
  12610. }
  12611. n_SchedulePeriods = i;
  12612. for(int i=0;i<n_SchedulePeriods;i++)
  12613. {
  12614. //*************startPeriod****************/
  12615. c = 0;
  12616. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12617. memset(sstr ,0, sizeof(sstr) );
  12618. while (loc[strlen("startPeriod")+2+c] != ',')
  12619. {
  12620. sstr[c] = loc[strlen("startPeriod")+2+c];
  12621. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12622. c++;
  12623. }
  12624. sstr[c] = '\0';
  12625. tempStartPeriodInt = atoi(sstr);
  12626. //*************limit****************/
  12627. c = 0;
  12628. loc = strstr(SchedulePeriodList[i], "limit");
  12629. memset(sstr ,0, sizeof(sstr) );
  12630. while (loc[strlen("limit")+2+c] != ',')
  12631. {
  12632. sstr[c] = loc[strlen("limit")+2+c];
  12633. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12634. c++;
  12635. }
  12636. sstr[c] = '\0';
  12637. tempLimitInt = atof(sstr);
  12638. //*************numberPhases****************/
  12639. c = 0;
  12640. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12641. memset(sstr ,0, sizeof(sstr) );
  12642. while (loc[strlen("numberPhases")+2+c] != '}')
  12643. {
  12644. sstr[c] = loc[strlen("numberPhases")+2+c];
  12645. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12646. c++;
  12647. }
  12648. sstr[c] = '\0';
  12649. tempNumberPhasesInt = atoi(sstr);
  12650. if(j == 0)
  12651. {
  12652. ChargePointMaxProfile.Duration = tempdurationInt;
  12653. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  12654. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  12655. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12656. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12657. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12658. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  12659. ChargePointMaxProfile_TEMP.TransactionId = 0;
  12660. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12661. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12662. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12663. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12664. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12665. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12666. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12667. }
  12668. }
  12669. if(MinChargingRate < tempminChargingRateFloat)
  12670. {
  12671. MinChargingRate = tempminChargingRateFloat;
  12672. }
  12673. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12674. if(confirmPeriods < n_SchedulePeriods)
  12675. {
  12676. confirmPeriods = n_SchedulePeriods;
  12677. }
  12678. j = j + 1;
  12679. }
  12680. fclose(fptr1);
  12681. }
  12682. }// the end of access file ChargePointMaxProfile
  12683. //****************************TxDefaultProfile************************************************/
  12684. switch(gunindex + 1)
  12685. {
  12686. case 0:
  12687. strcpy(fname, TxDefaultProfile_0_JSON );
  12688. break;
  12689. case 1:
  12690. strcpy(fname, TxDefaultProfile_1_JSON );
  12691. break;
  12692. case 2:
  12693. strcpy(fname, TxDefaultProfile_2_JSON );
  12694. break;
  12695. default:
  12696. strcpy(fname, TxDefaultProfile_1_JSON );
  12697. break;
  12698. }
  12699. TxDefaultProfileFileIsNull=TRUE;
  12700. if((access(fname,F_OK))!=-1)
  12701. {
  12702. fptr1 = fopen(fname, "r");
  12703. c = 0;
  12704. c = fgetc(fptr1);
  12705. //DEBUG_INFO("c:%d\n",c);
  12706. rewind(fptr1);
  12707. if(c == EOF)
  12708. {
  12709. DEBUG_INFO("\n End of file reached.");
  12710. TxDefaultProfileFileIsNull=TRUE;
  12711. fclose(fptr1);
  12712. }
  12713. else
  12714. {
  12715. TxDefaultProfileFileIsNull=FALSE;
  12716. while(fscanf(fptr1, "%s", word) != EOF)
  12717. {
  12718. if(strcmp(word, "chargingProfileId") == 0)
  12719. {
  12720. n_chargingProfile = n_chargingProfile + 1;
  12721. }
  12722. }
  12723. rewind(fptr1);
  12724. //search Charging Profile Element
  12725. int i = 0;
  12726. int j = 0;
  12727. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12728. #if 0
  12729. /***********connectorId****************/
  12730. c = 0;
  12731. loc = strstr(sLineWord, "connectorId");
  12732. memset(sstr ,0, sizeof(sstr) );
  12733. while (loc[strlen("connectorId")+2+c] != ',')
  12734. {
  12735. sstr[c] = loc[strlen("connectorId")+2+c];
  12736. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12737. c++;
  12738. }
  12739. sstr[c] = '\0';
  12740. tempconnectorIdInt = atoi(sstr);
  12741. #endif
  12742. //***********chargingProfileId**************/
  12743. c = 0;
  12744. loc = strstr(sLineWord, "chargingProfileId");
  12745. //DEBUG_INFO("loc=%s\n",loc);
  12746. memset(sstr ,0, sizeof(sstr) );
  12747. if(loc != NULL)
  12748. {
  12749. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12750. {
  12751. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12752. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12753. c++;
  12754. }
  12755. sstr[c] = '\0';
  12756. tempchargingProfileId = atoi(sstr);
  12757. }
  12758. else
  12759. {
  12760. tempchargingProfileId = 0;
  12761. }
  12762. //***********stackLevel**************/
  12763. c = 0;
  12764. loc = strstr(sLineWord, "stackLevel");
  12765. //DEBUG_INFO("loc=%s\n",loc);
  12766. memset(sstr ,0, sizeof(sstr) );
  12767. if(loc != NULL)
  12768. {
  12769. while (loc[2+strlen("stackLevel")+c] != '\"')
  12770. {
  12771. sstr[c] = loc[2+strlen("stackLevel")+c];
  12772. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12773. c++;
  12774. }
  12775. sstr[c] = '\0';
  12776. tempstackLevel = atoi(sstr);
  12777. }
  12778. else
  12779. {
  12780. tempstackLevel = 0;
  12781. }
  12782. //***********chargingProfilePurpose **************/
  12783. c = 0;
  12784. loc = strstr(sLineWord, "chargingProfilePurpose");
  12785. //DEBUG_INFO("loc=%s\n",loc);
  12786. memset(sstr ,0, sizeof(sstr) );
  12787. if(loc != NULL)
  12788. {
  12789. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12790. {
  12791. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12792. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12793. c++;
  12794. }
  12795. sstr[c] = '\0';
  12796. strcpy(tempchargingProfilePurposeStr,sstr);
  12797. }
  12798. else
  12799. {
  12800. strcpy(tempchargingProfilePurposeStr,"");
  12801. }
  12802. //***********chargingProfileKind **************/
  12803. c = 0;
  12804. loc = strstr(sLineWord, "chargingProfileKind");
  12805. //DEBUG_INFO("loc=%s\n",loc);
  12806. memset(sstr ,0, sizeof(sstr) );
  12807. if(loc != NULL)
  12808. {
  12809. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12810. {
  12811. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12812. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12813. c++;
  12814. }
  12815. sstr[c] = '\0';
  12816. strcpy(tempchargingProfileKindStr,sstr);
  12817. }
  12818. else
  12819. {
  12820. strcpy(tempchargingProfileKindStr,"");
  12821. }
  12822. //***********recurrencyKind **************/
  12823. c = 0;
  12824. loc = strstr(sLineWord, "recurrencyKind");
  12825. //DEBUG_INFO("loc=%s\n",loc);
  12826. memset(sstr ,0, sizeof(sstr) );
  12827. if(loc != NULL)
  12828. {
  12829. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12830. {
  12831. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12832. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12833. c++;
  12834. }
  12835. sstr[c] = '\0';
  12836. strcpy(temprecurrencyKindStr,sstr);
  12837. }
  12838. else
  12839. {
  12840. strcpy(temprecurrencyKindStr,"");
  12841. }
  12842. //***********validFrom**************/
  12843. c = 0;
  12844. loc = strstr(sLineWord, "validFrom");
  12845. if(loc != NULL)
  12846. {
  12847. memset(sstr ,0, sizeof(sstr) );
  12848. while (loc[3+strlen("validFrom")+c] != '\"')
  12849. {
  12850. sstr[c] = loc[3+strlen("validFrom")+c];
  12851. c++;
  12852. }
  12853. sstr[c] = '\0';
  12854. strcpy(tempvalidFromStr,sstr);
  12855. }
  12856. else
  12857. {
  12858. strcpy(tempvalidFromStr,"");
  12859. }
  12860. //***********validTo **************/
  12861. c = 0;
  12862. loc = strstr(sLineWord, "validTo");
  12863. if(loc != NULL)
  12864. {
  12865. memset(sstr ,0, sizeof(sstr) );
  12866. while (loc[3+strlen("validTo")+c] != '\"')
  12867. {
  12868. sstr[c] = loc[3+strlen("validTo")+c];
  12869. c++;
  12870. }
  12871. sstr[c] = '\0';
  12872. strcpy(tempvalidToStr,sstr);
  12873. }
  12874. else
  12875. {
  12876. strcpy(tempvalidToStr,"");
  12877. }
  12878. //***********duration**************/
  12879. c = 0;
  12880. loc = strstr(sLineWord, "duration");
  12881. if(loc != NULL)
  12882. {
  12883. memset(sstr ,0, sizeof(sstr) );
  12884. while (loc[2+strlen("duration")+c] != ',')
  12885. {
  12886. sstr[c] = loc[2+strlen("duration")+c];
  12887. c++;
  12888. }
  12889. sstr[c] = '\0';
  12890. tempdurationInt = atoi(sstr);
  12891. }
  12892. else
  12893. {
  12894. tempdurationInt = 0;
  12895. }
  12896. //**********startSchedule**********/
  12897. c = 0;
  12898. loc = strstr(sLineWord, "startSchedule");
  12899. memset(sstr ,0, sizeof(sstr) );
  12900. while (loc[3+strlen("startSchedule")+c] != '\"')
  12901. {
  12902. sstr[c] = loc[3+strlen("startSchedule")+c];
  12903. c++;
  12904. }
  12905. sstr[c] = '\0';
  12906. strcpy(tempstartScheduleStr, sstr);
  12907. strcpy(TxDefaultProfileScheduleStr, sstr);
  12908. //**********chargingRateUnit**********/
  12909. c = 0;
  12910. loc = strstr(sLineWord, "chargingRateUnit");
  12911. memset(sstr ,0, sizeof(sstr) );
  12912. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12913. {
  12914. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12915. c++;
  12916. }
  12917. sstr[c] = '\0';
  12918. strcpy(tempchargingRateUnitStr, sstr);
  12919. //**********minChargingRate*******/
  12920. c = 0;
  12921. loc = strstr(sLineWord, "minChargingRate");
  12922. if(loc != NULL)
  12923. {
  12924. memset(sstr ,0, sizeof(sstr) );
  12925. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12926. {
  12927. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12928. c++;
  12929. }
  12930. sstr[c] = '\0';
  12931. tempminChargingRateFloat = atof(sstr);
  12932. }
  12933. else
  12934. {
  12935. tempminChargingRateFloat = 0.0;
  12936. }
  12937. //
  12938. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12939. tp.tm_isdst = -1;
  12940. time_t utc = mktime(&tp);
  12941. time_t t = time(NULL);
  12942. diff_t = difftime(t, utc);
  12943. printf("diff between startScheduleStr and now =%f\n",diff_t);
  12944. //parsing strings to words
  12945. i = 0;
  12946. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12947. loc = loc+3+strlen("chargingSchedulePeriod");
  12948. pch = strtok(loc ,"{");
  12949. while (pch != NULL)
  12950. {
  12951. strcpy(SchedulePeriodList[i], pch);
  12952. pch = strtok (NULL, "{");
  12953. i = i + 1;
  12954. }
  12955. n_SchedulePeriods = i;
  12956. for(int i=0;i<n_SchedulePeriods;i++)
  12957. {
  12958. //*************startPeriod****************/
  12959. c = 0;
  12960. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12961. memset(sstr ,0, sizeof(sstr) );
  12962. while (loc[strlen("startPeriod")+2+c] != ',')
  12963. {
  12964. sstr[c] = loc[strlen("startPeriod")+2+c];
  12965. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12966. c++;
  12967. }
  12968. sstr[c] = '\0';
  12969. tempStartPeriodInt = atoi(sstr);
  12970. //*************limit****************/
  12971. c = 0;
  12972. loc = strstr(SchedulePeriodList[i], "limit");
  12973. memset(sstr ,0, sizeof(sstr) );
  12974. while (loc[strlen("limit")+2+c] != ',')
  12975. {
  12976. sstr[c] = loc[strlen("limit")+2+c];
  12977. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12978. c++;
  12979. }
  12980. sstr[c] = '\0';
  12981. tempLimitInt = atof(sstr);
  12982. //*************numberPhases****************/
  12983. c = 0;
  12984. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12985. memset(sstr ,0, sizeof(sstr) );
  12986. while (loc[strlen("numberPhases")+2+c] != '}')
  12987. {
  12988. sstr[c] = loc[strlen("numberPhases")+2+c];
  12989. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12990. c++;
  12991. }
  12992. sstr[c] = '\0';
  12993. tempNumberPhasesInt = atoi(sstr);
  12994. if(j == 0)
  12995. {
  12996. TxDefaultProfile.Duration = tempdurationInt;
  12997. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  12998. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  12999. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13000. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13001. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13002. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  13003. TxDefaultProfile_TEMP.TransactionId = 0;
  13004. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13005. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13006. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13007. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13008. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13009. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13010. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13011. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13012. }
  13013. else
  13014. {
  13015. //other stack level charging Profile
  13016. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  13017. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  13018. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  13019. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  13020. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  13021. }
  13022. }
  13023. if(MinChargingRate < tempminChargingRateFloat)
  13024. {
  13025. MinChargingRate = tempminChargingRateFloat;
  13026. }
  13027. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13028. if(confirmPeriods < n_SchedulePeriods)
  13029. confirmPeriods = n_SchedulePeriods;
  13030. j = j + 1;
  13031. }
  13032. fclose(fptr1);
  13033. //Stacking Charging Profiles
  13034. for(int l=0; l <(j-1) ;l++)
  13035. {
  13036. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  13037. {
  13038. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  13039. {
  13040. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  13041. {
  13042. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  13043. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  13044. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  13045. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13046. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13047. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13048. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13049. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13050. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13051. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13052. }
  13053. else
  13054. {
  13055. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  13056. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  13057. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  13058. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  13059. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  13060. }
  13061. }
  13062. }
  13063. }
  13064. //end of Stacking Charging Profiles
  13065. }
  13066. }// the end of ACCESS TxDefaultProfile
  13067. //****************************TxProfile************************************************/
  13068. switch(gunindex + 1)
  13069. {
  13070. case 0:
  13071. break;
  13072. case 1:
  13073. strcpy(fname, TxProfile_1_JSON );
  13074. break;
  13075. case 2:
  13076. strcpy(fname, TxProfile_2_JSON );
  13077. break;
  13078. default:
  13079. strcpy(fname, TxProfile_1_JSON );
  13080. break;
  13081. }
  13082. TxProfileIsNull=TRUE;
  13083. if((access(fname,F_OK))!=-1)
  13084. {
  13085. fptr1 = fopen(fname, "r");
  13086. c = 0;
  13087. c = fgetc(fptr1);
  13088. //DEBUG_INFO("c:%d\n",c);
  13089. rewind(fptr1);
  13090. if(c == EOF)
  13091. {
  13092. DEBUG_INFO("\n End of file reached.");
  13093. TxProfileIsNull=TRUE;
  13094. fclose(fptr1);
  13095. }
  13096. else
  13097. {
  13098. TxProfileIsNull=FALSE;
  13099. while(fscanf(fptr1, "%s", word) != EOF)
  13100. {
  13101. if(strcmp(word, "chargingProfileId") == 0)
  13102. {
  13103. n_chargingProfile = n_chargingProfile + 1;
  13104. }
  13105. }
  13106. rewind(fptr1);
  13107. //search Charging Profile Element
  13108. int i= 0;
  13109. int j= 0;
  13110. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13111. #if 0
  13112. /***********connectorId****************/
  13113. c = 0;
  13114. loc = strstr(sLineWord, "connectorId");
  13115. memset(sstr ,0, sizeof(sstr) );
  13116. while (loc[strlen("connectorId")+2+c] != ',')
  13117. {
  13118. sstr[c] = loc[strlen("connectorId")+2+c];
  13119. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13120. c++;
  13121. }
  13122. sstr[c] = '\0';
  13123. tempconnectorIdInt = atoi(sstr);
  13124. #endif
  13125. //***********chargingProfileId**************/
  13126. c = 0;
  13127. loc = strstr(sLineWord, "chargingProfileId");
  13128. memset(sstr ,0, sizeof(sstr) );
  13129. if(loc != NULL)
  13130. {
  13131. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13132. {
  13133. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13134. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13135. c++;
  13136. }
  13137. sstr[c] = '\0';
  13138. tempchargingProfileId = atoi(sstr);
  13139. }
  13140. else
  13141. {
  13142. tempchargingProfileId = 0;
  13143. }
  13144. //***********transactionId **************/
  13145. c = 0;
  13146. loc = strstr(sLineWord, "transactionId");
  13147. //DEBUG_INFO("loc=%s\n",loc);
  13148. memset(sstr ,0, sizeof(sstr) );
  13149. if(loc != NULL)
  13150. {
  13151. while (loc[2+strlen("transactionId")+c] != '\"')
  13152. {
  13153. sstr[c] = loc[2+strlen("transactionId")+c];
  13154. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13155. c++;
  13156. }
  13157. sstr[c] = '\0';
  13158. temptransactionId = atoi(sstr);
  13159. }
  13160. else
  13161. {
  13162. temptransactionId = 0;
  13163. }
  13164. //***********stackLevel**************/
  13165. c = 0;
  13166. loc = strstr(sLineWord, "stackLevel");
  13167. //DEBUG_INFO("loc=%s\n",loc);
  13168. memset(sstr ,0, sizeof(sstr) );
  13169. if(loc != NULL)
  13170. {
  13171. while (loc[2+strlen("stackLevel")+c] != '\"')
  13172. {
  13173. sstr[c] = loc[2+strlen("stackLevel")+c];
  13174. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13175. c++;
  13176. }
  13177. sstr[c] = '\0';
  13178. tempstackLevel = atoi(sstr);
  13179. }
  13180. else
  13181. {
  13182. tempstackLevel = 0;
  13183. }
  13184. //***********chargingProfilePurpose **************/
  13185. c = 0;
  13186. loc = strstr(sLineWord, "chargingProfilePurpose");
  13187. //DEBUG_INFO("loc=%s\n",loc);
  13188. memset(sstr ,0, sizeof(sstr) );
  13189. if(loc != NULL)
  13190. {
  13191. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13192. {
  13193. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13194. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13195. c++;
  13196. }
  13197. sstr[c] = '\0';
  13198. strcpy(tempchargingProfilePurposeStr,sstr);
  13199. }
  13200. else
  13201. {
  13202. strcpy(tempchargingProfilePurposeStr,"");
  13203. }
  13204. //***********chargingProfileKind **************/
  13205. c = 0;
  13206. loc = strstr(sLineWord, "chargingProfileKind");
  13207. //DEBUG_INFO("loc=%s\n",loc);
  13208. memset(sstr ,0, sizeof(sstr) );
  13209. if(loc != NULL)
  13210. {
  13211. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13212. {
  13213. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13214. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13215. c++;
  13216. }
  13217. sstr[c] = '\0';
  13218. strcpy(tempchargingProfileKindStr,sstr);
  13219. }
  13220. else
  13221. {
  13222. strcpy(tempchargingProfileKindStr,"");
  13223. }
  13224. //***********recurrencyKind **************/
  13225. c = 0;
  13226. loc = strstr(sLineWord, "recurrencyKind");
  13227. //DEBUG_INFO("loc=%s\n",loc);
  13228. memset(sstr ,0, sizeof(sstr) );
  13229. if(loc != NULL)
  13230. {
  13231. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13232. {
  13233. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13234. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13235. c++;
  13236. }
  13237. sstr[c] = '\0';
  13238. strcpy(temprecurrencyKindStr,sstr);
  13239. }
  13240. else
  13241. {
  13242. strcpy(temprecurrencyKindStr,"");
  13243. }
  13244. //***********validFrom**************/
  13245. c = 0;
  13246. loc = strstr(sLineWord, "validFrom");
  13247. if(loc != NULL)
  13248. {
  13249. memset(sstr ,0, sizeof(sstr) );
  13250. while (loc[3+strlen("validFrom")+c] != '\"')
  13251. {
  13252. sstr[c] = loc[3+strlen("validFrom")+c];
  13253. c++;
  13254. }
  13255. sstr[c] = '\0';
  13256. strcpy(tempvalidFromStr,sstr);
  13257. }
  13258. else
  13259. {
  13260. strcpy(tempvalidFromStr,"");
  13261. }
  13262. //***********validTo**************/
  13263. c = 0;
  13264. loc = strstr(sLineWord, "validTo");
  13265. if(loc != NULL)
  13266. {
  13267. memset(sstr ,0, sizeof(sstr) );
  13268. while (loc[3+strlen("validTo")+c] != '\"')
  13269. {
  13270. sstr[c] = loc[3+strlen("validTo")+c];
  13271. c++;
  13272. }
  13273. sstr[c] = '\0';
  13274. strcpy(tempvalidToStr,sstr);
  13275. }
  13276. else
  13277. {
  13278. strcpy(tempvalidToStr,"");
  13279. }
  13280. //***********duration**************/
  13281. c = 0;
  13282. loc = strstr(sLineWord, "duration");
  13283. //DEBUG_INFO("loc=%s\n",loc);
  13284. memset(sstr ,0, sizeof(sstr) );
  13285. if(loc != NULL)
  13286. {
  13287. while (loc[2+strlen("duration")+c] != '\"')
  13288. {
  13289. sstr[c] = loc[2+strlen("duration")+c];
  13290. c++;
  13291. }
  13292. sstr[c] = '\0';
  13293. tempdurationInt = atoi(sstr);
  13294. }
  13295. else
  13296. {
  13297. tempdurationInt = 0;
  13298. }
  13299. //**********startSchedule**********/
  13300. c = 0;
  13301. loc = strstr(sLineWord, "startSchedule");
  13302. memset(sstr ,0, sizeof(sstr) );
  13303. while (loc[3+strlen("startSchedule")+c] != '\"')
  13304. {
  13305. sstr[c] = loc[3+strlen("startSchedule")+c];
  13306. c++;
  13307. }
  13308. sstr[c] = '\0';
  13309. strcpy(tempstartScheduleStr, sstr);
  13310. strcpy(TxProfileScheduleStr, sstr);
  13311. //**********chargingRateUnit**********/
  13312. c = 0;
  13313. loc = strstr(sLineWord, "chargingRateUnit");
  13314. memset(sstr ,0, sizeof(sstr) );
  13315. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13316. {
  13317. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13318. c++;
  13319. }
  13320. sstr[c] = '\0';
  13321. strcpy(tempchargingRateUnitStr, sstr);
  13322. //**********minChargingRate*******/
  13323. c = 0;
  13324. loc = strstr(sLineWord, "minChargingRate");
  13325. if(loc != NULL)
  13326. {
  13327. memset(sstr ,0, sizeof(sstr) );
  13328. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13329. {
  13330. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13331. c++;
  13332. }
  13333. sstr[c] = '\0';
  13334. tempminChargingRateFloat = atof(sstr);
  13335. }
  13336. else
  13337. {
  13338. tempminChargingRateFloat = 0.0;
  13339. }
  13340. //
  13341. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13342. tp.tm_isdst = -1;
  13343. time_t utc = mktime(&tp);
  13344. time_t t = time(NULL);
  13345. diff_t = difftime(t, utc);
  13346. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13347. //parsing strings to words
  13348. i = 0;
  13349. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13350. loc = loc+3+strlen("chargingSchedulePeriod");
  13351. pch = strtok(loc ,"{");
  13352. while (pch != NULL)
  13353. {
  13354. strcpy(SchedulePeriodList[i], pch);
  13355. pch = strtok (NULL, "{");
  13356. i = i + 1;
  13357. }
  13358. n_SchedulePeriods = i;
  13359. for(int i=0;i<n_SchedulePeriods;i++)
  13360. {
  13361. //*************startPeriod****************/
  13362. c = 0;
  13363. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13364. memset(sstr ,0, sizeof(sstr) );
  13365. while (loc[strlen("startPeriod")+2+c] != ',')
  13366. {
  13367. sstr[c] = loc[strlen("startPeriod")+2+c];
  13368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13369. c++;
  13370. }
  13371. sstr[c] = '\0';
  13372. tempStartPeriodInt = atoi(sstr);
  13373. //*************limit****************/
  13374. c = 0;
  13375. loc = strstr(SchedulePeriodList[i], "limit");
  13376. memset(sstr ,0, sizeof(sstr) );
  13377. while (loc[strlen("limit")+2+c] != ',')
  13378. {
  13379. sstr[c] = loc[strlen("limit")+2+c];
  13380. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13381. c++;
  13382. }
  13383. sstr[c] = '\0';
  13384. tempLimitInt = atof(sstr);
  13385. //*************numberPhases****************/
  13386. c = 0;
  13387. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13388. memset(sstr ,0, sizeof(sstr) );
  13389. while (loc[strlen("numberPhases")+2+c] != '}')
  13390. {
  13391. sstr[c] = loc[strlen("numberPhases")+2+c];
  13392. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13393. c++;
  13394. }
  13395. sstr[c] = '\0';
  13396. tempNumberPhasesInt = atoi(sstr);
  13397. //TxProfile.Duration = durationInt;
  13398. TxProfile.TotalPeriod = n_SchedulePeriods;
  13399. TxProfile.Period[i].Limit = tempLimitInt;
  13400. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13401. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13402. }
  13403. if(MinChargingRate < tempminChargingRateFloat)
  13404. {
  13405. MinChargingRate = tempminChargingRateFloat;
  13406. }
  13407. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13408. if(confirmPeriods < n_SchedulePeriods)
  13409. confirmPeriods = n_SchedulePeriods;
  13410. if(j == 0)
  13411. {
  13412. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13413. TxProfile_TEMP.StackLevel = tempstackLevel;
  13414. TxProfile_TEMP.TransactionId = 0;
  13415. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13416. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13417. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13418. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13419. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13420. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13421. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13422. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13423. }
  13424. }
  13425. fclose(fptr1);
  13426. }
  13427. }// the end of ACCESS TxProfile
  13428. //CompositeSchedule
  13429. int period=0;
  13430. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13431. {
  13432. //TxProfile
  13433. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13434. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13435. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13436. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13437. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13438. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13439. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13440. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13441. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13442. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13443. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13444. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13445. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13446. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13447. {
  13448. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13449. {
  13450. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13451. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13452. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13453. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13454. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13455. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13456. period = period + 1;
  13457. }
  13458. else
  13459. {
  13460. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13461. {
  13462. }
  13463. else
  13464. {
  13465. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13466. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13467. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13468. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13469. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13470. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13471. period = period + 1;
  13472. }
  13473. }
  13474. }
  13475. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13476. {
  13477. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  13478. {
  13479. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13480. {
  13481. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13482. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13483. }
  13484. else
  13485. {
  13486. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13487. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13488. }
  13489. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13490. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13491. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13492. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13493. period = period + 1;
  13494. }
  13495. }
  13496. }
  13497. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13498. {
  13499. //TxDefaultProfile
  13500. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13501. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13502. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13503. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13504. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  13505. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13506. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13507. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13508. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13509. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13510. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13511. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13512. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13513. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13514. {
  13515. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13516. {
  13517. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13518. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13519. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13520. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13521. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13522. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13523. period = period + 1;
  13524. }
  13525. else
  13526. {
  13527. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13528. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13529. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13530. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13531. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13532. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13533. period = period + 1;
  13534. }
  13535. }
  13536. }
  13537. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  13538. {
  13539. //TxDefaultProfile
  13540. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13541. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13542. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13543. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13544. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  13545. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13546. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13547. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13548. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13549. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13550. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13551. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13552. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13553. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13554. {
  13555. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13556. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13557. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13558. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13559. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13560. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13561. period = period + 1;
  13562. }
  13563. }
  13564. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13565. {
  13566. //ChargePointMaxProfile
  13567. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  13568. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  13569. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13570. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  13571. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  13572. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13573. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13574. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  13575. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  13576. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  13577. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  13578. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  13579. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  13580. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  13581. {
  13582. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  13583. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  13584. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  13585. period = period + 1;
  13586. }
  13587. }
  13588. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  13589. {
  13590. //TxProfile
  13591. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13592. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13593. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13594. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13595. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13596. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13597. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13598. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13599. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13600. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13601. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13602. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13603. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13604. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13605. {
  13606. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  13607. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  13608. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  13609. }
  13610. }
  13611. confirmPeriods = period;
  13612. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  13613. 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,"
  13614. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  13615. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  13616. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  13617. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  13618. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  13619. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  13620. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  13621. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  13622. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  13623. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  13624. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  13625. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  13626. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  13627. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  13628. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  13629. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  13630. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  13631. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  13632. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  13633. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  13634. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  13635. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  13636. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  13637. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  13638. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  13639. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  13640. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  13641. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  13642. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  13643. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  13644. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  13645. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  13646. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  13647. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  13648. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  13649. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  13650. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  13651. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  13652. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  13653. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  13654. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  13655. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  13656. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  13657. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  13658. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  13659. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  13660. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  13661. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  13662. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  13663. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  13664. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  13665. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  13666. }
  13667. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13668. {
  13669. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13670. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13671. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13672. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13673. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13674. }
  13675. int GetWebSocketPingInterval(void)
  13676. {
  13677. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13678. }
  13679. void LWS_Send(char * str)
  13680. {
  13681. //=====================================================
  13682. // Check InternetConn 0: disconnected, 1: connected
  13683. //====================================================
  13684. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13685. {
  13686. DEBUG_INFO("\n offline now !!!\n");
  13687. return;
  13688. }
  13689. pthread_mutex_lock(&lock);
  13690. memset(SendBuffer,0,SendBufLen);
  13691. sprintf((char *)SendBuffer, "%s", str);
  13692. pthread_mutex_unlock(&lock);
  13693. lws_callback_on_writable(wsi_client);
  13694. lws_service(context, 10000);//timeout_ms
  13695. }